Isis 3 Programmer Reference
DbProfile.cpp
1 
7 /* SPDX-License-Identifier: CC0-1.0 */
8 
9 #include <string>
10 #include <vector>
11 #include <sstream>
12 #include <iostream>
13 
14 using std::ostringstream;
15 
16 #include "DbProfile.h"
17 #include "PvlGroup.h"
18 
19 namespace Isis {
20 
31  DbProfile::DbProfile(PvlContainer &pvl) : _name("Profile"), _keys() {
32  loadkeys(pvl);
33  if(_keys.exists("Name")) {
34  _name = value("Name");
35  }
36  }
37 
38 
60  DbProfile::DbProfile(const DbProfile &prof1, const DbProfile &prof2,
61  const QString &name) : _name(prof1.Name()),
62  _keys(prof1._keys) {
63  for(int nk = 0 ; nk < prof2._keys.size() ; nk++) {
64  _keys.add(prof2._keys.key(nk), prof2._keys.getNth(nk));
65  }
66 
67  if(!name.isEmpty()) {
68  _name = name;
69  }
70  }
71 
72 
82  void DbProfile::add(const QString &key, const QString &value) {
83  if(_keys.exists(key)) {
85  }
86  else {
88  }
89  }
90 
103  void DbProfile::replace(const QString &key, const QString &value) {
105  }
106 
107 
113  void DbProfile::remove(const QString &key) {
114  _keys.remove(key);
115  }
116 
127  int DbProfile::count(const QString &key) const {
128  if(_keys.exists(key)) {
129  return (_keys.get(key).size());
130  }
131  return (0);
132  }
133 
146  QString DbProfile::value(const QString &key, int nth) const {
147  try {
148  return (_keys.get(key)[nth]);
149  }
150  catch(IException &ie) {
151  ostringstream mess;
152  mess << "Error fetching value from key " << key;
153  if(nth != 0) {
154  mess << " (index=" << nth << ")";
155  }
156  throw IException(ie, IException::Programmer, mess.str(), _FILEINFO_);
157  }
158  }
159 
172  QString DbProfile::operator()(const QString &key, int nth) const {
173  return (value(key, nth));
174  }
175 
186  for(key = pvl.begin() ; key != pvl.end() ; ++key) {
187  _keys.add(key->name(), *key);
188  }
189  }
190 
191 #if 0
192  void DbProfile::printOn(std::ostream &o) const {
193 
194  // Create the ordered list of keywords
195  typedef CollectorMap<long, const PvlKeyword *> OrderedKeys;
196  OrderedKeys okeys;
197  DbProfileKeyList::CollectorConstIter keys;
198  for(keys = begin() ; keys != end() ; ++keys) {
199  const DbProfileKey &pk = keys->second;
200  okeys.add(pk._index, &pk.key);
201  }
202 
203  // Now write the keys in order
204  PvlGroup propGroup(_group);
205  OrderedKeys::CollectorConstIter okItr;
206  for(okItr = okeys.begin() ; okItr != okeys.end() ; ++okItr) {
207  propGroup.addKeyword(*(okItr->second));
208  }
209 
210  o << propGroup << std::endl;
211  }
212 #endif
213 
214 
215 }
Isis::DbProfile::operator()
QString operator()(const QString &key, int nth=0) const
Returns the specified value for the given keyword.
Definition: DbProfile.cpp:172
Isis::PvlKeyword
A single keyword-value pair.
Definition: PvlKeyword.h:82
Isis::CollectorMap::getNth
T & getNth(int nth)
Returns the nth value in the collection.
Definition: CollectorMap.h:624
Isis::PvlKeyword::addValue
void addValue(QString value, QString unit="")
Adds a value with units.
Definition: PvlKeyword.cpp:252
Isis::DbProfile::count
int count(const QString &key) const
Report number of values in keyword.
Definition: DbProfile.cpp:127
Isis::CollectorMap::get
T & get(const K &key)
Returns the value associated with the name provided.
Definition: CollectorMap.h:567
Isis::CollectorMap::size
int size() const
Returns the size of the collection.
Definition: CollectorMap.h:512
Isis::CollectorMap::remove
int remove(const K &key)
Removes and entry from the list.
Definition: CollectorMap.h:694
Isis::DbProfile::_keys
KeyList _keys
List of keys in profile.
Definition: DbProfile.h:165
Isis::DbProfile::replace
void replace(const QString &key, const QString &value="")
Adds a keyword and value pair to the profile.
Definition: DbProfile.cpp:103
Isis::DbProfile::add
void add(const QString &key, const QString &value="")
Adds a keyword and value pair to the profile.
Definition: DbProfile.cpp:82
Isis::CollectorMap::exists
bool exists(const K &key) const
Checks the existance of a particular key in the list.
Definition: CollectorMap.h:551
Isis::DbProfile::_name
QString _name
Name of this profile.
Definition: DbProfile.h:164
Isis::CollectorMap::key
const K & key(int nth) const
Returns the nth key in the collection.
Definition: CollectorMap.h:673
Isis::DbProfile::loadkeys
void loadkeys(PvlContainer &pvl)
Loads DbProfile keys from the given Pvl construct.
Definition: DbProfile.cpp:184
Isis::DbProfile
A DbProfile is a container for access parameters to a database.
Definition: DbProfile.h:51
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::CollectorMap::add
void add(const K &key, const T &value)
Adds the element to the list.
Definition: CollectorMap.h:540
Isis::IException::Programmer
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:146
Isis::CollectorMap
Collector/container for arbitrary items.
Definition: CollectorMap.h:419
Isis::PvlKeyword::size
int size() const
Returns the number of values stored in this keyword.
Definition: PvlKeyword.h:125
Isis::PvlContainer::PvlKeywordIterator
QList< PvlKeyword >::iterator PvlKeywordIterator
The keyword iterator.
Definition: PvlContainer.h:157
Isis::DbProfile::remove
void remove(const QString &key)
Removes a keyword from the profile.
Definition: DbProfile.cpp:113
Isis::PvlContainer::end
PvlKeywordIterator end()
Return the ending iterator.
Definition: PvlContainer.h:194
Isis::PvlContainer
Contains more than one keyword-value pair.
Definition: PvlContainer.h:49
Isis::DbProfile::value
QString value(const QString &key, int nth=0) const
Returns the specified value for the given keyword.
Definition: DbProfile.cpp:146
Isis::DbProfile::key
QString key(int nth) const
Returns the nth key in the profile.
Definition: DbProfile.h:141
Isis::PvlContainer::begin
PvlKeywordIterator begin()
Return the beginning iterator.
Definition: PvlContainer.h:178
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16