CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
ConfigFile.cc File Reference
#include "Validation/RecoJets/interface/ConfigFile.h"

Go to the source code of this file.

Functions

std::ostream & operator<< (std::ostream &os, const ConfigFile &cf)
 
std::istream & operator>> (std::istream &is, ConfigFile &cf)
 

Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const ConfigFile cf 
)

Definition at line 54 of file ConfigFile.cc.

References ConfigFile::myContents, ConfigFile::myDelimiter, and L1TEmulatorMonitor_cff::p.

55 {
56  // Save a ConfigFile to os
57  for( ConfigFile::mapci p = cf.myContents.begin();
58  p != cf.myContents.end();
59  ++p )
60  {
61  os << p->first << " " << cf.myDelimiter << " ";
62  os << p->second << std::endl;
63  }
64  return os;
65 }
std::map< std::string, std::string > myContents
Definition: ConfigFile.h:58
std::map< std::string, std::string >::const_iterator mapci
Definition: ConfigFile.h:61
std::string myDelimiter
Definition: ConfigFile.h:55
std::istream& operator>> ( std::istream &  is,
ConfigFile cf 
)

Definition at line 68 of file ConfigFile.cc.

References combine::key, geometryCSVtoXML::line, ConfigFile::myComment, ConfigFile::myContents, ConfigFile::myDelimiter, ConfigFile::mySentry, pos, createPayload::skip, and ConfigFile::trim().

69 {
70  // Load a ConfigFile from is
71  // Read in keys and values, keeping internal whitespace
73  const std::string& delim = cf.myDelimiter; // separator
74  const std::string& comm = cf.myComment; // comment
75  const std::string& sentry = cf.mySentry; // end of file sentry
76  const pos skip = delim.length(); // length of separator
77 
78  string nextline = ""; // might need to read ahead to see where value ends
79 
80  while( is || nextline.length() > 0 )
81  {
82  // Read an entire line at a time
83  string line;
84  if( nextline.length() > 0 )
85  {
86  line = nextline; // we read ahead; use it now
87  nextline = "";
88  }
89  else
90  {
91  std::getline( is, line );
92  }
93 
94  // Ignore comments
95  line = line.substr( 0, line.find(comm) );
96 
97  // Check for end of file sentry
98  if( sentry != "" && line.find(sentry) != std::string::npos ) return is;
99 
100  // Parse the line if it contains a delimiter
101  pos delimPos = line.find( delim );
102  if( delimPos < std::string::npos )
103  {
104  // Extract the key
105  string key = line.substr( 0, delimPos );
106  line.replace( 0, delimPos+skip, "" );
107 
108  // See if value continues on the next line
109  // Stop at blank line, next line with a key, end of stream,
110  // or end of file sentry
111  bool terminate = false;
112  while( !terminate && is )
113  {
114  std::getline( is, nextline );
115  terminate = true;
116 
117  string nlcopy = nextline;
118  ConfigFile::trim(nlcopy);
119  if( nlcopy == "" ) continue;
120 
121  nextline = nextline.substr( 0, nextline.find(comm) );
122  if( nextline.find(delim) != std::string::npos )
123  continue;
124  if( sentry != "" && nextline.find(sentry) != std::string::npos )
125  continue;
126 
127  nlcopy = nextline;
128  ConfigFile::trim(nlcopy);
129  if( nlcopy != "" ) line += "\n";
130  line += nextline;
131  terminate = false;
132  }
133 
134  // Store key and value
135  ConfigFile::trim(key);
136  ConfigFile::trim(line);
137  cf.myContents[key] = line; // overwrites if key is repeated
138  }
139  }
140 
141  return is;
142 }
static void trim(std::string &s)
Definition: ConfigFile.cc:45
std::map< std::string, std::string > myContents
Definition: ConfigFile.h:58
uint16_t size_type
std::string mySentry
Definition: ConfigFile.h:57
std::string myComment
Definition: ConfigFile.h:56
list key
Definition: combine.py:13
std::string myDelimiter
Definition: ConfigFile.h:55