QMCPACK
ReadFileBuffer Class Reference
+ Collaboration diagram for ReadFileBuffer:

Public Member Functions

 ReadFileBuffer (Communicate *c)
 
bool open_file (const std::string &fname)
 
bool read_contents ()
 
char * contents ()
 
void reset ()
 
 ~ReadFileBuffer ()
 

Public Attributes

bool is_open
 
int length
 

Private Member Functions

int get_file_length (std::ifstream *f) const
 

Private Attributes

char * cbuffer
 
std::ifstream * fin
 
CommunicatemyComm
 

Detailed Description

Definition at line 109 of file ECPComponentBuilder.h.

Constructor & Destructor Documentation

◆ ReadFileBuffer()

◆ ~ReadFileBuffer()

~ReadFileBuffer ( )
inline

Definition at line 125 of file ECPComponentBuilder.h.

References ReadFileBuffer::cbuffer, and ReadFileBuffer::fin.

126  {
127  delete[] cbuffer;
128  if (fin)
129  delete fin;
130  }

Member Function Documentation

◆ contents()

char* contents ( )
inline

◆ get_file_length()

int get_file_length ( std::ifstream *  f) const
private

Definition at line 72 of file ECPComponentBuilder.cpp.

Referenced by ReadFileBuffer::read_contents().

73 {
74  f->seekg(0, std::ios::end);
75  int len = f->tellg();
76  f->seekg(0, std::ios::beg);
77  return len;
78 }

◆ open_file()

bool open_file ( const std::string &  fname)

Definition at line 96 of file ECPComponentBuilder.cpp.

References Communicate::bcast(), ReadFileBuffer::fin, ReadFileBuffer::is_open, ReadFileBuffer::myComm, Communicate::rank(), and ReadFileBuffer::reset().

Referenced by ECPComponentBuilder::read_pp_file(), and qmcplusplus::TEST_CASE().

97 {
98  reset();
99 
100  if (myComm == NULL || myComm->rank() == 0)
101  {
102  fin = new std::ifstream(fname.c_str());
103  if (fin->is_open())
104  is_open = true;
105  }
106  if (myComm)
107  myComm->bcast(is_open);
108  return is_open;
109 }
int rank() const
return the rank
Definition: Communicate.h:116
void bcast(T &)

◆ read_contents()

bool read_contents ( )

Definition at line 111 of file ECPComponentBuilder.cpp.

References Communicate::bcast(), ReadFileBuffer::cbuffer, ReadFileBuffer::fin, ReadFileBuffer::get_file_length(), ReadFileBuffer::is_open, ReadFileBuffer::length, ReadFileBuffer::myComm, and Communicate::rank().

Referenced by ECPComponentBuilder::read_pp_file(), and qmcplusplus::TEST_CASE().

112 {
113  if (!is_open)
114  return false;
115 
116  if (myComm == NULL || myComm->rank() == 0)
117  {
119  }
120  if (myComm)
121  myComm->bcast(length);
122 
123  cbuffer = new char[length + 1];
124  cbuffer[length] = '\0';
125 
126  if (myComm == NULL || myComm->rank() == 0)
127  fin->read(cbuffer, length);
128 
129  if (myComm != NULL)
131 
132  return true;
133 }
int rank() const
return the rank
Definition: Communicate.h:116
int get_file_length(std::ifstream *f) const
void bcast(T &)

◆ reset()

void reset ( )

Definition at line 80 of file ECPComponentBuilder.cpp.

References ReadFileBuffer::cbuffer, ReadFileBuffer::fin, ReadFileBuffer::is_open, ReadFileBuffer::length, ReadFileBuffer::myComm, and Communicate::rank().

Referenced by ReadFileBuffer::open_file().

81 {
82  if (is_open)
83  {
84  if (myComm == NULL || myComm->rank() == 0)
85  {
86  delete fin;
87  fin = NULL;
88  }
89  delete[] cbuffer;
90  cbuffer = NULL;
91  is_open = false;
92  length = 0;
93  }
94 }
int rank() const
return the rank
Definition: Communicate.h:116

Member Data Documentation

◆ cbuffer

◆ fin

◆ is_open

◆ length

◆ myComm


The documentation for this class was generated from the following files: