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

xmlUtil::IdConverter Class Reference

An IdConverter is a collection of id conversions and associated functions to (1) verify self-consistency of the converter (2) apply the correct conversion to a supplied Identifier. More...

#include <IdConverter.h>

List of all members.

Public Types

typedef std::vector< IdConversion *> Conversions
typedef Conversions::iterator ConversionIt

Public Methods

 IdConverter (DOM_Element elt)
 ~IdConverter ()
std::ostream & displayConversions (std::ostream &s)
NamedIdconvert (const NamedId *in) const
 Return the result of converting a single NamedId. More...

Identifierconvert (const Identifier *inIdent) const
 Return the result of converting a single Identifier. More...

bool isConsistent ()

Private Types

enum  STATES { UNKNOWN = -1, NO = 0, YES = 1 }

Private Methods

void sortConvs ()

Private Attributes

std::string * inputDictName
IdDictinputDict
std::string * outputDictName
IdDictoutputDict
Conversions m_convCol
STATES m_consistent
STATES m_sorted

Static Private Attributes

IdDictMandictMan = 0


Detailed Description

An IdConverter is a collection of id conversions and associated functions to (1) verify self-consistency of the converter (2) apply the correct conversion to a supplied Identifier.

Definition at line 20 of file IdConverter.h.


Member Typedef Documentation

typedef Conversions::iterator xmlUtil::IdConverter::ConversionIt
 

Definition at line 67 of file IdConverter.h.

Referenced by sortConvs().

typedef std::vector<IdConversion*> xmlUtil::IdConverter::Conversions
 

Definition at line 66 of file IdConverter.h.


Member Enumeration Documentation

enum xmlUtil::IdConverter::STATES [private]
 

Enumeration values:
UNKNOWN 
NO 
YES 

Definition at line 88 of file IdConverter.h.

00088                 {
00089       UNKNOWN = -1,
00090       NO = 0,
00091       YES = 1};


Constructor & Destructor Documentation

xmlUtil::IdConverter::IdConverter DOM_Element    elt
 

Build IdConverter from its XML representation. Assume that the containing document has already been "normalized" in the sense that constants evaluation and substitution has been done.

Definition at line 16 of file IdConverter.cxx.

References dictMan, inputDict, inputDictName, isConsistent(), m_convCol, outputDict, and outputDictName.

00016                                           : m_consistent(UNKNOWN),
00017   m_sorted(NO) {
00018     if (!dictMan) dictMan = IdDictMan::getPointer();
00019 
00020     // An idConverter element may optionally have as first child
00021     // a constants element, but we're assuming that the XML document
00022     // has already had constants evaluation and substitution done
00023     // on it, if necessary.
00024     // Assume that any constant evaluations and substitutions have
00025     // already been dealt with 
00026     DOM_Element child = xml::Dom::getFirstChildElement(elt);
00027 
00028     if ( (child.getTagName()).equals(DOMString("constants")) ) { // move on
00029       child = xml::Dom::getSiblingElement(child);
00030     }
00031     while ( (child.getTagName()).equals(DOMString("idDict")) ) {
00032       IdDict* dict = new IdDict(child);
00033       dictMan->registerDict(dict);
00034       child = xml::Dom::getSiblingElement(child);
00035     }
00036 
00037     // Now that all id dictionaries we need should have been defined,
00038     // handle attributes
00039     std::string dictName = xml::Dom::getAttribute(elt, "fromDict");
00040     if (dictName.size() > 0 ) {  // then it's not just an empty string
00041       inputDictName = new std::string(dictName);
00042       inputDict = dictMan->findDict(dictName);
00043     }
00044     dictName = xml::Dom::getAttribute(elt, "toDict");
00045     if (dictName.size() > 0 ) {
00046       outputDictName = new std::string(dictName);
00047       outputDict = dictMan->findDict(dictName);
00048     }
00049 
00050     // All remaining elements should be idConv
00051     while (child != DOM_Element() ) {
00052       IdConversion *conv = new IdConversion(child);
00053       m_convCol.push_back(conv);
00054       child = xml::Dom::getSiblingElement(child);
00055     }
00056 
00057     // check for consistency before unleashing this object
00058     isConsistent();
00059   }

xmlUtil::IdConverter::~IdConverter  
 

Definition at line 61 of file IdConverter.cxx.

References m_convCol.

00061                             {
00062     m_convCol.clear();
00063   }


Member Function Documentation

Identifier * xmlUtil::IdConverter::convert const Identifier   inIdent const
 

Return the result of converting a single Identifier.

Can only do this if there is an input IdDict so that the IdDict can be asked for the NamedId corresponding to the Identifier

Definition at line 113 of file IdConverter.cxx.

References convert(), inputDict, m_consistent, and NO.

00113                                                                   {
00114     if (!inputDict) return 0;  // can't get names without dictionary
00115 
00116     if (m_consistent == NO) return 0;
00117 
00118     NamedId *inNamed = inputDict->getNamedId(*inIdent);
00119     if (inNamed == 0) return 0;
00120 
00121     NamedId *outNamed = convert(inNamed);
00122     
00123     Identifier *converted = outNamed->stripNames();
00124     delete inNamed;
00125     delete outNamed;
00126     return converted;
00127   }

NamedId * xmlUtil::IdConverter::convert const NamedId   in const
 

Return the result of converting a single NamedId.

Definition at line 97 of file IdConverter.cxx.

References m_consistent, m_convCol, and NO.

Referenced by convert(), and testConverter().

00097                                                        {
00098     unsigned int ix;
00099 
00100     if (m_consistent == NO) return 0;
00101 
00102     // Based on path, find appropriate conversion, if any
00103     for (ix = 0; ix < m_convCol.size(); ix++) {
00104       if ((m_convCol[ix])->inDomain(*in)) {  // convert
00105         return (m_convCol[ix]->convert(*in));
00106       }
00107     }
00108     //       else return copy of input  
00109     return new NamedId(*in);
00110   }

std::ostream & xmlUtil::IdConverter::displayConversions std::ostream &    s
 

Definition at line 129 of file IdConverter.cxx.

References m_convCol.

Referenced by main().

00129                                                            {
00130     Conversions::const_iterator it = m_convCol.begin();
00131 
00132     while (it != m_convCol.end() ) {
00133       s << (**it) << std::endl;
00134       ++it;
00135     }
00136     return s;
00137   }

bool xmlUtil::IdConverter::isConsistent  
 

Check that conversions comprising the converter have disjoint domains. This is equivalent to checking that no conversion has a path which is an initial subsequence of the path for another conversion.

Definition at line 75 of file IdConverter.cxx.

References m_consistent, m_convCol, NO, sortConvs(), UNKNOWN, and YES.

Referenced by IdConverter(), and testConverter().

00075                                  {
00076     if (m_consistent == UNKNOWN) {
00077       sortConvs();
00078       // Check whether a path is a subsequence of some other path,
00079       // unfortunately an o(n**2) procedure
00080       unsigned int ix, jx;
00081       for (ix = 0; ix < (m_convCol.size() - 1); ix++ ) {
00082         for (jx = ix + 1; jx < (m_convCol.size()); jx++) {
00083           // Since conversions are ordered by size, only need
00084           // to check whether ix-th path is subpath of jx-th,
00085           // not the reverse
00086           if (m_convCol[ix]->subpathOf(*(m_convCol[jx]))) {
00087             m_consistent = NO;
00088             return m_consistent;
00089           }
00090         }
00091       }
00092       m_consistent = YES;
00093     }
00094     return m_consistent;
00095   }

void xmlUtil::IdConverter::sortConvs   [private]
 

It's convenient to have the conversions sorted by length of path when checking for consistency.

Definition at line 66 of file IdConverter.cxx.

References ConversionIt, m_convCol, m_sorted, and YES.

Referenced by isConsistent().

00066                               {
00067     if (m_sorted != YES) {
00068       ConversionIt start = m_convCol.begin(), last = m_convCol.end();
00069       IdConverterLessThan weakOrder;
00070       std::sort(start, last, weakOrder);  // sort them
00071       m_sorted = YES;
00072     }
00073   }


Member Data Documentation

IdDictMan * xmlUtil::IdConverter::dictMan = 0 [static, private]
 

Definition at line 14 of file IdConverter.cxx.

Referenced by IdConverter().

IdDict* xmlUtil::IdConverter::inputDict [private]
 

Definition at line 72 of file IdConverter.h.

Referenced by convert(), and IdConverter().

std::string* xmlUtil::IdConverter::inputDictName [private]
 

Definition at line 71 of file IdConverter.h.

Referenced by IdConverter().

STATES xmlUtil::IdConverter::m_consistent [private]
 

Definition at line 93 of file IdConverter.h.

Referenced by convert(), and isConsistent().

Conversions xmlUtil::IdConverter::m_convCol [private]
 

Definition at line 86 of file IdConverter.h.

Referenced by convert(), displayConversions(), IdConverter(), isConsistent(), sortConvs(), and ~IdConverter().

STATES xmlUtil::IdConverter::m_sorted [private]
 

Definition at line 94 of file IdConverter.h.

Referenced by sortConvs().

IdDict* xmlUtil::IdConverter::outputDict [private]
 

Definition at line 76 of file IdConverter.h.

Referenced by IdConverter().

std::string* xmlUtil::IdConverter::outputDictName [private]
 

Definition at line 75 of file IdConverter.h.

Referenced by IdConverter().


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