#include <colvarparse.h>
Public Member Functions | |
| read_block (std::string const &key_in, std::string &data_in) | |
| ~read_block () | |
Friends | |
| std::istream & | operator>> (std::istream &is, read_block const &rb) |
Useful on restarts, where the file is too big to be loaded in a string by key_lookup; it can only check that the keyword is correct and the block is properly delimited by braces, not skipping other blocks
Definition at line 148 of file colvarparse.h.
|
||||||||||||
|
Definition at line 154 of file colvarparse.h. 00155 : key (key_in), data (&data_in)
00156 {}
|
|
|
Definition at line 157 of file colvarparse.h. 00157 {}
|
|
||||||||||||
|
Definition at line 573 of file colvarparse.C. 00574 {
00575 size_t start_pos = is.tellg();
00576 std::string read_key, next;
00577
00578 if ( !(is >> read_key) || !(read_key == rb.key) ||
00579 !(is >> next) ) {
00580 // the requested keyword has not been found, or it is not possible
00581 // to read data after it
00582 is.clear();
00583 is.seekg (start_pos, std::ios::beg);
00584 is.setstate (std::ios::failbit);
00585 return is;
00586 }
00587
00588 if (next != "{") {
00589 (*rb.data) = next;
00590 return is;
00591 }
00592
00593 size_t brace_count = 1;
00594 std::string line;
00595 while (colvarparse::getline_nocomments (is, line)) {
00596 size_t br = 0, br_old;
00597 while ( (br = line.find_first_of ("{}", br)) != std::string::npos) {
00598 if (line[br] == '{') brace_count++;
00599 if (line[br] == '}') brace_count--;
00600 br_old = br;
00601 br++;
00602 }
00603 if (brace_count) (*rb.data).append (line + "\n");
00604 else {
00605 (*rb.data).append (line, 0, br_old);
00606 break;
00607 }
00608 }
00609 if (brace_count) {
00610 // end-of-file reached
00611 // restore initial position
00612 is.clear();
00613 is.seekg (start_pos, std::ios::beg);
00614 is.setstate (std::ios::failbit);
00615 }
00616 return is;
00617 }
|
1.3.9.1