Diana Software
QAliases.cc
Go to the documentation of this file.
1 #include "QAliases.hh"
2 #include <fstream>
3 #include <sstream>
4 
6 
8 {
9 }
10 
11 
12 QError QAliases::Get(const std::string& alias, QAliases::AliasInfo& ai) const
13 {
14  std::map<std::string, AliasInfo >::const_iterator iter;
15  AliasInfo info;
16  ai = info;
17  iter = fAliases.find(alias);
18  if(iter != fAliases.end() )
19  ai = iter->second;
20  else
21  return QERR_OUT_OF_RANGE;
22  return QERR_SUCCESS;
23 }
24 
25 std::map<std::string,std::string> QAliases::Find(const QEventLabel& label) const
26 {
27  std::map<std::string, std::string> labelAliases;
28 
29  std::map<std::string, AliasInfo >::const_iterator iter = fAliases.begin();
30  while(iter != fAliases.end()) {
31  QEventLabel mLabel = iter->second.fLabel;
32  if(mLabel == label) {
33  labelAliases[iter->first] = iter->second.fPath;
34  }
35  iter++;
36  }
37  return labelAliases;
38 
39 }
40 
41 void QAliases::Add(const std::string& path, const std::string& alias)
42 {
43  AliasInfo info;
44  size_t dotpos = path.find_first_of(".");
45  info.fLabel = QEventLabel(path.substr(0,dotpos));
46  info.fPath = path.substr(dotpos+1,std::string::npos);
47  fAliases[alias] = info;
48 }
49 
50 void QAliases::Add(const QEventLabel& label, const std::string& path, const std::string& alias)
51 {
52  AliasInfo info;
53  info.fLabel = label;
54  if(path == ".")
55  info.fPath = "";
56  else
57  info.fPath = path;
58 
59  fAliases[alias] = info;
60  // std::cout<<"Adding alias: "<<alias<<" "<<info.fLabel.owner<<" "<<info.fLabel.name<<" "<<info.fPath<<std::endl;
61 }
62 
63 QError QAliases::FillFromFile(const std::string& filename)
64 {
66  std::ifstream inputFileList (filename.c_str());
67  if(!inputFileList.is_open())
68  return QError(QERR_CANNOT_OPEN_FILE,__FILE__,__LINE__,filename);
69 
70 // fAliases.clear();
71  std::string line;
72  while(!inputFileList.eof()) {
73  getline(inputFileList,line);
74  //std::cout<<"L: "<<line<<std::endl;
75  if(line.empty()) continue;
76  else if(line.at(0) == '#') continue;
77  else if(line.find("include") != std::string::npos)
78  {
79  size_t q1,q2;
80  q1 = line.find_first_of("\"");
81  q2 = line.find_last_of("\"");
82  std::string newfile = line.substr(q1,q2-q1);
83  err = FillFromFile(newfile);
84  if(err != QERR_SUCCESS) return err;
85  continue;
86  }
87  std::stringstream strstr;
88  std::string alias, owner, type, path;
89  strstr<<line;
90  if(strstr.good()) strstr>>alias;
91  if(strstr.good()) strstr>>owner;
92  if(strstr.good()) strstr>>type;
93  if(strstr.good()) strstr>>path;
94  if(!path.empty()) Add(QEventLabel(owner.c_str(),type.c_str()),path,alias);
95  }
96  return err;
97 }
98 
err
Definition: CheckOF.C:114
#define Q_END_NAMESPACE
Definition: QDiana.hh:22
#define Q_BEGIN_NAMESPACE
Definition: QDiana.hh:20
@ QERR_CANNOT_OPEN_FILE
Definition: QError.hh:33
@ QERR_OUT_OF_RANGE
Definition: QError.hh:28
@ QERR_SUCCESS
Definition: QError.hh:27
std::string fPath
Definition: QAliases.hh:17
QEventLabel fLabel
Definition: QAliases.hh:16
std::map< std::string, AliasInfo > fAliases
Definition: QAliases.hh:36
QError FillFromFile(const std::string &filename)
Definition: QAliases.cc:63
QAliases()
Definition: QAliases.cc:7
void Add(const QEventLabel &label, const std::string &path, const std::string &alias)
Definition: QAliases.cc:50
std::map< std::string, std::string > Find(const QEventLabel &label) const
Definition: QAliases.cc:25
std::map< std::string, AliasInfo > Get() const
Definition: QAliases.hh:24
error class with error type and description
Definition: QError.hh:115
label for QObject in the QEvent
Definition: QEventLabel.hh:23