Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

xmlUtil::IdConversion Class Reference

An IdConversion object (corresponding to an idConv element as defined in gdd.dtd) "has" a path (list of id field names) a condition an operation to be performed on identifiers starting with the specified path and satisfying the condition and producing a new NamedId. More...

#include <IdConversion.h>

List of all members.

Public Methods

 IdConversion ()
 Default constructor produces a conversion which acts on any NamedId and does nothing to it; that is, returns a copy. More...

 IdConversion (const DOM_Element)
 The usual case: build a conversion from its XML description. More...

 ~IdConversion ()
bool inDomain (const NamedId &inputId)
 Check that start of inputId fieldnames match path. More...

NamedIdconvert (const NamedId &inputId)
 Convert the identifier if in domain; else return null. More...

bool subpathOf (const IdConversion &other) const
 Return true if our path is subpath of other. More...


Private Types

typedef std::string Condition
 For now only condition recognized is hasField, which can be represented by a string: the field name. More...


Private Methods

bool satisfies (const NamedId &inputId)
NamedIdinternalConvert (const NamedId &inputId)
 Doesn't check that input is in domain. Typically invoked from convert. More...

void makePath (const DOM_Element &pathElt)
 Form path component from corresponding piece of xml. More...

void buildOp (const DOM_Element &optElt)
 Determine operation type and instantiate object of appropriate operation class. More...


Private Attributes

NameSeqm_path
 Defines domain of conversion. More...

Conditionm_condition
 Given an identifier in domain, convert if condition is satisfied. More...

IdOperationm_op
 op knows how to do a conversion. More...


Friends

class IdConverterLessThan
std::ostream & operator<< (std::ostream &s, const IdConversion &convers)


Detailed Description

An IdConversion object (corresponding to an idConv element as defined in gdd.dtd) "has" a path (list of id field names) a condition an operation to be performed on identifiers starting with the specified path and satisfying the condition and producing a new NamedId.

Definition at line 23 of file IdConversion.h.


Member Typedef Documentation

typedef std::string xmlUtil::IdConversion::Condition [private]
 

For now only condition recognized is hasField, which can be represented by a string: the field name.

Definition at line 68 of file IdConversion.h.


Constructor & Destructor Documentation

xmlUtil::IdConversion::IdConversion  
 

Default constructor produces a conversion which acts on any NamedId and does nothing to it; that is, returns a copy.

Definition at line 12 of file IdConversion.cxx.

References m_op.

00012                              : m_path(0), m_condition(0) {
00013     m_op = new IdOperation();
00014   }

xmlUtil::IdConversion::IdConversion const DOM_Element    conversion
 

The usual case: build a conversion from its XML description.

Definition at line 16 of file IdConversion.cxx.

References buildOp(), m_condition, and makePath().

00016                                                    {
00017 
00018     // Get first child; invoke private function to build path
00019     DOM_Element child = xml::Dom::getFirstChildElement(conversion);
00020     makePath(child);
00021 
00022     // Get next child; save field name in condition component
00023     child = xml::Dom::getSiblingElement(child);
00024     m_condition = new std::string(xml::Dom::getAttribute(child, "name"));
00025 
00026     // Get next child;  build new op component.
00027     child = xml::Dom::getSiblingElement(child);
00028     buildOp(child);
00029   }

xmlUtil::IdConversion::~IdConversion  
 


Member Function Documentation

void xmlUtil::IdConversion::buildOp const DOM_Element &    opElt [private]
 

Determine operation type and instantiate object of appropriate operation class.

Definition at line 72 of file IdConversion.cxx.

References m_op.

Referenced by IdConversion().

00072                                                      {
00073     DOMString opType = opElt.getTagName();
00074 
00075     if (opType.equals("truncate"))
00076     {
00077       m_op = new IdOpTruncate(opElt);
00078     }
00079     else if (opType.equals("disappear")) {
00080       m_op = new IdOpDisappear(opElt);
00081     }
00082     else if (opType.equals(DOMString("compress"))) {
00083       m_op = new IdOpCompress(opElt);
00084     }
00085     else { // default to identity operation, implemented by base class
00086       m_op = new IdOperation(opElt);
00087     }
00088   }

NamedId * xmlUtil::IdConversion::convert const NamedId   inputId
 

Convert the identifier if in domain; else return null.

Definition at line 41 of file IdConversion.cxx.

References inDomain(), and internalConvert().

00041                                                         {
00042     if (!inDomain(inputId)) return 0;
00043     return internalConvert(inputId);
00044   }

bool xmlUtil::IdConversion::inDomain const NamedId   inputId
 

Check that start of inputId fieldnames match path.

Definition at line 31 of file IdConversion.cxx.

References m_path.

Referenced by convert().

00031                                                     {
00032     return inputId.hasSubpath(*m_path);
00033   }

NamedId * xmlUtil::IdConversion::internalConvert const NamedId   inputId [private]
 

Doesn't check that input is in domain. Typically invoked from convert.

Definition at line 46 of file IdConversion.cxx.

References m_op, and satisfies().

Referenced by convert().

00046                                                                 {
00047     if (satisfies(inputId)) {  // let the operation do its thing
00048       return m_op->convert(inputId);
00049     }
00050     else { // clone input and return
00051       return new NamedId(inputId);
00052     }
00053   }

void xmlUtil::IdConversion::makePath const DOM_Element &    pathElt [private]
 

Form path component from corresponding piece of xml.

Definition at line 55 of file IdConversion.cxx.

References m_path, and xmlUtil::NameSeq.

Referenced by IdConversion().

00055                                                         {
00056     
00057     // "path" consists of a list of fields.  Fields have 
00058     // a required attribute "name".  Save its value.
00059     m_path = new NameSeq;
00060     DOM_Element child = xml::Dom::getFirstChildElement(pathElt);
00061 
00062     while (child != DOM_Element()) {
00063       m_path->push_back(new std::string(xml::Dom::getAttribute(child, "name")));
00064       child = xml::Dom::getSiblingElement(child);
00065     }
00066 
00067   }

bool xmlUtil::IdConversion::satisfies const NamedId   inputId [private]
 

Definition at line 35 of file IdConversion.cxx.

References m_condition.

Referenced by internalConvert().

00035                                                      {
00036     if (m_condition == 0) return true;
00037 
00038     return (inputId.hasField(*m_condition) >= 0);
00039   }

bool xmlUtil::IdConversion::subpathOf const IdConversion &    other const
 

Return true if our path is subpath of other.

Definition at line 91 of file IdConversion.cxx.

References m_path.

00091                                                               {
00092     unsigned int ourLen = m_path->size();
00093     if (ourLen > other.m_path->size() ) return false;
00094 
00095     for (unsigned int ix = 0; ix < ourLen; ix++) {
00096       if ((*(other.m_path))[ix]->compare((*(*m_path)[ix])) ) return false;
00097     }
00098     return true;
00099   }


Friends And Related Function Documentation

friend class IdConverterLessThan [friend]
 

Definition at line 49 of file IdConversion.h.

std::ostream& operator<< std::ostream &    s,
const IdConversion &    convers
[friend]
 

Definition at line 101 of file IdConversion.cxx.

00101                                                                      {
00102     s << (*(convers.m_op)) << std::endl << " Path: " << (*(convers.m_path)) << 
00103       " Condition: hasField " << (*(convers.m_condition));
00104     return s;
00105   }


Member Data Documentation

Condition* xmlUtil::IdConversion::m_condition [private]
 

Given an identifier in domain, convert if condition is satisfied.

Definition at line 75 of file IdConversion.h.

Referenced by IdConversion(), and satisfies().

IdOperation* xmlUtil::IdConversion::m_op [private]
 

op knows how to do a conversion.

Definition at line 78 of file IdConversion.h.

Referenced by buildOp(), IdConversion(), and internalConvert().

NameSeq* xmlUtil::IdConversion::m_path [private]
 

Defines domain of conversion.

Definition at line 72 of file IdConversion.h.

Referenced by inDomain(), makePath(), and subpathOf().


The documentation for this class was generated from the following files:
Generated on Wed Oct 16 14:02:50 2002 by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001