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
14using std::ostringstream;
15
16#include "DbAccess.h"
17#include "Pvl.h"
18#include "PvlGroup.h"
19#include "PvlObject.h"
20#include "IString.h"
21
22namespace 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}
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.
T & getNth(int nth)
Returns the nth value in the collection.
ProfileList _profiles
List of profiles.
Definition DbAccess.h:166
const DbProfile getProfile(const QString &name="") const
Retrieves the specified access profile.
Definition DbAccess.cpp:92
QString _defProfileName
Name of default profile.
Definition DbAccess.h:165
QString getDefaultProfileName() const
Determine the name of the default profile.
Definition DbAccess.cpp:189
void load(const QString &filename)
Loads a Database access configuration file.
Definition DbAccess.cpp:142
A DbProfile is a container for access parameters to a database.
Definition DbProfile.h:51
QString value(const QString &key, int nth=0) const
Returns the specified value for the given keyword.
bool exists(const QString &key) const
Checks for the existance of a keyword.
Definition DbProfile.h:115
void loadkeys(PvlContainer &pvl)
Loads DbProfile keys from the given Pvl construct.
Container for cube-like labels.
Definition Pvl.h:119
Contains Pvl Groups and Pvl Objects.
Definition PvlObject.h:61
QList< Isis::PvlGroup >::iterator PvlGroupIterator
The counter for groups.
Definition PvlObject.h:83
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
Definition PvlObject.h:276
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16