Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends

ts::config::Value Class Reference

This holds a value from the configuration. More...

#include <TsValue.h>

Collaboration diagram for ts::config::Value:
Collaboration graph
[legend]

Public Types

typedef Value self
 Self reference type.

Public Member Functions

 Value ()
 Default constructors.
 ~Value ()
 Destructor.
ValueType getType () const
 Get the type of value.
bool hasValue () const
 Test if this is a valid value.
bool operator! () const
 Operator form of hasValue.
 operator detail::PseudoBool::Type () const
 Logical form of hasValue for use in logical expressions.
ConstBuffer const & getText () const
 Get the value text.
selfsetText (ConstBuffer const &text)
 Set the text for this value.
ConstBuffer const & getName () const
 Get local name.
size_t getIndex () const
 Get local index.
bool isLiteral () const
 Test for a literal value.
bool isContainer () const
 Test for value container.
Value getParent () const
 Get the parent value.
bool isRoot () const
 Test if this is the root value for the configuration.
size_t childCount () const
 Get the number of child values.
Value operator[] (size_t idx) const
 Child access by index.
Value operator[] (ConstBuffer const &name) const
 Child access by name.
Value operator[] (char const *name) const
 Child access by name.
Value find (ConstBuffer const &path)
 Find a value.
Value find (char const *path)
 Find a value.
Value find (Path const &path)
 Find a value using a precondensed path.
selfreset ()
 Reset to default constructed state.
selfsetSourceLine (int line)
 Set source line.
selfsetSourceColumn (int col)
 Set source column.
selfsetSource (int line, int col)
 Set the source location.
int getSourceLine () const
 Get source line.
int getSourceColumn () const
 Get source column.
Creating child values.

These methods all take an optional name argument.

This is required if this is a Group and ignored if this is a List.

These methods will fail if

  • this is not a container.
  • this is a Group and no name is provided.
Note:
Currently for groups, duplicate names are not detected. The duplicates will be inaccessible by name but can still be found by index. This is a problem but I am still pondering the appropriate solution.
See also:
isContainer
Returns:
The new value, or an invalid value plus errata on failure.
Rv< ValuemakeString (ConstBuffer const &text, ConstBuffer const &name=detail::NULL_BUFFER)
 Create a String value.
Rv< ValuemakeInteger (ConstBuffer const &text, ConstBuffer const &name=detail::NULL_BUFFER)
 Create an Integer value.
Rv< ValuemakeGroup (ConstBuffer const &name=detail::NULL_BUFFER)
 Create a Group value.
Rv< ValuemakeList (ConstBuffer const &name=detail::NULL_BUFFER)
 Create a List value.
Rv< ValuemakePath (Path const &path, ConstBuffer const &name=detail::NULL_BUFFER)
 Create a Path value.
Rv< ValuemakeChild (ValueType type, ConstBuffer const &name=detail::NULL_BUFFER)
 Create a child by type.

Protected Member Functions

 Value (Configuration cfg, detail::ValueIndex vidx)
 Construct from raw data.
detail::ValueItemitem ()
 Get raw item pointer.
detail::ValueItem const * item () const
 Get constant raw item pointer.

Protected Attributes

Configuration _config
 The configuration for this value.
detail::ValueIndex _vidx
 Index of item.

Static Protected Attributes

static Buffer const NULL_BUFFER
 Empty buffer to return on method failures.

Friends

class Configuration

Detailed Description

This holds a value from the configuration.

Definition at line 420 of file TsValue.h.


Member Typedef Documentation

Self reference type.

Definition at line 423 of file TsValue.h.


Constructor & Destructor Documentation

ts::config::Value::Value (  )  [inline]

Default constructors.

Creates an NULL instance.

Definition at line 653 of file TsValue.h.

Referenced by getParent(), makeChild(), and operator[]().

ts::config::Value::~Value (  )  [inline]

Destructor.

Definition at line 652 of file TsValue.h.

ts::config::Value::Value ( Configuration  cfg,
detail::ValueIndex  vidx 
) [inline, protected]

Construct from raw data.

Parameters:
cfg Source configuration.
vidx Index of value.

Definition at line 654 of file TsValue.h.


Member Function Documentation

size_t ts::config::Value::childCount (  )  const [inline]

Get the number of child values.

Definition at line 684 of file TsValue.h.

References ts::config::detail::ValueItem::_children, and item().

Referenced by ts::config::Configuration::childCount().

Value ts::config::Value::find ( ConstBuffer const &  path  ) 

Find a value.

Returns:
The value if found, an void valid if not.
Parameters:
path Path relative to this value.

Definition at line 150 of file TsValue.cc.

References ts::ConstBuffer::_size, ts::config::Path::Parser::EOP, ts::config::Path::Parser::ERROR, ts::config::Path::Parser::INDEX, ts::config::Path::Parser::parse(), reset(), and ts::config::Path::Parser::TAG.

Referenced by ts::config::Configuration::find(), find(), and operator[]().

Value ts::config::Value::find ( char const *  path  )  [inline]

Find a value.

Returns:
The value if found, an void valid if not.
Parameters:
path Path relative to this value.

Definition at line 688 of file TsValue.h.

References find().

Value ts::config::Value::find ( Path const &  path  ) 

Find a value using a precondensed path.

Returns:
The value if found, an void valid if not.
Parameters:
path Path relative to this value.

Definition at line 165 of file TsValue.cc.

References ts::ConstBuffer::_ptr, ts::ConstBuffer::_size, and ts::config::Path::count().

size_t ts::config::Value::getIndex (  )  const [inline]

Get local index.

This gets the local index for the value. This is the index which, if used on the parent, would yield this value.

Returns:
The local index.

Definition at line 671 of file TsValue.h.

References ts::config::detail::ValueItem::_local_index, and item().

ConstBuffer const & ts::config::Value::getName (  )  const [inline]

Get local name.

This gets the local name of the value. That is the name by which it is known to its parent container.

Definition at line 667 of file TsValue.h.

References ts::config::detail::ValueItem::_name, item(), and ts::config::detail::NULL_CONST_BUFFER.

Value ts::config::Value::getParent (  )  const [inline]

Get the parent value.

Definition at line 678 of file TsValue.h.

References _config, ts::config::Configuration::_table, _vidx, hasValue(), and Value().

Referenced by ts::config::Builder::groupClose(), and ts::config::Builder::listClose().

int ts::config::Value::getSourceColumn (  )  const [inline]

Get source column.

Returns:
The column in the source stream for this value.

Definition at line 693 of file TsValue.h.

References ts::config::detail::ValueItem::_srcColumn, and item().

int ts::config::Value::getSourceLine (  )  const [inline]

Get source line.

Returns:
The line in the source stream for this value.

Definition at line 689 of file TsValue.h.

References ts::config::detail::ValueItem::_srcLine, and item().

ConstBuffer const & ts::config::Value::getText (  )  const [inline]

Get the value text.

Returns:
The text in the configuration file for this item if the item is a scalar, an empty buffer otherwise.

Definition at line 659 of file TsValue.h.

References _config, ts::config::Configuration::_table, _vidx, hasValue(), and ts::config::detail::NULL_CONST_BUFFER.

Referenced by main().

ValueType ts::config::Value::getType (  )  const [inline]

Get the type of value.

Definition at line 658 of file TsValue.h.

References _config, ts::config::Configuration::_table, _vidx, and hasValue().

Referenced by isContainer(), isLiteral(), and operator[]().

bool ts::config::Value::hasValue (  )  const [inline]

Test if this is a valid value.

Returns:
true if this contains a value, false otherwise.

Definition at line 655 of file TsValue.h.

References _config, _vidx, and ts::config::detail::NULL_VALUE_INDEX.

Referenced by getParent(), getText(), getType(), isRoot(), item(), operator detail::PseudoBool::Type(), and operator!().

bool ts::config::Value::isContainer (  )  const [inline]

Test for value container.

Returns:
true if the value is a container (can have child values), false otherwise.

Definition at line 677 of file TsValue.h.

References getType(), ts::config::detail::IS_CONTAINER, and ts::config::detail::Type_Property.

bool ts::config::Value::isLiteral (  )  const [inline]

Test for a literal value.

Returns:
true if the value is a literal, false if it is a container or invalid.

Definition at line 676 of file TsValue.h.

References getType(), ts::config::detail::IS_LITERAL, and ts::config::detail::Type_Property.

bool ts::config::Value::isRoot (  )  const [inline]

Test if this is the root value for the configuration.

Definition at line 679 of file TsValue.h.

References _vidx, and hasValue().

detail::ValueItem * ts::config::Value::item (  )  [inline, protected]

Get raw item pointer.

Note:
This pointer is unstable and must be recomputed on each method invocation.
Returns:
The item pointer or NULL if this value is invalid.

Definition at line 681 of file TsValue.h.

References _config, ts::config::Configuration::_table, _vidx, and hasValue().

Referenced by childCount(), getIndex(), getName(), getSourceColumn(), getSourceLine(), item(), operator[](), setSource(), setSourceColumn(), setSourceLine(), and setText().

detail::ValueItem const * ts::config::Value::item (  )  const [inline, protected]

Get constant raw item pointer.

Note:
This pointer is unstable and must be recomputed on each method invocation.
Returns:
The item pointer or NULL if this value is invalid.

Definition at line 682 of file TsValue.h.

References item().

Rv< Value > ts::config::Value::makeChild ( ValueType  type,
ConstBuffer const &  name = detail::NULL_BUFFER 
)

Create a child by type.

Client must fill in any other required elements.

Parameters:
type Type of child.
name Optional name of value.

Definition at line 176 of file TsValue.cc.

References _config, ts::config::Configuration::_table, _vidx, ts::Rv< R >::errata(), ts::RvBase::isOK(), ts::config::detail::ValueTable::make(), ts::Rv< R >::result(), and Value().

Referenced by makeGroup(), makeInteger(), makeList(), makePath(), and makeString().

Rv< Value > ts::config::Value::makeGroup ( ConstBuffer const &  name = detail::NULL_BUFFER  ) 

Create a Group value.

Parameters:
name Optional name of value.

Definition at line 185 of file TsValue.cc.

References ts::config::GroupValue, and makeChild().

Referenced by ts::config::Builder::groupOpen().

Rv< Value > ts::config::Value::makeInteger ( ConstBuffer const &  text,
ConstBuffer const &  name = detail::NULL_BUFFER 
)

Create an Integer value.

Parameters:
text Text of number.
name Optional name of value.

Definition at line 202 of file TsValue.cc.

References ts::config::IntegerValue, ts::RvBase::isOK(), makeChild(), and ts::Rv< R >::result().

Referenced by ts::config::Builder::literalValue().

Rv< Value > ts::config::Value::makeList ( ConstBuffer const &  name = detail::NULL_BUFFER  ) 

Create a List value.

Parameters:
name Optional name of value.

Definition at line 190 of file TsValue.cc.

References ts::config::ListValue, and makeChild().

Referenced by ts::config::Builder::listOpen().

Rv< Value > ts::config::Value::makePath ( Path const &  path,
ConstBuffer const &  name = detail::NULL_BUFFER 
)

Create a Path value.

Parameters:
path Path.
name Optional name of value.

Definition at line 209 of file TsValue.cc.

References _config, ts::config::Configuration::_table, ts::RvBase::isOK(), makeChild(), ts::config::PathValue, and ts::Rv< R >::result().

Referenced by ts::config::Builder::pathClose().

Rv< Value > ts::config::Value::makeString ( ConstBuffer const &  text,
ConstBuffer const &  name = detail::NULL_BUFFER 
)

Create a String value.

Parameters:
text String content.
name Optional name of value.

Definition at line 195 of file TsValue.cc.

References ts::RvBase::isOK(), makeChild(), ts::Rv< R >::result(), and ts::config::StringValue.

Referenced by ts::config::Builder::literalValue().

ts::config::Value::operator detail::PseudoBool::Type (  )  const [inline]

Logical form of hasValue for use in logical expressions.

See also:
hasValue
Returns:
The equivalent of true if this does not contain a value, the equivalent of false if it does.

Definition at line 656 of file TsValue.h.

References ts::config::detail::PseudoBool::FALSE, hasValue(), and ts::config::detail::PseudoBool::TRUE.

bool ts::config::Value::operator! (  )  const [inline]

Operator form of hasValue.

See also:
hasValue
Returns:
true if this does not contain a value, false if it does.

Definition at line 657 of file TsValue.h.

References hasValue().

Value ts::config::Value::operator[] ( ConstBuffer const &  name  )  const

Child access by name.

Returns:
The child or a Void value if there is no child with name.

Definition at line 134 of file TsValue.cc.

References ts::config::detail::ValueItem::_children, _config, ts::config::Configuration::_table, _vidx, find(), ts::config::Configuration::getRoot(), getType(), item(), ts::config::PathValue, and Value().

Value ts::config::Value::operator[] ( char const *  name  )  const [inline]

Child access by name.

Returns:
The child or a Void value if there is no child with name.
Parameters:
name Null terminated string.

Definition at line 683 of file TsValue.h.

Value ts::config::Value::operator[] ( size_t  idx  )  const

Child access by index.

Returns:
The child or a Void value if there is no child with name.
Parameters:
idx Index of child value.

Definition at line 123 of file TsValue.cc.

References ts::config::detail::ValueItem::_children, _config, ts::config::Configuration::_table, _vidx, find(), ts::config::Configuration::getRoot(), getType(), item(), ts::config::PathValue, and Value().

Value & ts::config::Value::reset (  )  [inline]

Reset to default constructed state.

Note:
This wrapper is reset, the value in the configuration is unchanged.
Returns:
this object.

Definition at line 680 of file TsValue.h.

References _config, _vidx, Configuration, and ts::config::detail::NULL_VALUE_INDEX.

Referenced by find().

Value & ts::config::Value::setSource ( int  line,
int  col 
) [inline]

Set the source location.

Parameters:
line Line in source stream.
col Column in source stream.

Definition at line 707 of file TsValue.h.

References ts::config::detail::ValueItem::_srcColumn, ts::config::detail::ValueItem::_srcLine, and item().

Referenced by ts::config::Builder::groupOpen(), and ts::config::Builder::listOpen().

Value & ts::config::Value::setSourceColumn ( int  col  )  [inline]

Set source column.

Returns:
this object.
Parameters:
col Column in source stream.

Definition at line 702 of file TsValue.h.

References ts::config::detail::ValueItem::_srcColumn, and item().

Value & ts::config::Value::setSourceLine ( int  line  )  [inline]

Set source line.

Returns:
this object.
Parameters:
line Line in source stream.

Definition at line 697 of file TsValue.h.

References ts::config::detail::ValueItem::_srcLine, and item().

Value & ts::config::Value::setText ( ConstBuffer const &  text  )  [inline]

Set the text for this value.

Definition at line 662 of file TsValue.h.

References ts::config::detail::ValueItem::_text, and item().


Friends And Related Function Documentation

friend class Configuration [friend]

Definition at line 421 of file TsValue.h.

Referenced by reset().


Field Documentation

The configuration for this value.

Definition at line 615 of file TsValue.h.

Referenced by getParent(), getText(), getType(), hasValue(), item(), makeChild(), makePath(), operator[](), and reset().

Index of item.

Definition at line 616 of file TsValue.h.

Referenced by getParent(), getText(), getType(), hasValue(), isRoot(), item(), makeChild(), operator[](), and reset().

Buffer const ts::config::Value::NULL_BUFFER [static, protected]

Empty buffer to return on method failures.

Definition at line 618 of file TsValue.h.


The documentation for this class was generated from the following files: