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. More...
 
typedef QMap< QString, PvlKeyword >::iterator PvlFlatMapIterator
 An iterator for the underlying QMap that PvlFlatMap is built on. More...
 

Public Member Functions

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

Static Public Member Functions

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

Private Member Functions

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

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 236 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 240 of file PvlFlatMap.h.

◆ PvlFlatMapIterator

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

Definition at line 242 of file PvlFlatMap.h.

Constructor & Destructor Documentation

◆ PvlFlatMap() [1/5]

Isis::PvlFlatMap::PvlFlatMap ( )

Default constructor.

Definition at line 360 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 369 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 390 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 411 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 432 of file PvlFlatMap.cpp.

References loadKeywords().

◆ ~PvlFlatMap()

Isis::PvlFlatMap::~PvlFlatMap ( )
virtual

Destructor.

Definition at line 442 of file PvlFlatMap.cpp.

Member Function Documentation

◆ add() [1/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 505 of file PvlFlatMap.cpp.

Referenced by loadKeywords(), and merge().

◆ add() [2/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 517 of file PvlFlatMap.cpp.

References Isis::PvlKeyword::name().

◆ 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 658 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 546 of file PvlFlatMap.cpp.

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

Referenced by 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 531 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 467 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 574 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 453 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 593 of file PvlFlatMap.cpp.

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

Referenced by Isis::Strategy::applyToIntersectedGeometry(), Isis::ShapeModelFactory::create(), Isis::Strategy::importGeometry(), Isis::Strategy::initProgress(), Isis::Strategy::Strategy(), 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 621 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 487 of file PvlFlatMap.cpp.

References exists(), and keyword().

◆ 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 677 of file PvlFlatMap.cpp.

References _FILEINFO_, and 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 719 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 835 of file PvlFlatMap.cpp.

References Isis::PvlConstraints::excludeSize(), Isis::PvlConstraints::includeSize(), Isis::PvlConstraints::isExcluded(), Isis::PvlConstraints::isIncluded(), 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 805 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 890 of file PvlFlatMap.cpp.

References add(), Isis::PvlContainer::begin(), Isis::PvlContainer::end(), Isis::PvlConstraints::isKeyInList(), and Isis::PvlConstraints::keyListSize().

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 747 of file PvlFlatMap.cpp.

References Isis::PvlConstraints::excludeSize(), Isis::PvlConstraints::includeSize(), Isis::PvlConstraints::isExcluded(), Isis::PvlConstraints::isIncluded(), loadGroups(), and loadKeywords().

Referenced by 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 697 of file PvlFlatMap.cpp.

References add().

Referenced by Isis::ShapeModelFactory::create(), 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 644 of file PvlFlatMap.cpp.


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