lbm_reference
ConfBlock.cpp
Go to the documentation of this file.
1 //! \file ConfBlock.cpp
2 //! Brief description
3 
4 //! \date Jan 17, 2009
5 //! \author fuan
6 //!
7 //! Detailed description
8 
9 #include <fstream>
10 
11 #include "ConfBlock.h"
12 
13 namespace confparser {
14 
15 // ======= //
16 // Setters //
17 // ======= //
18 
19 void ConfBlock::writeConfigFile( std::string fileName ) {
20 
21  std::ofstream f( fileName.c_str() );
22  f << "# Automatically generated config file\n\n";
23  writeConfigFileRec( f, "" );
24  f.close();
25 
26 }
27 
28 // ========================== //
29 // Protected helper functions //
30 // ========================== //
31 
32 void ConfBlock::writeConfigFileRec( std::ofstream &fileHandle, std::string indent ) {
33 
34  // Write out all data of current block
35  std::map<std::string,std::string>::iterator mit;
36  for ( mit = props_.begin(); mit != props_.end(); ++mit ) {
37  fileHandle << indent << mit->first << " " << mit->second << ";\n";
38  }
39  fileHandle << '\n';
40 
41  // Process children, if any
42  for ( childIter bit = children_.begin(); bit != children_.end(); ++bit ) {
43  // Start new block
44  fileHandle << indent << bit->first << " {\n\n";
45  // Recurse into block
46  bit->second.writeConfigFileRec( fileHandle, indent + " " );
47  // End block
48  fileHandle << indent << "}\n\n";
49  }
50 
51 }
52 
53 } // namespace confparser