Isis 3 Programmer Reference
DbAccess.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 "DbAccess.h"
31 #include "Pvl.h"
32 #include "PvlGroup.h"
33 #include "PvlObject.h"
34 #include "IString.h"
35 
36 namespace Isis {
37 
60  DbAccess::DbAccess(const QString &dbaccFile,
61  const QString &defProfileName) : DbProfile("Database"),
62  _defProfileName(defProfileName), _profiles() {
63  load(dbaccFile);
64  }
65 
66 
76  DbAccess::DbAccess(PvlObject &pvl, const QString &defProfileName) :
77  DbProfile("Database"), _defProfileName(defProfileName),
78  _profiles() {
79  load(pvl);
80  }
81 
106  const DbProfile DbAccess::getProfile(const QString &name) const {
107  QString defName(name);
108  if(defName.isEmpty()) {
109  defName = getDefaultProfileName();
110  }
111  else {
112  if(!_profiles.exists(defName)) {
113  return (DbProfile(defName));
114  }
115  }
116 
117 // We have identified the proper profile
118  if(_profiles.exists(defName)) {
119  // Return the composite of this access scheme
120  return(DbProfile(*this, _profiles.get(defName), defName));
121  }
122  else {
123  // Return only the high level database access keys and hope it is enough
124  return (DbProfile(*this, DbProfile(), defName));
125  }
126  }
127 
140  const DbProfile DbAccess::getProfile(int nth) const {
141  const DbProfile &p = _profiles.getNth(nth);
142  return(DbProfile(*this, p, p.Name()));
143  }
144 
156  void DbAccess::load(const QString &filename) {
157  Pvl pvl(filename);
158  PvlObject db = pvl.findObject("Database");
159  load(db);
160  }
161 
176 
177  // Load database keywords
178  loadkeys(pvl);
179 
180  // Get all database user access profiles
181  PvlObject::PvlGroupIterator group = pvl.findGroup("Profile",
182  pvl.beginGroup(),
183  pvl.endGroup());
184  while(group != pvl.endGroup()) {
185  DbProfile dbgroup(*group);
186  _profiles.add(dbgroup.Name(), dbgroup);
187  group = pvl.findGroup("Profile", ++group, pvl.endGroup());
188  }
189  return;
190  }
191 
204  if(!_defProfileName.isEmpty()) {
205  return (_defProfileName);
206  }
207  else if(exists("DefaultProfile")) {
208  return (value("DefaultProfile"));
209  }
210  return ("");
211  }
212 
213 
214 }
void load(const QString &filename)
Loads a Database access configuration file.
Definition: DbAccess.cpp:156
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:141
T & get(const K &key)
Returns the value associated with the name provided.
Definition: CollectorMap.h:583
T & getNth(int nth)
Returns the nth value in the collection.
Definition: CollectorMap.h:640
PvlGroupIterator endGroup()
Returns the ending group index.
Definition: PvlObject.h:121
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
Definition: PvlObject.h:286
bool exists(const QString &key) const
Checks for the existance of a keyword.
Definition: DbProfile.h:129
A DbProfile is a container for access parameters to a database.
Definition: DbProfile.h:65
const DbProfile getProfile(const QString &name="") const
Retrieves the specified access profile.
Definition: DbAccess.cpp:106
bool exists(const K &key) const
Checks the existance of a particular key in the list.
Definition: CollectorMap.h:567
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
QString _defProfileName
Name of default profile.
Definition: DbAccess.h:179
Container for cube-like labels.
Definition: Pvl.h:135
QList< Isis::PvlGroup >::iterator PvlGroupIterator
The counter for groups.
Definition: PvlObject.h:95
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
QString getDefaultProfileName() const
Determine the name of the default profile.
Definition: DbAccess.cpp:203
QString Name() const
Returns the name of this property.
Definition: DbProfile.h:118
void loadkeys(PvlContainer &pvl)
Loads DbProfile keys from the given Pvl construct.
Definition: DbProfile.cpp:198
Contains Pvl Groups and Pvl Objects.
Definition: PvlObject.h:74
ProfileList _profiles
List of profiles.
Definition: DbAccess.h:180
PvlGroupIterator beginGroup()
Returns the beginning group index.
Definition: PvlObject.h:103