version  0.0.1
Defines the C++ API for MsPASS
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.

27 {};

◆ 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.

97 {
98  itoe=parent.itoe;
99  etoi=parent.etoi;
100  imdtypemap=parent.imdtypemap;
101 }

Member Function Documentation

◆ external()

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

Get external name for attribute with internal name key.

124 {
125  map<string,string>::const_iterator iptr;
126  iptr=itoe.find(key);
127  if(iptr==itoe.end())
128  throw MsPASSError(string("AttribureCrossReference::external: ")
129  + "Cannot find attribute "+key
130  + " in internal to external namespace map");
131  return(iptr->second);
132 }
Base class for error object thrown by MsPASS library routines.
Definition: MsPASSError.h:40

◆ 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.

168 {
169  map<string,string>::const_iterator mptr;
170  set<string> keys;
171  for(mptr=etoi.begin();mptr!=etoi.end();++mptr)
172  {
173  keys.insert(mptr->first);
174  }
175  return keys;
176 }

◆ internal()

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

Get internal name for attribute with external name key.

114 {
115  map<string,string>::const_iterator iptr;
116  iptr=etoi.find(key);
117  if(iptr==etoi.end())
118  throw MsPASSError(string("AttribureCrossReference::internal: ")
119  + "Cannot find attribute "+key
120  + " in external to internal namespace map");
121  return(iptr->second);
122 }

◆ 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.

158 {
159  map<string,string>::const_iterator mptr;
160  set<string> keys;
161  for(mptr=itoe.begin();mptr!=itoe.end();++mptr)
162  {
163  keys.insert(mptr->first);
164  }
165  return keys;
166 }

◆ operator=()

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

Standard assignment operator.

104 {
105  if(this!=&parent)
106  {
107  itoe=parent.itoe;
108  etoi=parent.etoi;
109  imdtypemap=parent.imdtypemap;
110  }
111  return(*this);
112 }

◆ 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.
149 {
150  itoe.insert(pair<string,string>(i,e));
151  etoi.insert(pair<string,string>(e,i));
152 }

◆ size()

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

Return number of entries in the cross reference map.

144 {
145  // Assume the two maps are the same size
146  return(itoe.size());
147 }

◆ type()

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

Get type information for attribute with internal name key.

134 {
135  map<string,MDtype>::const_iterator iptr;
136  iptr=imdtypemap.find(key);
137  if(iptr==imdtypemap.end())
138  throw MsPASSError(string("AttributeCrossReference::type: ")
139  + "Cannot find attribute "+key
140  + " in type definitions");
141  return(iptr->second);
142 }

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