creaImageIO_lib
creaImageIO::Settings Class Reference

#include <creaImageIOSettings.h>

Public Member Functions

 Settings (const std::string i_path)
 
 ~Settings ()
 
const std::string getValue (const std::string i_key)
 
void addDB (const std::string &i_path)
 
void removeDB (const std::string &i_path)
 
void updateSetting (const std::string &key, const std::string &val)
 
void writeSettingsFile ()
 

Private Member Functions

void readSettings (std::vector< std::string > &i_Keys, const std::string &i_file)
 
void createFile ()
 
void writeSettings (std::ofstream &o_filebuf)
 

Private Attributes

std::map< std::string,
std::string > 
m_SettingsMap
 
std::string m_SettingsFileName
 

Detailed Description

Definition at line 44 of file creaImageIOSettings.h.

Constructor & Destructor Documentation

creaImageIO::Settings::Settings ( const std::string  i_path)

Definition at line 47 of file creaImageIOSettings.cpp.

References SETTINGS_COPY_PATH, SETTINGS_DBPATH, SETTINGS_OUTPUT_ASK, SETTINGS_OUTPUT_DIM, SETTINGS_REMOVE_PATIENT_DISPLAY, SETTINGS_SYNC_EVENT, and SETTINGS_SYNC_FREQ.

48  {
49  //need to position path in user directory first.
50  m_SettingsFileName = i_path + "\\.creaImageIO\\share\\creaImageIO\\app.config";
51  //Test if Settings File exist
52  if(!boost::filesystem::exists(m_SettingsFileName) )
53  {
54  createFile();
55  }
56  std::ifstream ifs(m_SettingsFileName.c_str());
57  std::string line;
58  std::string sets;
59  if (ifs.is_open())
60  {
61  while (! ifs.eof() )
62  {
63  getline(ifs,line);
64  sets += line;
65  }
66  ifs.close();
67  }
68  std::vector<std::string> Keys;
69  Keys.push_back(SETTINGS_SYNC_EVENT);
70  Keys.push_back(SETTINGS_DBPATH);
71  Keys.push_back(SETTINGS_SYNC_FREQ);
72  Keys.push_back(SETTINGS_COPY_PATH);
73  Keys.push_back(SETTINGS_REMOVE_PATIENT_DISPLAY);
74  Keys.push_back(SETTINGS_OUTPUT_ASK);
75  Keys.push_back(SETTINGS_OUTPUT_DIM);
76  readSettings(Keys, sets);
77 
78  }
creaImageIO::Settings::~Settings ( )

Definition at line 80 of file creaImageIOSettings.cpp.

81  {
82 
83  }

Member Function Documentation

void creaImageIO::Settings::addDB ( const std::string &  i_path)

Definition at line 140 of file creaImageIOSettings.cpp.

References SETTINGS_DBPATH.

Referenced by creaImageIO::Gimmick::addDB().

141  {
142  if(m_SettingsMap[SETTINGS_DBPATH].find(i_path) == std::string::npos)
143  {
144  m_SettingsMap[SETTINGS_DBPATH] += i_path + ";";
145  }
146  }

Here is the caller graph for this function:

const std::string creaImageIO::Settings::getValue ( const std::string  i_key)
inline

Definition at line 50 of file creaImageIOSettings.h.

References m_SettingsMap.

Referenced by creaImageIO::Gimmick::addDBSettings(), creaImageIO::Gimmick::CopyFiles(), and creaImageIO::Gimmick::GetSetting().

50 {return m_SettingsMap[i_key];}

Here is the caller graph for this function:

void creaImageIO::Settings::readSettings ( std::vector< std::string > &  i_Keys,
const std::string &  i_file 
)
private

Definition at line 110 of file creaImageIOSettings.cpp.

111  {
112  std::vector<std::string>::iterator it_key = i_Keys.begin();
113  for(; it_key< i_Keys.end(); ++it_key)
114  {
115  size_t fpos = i_file.find(it_key->c_str());
116  size_t lpos = i_file.rfind(it_key->c_str());
117  if(fpos != std::string::npos && lpos != std::string::npos)
118  {
119  m_SettingsMap[it_key->c_str()] = i_file.substr(fpos + it_key->size(),lpos-fpos - it_key->size());
120  }
121  }
122  }
void creaImageIO::Settings::removeDB ( const std::string &  i_path)

Definition at line 154 of file creaImageIOSettings.cpp.

References SETTINGS_DBPATH.

155  {
156  boost::algorithm::replace_all(m_SettingsMap[SETTINGS_DBPATH],i_path + ";","");
157  }
void creaImageIO::Settings::updateSetting ( const std::string &  key,
const std::string &  val 
)

Definition at line 130 of file creaImageIOSettings.cpp.

Referenced by creaImageIO::Gimmick::UpdateSetting().

131  {
132  m_SettingsMap[key.c_str()] = val;
133  }

Here is the caller graph for this function:

void creaImageIO::Settings::writeSettings ( std::ofstream &  o_filebuf)
private

Definition at line 165 of file creaImageIOSettings.cpp.

166  {
167  std::map<std::string, std::string>::iterator it_map = m_SettingsMap.begin();
168  std::stringstream st;
169  for(; it_map != m_SettingsMap.end(); ++it_map)
170  {
171  o_file << it_map->first.c_str();
172  o_file << it_map->second.c_str();
173  o_file << it_map->first.c_str();
174  o_file << std::endl;
175  }
176  }
void creaImageIO::Settings::writeSettingsFile ( )

Definition at line 183 of file creaImageIOSettings.cpp.

Referenced by creaImageIO::Gimmick::UpdateSetting(), and creaImageIO::Gimmick::~Gimmick().

184  {
185  std::ofstream ofs(m_SettingsFileName.c_str());
186  ofs.clear();
187  writeSettings(ofs);
188  ofs.close();
189  }

Here is the caller graph for this function:

Member Data Documentation

std::string creaImageIO::Settings::m_SettingsFileName
private

Definition at line 70 of file creaImageIOSettings.h.

std::map<std::string, std::string> creaImageIO::Settings::m_SettingsMap
private

Definition at line 63 of file creaImageIOSettings.h.

Referenced by getValue().


The documentation for this class was generated from the following files: