Isis 3 Programmer Reference
Isis::PvlFlatMap Class Reference

Provides a flat map of PvlKeywords. More...

#include <PvlFlatMap.h>

Inheritance diagram for Isis::PvlFlatMap:
Inheritance graph
Collaboration diagram for Isis::PvlFlatMap:
Collaboration graph

Public Types

typedef QMap< QString, PvlKeyword >::const_iterator ConstPvlFlatMapIterator
 A const iterator for the underling QMap that PvlFlatMap is built on.
 
typedef QMap< QString, PvlKeyword >::iterator PvlFlatMapIterator
 An iterator for the underlying QMap that PvlFlatMap is built on.
 

Public Member Functions

 PvlFlatMap ()
 Default constructor.
 
 PvlFlatMap (const PvlFlatMap &other)
 Constructs a PvlFlatMap from another PvlFlatMap object.
 
 PvlFlatMap (const PvlFlatMap &pmap1, const PvlFlatMap &pmap2)
 Constructs a PvlFlatMap from two PvlFlatMap objects.
 
 PvlFlatMap (const PvlObject &pvl, const PvlConstraints &constraints=PvlConstraints())
 Constructs a PvlFlatMap (with constraints) from a PvlObject.
 
 PvlFlatMap (const PvlContainer &pvl, const PvlConstraints &constraints=PvlConstraints())
 Constructs a PvlFlatMap (with constraints) from the keywords in a PvlContainer (i.e PvlObject or PvlGroup).
 
virtual ~PvlFlatMap ()
 Destructor.
 
bool exists (const QString &key) const
 Determines whether a given keyword exists in the PvlFlatMap.
 
int count (const QString &key) const
 Returns the number of values associated with a given keyword.
 
bool isNull (const QString &key, const int index=0) const
 Determines if the value of a keyword is Null.
 
void add (const QString &key, const QString &value)
 Adds PvlKeyword with the given name and value to the PvlFlatMap.
 
void add (const PvlKeyword &keyword)
 Adds the given PvlKeyword to the PvlFlatMap.
 
void append (const PvlKeyword &key)
 Appends the given PvlKeyword's values to the PvlFlatMap.
 
void append (const QString &key, const QString &value)
 Appends a the given keyword and value to the PvlFlatMap.
 
bool erase (const QString &key)
 Erases a keyword from the PvlFlatMap.
 
QString get (const QString &key, const int &index=0) const
 Gets the value of a keyword in the PvlFlatMap.
 
QString get (const QString &key, const QString &defValue, const int &index=0) const
 Gets the value of a keyword in the PvlFlatMap.
 
QString operator() (const QString &name) const
 Gets the first value of a keyword in the PvlFlatMap.
 
QStringList allValues (const QString &key) const
 Gets all the values associated with a keyword in the PvlFlatMap.
 
PvlKeyword keyword (const QString &key) const
 Finds a keyword in the PvlFlatMap.
 
int merge (const PvlFlatMap &other)
 Adds the keywords from another PvlFlatMap.
 

Static Public Member Functions

static QStringList keywordValues (const PvlKeyword &keyword)
 Gets all of a PvlKeyword's values.
 

Private Member Functions

int loadObject (const PvlObject &object, const PvlConstraints &constraints)
 Loads PvlObjects into the PvlFlatMap.
 
int loadGroups (const PvlObject &object, const PvlConstraints &constraints)
 Loads PvlGroups into the PvlFlatMap.
 
int loadGroup (const PvlGroup &group, const PvlConstraints &constraints)
 Loads a PvlGroup into the PvlFlatMap.
 
int loadKeywords (const PvlContainer &pvl, const PvlConstraints &constraints)
 Loads PvlKeywords within a PvlContainer into the PvlFlatMap.
 

Detailed Description

Provides a flat map of PvlKeywords.

This class provides a very fast convenient way to store PVL keywords for applications that require extensive use of them. It is intended to provide a much easier interface to ISIS Pvl structures that represents them as a single flat lookup table.

Note that if you use the methods provided in this class, then the keywords names will be converted to lowercase to provide a consistent interface. One could choose to use the Qt QMap interface directly (which is the base class of this class) to use a case sensitive map. Restricting use to add() and get() methods provides the case insensitive representation.

Author
2012-07-15 Kris Becker
History

2012-07-15 Kris Becker - Original version.

2015-03-18 Jeannie Backer - Brought class files closer to ISIS coding standards.

2015-03-20 Ian Humphrey - Updated documentation. Modified loadGroups() and added loadGroup() method to correctly load PvlGroups against PvlConstraints.

2016-02-28 Jeannie Backer - Moved from isisminer app to base class area. Brought closer to ISIS coding standards. Improved documentation. Created unit test. Fixes #2399

2016-02-28 Jeannie Backer - Changed readKeyListFile() to read the keylist in as an Isis::TextFile. References #2262

Definition at line 218 of file PvlFlatMap.h.

Member Typedef Documentation

◆ ConstPvlFlatMapIterator

typedef QMap<QString,PvlKeyword>::const_iterator Isis::PvlFlatMap::ConstPvlFlatMapIterator

A const iterator for the underling QMap that PvlFlatMap is built on.

Definition at line 222 of file PvlFlatMap.h.

◆ PvlFlatMapIterator

An iterator for the underlying QMap that PvlFlatMap is built on.

Definition at line 224 of file PvlFlatMap.h.

Constructor & Destructor Documentation

◆ PvlFlatMap() [1/5]

Isis::PvlFlatMap::PvlFlatMap ( )

Default constructor.

Definition at line 343 of file PvlFlatMap.cpp.

◆ PvlFlatMap() [2/5]

Isis::PvlFlatMap::PvlFlatMap ( const PvlFlatMap & other)

Constructs a PvlFlatMap from another PvlFlatMap object.

Parameters
otherThe PvlFlatMap to copy

Definition at line 352 of file PvlFlatMap.cpp.

References merge().

◆ PvlFlatMap() [3/5]

Isis::PvlFlatMap::PvlFlatMap ( const PvlFlatMap & pmap1,
const PvlFlatMap & pmap2 )

Constructs a PvlFlatMap from two PvlFlatMap objects.

This constructor creates a PvlFlatMap from the contents of two PvlFlatMap objects. The constructed PvlFlatMap contains the first PvlFlatMap's contents followed by the second PvlFlatMap's contents.

If there are keywords of the same in both maps, then the last loaded keyword in pmap2 will overwrite any previous values.

See also
merge()
Parameters
pmap1The first PvlFlatMap
pmap2The second PvlFlatMap

Definition at line 373 of file PvlFlatMap.cpp.

References merge().

◆ PvlFlatMap() [4/5]

Isis::PvlFlatMap::PvlFlatMap ( const PvlObject & pvl,
const PvlConstraints & constraints = PvlConstraints() )

Constructs a PvlFlatMap (with constraints) from a PvlObject.

This Constructor creates a PvlFlatMap from a PvlObject according to any constraints passed to the constructor. If no PvlConstraints object is provided, the PvlFlatMap will be created from all the objects and groups within the passed PvlObject.

See also
loadObject()
Parameters
pvlThe PvlObject to use for creating the PvlFlatMap
constraintsThe PvlConstraints that determine which Pvl objects/groups are included or excluded in the constructed PvlFlatMap

Definition at line 394 of file PvlFlatMap.cpp.

References loadObject().

◆ PvlFlatMap() [5/5]

Isis::PvlFlatMap::PvlFlatMap ( const PvlContainer & pvl,
const PvlConstraints & constraints = PvlConstraints() )

Constructs a PvlFlatMap (with constraints) from the keywords in a PvlContainer (i.e PvlObject or PvlGroup).

This constructor creates a PvlFlatMap from a PvlGroup object according to any constraints passed to the constructor. If no PvlConstraints object is provided, the PvlFlatMap will be created from all of the objects and groups within the passed PvlContainer.

See also
loadKeywords()
Parameters
pvlThe PvlContainer to use for creating the PvlFlatMap
constraintsThe PvlConstraints that determine which Pvl objects/groups are included or excluded in the constructed PvlFlatMap

Definition at line 415 of file PvlFlatMap.cpp.

References loadKeywords().

◆ ~PvlFlatMap()

Isis::PvlFlatMap::~PvlFlatMap ( )
virtual

Destructor.

Definition at line 425 of file PvlFlatMap.cpp.

Member Function Documentation

◆ add() [1/2]

void Isis::PvlFlatMap::add ( const PvlKeyword & key)

Adds the given PvlKeyword to the PvlFlatMap.

This will overwrite any existing keyword in the map keyword with the same name.

Parameters
keyThe PvlKeyword to add to the map.

Definition at line 500 of file PvlFlatMap.cpp.

References Isis::PvlKeyword::name().

◆ add() [2/2]

void Isis::PvlFlatMap::add ( const QString & key,
const QString & value )

Adds PvlKeyword with the given name and value to the PvlFlatMap.

This will overwrite any existing keyword in the map with the same name.

Parameters
keyThe name of the keyword to add
valueThe value of the added keyword

Definition at line 488 of file PvlFlatMap.cpp.

References add().

Referenced by add(), loadKeywords(), and merge().

◆ allValues()

QStringList Isis::PvlFlatMap::allValues ( const QString & key) const

Gets all the values associated with a keyword in the PvlFlatMap.

If the keyword does not exist, an empty QStringList is returned.

Parameters
keyThe name of the keyword
Returns
QStringList The list of values associated with the keyword

Definition at line 641 of file PvlFlatMap.cpp.

References keywordValues().

Referenced by Isis::Strategy::composite(), Isis::Strategy::importGeometry(), Isis::Strategy::propagateKeys(), and Isis::Strategy::translateKeywordArgs().

◆ append() [1/2]

void Isis::PvlFlatMap::append ( const PvlKeyword & key)

Appends the given PvlKeyword's values to the PvlFlatMap.

If the keyword already exists in the PvlFlatMap, the values of the provided keyword are appended to the keyword's list of values in the map.

Parameters
keyA PvlKeyword to append to the map.

Definition at line 529 of file PvlFlatMap.cpp.

References append(), exists(), Isis::PvlKeyword::name(), and Isis::PvlKeyword::size().

Referenced by append(), and append().

◆ append() [2/2]

void Isis::PvlFlatMap::append ( const QString & key,
const QString & value )

Appends a the given keyword and value to the PvlFlatMap.

If the keyword already exists in the PvlFlatMap, the provided value is appended to the keyword's list of values in the map.

Parameters
keyThe name of the keyword to be appended
valueThe value of the keyword to be appended

Definition at line 514 of file PvlFlatMap.cpp.

References append().

◆ count()

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

Returns the number of values associated with a given keyword.

If the keyword does not exist, this method returns 0.

Parameters
keyThe name of the keyword
Returns
int The number of values associated with the keyword.

Definition at line 450 of file PvlFlatMap.cpp.

References exists(), and keyword().

◆ erase()

bool Isis::PvlFlatMap::erase ( const QString & key)

Erases a keyword from the PvlFlatMap.

Parameters
keyThe keyword to erase
Returns
bool Indicates whether a keyword of the given name was found and succesfully erased.

Definition at line 557 of file PvlFlatMap.cpp.

◆ exists()

bool Isis::PvlFlatMap::exists ( const QString & key) const

Determines whether a given keyword exists in the PvlFlatMap.

Parameters
keyThe name of the keyword
Returns
bool True if the keyword exists in the PvlFlatMap

Definition at line 436 of file PvlFlatMap.cpp.

Referenced by append(), count(), Isis::Strategy::importGeometry(), isNull(), and Isis::Strategy::translateKeywordArgs().

◆ get() [1/2]

QString Isis::PvlFlatMap::get ( const QString & key,
const int & index = 0 ) const

Gets the value of a keyword in the PvlFlatMap.

By default, this method gets the first value associated with the passed keyword name. If the keyword does not exist, an exception is thrown.

Parameters
keyThe name of the keyword
indexThe index of the value to get
Returns
QString The keyword's value at the specified index
Exceptions
IException::Programmer"Keyword does not exist."
IException::Programmer"Index does not exist for the given keyword."

Definition at line 576 of file PvlFlatMap.cpp.

References Isis::IException::Programmer, and Isis::toString().

Referenced by Isis::Strategy::applyToIntersectedGeometry(), Isis::ShapeModelFactory::create(), Isis::Strategy::importGeometry(), operator()(), and Isis::Strategy::translateKeywordArgs().

◆ get() [2/2]

QString Isis::PvlFlatMap::get ( const QString & key,
const QString & defValue,
const int & index = 0 ) const

Gets the value of a keyword in the PvlFlatMap.

By default, this method gets the first value associated with the passed keyword name. If the keyword does not exist, this method returns the QString specified in defValue.

Parameters
keyThe name of the keyword
defValueThe default value to return if the keyword does not exist
indexThe index of the value to get
Returns
QString The keyword's value

Definition at line 604 of file PvlFlatMap.cpp.

◆ isNull()

bool Isis::PvlFlatMap::isNull ( const QString & key,
const int index = 0 ) const

Determines if the value of a keyword is Null.

By default, this method checks the first value associated with the passed keyword. If the keyword does not exist, this method returns true.

Parameters
keyThe name of the keyword
indexThe index of the value associated with the keyword
Returns
bool True if the keyword's value at the given index is Null or if the keyword does not exist

Definition at line 470 of file PvlFlatMap.cpp.

References exists(), isNull(), and keyword().

Referenced by isNull().

◆ keyword()

PvlKeyword Isis::PvlFlatMap::keyword ( const QString & key) const

Finds a keyword in the PvlFlatMap.

Parameters
keyThe name of the keyword to find
Returns
PvlKeyword The found keyword
Exceptions
IException::Programmer"Keyword does not exist"

Definition at line 660 of file PvlFlatMap.cpp.

References Isis::IException::Programmer.

Referenced by count(), isNull(), and keywordValues().

◆ keywordValues()

QStringList Isis::PvlFlatMap::keywordValues ( const PvlKeyword & keyword)
static

Gets all of a PvlKeyword's values.

(Helper method for PvlFlatMap::allValues)

Parameters
keywordThe PvlKeyword to get values from
Returns
QStringList A list of the PvlKeyword's values

Definition at line 702 of file PvlFlatMap.cpp.

References keyword(), and Isis::PvlKeyword::size().

Referenced by allValues().

◆ loadGroup()

int Isis::PvlFlatMap::loadGroup ( const PvlGroup & group,
const PvlConstraints & constraints )
private

Loads a PvlGroup into the PvlFlatMap.

This method is the loadGroups() helper method that loads a PvlGroup into the PvlFlatMap according to any provided PvlConstraints. If the PvlGroup is to be excluded, none of its contained PvlKeywords will be loaded. If the PvlGroup is to be included, only it and any other included PvlGroups will be loaded. When a PvlGroup can be loaded, the group's PvlKeywords are loaded against any keyword constraints. Returns the number of PvlKeywords loaded from the PvlGroup.

See also
loadKeywords()
Parameters
groupThe PvlGroup to load into the PvlFlatmap
constraintsAny PvlConstraints that determine how the PvlGroup should be loaded
Returns
int The number of PvlKewyords loaded from the PvlGroup

Definition at line 818 of file PvlFlatMap.cpp.

References loadKeywords(), and Isis::PvlContainer::name().

Referenced by loadGroups().

◆ loadGroups()

int Isis::PvlFlatMap::loadGroups ( const PvlObject & object,
const PvlConstraints & constraints )
private

Loads PvlGroups into the PvlFlatMap.

This method loads PvlGroups into the PvlFlatMap according to any provided PvlConstraints. This method iterates through a provided PvlObject and calls its helper method, loadGroup(), on each PvlGroup contained in the PvlObject. Returns the number of PvlKeywords loaded from the PvlGroups.

See also
loadGroup()
Parameters
objectThe PvlObject to load PvlGroups from
constraintsAny PvlConstraints that determine how PvlGroups should be loaded
Returns
int The number of PvlKeywords loaded from PvlGroups

Definition at line 788 of file PvlFlatMap.cpp.

References loadGroup().

Referenced by loadObject().

◆ loadKeywords()

int Isis::PvlFlatMap::loadKeywords ( const PvlContainer & pvl,
const PvlConstraints & constraints )
private

Loads PvlKeywords within a PvlContainer into the PvlFlatMap.

This method loads the PvlKeywords within a PvlContainer according to any PvlConstraints given.

If there is more than one PvlKeyword with the same name, then the last loaded keyword will overwrite the previous.

If any keyword constraints exist, only the PvlKeywords included in the keyword constraints will be loaded into the PvlFlatMap. If no keyword constraints are given all PvlKeywords in the PvlContainer will be included in the PvlFlatMap.

Returns the number of PvlKeywords in the provided PvlContainer that are loaded into the PvlFlatMap.

Parameters
pvlThe PvlContainer (i.e. PvlObject or PvlGroup) to load PvlKeywords from
constraintsThe keyword constraints that define which PvlKeyword will be loaded
Returns
int The number of PvlKeywords loaded into the PvlFlatMap

Definition at line 873 of file PvlFlatMap.cpp.

References add().

Referenced by loadGroup(), loadObject(), and PvlFlatMap().

◆ loadObject()

int Isis::PvlFlatMap::loadObject ( const PvlObject & object,
const PvlConstraints & constraints )
private

Loads PvlObjects into the PvlFlatMap.

This method loads PvlObjects into the PvlFlatMap according to any provided PvlConstraints. If a PvlObject is to be excluded, none of its contained PvlObjects, PvlGroups, or PvlKeywords will be loaded. If the PvlObject is to be included, only it and any other included PvlObjects will be loaded. When PvlObject can be loaded, any contained PvlKeywords, PvlGroups, and PvlObjects will be loaded against any provided PvlConstraints. After finishing loading any PvlKeywords and PvlGroups contained in the PvlObject, this method will try to load subsequent PvlObjects. Returns the total number of PvlKeywords loaded into the PvlFlatMap

See also
loadKeywords()
loadGroups()
Parameters
objectThe PvlObject to load PvlKeywords, PvlGroups, and PvlObjects from
constraintsAny PvlConstraints that define what is loaded into the PvlFlatMap
Returns
int The total number of PvlKeywords loaded into the PvlFlatMap

Definition at line 730 of file PvlFlatMap.cpp.

References loadGroups(), loadKeywords(), and loadObject().

Referenced by loadObject(), and PvlFlatMap().

◆ merge()

int Isis::PvlFlatMap::merge ( const PvlFlatMap & other)

Adds the keywords from another PvlFlatMap.

If there are keywords of the same in both maps, then the last loaded keyword in the "other" map will overwrite any previous values.

Parameters
otherThe PvlFlatMap to get keywords from
Returns
int The number of keywords added

Definition at line 680 of file PvlFlatMap.cpp.

References add().

Referenced by Isis::ShapeModelFactory::create(), PvlFlatMap(), and PvlFlatMap().

◆ operator()()

QString Isis::PvlFlatMap::operator() ( const QString & name) const

Gets the first value of a keyword in the PvlFlatMap.

This method will get the first value of the keyword if the keyword has multiple values associated with it.

Parameters
nameThe name of the keyword
Returns
QString The value of the keyword

Definition at line 627 of file PvlFlatMap.cpp.

References get().


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