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
14using std::ostringstream;
15
16#include "DbProfile.h"
17#include "PvlGroup.h"
18
19namespace 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) {
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}
int remove(const K &key)
Removes and entry from the list.
T & get(const K &key)
Returns the value associated with the name provided.
bool exists(const K &key) const
Checks the existance of a particular key in the list.
void add(const K &key, const T &value)
Adds the element to the list.
A DbProfile is a container for access parameters to a database.
Definition DbProfile.h:51
QString _name
Name of this profile.
Definition DbProfile.h:164
void add(const QString &key, const QString &value="")
Adds a keyword and value pair to the profile.
Definition DbProfile.cpp:82
KeyList _keys
List of keys in profile.
Definition DbProfile.h:165
QString value(const QString &key, int nth=0) const
Returns the specified value for the given keyword.
QString operator()(const QString &key, int nth=0) const
Returns the specified value for the given keyword.
void remove(const QString &key)
Removes a keyword from the profile.
void loadkeys(PvlContainer &pvl)
Loads DbProfile keys from the given Pvl construct.
QString key(int nth) const
Returns the nth key in the profile.
Definition DbProfile.h:141
void replace(const QString &key, const QString &value="")
Adds a keyword and value pair to the profile.
int count(const QString &key) const
Report number of values in keyword.
Isis exception class.
Definition IException.h:91
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition IException.h:146
Contains more than one keyword-value pair.
QList< PvlKeyword >::iterator PvlKeywordIterator
The keyword iterator.
A single keyword-value pair.
Definition PvlKeyword.h:87
int size() const
Returns the number of values stored in this keyword.
Definition PvlKeyword.h:133
void addValue(QString value, QString unit="")
Adds a value with units.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16