Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Related Functions

FCam::TagValue Class Reference

The values with which a Device can tag a Frame. More...

#include <TagValue.h>

Collaboration diagram for FCam::TagValue:
Collaboration graph

List of all members.

Public Types

enum  Type {
  Null = 0, Int, Float, Double,
  String, Time, IntVector, FloatVector,
  DoubleVector, StringVector, TimeVector

A TagValue can represent one of a number of types listed below.


Public Member Functions

bool valid ()
 Does this tag exist? That is, is type equal to Null.
std::string toString () const
 Serialize into a human-and-python readable format.
std::string toBlob ()
 Serialize into a more efficient binary format.

TagValues can be constructed from many different types.

The default constructor makes a Null TagValue. Each other constructor makes a copy of its argument.

 TagValue ()
 TagValue (int)
 TagValue (float)
 TagValue (double)
 TagValue (std::string)
 TagValue (FCam::Time)
 TagValue (std::vector< int >)
 TagValue (std::vector< float >)
 TagValue (std::vector< double >)
 TagValue (std::vector< std::string >)
 TagValue (std::vector< FCam::Time >)
 TagValue (const TagValue &)

You assign to a TagValue from any of the types a TagValue supports.

This sets the TagValue to a copy of the argument.

const TagValueoperator= (const int &)
const TagValueoperator= (const float &)
const TagValueoperator= (const double &)
const TagValueoperator= (const std::string &)
const TagValueoperator= (const FCam::Time &)
const TagValueoperator= (const std::vector< int > &)
const TagValueoperator= (const std::vector< float > &)
const TagValueoperator= (const std::vector< double > &)
const TagValueoperator= (const std::vector< std::string > &)
const TagValueoperator= (const std::vector< FCam::Time > &)
const TagValueoperator= (const TagValue &)
Cast Operators

A TagValue can be implicitly cast to the appropriate type.

Trying to cast a TagValue to the wrong type will result in a default value returned and a BadCast error placed on the event queue. If you wish to inspect or modify a large tag value in-place (e.g. an IntVector), cast it to a reference to the appropriate type, rather than a concrete instance of that type. The latter will make a fresh copy of the potentially large data. For example:

Frame frame = Sensor.getFrame();

// This makes a copy of a potentially large array
std::vector<int> bigTag = frame["bigTag"];

// This does not, and so is usually what you want to do.
std::vector<int> &bigTagRef = frame["bigTag"];
 operator int & () const
 operator float & () const
 operator double & () const
 operator std::string & () const
 operator FCam::Time & () const
 operator std::vector< int > & () const
 operator std::vector< float > & () const
 operator std::vector< double > & () const
 operator std::vector< std::string > & () const
 operator std::vector< FCam::Time > & () const
Cast methods

A TagValue also has explicit methods to cast it to various types.

These have the same semantics as the implicit casts, but are more readable in many cases. For example:

TagValue tag = std::vector<int>();

// Use the overloaded cast operator
((std::vector<int> &)tag).push_back(3);

// Do the same thing using the cast method
int & asInt ()
float & asFloat ()
double & asDouble ()
std::string & asString ()
FCam::TimeasTime ()
std::vector< int > & asIntVector ()
std::vector< float > & asFloatVector ()
std::vector< double > & asDoubleVector ()
std::vector< std::string > & asStringVector ()
std::vector< FCam::Time > & asTimeVector ()

Static Public Member Functions

static TagValue fromString (const std::string &)
 Deserialize from either format.

Public Attributes

Type type
 The type of this tag.
void * data
 A pointer to the actual value of this tag.

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &out, const TagValue &t)
 Serialize the TagValue into a human readable format.
std::istream & operator>> (std::istream &in, TagValue &t)
 Deserialize a TagValue from either the human-readable or the binary format.

Detailed Description

The values with which a Device can tag a Frame.

Definition at line 16 of file TagValue.h.

Member Enumeration Documentation

A TagValue can represent one of a number of types listed below.


A Null TagValue represents nothing, and indicates no such tag exists.


A 32-bit signed integer.


A 32-bit float.


A 64-bit double.


An std::string.

Also useful to represent a blob of binary data.


A Time.


A std::vector of ints.


A std::vector of floats.


A std::vector of doubles.


A std::vector of std::strings.


A std::vector of Times.

Definition at line 21 of file TagValue.h.

Member Function Documentation

bool FCam::TagValue::valid (  )  [inline]

Does this tag exist? That is, is type equal to Null.

Definition at line 140 of file TagValue.h.

std::string FCam::TagValue::toBlob (  ) 

Serialize into a more efficient binary format.

For tags containing large arrays of data, this format can be over 100x more time-efficient than the human readable format, and about 2.5x more space efficient.

Definition at line 705 of file TagValue.cpp.

Friends And Related Function Documentation

std::istream & operator>> ( std::istream &  in,
TagValue t 
) [related]

Deserialize a TagValue from either the human-readable or the binary format.

Definition at line 1006 of file TagValue.cpp.

Member Data Documentation

The type of this tag.

Definition at line 155 of file TagValue.h.

A pointer to the actual value of this tag.

Definition at line 158 of file TagValue.h.

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