AttributeParser.h

Go to the documentation of this file.
00001 // $Id: AttributeParser.h 241 2006-07-05 07:29:52Z bingmann $
00002 
00003 #ifndef VGS_AttributeParser_H
00004 #define VGS_AttributeParser_H
00005 
00006 #include <string>
00007 #include "AnyType.h"
00008 #include "AttributeProperties.h"
00009 
00010 #include "AttributeBlob.h"
00011 
00012 namespace VGServer {
00013 
00019 class ParseNode
00020 {
00021 protected:
00023     inline ParseNode()
00024     { }
00025 
00027     ParseNode(const ParseNode &pn);
00028     
00029 public:
00032     virtual ~ParseNode()
00033     { }
00034 
00037     virtual bool getValue(AnyType &dest, const class GraphContainer &gc, const class Changelist &cl,
00038                           vertex_or_edge_t voe, unsigned int vid1, unsigned int vid2) const = 0;
00039 
00046     virtual bool getConstVal(AnyType *dest) const = 0;
00047 
00050     virtual std::string toString() const = 0;
00051 };
00052 
00058 class AttributeSelectorList : private std::vector<const class ParseNode*>,
00059                               public AttributePropertiesList
00060 {
00061 private:
00063     typedef std::vector<const class ParseNode*> sellist;
00064 
00066     typedef AttributePropertiesList attrlist;
00067 
00068 public:
00070     ~AttributeSelectorList()
00071     {
00072         clear();
00073     }
00074 
00076     void clear() {
00077         attrlist::clear();
00078         for(sellist::const_iterator i = sellist::begin(); i != sellist::end(); i++) {
00079             delete *i;
00080         }
00081         sellist::clear();
00082     }
00083     
00085     void        selectStar(const AttributePropertiesList &otherlist, vertex_or_edge_t voe);
00086 
00089     void        addAttrsel(const class ParseNode *attrsel);
00090 
00095     bool        parseString(const std::string &input, const class GraphProperties &gp, vertex_or_edge_t voe);
00096 
00099     std::string toString() const;
00100 
00103     size_t size() const {
00104         assert(sellist::size() == attrlist::size());
00105         return sellist::size();
00106     }
00107 
00109     inline const class ParseNode* getSelector(unsigned int i) const
00110     { return sellist::operator[](i); }
00111 
00113     inline const class AttributeProperties& getProperties(unsigned int i) const
00114     { return attrlist::operator[](i); }
00115 
00119     inline unsigned int processVertexAttributeBlob(AttributeVertexTinyBlob &attrblob,
00120                                                    const class GraphContainer &gc,
00121                                                    const class Changelist &cl, unsigned int vid) const
00122     {
00123         unsigned int p = defbytes;
00124         attrblob.zero(0, p);
00125         
00126         for(unsigned int ai = 0; ai < size(); ai++)
00127         {
00128             // Calculate the value of the attribute selector
00129             AnyType attrval(ATTRTYPE_INVALID);
00130 
00131             getSelector(ai)->getValue(attrval, gc, cl, VE_VERTEX, vid, 0);
00132 
00133             // bools are in the default bitfield
00134             if (getProperties(ai).getType() == ATTRTYPE_BOOL) {
00135                 attrblob.putBool(0, ai, attrval.getInteger() != 0);
00136             }
00137             // check if it's the default value.
00138             else if (attrval == getProperties(ai)) {
00139                 // set default bit
00140                 attrblob.putBool(0, ai, true);
00141             }
00142             else {
00143                 // otherwise append the value.
00144                 attrblob.putAnyType(p, attrval);
00145                 p += attrval.getValueLength();
00146             }
00147         }
00148 
00149         return p;
00150     }
00151 
00155     inline unsigned int processEdgeAttributeBlob(AttributeVertexTinyBlob &attrblob,
00156                                                  const class GraphContainer &gc,
00157                                                  const class Changelist &cl, unsigned int esrc, unsigned etgt) const
00158     {
00159         unsigned int p = defbytes;
00160         attrblob.zero(0, p);
00161         
00162         for(unsigned int ai = 0; ai < size(); ai++)
00163         {
00164             // Calculate the value of the attribute selector
00165             AnyType attrval(ATTRTYPE_INVALID);
00166 
00167             getSelector(ai)->getValue(attrval, gc, cl, VE_EDGE, esrc, etgt);
00168 
00169             // bools are in the default bitfield
00170             if (getProperties(ai).getType() == ATTRTYPE_BOOL) {
00171                 attrblob.putBool(0, ai, attrval.getInteger() != 0);
00172             }
00173             // check if it's the default value.
00174             else if (attrval == getProperties(ai)) {
00175                 // set default bit
00176                 attrblob.putBool(0, ai, true);
00177             }
00178             else {
00179                 // otherwise append the value.
00180                 attrblob.putAnyType(p, attrval);
00181                 p += attrval.getValueLength();
00182             }
00183         }
00184 
00185         return p;
00186     }
00187 
00188 };
00189 
00193 class FilterRoot
00194 {
00195 private:
00197     const class ParseNode       *filter;
00198 
00200     vertex_or_edge_t    vertexoredge;
00201 
00202 public:
00203     FilterRoot()
00204         : filter(NULL)
00205     {
00206     }
00207 
00209     ~FilterRoot()
00210     {
00211         if (filter)
00212             delete filter;
00213     }
00214 
00218     bool        parseString(const std::string &input, const class GraphProperties &gp);
00219 
00222     std::string toString() const;
00223 
00225     bool        isEmpty() const
00226     { return (filter == NULL); }
00227 
00229     vertex_or_edge_t    getType() const
00230     { return vertexoredge; }
00231 
00233     inline bool eval_vertex(const class GraphContainer &gc, const class Changelist &cl,
00234                             unsigned int vid) const
00235     {
00236         AnyType at(ATTRTYPE_INVALID);
00237 
00238         assert(filter);
00239         filter->getValue(at, gc, cl, VE_VERTEX, vid, 0);
00240         return (at.getInteger() != 0);
00241     }
00242 
00244     inline bool eval_edge(const class GraphContainer &gc, const class Changelist &cl,
00245                           unsigned int vidsrc, unsigned int vidtgt) const
00246     {
00247         AnyType at(ATTRTYPE_INVALID);
00248 
00249         assert(filter);
00250         filter->getValue(at, gc, cl, VE_EDGE, vidsrc, vidtgt);
00251         return (at.getInteger() != 0);
00252     }
00253 };
00254 
00259 class AttributeParseException : public GraphException
00260 {
00261 public:
00262     inline AttributeParseException(const std::string &s) throw()
00263         : GraphException(s)
00264     { }
00265 };
00266 
00267 
00268 } // namespace VGServer
00269 
00270 #endif // VGS_AttributeParser_H
00271 

Generated on Wed Sep 27 14:34:00 2006 for VGServer by  doxygen 1.4.7