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

xmlUtil::DictConstraints Class Reference

Represent constraints on values for an id dictionary node. More...

#include <DictConstraints.h>

List of all members.

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
DictValListm_valList
unsigned m_minVal
unsigned m_maxVal
 Will be initialized correctly even for list. More...


Detailed Description

Represent constraints on values for an id dictionary node.

Definition at line 15 of file DictConstraints.h.


Member Typedef Documentation

typedef std::vector<unsigned> xmlUtil::DictConstraints::DictValList [private]
 

Definition at line 47 of file DictConstraints.h.

Referenced by deepCopy(), DictConstraints(), and getType().


Member Enumeration Documentation

enum xmlUtil::DictConstraints::eStyle [private]
 

Enumeration values:
ESTYLE_uninit 
ESTYLE_single 
ESTYLE_interval 
ESTYLE_list 

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     };


Constructor & Destructor Documentation

xmlUtil::DictConstraints::DictConstraints DOM_Element    elt
 

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   }

xmlUtil::DictConstraints::~DictConstraints   [inline]
 

Definition at line 21 of file DictConstraints.h.

References DictConstraints(), and m_valList.

00021 {if (m_valList) delete m_valList;}

xmlUtil::DictConstraints::DictConstraints const DictConstraints &    toCopy
 

Definition at line 106 of file DictConstraints.cxx.

References deepCopy().

00106                                                                 {
00107     deepCopy(toCopy);
00108   }

xmlUtil::DictConstraints::DictConstraints   [inline, private]
 

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) {};

xmlUtil::DictConstraints::DictConstraints const unsigned    soleValue [private]
 

Definition at line 85 of file DictConstraints.cxx.

00085                                                            :
00086     m_style(ESTYLE_single), m_valList(0), m_minVal(soleValue), 
00087     m_maxVal(soleValue) {}

xmlUtil::DictConstraints::DictConstraints const unsigned    min,
const unsigned    max
[private]
 

Definition at line 89 of file DictConstraints.cxx.

00089                                                                          :
00090     m_style(ESTYLE_interval), m_valList(0),
00091     m_minVal(min), m_maxVal(max) {}

xmlUtil::DictConstraints::DictConstraints const DictValList *const    list [private]
 

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   }


Member Function Documentation

bool xmlUtil::DictConstraints::allowed DictConstraints *    other const
 

Definition at line 157 of file DictConstraints.cxx.

References allowed().

00157                                                             {
00158     return allowed(*other);
00159   }

bool xmlUtil::DictConstraints::allowed const DictConstraints &    other const
 

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   }

bool xmlUtil::DictConstraints::allowed const unsigned    value const
 

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   }

void xmlUtil::DictConstraints::deepCopy const DictConstraints &    toCopy [private]
 

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=().

00110                                                               {
00111     // Nothing to it unless the DictValList is being used
00112     m_style = toCopy.m_style;
00113     m_valList = 0;
00114     m_minVal = toCopy.m_minVal;
00115     m_maxVal = toCopy.m_maxVal;
00116     if (toCopy.m_valList) {
00117       m_valList = new DictValList(*(toCopy.m_valList));
00118     }
00119   }

bool xmlUtil::DictConstraints::disjoint DictConstraints *    other const
 

Definition at line 205 of file DictConstraints.cxx.

References disjoint().

00205                                                              {
00206     return disjoint(*other);
00207   }

bool xmlUtil::DictConstraints::disjoint const DictConstraints &    other const
 

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   }

bool xmlUtil::DictConstraints::equals const DictConstraints &    other
 

Definition at line 130 of file DictConstraints.cxx.

References ESTYLE_list, m_maxVal, m_minVal, m_style, and m_valList.

00130                                                            {
00131     if ((m_style != other.m_style) ||
00132         (m_minVal != other.m_minVal) ||
00133         (m_maxVal != other.m_maxVal) ) return false;
00134 
00135     if (m_style == ESTYLE_list) {
00136       return (*m_valList == *(other.m_valList));
00137     }
00138     else return true;
00139   }

unsigned xmlUtil::DictConstraints::getMax   const [inline]
 

Definition at line 34 of file DictConstraints.h.

References DictConstraints(), and m_maxVal.

00034 {return m_maxVal;}

unsigned xmlUtil::DictConstraints::getMin   const [inline]
 

Definition at line 33 of file DictConstraints.h.

References m_minVal.

00033 {return m_minVal;}

eStyle xmlUtil::DictConstraints::getType   const [inline, private]
 

Definition at line 67 of file DictConstraints.h.

References DictValList, eStyle, and m_style.

00067 {return m_style;}

void xmlUtil::DictConstraints::insertValues std::set< unsigned > &    aSet const
 

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.

00209                                                                  {
00210     if (m_valList == 0) {
00211       for (unsigned i = m_minVal; i <= m_maxVal; i++) {
00212         aSet.insert(i);
00213       }
00214     }
00215     else {
00216       aSet.insert(m_valList->begin(), m_valList->end());
00217     }
00218     return;
00219   }

DictConstraints & xmlUtil::DictConstraints::operator= const DictConstraints &    d
 

Definition at line 122 of file DictConstraints.cxx.

References deepCopy(), and m_valList.

00122                                                                       {
00123     if (this != &d) {
00124       if (m_valList) delete m_valList;
00125       deepCopy(d);
00126     }
00127     return *this;
00128   }


Member Data Documentation

unsigned xmlUtil::DictConstraints::m_maxVal [private]
 

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().

unsigned xmlUtil::DictConstraints::m_minVal [private]
 

Definition at line 61 of file DictConstraints.h.

Referenced by allowed(), deepCopy(), DictConstraints(), disjoint(), equals(), getMin(), and insertValues().

eStyle xmlUtil::DictConstraints::m_style [private]
 

Definition at line 58 of file DictConstraints.h.

Referenced by deepCopy(), DictConstraints(), equals(), and getType().

DictValList* xmlUtil::DictConstraints::m_valList [private]
 

Definition at line 60 of file DictConstraints.h.

Referenced by allowed(), deepCopy(), DictConstraints(), disjoint(), equals(), insertValues(), operator=(), and ~DictConstraints().


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