Isis 3 Programmer Reference
DbAccess.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 "DbAccess.h"
17 #include "Pvl.h"
18 #include "PvlGroup.h"
19 #include "PvlObject.h"
20 #include "IString.h"
21 
22 namespace Isis {
23 
46  DbAccess::DbAccess(const QString &dbaccFile,
47  const QString &defProfileName) : DbProfile("Database"),
48  _defProfileName(defProfileName), _profiles() {
49  load(dbaccFile);
50  }
51 
52 
62  DbAccess::DbAccess(PvlObject &pvl, const QString &defProfileName) :
63  DbProfile("Database"), _defProfileName(defProfileName),
64  _profiles() {
65  load(pvl);
66  }
67 
92  const DbProfile DbAccess::getProfile(const QString &name) const {
93  QString defName(name);
94  if(defName.isEmpty()) {
95  defName = getDefaultProfileName();
96  }
97  else {
98  if(!_profiles.exists(defName)) {
99  return (DbProfile(defName));
100  }
101  }
102 
103 // We have identified the proper profile
104  if(_profiles.exists(defName)) {
105  // Return the composite of this access scheme
106  return(DbProfile(*this, _profiles.get(defName), defName));
107  }
108  else {
109  // Return only the high level database access keys and hope it is enough
110  return (DbProfile(*this, DbProfile(), defName));
111  }
112  }
113 
126  const DbProfile DbAccess::getProfile(int nth) const {
127  const DbProfile &p = _profiles.getNth(nth);
128  return(DbProfile(*this, p, p.Name()));
129  }
130 
142  void DbAccess::load(const QString &filename) {
143  Pvl pvl(filename);
144  PvlObject db = pvl.findObject("Database");
145  load(db);
146  }
147 
162 
163  // Load database keywords
164  loadkeys(pvl);
165 
166  // Get all database user access profiles
167  PvlObject::PvlGroupIterator group = pvl.findGroup("Profile",
168  pvl.beginGroup(),
169  pvl.endGroup());
170  while(group != pvl.endGroup()) {
171  DbProfile dbgroup(*group);
172  _profiles.add(dbgroup.Name(), dbgroup);
173  group = pvl.findGroup("Profile", ++group, pvl.endGroup());
174  }
175  return;
176  }
177 
190  if(!_defProfileName.isEmpty()) {
191  return (_defProfileName);
192  }
193  else if(exists("DefaultProfile")) {
194  return (value("DefaultProfile"));
195  }
196  return ("");
197  }
198 
199 
200 }
Isis::PvlObject::endGroup
PvlGroupIterator endGroup()
Returns the ending group index.
Definition: PvlObject.h:109
Isis::PvlObject::findGroup
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:129
Isis::PvlObject::PvlGroupIterator
QList< Isis::PvlGroup >::iterator PvlGroupIterator
The counter for groups.
Definition: PvlObject.h:83
Isis::PvlObject
Contains Pvl Groups and Pvl Objects.
Definition: PvlObject.h:61
Isis::DbAccess::_profiles
ProfileList _profiles
List of profiles.
Definition: DbAccess.h:166
Isis::DbProfile::Name
QString Name() const
Returns the name of this property.
Definition: DbProfile.h:104
Isis::DbProfile::exists
bool exists(const QString &key) const
Checks for the existance of a keyword.
Definition: DbProfile.h:115
Isis::CollectorMap::getNth
T & getNth(int nth)
Returns the nth value in the collection.
Definition: CollectorMap.h:624
Isis::CollectorMap::get
T & get(const K &key)
Returns the value associated with the name provided.
Definition: CollectorMap.h:567
Isis::Pvl
Container for cube-like labels.
Definition: Pvl.h:119
Isis::DbAccess::_defProfileName
QString _defProfileName
Name of default profile.
Definition: DbAccess.h:165
Isis::DbAccess::getDefaultProfileName
QString getDefaultProfileName() const
Determine the name of the default profile.
Definition: DbAccess.cpp:189
Isis::CollectorMap::exists
bool exists(const K &key) const
Checks the existance of a particular key in the list.
Definition: CollectorMap.h:551
Isis::DbAccess::load
void load(const QString &filename)
Loads a Database access configuration file.
Definition: DbAccess.cpp:142
Isis::PvlObject::findObject
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
Definition: PvlObject.h:274
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::CollectorMap::add
void add(const K &key, const T &value)
Adds the element to the list.
Definition: CollectorMap.h:540
Isis::PvlObject::beginGroup
PvlGroupIterator beginGroup()
Returns the beginning group index.
Definition: PvlObject.h:91
Isis::DbAccess::getProfile
const DbProfile getProfile(const QString &name="") const
Retrieves the specified access profile.
Definition: DbAccess.cpp:92
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
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16