Permalink
Browse files

Added interface for keys(), no impl yet!

  • Loading branch information...
pibara committed Jul 6, 2011
1 parent 0973eb1 commit c1a59134ea065420c093a84f15c7efb39fbc7601
Showing with 23 additions and 0 deletions.
  1. +3 −0 Node.cpp
  2. +2 −0 gobj/GobjectImplFsTopNode.hpp
  3. +2 −0 gobj/GobjectImplNode.hpp
  4. +2 −0 gobj/GobjectImplStringTopNode.hpp
  5. +14 −0 json-me.hpp
View
@@ -6,6 +6,9 @@ namespace jsonme {
jsonme::nodetype Node::nodetype() const {
return mNode->nodetype();
}
+ AbstractKeys & Node::keys() {
+ return mNode->keys();
+ }
Node Node::operator[](std::string const & name) const {
return (*mNode)[name];
}
@@ -8,9 +8,11 @@ namespace jsonme {
class GobjectImplFsTopNode: public jsonme::AbstractNode {
GobjectImplParser mParser;
GobjectImplNode *mRoot;
+ NullKeys mNullKeys;
public:
GobjectImplFsTopNode(std::string const & jsonstring);
~GobjectImplFsTopNode();
+ AbstractKeys &keys() { return mNullKeys;}
jsonme::nodetype nodetype() const;
Node operator[](std::string const & name) const;
size_t size() const;
View
@@ -7,8 +7,10 @@ namespace jsonme {
namespace impl {
class GobjectImplNode: public AbstractNode {
JsonNode * const mNode;
+ NullKeys mNullKeys;
public:
GobjectImplNode(JsonNode * const node);
+ AbstractKeys &keys() { return mNullKeys;}
jsonme::nodetype nodetype() const ;
Node operator[](std::string const & name) const ;
size_t size() const;
@@ -9,9 +9,11 @@ namespace jsonme {
class GobjectImplStringTopNode: public jsonme::AbstractNode {
GobjectImplParser mParser;
GobjectImplNode const * mRoot;
+ NullKeys mNullKeys;
public:
GobjectImplStringTopNode(std::string const & jsonstring);
~GobjectImplStringTopNode();
+ AbstractKeys &keys() { return mNullKeys;}
jsonme::nodetype nodetype() const ;
Node operator[](std::string const & name) const ;
size_t size() const;
View
@@ -57,6 +57,16 @@ namespace jsonme {
//A json node is either an object, an array or a scalar.
typedef enum {OBJECT,ARRAY,SCALAR,INVALID} nodetype;
+ class AbstractKeys {
+ public:
+ virtual std::string operator[](size_t index) const=0;
+ virtual size_t size() const=0;
+ };
+ class NullKeys: public AbstractKeys {
+ public:
+ std::string operator[](size_t index) const { return "";}
+ size_t size() const{ return 0;}
+ };
class Node;
//The node has a type, and depending on its type can:
//* SCALAR: be cast to a Scalar
@@ -65,6 +75,7 @@ namespace jsonme {
class AbstractNode {
public:
virtual ~AbstractNode(){}
+ virtual AbstractKeys & keys()=0;
virtual jsonme::nodetype nodetype() const=0;
virtual Node operator[](std::string const & name) const=0;
virtual size_t size() const=0;
@@ -77,7 +88,9 @@ namespace jsonme {
Node();
private:
class NullNode: public AbstractNode {
+ NullKeys mNullKeys;
public:
+ AbstractKeys & keys() { return mNullKeys;}
jsonme::nodetype nodetype() const {return INVALID;}
Node operator[](std::string const & name) const { return Node();}
size_t size() const { return 0;}
@@ -87,6 +100,7 @@ namespace jsonme {
boost::shared_ptr<AbstractNode> mNode;
public:
Node(AbstractNode *node);
+ AbstractKeys & keys();
jsonme::nodetype nodetype() const;
Node operator[](std::string const & name) const;
Node operator[](char const * const) const;

0 comments on commit c1a5913

Please sign in to comment.