version  0.0.1
Defines the C++ API for MsPASS
Loading...
Searching...
No Matches
Public Member Functions | List of all members
mspass::utility::AttributeCrossReference Class Reference

Cross reference between external and internal names. More...

#include <AttributeCrossReference.h>

Public Member Functions

 AttributeCrossReference ()
 
 AttributeCrossReference (const std::string lines_to_parse)
 
 AttributeCrossReference (const std::list< std::string > &lines)
 
 AttributeCrossReference (const std::map< std::string, std::string > internal2external, const mspass::utility::MetadataList &mdlist)
 
 AttributeCrossReference (const AttributeCrossReference &parent)
 
std::string internal (const std::string key) const
 
std::string external (const std::string key) const
 
MDtype type (const std::string key) const
 
AttributeCrossReferenceoperator= (const AttributeCrossReference &parent)
 
int size () const
 
void put (const std::string intern, const std::string ext)
 
std::set< std::string > internal_names () const
 
std::set< std::string > external_names () const
 

Detailed Description

Cross reference between external and internal names.

Data formats commonly have a frozen namespace with which people are very familiar. An example is SAC where scripts commonly manipulate header attribute by a fixed set of names. For good reasons one may want to use a different naming convention internally in a piece of software that loads data using an external format but wishes to use a different set of names internally. This object simplifies the task of managing the differences in internal and external names

Constructor & Destructor Documentation

◆ AttributeCrossReference() [1/5]

mspass::utility::AttributeCrossReference::AttributeCrossReference ( )
inline

Default constructor.

The default constructor is a pure placeholder that does nothing. Result is a null namespace mapper.

25{};

◆ AttributeCrossReference() [2/5]

mspass::utility::AttributeCrossReference::AttributeCrossReference ( const std::string  lines_to_parse)

Construct from a string.

This constructor assumes the string variable passed is a complete image of a set of (newline separated) lines defining the mapping. The format of each line is assumed to be: internal_name external_name type. As the names imply "internal_name" is the name to use internally and "external_name" is the foramt specific external name. The "type" variable is generic and should be one of the simple keywords real, int, string, or boolean.

Parameters
lines_to_parseis the (multiline) string in the format described above.
Exceptions
MsPASSErrorwill be thrown for parsing errors.

◆ AttributeCrossReference() [3/5]

mspass::utility::AttributeCrossReference::AttributeCrossReference ( const std::list< std::string > &  lines)

Construct from a list container.

This constructor is nearly identical to the single string with newline constructor. The list elements are expected to be the contents of each line (newline break) for the string version.

\lines list container with input lines in same format as that described above for single string constructor.

Exceptions
MsPASSErrorwill be thrown if there are parsing errors.

◆ AttributeCrossReference() [4/5]

mspass::utility::AttributeCrossReference::AttributeCrossReference ( const std::map< std::string, std::string >  internal2external,
const mspass::utility::MetadataList &  mdlist 
)

Build for a set of STL containers.

This is lower level constructor that effectively builds this object from a set of components that are used to actually implement the concept.

Parameters
internal2externalis an associative array keyed by the internal name that defines external names linked to each internal name.
mdlistis a MsPASS::MetadataList object defining the complete internal namespace.

◆ AttributeCrossReference() [5/5]

mspass::utility::AttributeCrossReference::AttributeCrossReference ( const AttributeCrossReference parent)

Standard copy constructor.

90 {
91 itoe = parent.itoe;
92 etoi = parent.etoi;
93 imdtypemap = parent.imdtypemap;
94}

Member Function Documentation

◆ external()

string mspass::utility::AttributeCrossReference::external ( const std::string  key) const

Get external name for attribute with internal name key.

113 {
114 map<string, string>::const_iterator iptr;
115 iptr = itoe.find(key);
116 if (iptr == itoe.end())
117 throw MsPASSError(string("AttribureCrossReference::external: ") +
118 "Cannot find attribute " + key +
119 " in internal to external namespace map");
120 return (iptr->second);
121}
Base class for error object thrown by MsPASS library routines.
Definition MsPASSError.h:38

◆ external_names()

set< string > mspass::utility::AttributeCrossReference::external_names ( ) const

Return the set of external names defined by this object.

Returns an std::set container of strings that are the external names defined by this object.

150 {
151 map<string, string>::const_iterator mptr;
152 set<string> keys;
153 for (mptr = etoi.begin(); mptr != etoi.end(); ++mptr) {
154 keys.insert(mptr->first);
155 }
156 return keys;
157}

◆ internal()

string mspass::utility::AttributeCrossReference::internal ( const std::string  key) const

Get internal name for attribute with external name key.

104 {
105 map<string, string>::const_iterator iptr;
106 iptr = etoi.find(key);
107 if (iptr == etoi.end())
108 throw MsPASSError(string("AttribureCrossReference::internal: ") +
109 "Cannot find attribute " + key +
110 " in external to internal namespace map");
111 return (iptr->second);
112}

◆ internal_names()

set< string > mspass::utility::AttributeCrossReference::internal_names ( ) const

Return the set of internal names defined by this object.

Returns an std::set container of strings that are the internal names defined by this object.

142 {
143 map<string, string>::const_iterator mptr;
144 set<string> keys;
145 for (mptr = itoe.begin(); mptr != itoe.end(); ++mptr) {
146 keys.insert(mptr->first);
147 }
148 return keys;
149}

◆ operator=()

AttributeCrossReference & mspass::utility::AttributeCrossReference::operator= ( const AttributeCrossReference parent)

Standard assignment operator.

96 {
97 if (this != &parent) {
98 itoe = parent.itoe;
99 etoi = parent.etoi;
100 imdtypemap = parent.imdtypemap;
101 }
102 return (*this);
103}

◆ put()

void mspass::utility::AttributeCrossReference::put ( const std::string  intern,
const std::string  ext 
)

Add a new entry to the map.

This method is used to extend the namespace.

Parameters
internis the internal name
extis the external name to be added.
134 {
135 itoe.insert(pair<string, string>(i, e));
136 etoi.insert(pair<string, string>(e, i));
137}

◆ size()

int mspass::utility::AttributeCrossReference::size ( ) const

Return number of entries in the cross reference map.

130 {
131 // Assume the two maps are the same size
132 return (itoe.size());
133}

◆ type()

MDtype mspass::utility::AttributeCrossReference::type ( const std::string  key) const

Get type information for attribute with internal name key.

122 {
123 map<string, MDtype>::const_iterator iptr;
124 iptr = imdtypemap.find(key);
125 if (iptr == imdtypemap.end())
126 throw MsPASSError(string("AttributeCrossReference::type: ") +
127 "Cannot find attribute " + key + " in type definitions");
128 return (iptr->second);
129}

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