USGS

Isis 3.0 Object Programmers' Reference

Home

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 }