Isis 3 Programmer Reference
DbProfile.cpp
Go to the documentation of this file.
1 
23 #include <string>
24 #include <vector>
25 #include <sstream>
26 #include <iostream>
27 
28 using std::ostringstream;
29 
30 #include "DbProfile.h"
31 #include "PvlGroup.h"
32 
33 namespace Isis {
34 
45  DbProfile::DbProfile(PvlContainer &pvl) : _name("Profile"), _keys() {
46  loadkeys(pvl);
47  if(_keys.exists("Name")) {
48  _name = value("Name");
49  }
50  }
51 
52 
74  DbProfile::DbProfile(const DbProfile &prof1, const DbProfile &prof2,
75  const QString &name) : _name(prof1.Name()),
76  _keys(prof1._keys) {
77  for(int nk = 0 ; nk < prof2._keys.size() ; nk++) {
78  _keys.add(prof2._keys.key(nk), prof2._keys.getNth(nk));
79  }
80 
81  if(!name.isEmpty()) {
82  _name = name;
83  }
84  }
85 
86 
96  void DbProfile::add(const QString &key, const QString &value) {
97  if(_keys.exists(key)) {
99  }
100  else {
102  }
103  }
104 
117  void DbProfile::replace(const QString &key, const QString &value) {
119  }
120 
121 
127  void DbProfile::remove(const QString &key) {
128  _keys.remove(key);
129  }
130 
141  int DbProfile::count(const QString &key) const {
142  if(_keys.exists(key)) {
143  return (_keys.get(key).size());
144  }
145  return (0);
146  }
147 
160  QString DbProfile::value(const QString &key, int nth) const {
161  try {
162  return (_keys.get(key)[nth]);
163  }
164  catch(IException &ie) {
165  ostringstream mess;
166  mess << "Error fetching value from key " << key;
167  if(nth != 0) {
168  mess << " (index=" << nth << ")";
169  }
170  throw IException(ie, IException::Programmer, mess.str(), _FILEINFO_);
171  }
172  }
173 
186  QString DbProfile::operator()(const QString &key, int nth) const {
187  return (value(key, nth));
188  }
189 
200  for(key = pvl.begin() ; key != pvl.end() ; ++key) {
201  _keys.add(key->name(), *key);
202  }
203  }
204 
205 #if 0
206  void DbProfile::printOn(std::ostream &o) const {
207 
208  // Create the ordered list of keywords
209  typedef CollectorMap<long, const PvlKeyword *> OrderedKeys;
210  OrderedKeys okeys;
211  DbProfileKeyList::CollectorConstIter keys;
212  for(keys = begin() ; keys != end() ; ++keys) {
213  const DbProfileKey &pk = keys->second;
214  okeys.add(pk._index, &pk.key);
215  }
216 
217  // Now write the keys in order
218  PvlGroup propGroup(_group);
219  OrderedKeys::CollectorConstIter okItr;
220  for(okItr = okeys.begin() ; okItr != okeys.end() ; ++okItr) {
221  propGroup.addKeyword(*(okItr->second));
222  }
223 
224  o << propGroup << std::endl;
225  }
226 #endif
227 
228 
229 }
QString operator()(const QString &key, int nth=0) const
Returns the specified value for the given keyword.
Definition: DbProfile.cpp:186
PvlKeywordIterator end()
Return the ending iterator.
Definition: PvlContainer.h:208
T & get(const K &key)
Returns the value associated with the name provided.
Definition: CollectorMap.h:583
Contains more than one keyword-value pair.
Definition: PvlContainer.h:63
int count(const QString &key) const
Report number of values in keyword.
Definition: DbProfile.cpp:141
T & getNth(int nth)
Returns the nth value in the collection.
Definition: CollectorMap.h:640
void remove(const QString &key)
Removes a keyword from the profile.
Definition: DbProfile.cpp:127
PvlKeywordIterator begin()
Return the beginning iterator.
Definition: PvlContainer.h:192
int remove(const K &key)
Removes and entry from the list.
Definition: CollectorMap.h:710
int size() const
Returns the size of the collection.
Definition: CollectorMap.h:528
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:162
QString _name
Name of this profile.
Definition: DbProfile.h:178
A DbProfile is a container for access parameters to a database.
Definition: DbProfile.h:65
void replace(const QString &key, const QString &value="")
Adds a keyword and value pair to the profile.
Definition: DbProfile.cpp:117
const K & key(int nth) const
Returns the nth key in the collection.
Definition: CollectorMap.h:689
int size() const
Returns the number of values stored in this keyword.
Definition: PvlKeyword.h:141
KeyList _keys
List of keys in profile.
Definition: DbProfile.h:179
bool exists(const K &key) const
Checks the existance of a particular key in the list.
Definition: CollectorMap.h:567
void add(const QString &key, const QString &value="")
Adds a keyword and value pair to the profile.
Definition: DbProfile.cpp:96
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
QString value(const QString &key, int nth=0) const
Returns the specified value for the given keyword.
Definition: DbProfile.cpp:160
void add(const K &key, const T &value)
Adds the element to the list.
Definition: CollectorMap.h:556
A single keyword-value pair.
Definition: PvlKeyword.h:98
Collector/container for arbitrary items.
Definition: CollectorMap.h:435
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
void loadkeys(PvlContainer &pvl)
Loads DbProfile keys from the given Pvl construct.
Definition: DbProfile.cpp:198
QString key(int nth) const
Returns the nth key in the profile.
Definition: DbProfile.h:155
void addValue(QString value, QString unit="")
Adds a value with units.
Definition: PvlKeyword.cpp:268
QList< PvlKeyword >::iterator PvlKeywordIterator
The keyword iterator.
Definition: PvlContainer.h:171