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 161 of file FWConfiguration.cc.

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

Referenced by streamTo().

162 {
164  index = 0;
165  while (std::string::npos != (index=value.find('&',index))){
166  value.replace(index, 1,"&amp;", 5);
167  // Do not check "&quot;" for quotes.
168  index += 5;
169  }
170 
171  while (std::string::npos != (index=value.find('"',index))){
172  value.replace(index, 1,"&quot;", 6);
173  // Do not check "&quot;" for quotes.
174  index += 6;
175  }
176 
177  index = 0;
178  while (std::string::npos != (index=value.find('<',index))){
179  value.replace(index, 1,"&lt;", 4);
180  // Do not check "&quot;" for quotes.
181  index += 4;
182  }
183 
184  index = 0;
185  while (std::string::npos != (index=value.find('>',index))){
186  value.replace(index, 1,"&gt;", 4);
187  // Do not check "&quot;" for quotes.
188  index += 4;
189  }
190 
191  return value;
192 }
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 215 of file FWConfiguration.cc.

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

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

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