#include <DictConstraints.h>
Public Methods | |
| DictConstraints (DOM_Element elt) | |
| Build constraints object from xml representation. More... | |
| bool | equals (const DictConstraints &other) |
| ~DictConstraints () | |
| bool | allowed (const unsigned value) const |
| Does the specified value satisfy the constraints? More... | |
| bool | allowed (const DictConstraints &other) const |
| Are the constraints of the argument a refinement (i.e., define a subset of possible values)? More... | |
| bool | allowed (DictConstraints *other) const |
| bool | disjoint (const DictConstraints &other) const |
| bool | disjoint (DictConstraints *other) const |
| unsigned | getMin () const |
| unsigned | getMax () const |
| void | insertValues (std::set< unsigned > &aSet) const |
| Add our allowed values to specified set so we can use set operations to look for overlap. More... | |
| DictConstraints (const DictConstraints &toCopy) | |
| DictConstraints & | operator= (const DictConstraints &) |
Private Types | |
| typedef std::vector< unsigned > | DictValList |
| enum | eStyle { ESTYLE_uninit = 0, ESTYLE_single = 1, ESTYLE_interval = 2, ESTYLE_list = 3 } |
Private Methods | |
| void | deepCopy (const DictConstraints &toCopy) |
| Utility used by copy constructor, copy assignment operator. More... | |
| DictConstraints () | |
| Will be initialized correctly even for list Default constructor, not normally invoked. More... | |
| eStyle | getType () const |
| DictConstraints (const unsigned soleValue) | |
| DictConstraints (const unsigned min, const unsigned max) | |
| DictConstraints (const DictValList *const list) | |
Private Attributes | |
| eStyle | m_style |
| DictValList * | m_valList |
| unsigned | m_minVal |
| unsigned | m_maxVal |
| Will be initialized correctly even for list. More... | |
Definition at line 15 of file DictConstraints.h.
|
|
Definition at line 47 of file DictConstraints.h. Referenced by deepCopy(), DictConstraints(), and getType(). |
|
|
Definition at line 52 of file DictConstraints.h. Referenced by getType().
00052 {
00053 ESTYLE_uninit = 0,
00054 ESTYLE_single = 1,
00055 ESTYLE_interval = 2,
00056 ESTYLE_list = 3
00057 };
|
|
|
Build constraints object from xml representation. One and only public constructor. Note that constraints specified as a list in xml, but describable in terms of a min and max bound will be represented in terms of the bounds. The list representation is only used when there is no other option. Definition at line 17 of file DictConstraints.cxx. References ESTYLE_interval, ESTYLE_list, ESTYLE_single, ESTYLE_uninit, m_maxVal, m_minVal, m_style, and m_valList. Referenced by getMax(), and ~DictConstraints().
00017 : 00018 m_style(ESTYLE_uninit), m_valList(0), m_minVal(0), m_maxVal(0) 00019 { 00020 DOMString vType = elt.getTagName(); 00021 if (vType.equals("vEnumVal")) { 00022 DOMString attVal = elt.getAttribute("value"); 00023 m_minVal = atoi(xml::Dom::transToChar(attVal)); 00024 m_maxVal = m_minVal; 00025 m_style = ESTYLE_single; 00026 } 00027 else if (vType.equals("vMinMax") ) { 00028 DOMString minVal = elt.getAttribute("min"); 00029 m_minVal = atoi(xml::Dom::transToChar(minVal)); 00030 DOMString maxVal = elt.getAttribute("max"); 00031 m_maxVal = atoi(xml::Dom::transToChar(maxVal)); 00032 m_style = (m_minVal == m_maxVal) ? ESTYLE_single : ESTYLE_interval; 00033 } 00034 // Probably should revise this to sort the list before storing 00035 // For now, just update min and max correctly 00036 else if (vType.equals("vList")) { 00037 m_minVal = 0xffffffff; 00038 00039 DOM_NodeList children = elt.getChildNodes(); 00040 unsigned nChild = children.getLength(); 00041 if (nChild == 0) { 00042 m_style = ESTYLE_uninit; 00043 return; 00044 } 00045 m_valList = new std::vector<unsigned>(nChild); 00046 for (unsigned ix = 0; ix < nChild; ix++) { 00047 int temp; 00048 DOM_Node childNode = children.item(ix); 00049 DOM_Element child = static_cast<DOM_Element &>(childNode); 00050 temp = 00051 atoi(xml::Dom::transToChar(child.getAttribute("value"))); 00052 if (temp < 0) { 00053 //complain 00054 } 00055 else { 00056 unsigned newVal = temp; 00057 m_valList->push_back(newVal); 00058 if (newVal < m_minVal) m_minVal = newVal; 00059 if (newVal > m_maxVal) m_maxVal = newVal; 00060 } 00061 } 00062 // if ((m_minVal < 0 ) || (m_maxVal < 0)) { 00063 //complain 00064 // } 00065 00066 // Check if it's really an interval after all. Look for all 00067 // inbetween elements 00068 if (m_valList) { 00069 for (unsigned iy = m_minVal + 1; iy < m_maxVal; iy++) { 00070 // if there is anything we can't find, we really need a list 00071 if (std::find(m_valList->begin(), m_valList->end(), iy) == 00072 m_valList->end()) { 00073 m_style = ESTYLE_list; 00074 return; 00075 } 00076 } 00077 // Everything was there. The bounds are sufficient. 00078 delete m_valList; 00079 m_style = (m_minVal == m_maxVal) ? ESTYLE_single : ESTYLE_interval; 00080 m_valList = 0; 00081 } 00082 } 00083 } |
|
|
Definition at line 21 of file DictConstraints.h. References DictConstraints(), and m_valList.
00021 {if (m_valList) delete m_valList;}
|
|
|
Definition at line 106 of file DictConstraints.cxx. References deepCopy().
00106 {
00107 deepCopy(toCopy);
00108 }
|
|
|
Will be initialized correctly even for list Default constructor, not normally invoked.
Definition at line 65 of file DictConstraints.h. References ESTYLE_uninit, m_style, and m_valList.
00065 : m_style(ESTYLE_uninit), m_valList(0) {}; |
|
|
Definition at line 85 of file DictConstraints.cxx.
00085 : 00086 m_style(ESTYLE_single), m_valList(0), m_minVal(soleValue), 00087 m_maxVal(soleValue) {} |
|
||||||||||||
|
Definition at line 89 of file DictConstraints.cxx.
00089 : 00090 m_style(ESTYLE_interval), m_valList(0), 00091 m_minVal(min), m_maxVal(max) {} |
|
|
Definition at line 93 of file DictConstraints.cxx. References DictValList, m_maxVal, m_minVal, and m_valList.
00093 : 00094 m_style(ESTYLE_list) { 00095 m_valList = new DictValList(*list); 00096 m_minVal = 0xffffffff; 00097 m_maxVal = 0; 00098 for (DictValList::iterator it = (unsigned int *) list->begin(); 00099 it != list->end(); ++it) { 00100 const unsigned val = *it; 00101 if (val > m_maxVal) m_maxVal = val; 00102 if (val < m_minVal) m_minVal = val; 00103 } 00104 } |
|
|
Definition at line 157 of file DictConstraints.cxx. References allowed().
00157 {
00158 return allowed(*other);
00159 }
|
|
|
Are the constraints of the argument a refinement (i.e., define a subset of possible values)?
Definition at line 161 of file DictConstraints.cxx. References allowed(), m_maxVal, m_minVal, and m_valList.
00161 {
00162
00163 bool boundsOk = ((other.m_minVal >= m_minVal) &&
00164 (other.m_maxVal <= m_maxVal) );
00165 // if this isn't a list, this is all there is to check
00166 if (m_valList == 0) return boundsOk;
00167 // If either has a list of values, bounds must still be ok
00168 if (!(boundsOk)) return false;
00169
00170 // All that's left to check is case where this has a list
00171 // and bounds are ok. Just do the brute force thing and
00172 // check each possible value separately. This would be horrible
00173 // if both were large enumerated sets, but it's very unlikely
00174 // that large sets will be described as a list rather than as an
00175 // interval
00176
00177 else if (other.m_valList) {
00178 for (unsigned ix = 0; ix < (other.m_valList)->size(); ix++) {
00179 if (!allowed((*(other.m_valList))[ix])) return false;
00180 }
00181 }
00182 else { // other is interval-type constraint
00183 for (unsigned iy = other.m_minVal; iy <= other.m_maxVal; iy++) {
00184 if (!allowed(iy)) return false;
00185 }
00186 }
00187 return true;
00188 }
|
|
|
Does the specified value satisfy the constraints?
Definition at line 141 of file DictConstraints.cxx. References ESTYLE_interval, ESTYLE_list, ESTYLE_single, m_maxVal, m_minVal, and m_valList. Referenced by allowed().
00141 {
00142 switch(m_style) {
00143 case ESTYLE_single: return (value == m_minVal);
00144 case ESTYLE_interval:
00145 return ((value >= m_minVal) & (value <= m_maxVal));
00146 case ESTYLE_list:
00147 return
00148 (std::find(m_valList->begin(), m_valList->end(), value) !=
00149 m_valList->end());
00150 default:
00151
00152 return false;
00153 }
00154 return false;
00155 }
|
|
|
Utility used by copy constructor, copy assignment operator.
Definition at line 110 of file DictConstraints.cxx. References DictValList, m_maxVal, m_minVal, m_style, and m_valList. Referenced by DictConstraints(), and operator=().
|
|
|
Definition at line 205 of file DictConstraints.cxx. References disjoint().
00205 {
00206 return disjoint(*other);
00207 }
|
|
|
Definition at line 190 of file DictConstraints.cxx. References m_maxVal, m_minVal, and m_valList. Referenced by disjoint().
00190 {
00191 if ((other.m_minVal > m_maxVal) ||
00192 (other.m_maxVal < m_minVal)) return true;
00193 // If either is an interval, we'll have an intersection
00194 if ((!m_valList) || (!other.m_valList)) return false;
00195
00196 // Both are lists. Check for duplicates one at a time
00197 for (DictValList::iterator it = m_valList->begin();
00198 it !=m_valList->end(); ++it) {
00199 unsigned val = *it;
00200 if (other.allowed(val)) return false;
00201 }
00202 return true;
00203 }
|
|
|
Definition at line 130 of file DictConstraints.cxx. References ESTYLE_list, m_maxVal, m_minVal, m_style, and m_valList.
|
|
|
Definition at line 34 of file DictConstraints.h. References DictConstraints(), and m_maxVal.
00034 {return m_maxVal;}
|
|
|
Definition at line 33 of file DictConstraints.h. References m_minVal.
00033 {return m_minVal;}
|
|
|
Definition at line 67 of file DictConstraints.h. References DictValList, eStyle, and m_style.
00067 {return m_style;}
|
|
|
Add our allowed values to specified set so we can use set operations to look for overlap.
Definition at line 209 of file DictConstraints.cxx. References m_maxVal, m_minVal, and m_valList.
|
|
|
Definition at line 122 of file DictConstraints.cxx. References deepCopy(), and m_valList.
|
|
|
Will be initialized correctly even for list.
Definition at line 62 of file DictConstraints.h. Referenced by allowed(), deepCopy(), DictConstraints(), disjoint(), equals(), getMax(), and insertValues(). |
|
|
Definition at line 61 of file DictConstraints.h. Referenced by allowed(), deepCopy(), DictConstraints(), disjoint(), equals(), getMin(), and insertValues(). |
|
|
Definition at line 58 of file DictConstraints.h. Referenced by deepCopy(), DictConstraints(), equals(), and getType(). |
|
|
Definition at line 60 of file DictConstraints.h. Referenced by allowed(), deepCopy(), DictConstraints(), disjoint(), equals(), insertValues(), operator=(), and ~DictConstraints(). |
1.2.13.1 written by Dimitri van Heesch,
© 1997-2001