Isis 3 Developer Reference
Isis::DbProfile Class Reference

A DbProfile is a container for access parameters to a database. More...

#include <DbProfile.h>

Inheritance diagram for Isis::DbProfile:
Inheritance graph
Collaboration diagram for Isis::DbProfile:
Collaboration graph

Public Member Functions

 DbProfile ()
 
 DbProfile (const QString &name)
 
 DbProfile (const DbProfile &prof1, const DbProfile &prof2, const QString &name="")
 Creates a profile from the merging of two a DbProfiles. More...
 
 DbProfile (PvlContainer &pvl)
 Creates a DbProfile from a Pvl entity. More...
 
virtual ~DbProfile ()
 Destructor ensures everything is cleaned up properly. More...
 
bool isValid () const
 Reports if this is a valid profile. More...
 
int size () const
 Reports the number of keywords in this user profile. More...
 
void setName (const QString &name)
 Set the name of this profile. More...
 
QString Name () const
 Returns the name of this property. More...
 
bool exists (const QString &key) const
 Checks for the existance of a keyword. More...
 
void add (const QString &key, const QString &value="")
 Adds a keyword and value pair to the profile. More...
 
void replace (const QString &key, const QString &value="")
 Adds a keyword and value pair to the profile. More...
 
void remove (const QString &key)
 Removes a keyword from the profile. More...
 
int count (const QString &key) const
 Report number of values in keyword. More...
 
QString key (int nth) const
 Returns the nth key in the profile. More...
 
QString value (const QString &key, int nth=0) const
 Returns the specified value for the given keyword. More...
 
QString operator() (const QString &key, int nth=0) const
 Returns the specified value for the given keyword. More...
 

Protected Types

typedef CollectorMap< IString, PvlKeyword, NoCaseStringCompareKeyList
 

Protected Member Functions

void loadkeys (PvlContainer &pvl)
 Loads DbProfile keys from the given Pvl construct. More...
 
const KeyListgetKeyList () const
 Returns a reference to the key list. More...
 

Detailed Description

A DbProfile is a container for access parameters to a database.

This class provides a utility for (keyword) parameter management to access a database system. Profiles can be used to specify all parameters necessary to apply to programatic interfaces to database software such as Qt's SQL Module class, QSqlDatabase.

Using QSqlDatabase as an example, keywords such as User, Host, Port, and Dbname can be stored in this object and retrieved easily.

It can be easily adapted to any database software API by externally managing the contents of a configuration file. See DbAccess for additional details on how this scheme can be utilized.

Author
2006-11-09 Kris Becker

Member Typedef Documentation

◆ KeyList

Constructor & Destructor Documentation

◆ DbProfile() [1/4]

Isis::DbProfile::DbProfile ( )
inline

◆ DbProfile() [2/4]

Isis::DbProfile::DbProfile ( const QString &  name)
inline

◆ DbProfile() [3/4]

Isis::DbProfile::DbProfile ( const DbProfile prof1,
const DbProfile prof2,
const QString &  name = "" 
)

Creates a profile from the merging of two a DbProfiles.

This constructor will create a new DbProfile from two existing DbProfiles. Its intended use is for the merging of keys in an ordered fashion. It is useful when a higher level class inherits this class and a specific implementations calls for the keys to come from both the parent and the child DbProfile.

It should be noted that this is a convenient way to merge high level database access parameters with individual profile access where the last keys take precedence over the first. Thus, in the case where the same keys exist in both the first and second profiles, keys in the second profile take precedence. This is great for defining general database parameters in the top level database configure section and having individual profiles redefine certain access parameters.

Parameters
nameName of new profile
prof1First profile to merge
prof2Second profile to merge

References Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::add(), Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::getNth(), Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::key(), and Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::size().

◆ DbProfile() [4/4]

Isis::DbProfile::DbProfile ( PvlContainer pvl)

Creates a DbProfile from a Pvl entity.

This constructor will create a DbProfile by reading keywords from a Pvl container. Pvl Containers can be an Object or a Group, or simply a list of keywords. This PvlContainer is expected to point to the appropriate keywords that the caller has pre-established by normal Isis Pvl methods.

Parameters
pvlPvl container of keywords to make a DbProfile from

References Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::exists(), loadkeys(), and value().

◆ ~DbProfile()

virtual Isis::DbProfile::~DbProfile ( )
inlinevirtual

Destructor ensures everything is cleaned up properly.

Member Function Documentation

◆ add()

void Isis::DbProfile::add ( const QString &  key,
const QString &  value = "" 
)

Adds a keyword and value pair to the profile.

This method adds a keyword and value pair to the profile if it doesn't exist. If the keyword already exists,it appends the value to the existing keyword.

Parameters
keyKeyword to add or ammend
valueValue to add to the keyword

References Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::add(), Isis::PvlKeyword::addValue(), Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::exists(), Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::get(), key(), and value().

◆ count()

int Isis::DbProfile::count ( const QString &  key) const

Report number of values in keyword.

This method will return the number of values in the specified keyword. If the keyword does not exist, 0 is returned.

Parameters
keyName of key to get value count for
Returns
int Number values in key, or 0 if the key does not exist

References Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::exists(), Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::get(), key(), and Isis::PvlKeyword::size().

Referenced by Isis::PhotometricFunction::ConfKey(), and Isis::ConfKey().

◆ exists()

bool Isis::DbProfile::exists ( const QString &  key) const
inline

◆ getKeyList()

const KeyList& Isis::DbProfile::getKeyList ( ) const
inlineprotected

Returns a reference to the key list.

Direct access to the keyword container allows class developers some additional flexibility whilst maintaining integrity through the public interface.

Returns
const KeyList& Reference to keyword list

◆ isValid()

bool Isis::DbProfile::isValid ( ) const
inline

Reports if this is a valid profile.

A valid profile is simply defined to contain keys. If there are no keys defined for the profile, it is deemed invalid.

Returns
bool True if the profile is valid, therefore containing keys

References size().

Referenced by Isis::Database::init().

◆ key()

QString Isis::DbProfile::key ( int  nth) const
inline

Returns the nth key in the profile.

This method returns the name of the nth keyword in the profile so one can iterate through all existing keys. Note that database passwords could be vulnerable to exposure via this method.

Keywords in the profile are sorted in alphabetical order and not in the order in which they are read.

Parameters
nthSpecifies the nth key in the profile
Returns
QString Name of nth keyword in the profile.
Exceptions
Out-of-rangeexception if the nth keyword does not exist

References Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::key(), and Isis::IString::ToQt().

Referenced by add(), count(), exists(), loadkeys(), operator()(), remove(), replace(), and value().

◆ loadkeys()

void Isis::DbProfile::loadkeys ( PvlContainer pvl)
protected

Loads DbProfile keys from the given Pvl construct.

This method iterates through all keywords in the Pvl container and loads them into this property.

Parameters
pvlContainer of keywords that will be loaded

References Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::add(), Isis::PvlContainer::begin(), Isis::PvlContainer::end(), and key().

Referenced by DbProfile(), and Isis::DbAccess::load().

◆ Name()

QString Isis::DbProfile::Name ( ) const
inline

◆ operator()()

QString Isis::DbProfile::operator() ( const QString &  key,
int  nth = 0 
) const

Returns the specified value for the given keyword.

This method returns a value from the specified keyword. If the keyword or the specified value does not exist, an exception is thrown.

Parameters
keyName of keyword to return value for.
nthSpecifies the nth value in the keyword
Returns
QString The requested value in the keyword

References key(), and value().

◆ remove()

void Isis::DbProfile::remove ( const QString &  key)

Removes a keyword from the profile.

Parameters
keyKeyword to remove

References key(), and Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::remove().

◆ replace()

void Isis::DbProfile::replace ( const QString &  key,
const QString &  value = "" 
)

Adds a keyword and value pair to the profile.

This method adds a keyword and value pair to the profile if it doesn't exist.

If the keyword already exists, it is deleted and replaced with this new keyword and value.

Parameters
keyKeyword to replace
valueValue to add to the keyword

References Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::add(), key(), and value().

◆ setName()

void Isis::DbProfile::setName ( const QString &  name)
inline

Set the name of this profile.

Parameters
nameQString used to set the name of this profile

◆ size()

int Isis::DbProfile::size ( ) const
inline

Reports the number of keywords in this user profile.

Returns
int Number keywords found in profile

References Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::size().

Referenced by isValid().

◆ value()

QString Isis::DbProfile::value ( const QString &  key,
int  nth = 0 
) const

Returns the specified value for the given keyword.

This method returns a value from the specified keyword. If the keyword or the specified value does not exist, an exception is thrown.

Parameters
keyName of keyword to return value for.
nthSpecifies the nth value in the keyword
Returns
QString The requested value in the keyword

References _FILEINFO_, Isis::CollectorMap< K, T, ComparePolicy, RemovalPolicy, CopyPolicy >::get(), key(), and Isis::IException::Programmer.

Referenced by add(), Isis::DatabaseFactory::addAccessProfile(), Isis::PhotometricFunction::ConfKey(), Isis::ConfKey(), DbProfile(), Isis::DbAccess::getDefaultProfileName(), operator()(), and replace().


The documentation for this class was generated from the following files: