HCE project C++ developers source code library  1.1.1
HCE project developer library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SphinxConfigCreator.cpp
Go to the documentation of this file.
2 
3 namespace HCE {
4 namespace sphinx {
5 
6 SphinxConfigCreator::SphinxConfigCreator(void):Poco::Util::PropertyFileConfiguration(),data(){}
7 
8 SphinxConfigCreator::SphinxConfigCreator (const std::string& path):
9  Poco::Util::PropertyFileConfiguration(path),data() { this->parse(); }
10 
12 
13 void SphinxConfigCreator::setPropertyFileConfiguration (const std::string& path) {
14  this->load(path);
15  this->parse();
16 }
17 
19  this->data.clear();
20  for (auto it = this->begin(); it != this->end(); ++it) {
21  Poco::StringTokenizer record (it->first,".");
22  std::string section ( *record.begin() );
23  std::string key ( *( record.end()-1) );
24  std::string value (it->second);
25  data[section].push_back(std::pair<_key,_value>(key,value));
26  }
27 }
28 
30  std::string sphinxConfig("");
31  for (std::map<_section,std::vector<std::pair<_key,_value>>>::const_iterator iteratorOnMap = this->data.begin(); iteratorOnMap != this->data.end(); ++iteratorOnMap) {
32  sphinxConfig += (iteratorOnMap->first + "\n{\n");
33  for (std::vector<std::pair<_key,_value> >::const_iterator iteratorOnVector = iteratorOnMap->second.begin(); iteratorOnVector != iteratorOnMap->second.end(); ++iteratorOnVector) {
34  sphinxConfig += (iteratorOnVector->first + " = " + iteratorOnVector->second + "\n");
35  }
36  sphinxConfig += "}\n";
37  }
38  return sphinxConfig;
39 }
40 
41 void SphinxConfigCreator::cloneSphinxConfigSection (const std::string& oldName, const std::string& newName) {
42  auto pointerToTheDataWithOldName = this->data.find(oldName);
43  if (pointerToTheDataWithOldName != data.end()) {
44  auto dataWhereKeyIsOldName (pointerToTheDataWithOldName->second);
45  this->data[newName] = dataWhereKeyIsOldName;
46 
47  for (Poco::Util::MapConfiguration::StringMap::const_iterator it=this->begin();it!=this->end();++it) {
48  Poco::StringTokenizer record (it->first,".");
49  std::string section ( *record.begin() );
50  std::string key ( *( record.end()-1) );
51  std::string value (it->second);
52 
53  if (oldName==section) {
54  setString(newName+"."+key, value);
55  }
56  }
57  }
58 }
59 
60 void SphinxConfigCreator::renameSphinxConfigSection (const std::string& oldName, const std::string& newName) {
61  auto pointerToTheDataWithOldName = this->data.find(oldName);
62  if (pointerToTheDataWithOldName != data.end()) {
63  auto dataWhereKeyIsOldName (pointerToTheDataWithOldName->second);
64  this->data[newName] = dataWhereKeyIsOldName;
65  }
66  pointerToTheDataWithOldName = this->data.find(oldName);
67  if (pointerToTheDataWithOldName != data.end()) {
68  this->data.erase(pointerToTheDataWithOldName);
69  }
70 }
71 
73  auto pointerToTheSection = this->data.find(sectionName);
74  if (pointerToTheSection != data.end()) {
75  this->data.erase(pointerToTheSection);
76  }
77 }
78 
79 }
80 }
81