#include <IdConverter.h>
Public Types | |
| typedef std::vector< IdConversion *> | Conversions |
| typedef Conversions::iterator | ConversionIt |
Public Methods | |
| IdConverter (DOM_Element elt) | |
| ~IdConverter () | |
| std::ostream & | displayConversions (std::ostream &s) |
| NamedId * | convert (const NamedId *in) const |
| Return the result of converting a single NamedId. More... | |
| Identifier * | convert (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 |
| IdDict * | inputDict |
| std::string * | outputDictName |
| IdDict * | outputDict |
| Conversions | m_convCol |
| STATES | m_consistent |
| STATES | m_sorted |
Static Private Attributes | |
| IdDictMan * | dictMan = 0 |
Definition at line 20 of file IdConverter.h.
|
|
Definition at line 67 of file IdConverter.h. Referenced by sortConvs(). |
|
|
Definition at line 66 of file IdConverter.h. |
|
|
Definition at line 88 of file IdConverter.h.
|
|
|
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 } |
|
|
Definition at line 61 of file IdConverter.cxx. References m_convCol.
00061 {
00062 m_convCol.clear();
00063 }
|
|
|
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 }
|
|
|
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 }
|
|
|
Definition at line 129 of file IdConverter.cxx. References m_convCol. Referenced by main().
|
|
|
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 }
|
|
|
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().
|
|
|
Definition at line 14 of file IdConverter.cxx. Referenced by IdConverter(). |
|
|
Definition at line 72 of file IdConverter.h. Referenced by convert(), and IdConverter(). |
|
|
Definition at line 71 of file IdConverter.h. Referenced by IdConverter(). |
|
|
Definition at line 93 of file IdConverter.h. Referenced by convert(), and isConsistent(). |
|
|
Definition at line 86 of file IdConverter.h. Referenced by convert(), displayConversions(), IdConverter(), isConsistent(), sortConvs(), and ~IdConverter(). |
|
|
Definition at line 94 of file IdConverter.h. Referenced by sortConvs(). |
|
|
Definition at line 76 of file IdConverter.h. Referenced by IdConverter(). |
|
|
Definition at line 75 of file IdConverter.h. Referenced by IdConverter(). |
1.2.13.1 written by Dimitri van Heesch,
© 1997-2001