CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
FWConfiguration.cc File Reference
#include <stdexcept>
#include <algorithm>
#include <boost/bind.hpp>
#include "Fireworks/Core/interface/FWConfiguration.h"

Go to the source code of this file.

Functions

std::string attrEscape (std::string value)
 
void streamTo (std::ostream &oTo, const FWConfiguration &iConfig, const std::string &name)
 

Function Documentation

std::string attrEscape ( std::string  value)

Helper function to make sure we escape correctly xml entities embedded in the string value.

Definition at line 160 of file FWConfiguration.cc.

References getHLTprescales::index, and relativeConstraints::value.

Referenced by streamTo().

161 {
163  index = 0;
164  while (std::string::npos != (index=value.find('&',index))){
165  value.replace(index, 1,"&amp;", 5);
166  // Do not check "&quot;" for quotes.
167  index += 5;
168  }
169 
170  while (std::string::npos != (index=value.find('"',index))){
171  value.replace(index, 1,"&quot;", 6);
172  // Do not check "&quot;" for quotes.
173  index += 6;
174  }
175 
176  index = 0;
177  while (std::string::npos != (index=value.find('<',index))){
178  value.replace(index, 1,"&lt;", 4);
179  // Do not check "&quot;" for quotes.
180  index += 4;
181  }
182 
183  index = 0;
184  while (std::string::npos != (index=value.find('>',index))){
185  value.replace(index, 1,"&gt;", 4);
186  // Do not check "&quot;" for quotes.
187  index += 4;
188  }
189 
190  return value;
191 }
uint16_t size_type
void streamTo ( std::ostream &  oTo,
const FWConfiguration iConfig,
const std::string &  name 
)

Streaming FWConfiguration objects to xml.

Example of dump is:

<config name="top" version="1"> <string value="S1"> <string value="S2"> ... <string value="SN"> <config name="c1"> ... </configuration> <config name="c2"> ... </config> ... </config>

Streaming the top level configuration item will stream all its children.

Definition at line 214 of file FWConfiguration.cc.

References attrEscape(), FWConfiguration::keyValues(), streamTo(), AlCaHLTBitMon_QueryRunRegistry::string, FWConfiguration::stringValues(), and FWConfiguration::version().

Referenced by streamTo(), and FWConfigurationManager::writeToFile().

215 {
216  static int recursionLevel = -1;
217  recursionLevel += 1;
218  std::string indentation(recursionLevel, ' ');
219  oTo << indentation << "<config name=\"" << name
220  << "\" version=\"" << iConfig.version() << "\">\n";
221  if(iConfig.stringValues()) {
222  for(FWConfiguration::StringValues::const_iterator it = iConfig.stringValues()->begin();
223  it != iConfig.stringValues()->end();
224  ++it) {
225  oTo << indentation << " <string>" << attrEscape(*it) << "</string>\n";
226  }
227  }
228  if(iConfig.keyValues()) {
229  for(FWConfiguration::KeyValues::const_iterator it = iConfig.keyValues()->begin();
230  it != iConfig.keyValues()->end();
231  ++it) {
232  streamTo(oTo, it->second, attrEscape(it->first));
233  }
234  }
235  oTo << indentation << "</config>" << std::endl;
236  recursionLevel -= 1;
237 }
const StringValues * stringValues() const
const KeyValues * keyValues() const
void streamTo(std::ostream &, const FWConfiguration &, const std::string &name)
unsigned int version() const
std::string attrEscape(std::string value)