Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize is_open value in ReadFileBuffer. #254

Merged
merged 2 commits into from
Jun 7, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/QMCHamiltonians/ECPComponentBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ bool ECPComponentBuilder::parse(const std::string& fname, xmlNodePtr cur)
return read_pp_file(fname);
}

int get_file_length(std::ifstream *fin)
int ReadFileBuffer::get_file_length(std::ifstream *f)
{
fin->seekg (0, std::ios::end);
int length = fin->tellg();
fin->seekg (0, std::ios::beg);
return length;
f->seekg (0, std::ios::end);
int len = f->tellg();
f->seekg (0, std::ios::beg);
return len;
}

bool ReadFileBuffer::open_file(const std::string &fname)
Expand Down Expand Up @@ -104,21 +104,21 @@ bool ECPComponentBuilder::read_pp_file(const std::string &fname)
bool okay = buf.open_file(fname);
if(!okay)
{
APP_ABORT("ECPComponentBuilder::parse Missing PP file " + fname +"\n");
APP_ABORT("ECPComponentBuilder::read_pp_file Missing PP file " + fname +"\n");
}

okay = buf.read_contents();
if(!okay)
{
APP_ABORT("ECPComponentBuilder::parse Unable to read PP file " + fname +"\n");
APP_ABORT("ECPComponentBuilder::read_pp_file Unable to read PP file " + fname +"\n");
}

xmlDocPtr m_doc = xmlReadMemory(buf.contents(),buf.length,NULL,NULL,0);

if (m_doc == NULL)
{
xmlFreeDoc(m_doc);
APP_ABORT("ECPComponentBuilder::parse xml file "+fname+" is invalid");
APP_ABORT("ECPComponentBuilder::read_pp_file xml file "+fname+" is invalid");
}
// Check the document is of the right kind
xmlNodePtr cur = xmlDocGetRootElement(m_doc);
Expand Down
4 changes: 3 additions & 1 deletion src/QMCHamiltonians/ECPComponentBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ class ReadFileBuffer
char *cbuffer;
std::ifstream *fin;
Communicate *myComm;
int get_file_length(std::ifstream *f);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add const if this routine doesn't touch member variables.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about remove the argument and directly operates on fin?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to write get_file_length was mentioned in the bug report on OO vs. functional. Yes, it could operate directly on fin and write to length. However, I think that makes it harder to understand in isolation vs. using a more functional style.


public:
bool is_open;
int length;
ReadFileBuffer(Communicate *c) : cbuffer(NULL), fin(NULL), myComm(c), length(0) {}
ReadFileBuffer(Communicate *c) : cbuffer(NULL), fin(NULL), myComm(c), is_open(false), length(0) {}
bool open_file(const std::string &fname);
bool read_contents();
char *contents() { return cbuffer; }
Expand Down