Value Class Reference

This abstract base class represents all value objects. More...

#include <value.h>

Inheritance diagram for Value:

ArrayValue BoolValue FloatValue IntValue NullValue ObjectValue StringValue List of all members.

Public Types

enum  ValueType {
  string, number, object, array,
  boolean, null
}
 Types of JSON values. More...

Public Member Functions

virtual ~Value ()
 Destructor is declared virtual, as it always should be.
virtual ValueType GetType () const=0
 Return this instance's type.
virtual Valueoperator[] (unsigned int i)
 Gets the subelement at the specified index.
virtual Valueoperator[] (const Ustr &s)
 Gets the subelement at the specified index.
virtual Valueoperator[] (const std::string &s)
 Gets the subelement at the specified index.
virtual std::string AsString () const
 Gets the value as a string.
virtual Ustr AsUstr () const
 Gets the value as a string.
virtual long AsInt () const
 Gets the value as an int.
virtual double AsFloat () const
 Gets the value as a float.
virtual bool AsBool () const
 Gets the value as a bool.
virtual bool IsNull () const
 Check if this value is null.
virtual unsigned int Size () const
 Returns the number of sub values this value contains.
virtual bool Has (unsigned int i) const
 Check if this value contains the specified sub value.
virtual bool Has (const Ustr s) const
 Check if this value contains the specified sub value.
virtual bool Has (const std::string s) const
 Check if this value contains the specified sub value.

Detailed Description

This abstract base class represents all value objects.

Values as defined by JSON can be objects, arrays, strings, numbers, the boolean values true and false, or null. This is a base class that can represent any one of those types. To get useful information out of it you need to know its actual type. Often you will know what types of information to expect given the source of the JSON message. If you don't, you can check a Value's type with the GetType() method, which returns the type of the underlying Value as an enum.

Once you know the Value's type, you can get its data with the appropriate AsX() method, or access its members with the indexor operator.

This type is returned from the ParseJSON() function.

Author:
Matthew Welch


Member Enumeration Documentation

enum Value::ValueType

Types of JSON values.

Enumerator:
string  Indicates a JSON string value type.
number  Indicates a JSON number value type.
object  Indicates a JSON object value type.
array  Indicates a JSON array value type.
boolean  Indicates a JSON boolean value type (true or false).
null  Indicates a JSON null value type.


Constructor & Destructor Documentation

virtual Value::~Value (  )  [inline, virtual]

Destructor is declared virtual, as it always should be.


Member Function Documentation

virtual ValueType Value::GetType (  )  const [pure virtual]

Return this instance's type.

Returns:
ValueType enum of this intance's type.

Implemented in StringValue, IntValue, FloatValue, BoolValue, NullValue, ObjectValue, and ArrayValue.

virtual Value& Value::operator[] ( unsigned int  i  )  [inline, virtual]

Gets the subelement at the specified index.

Reimplemented in ObjectValue, and ArrayValue.

virtual Value& Value::operator[] ( const Ustr s  )  [inline, virtual]

Gets the subelement at the specified index.

Reimplemented in ObjectValue.

virtual Value& Value::operator[] ( const std::string &  s  )  [inline, virtual]

Gets the subelement at the specified index.

virtual std::string Value::AsString (  )  const [inline, virtual]

Gets the value as a string.

Reimplemented in StringValue, IntValue, and FloatValue.

virtual Ustr Value::AsUstr (  )  const [inline, virtual]

Gets the value as a string.

Reimplemented in StringValue.

virtual long Value::AsInt (  )  const [inline, virtual]

Gets the value as an int.

Reimplemented in StringValue, IntValue, and FloatValue.

virtual double Value::AsFloat (  )  const [inline, virtual]

Gets the value as a float.

Reimplemented in StringValue, IntValue, and FloatValue.

virtual bool Value::AsBool (  )  const [inline, virtual]

Gets the value as a bool.

Reimplemented in IntValue, FloatValue, and BoolValue.

virtual bool Value::IsNull (  )  const [inline, virtual]

Check if this value is null.

Reimplemented in NullValue.

virtual unsigned int Value::Size (  )  const [inline, virtual]

Returns the number of sub values this value contains.

Reimplemented in ObjectValue, and ArrayValue.

virtual bool Value::Has ( unsigned int  i  )  const [inline, virtual]

Check if this value contains the specified sub value.

Reimplemented in ObjectValue, and ArrayValue.

virtual bool Value::Has ( const Ustr  s  )  const [inline, virtual]

Check if this value contains the specified sub value.

Reimplemented in ObjectValue.

virtual bool Value::Has ( const std::string  s  )  const [inline, virtual]

Check if this value contains the specified sub value.


The documentation for this class was generated from the following file:
Generated on Wed Apr 18 15:50:12 2007 for JSON Parser by  doxygen 1.5.2