Streaming C++ API
sb::Tuple Class Reference

Tuples are value types that can be copied and modified separately thus. More...

#include <Tuple.hpp>

Public Types

enum  Flags { NONE = 0 , TRUNCATE = 1 }
 Flags that can be passed to setString(). More...
 

Public Member Functions

 Tuple (const Tuple &t)
 Copy constructor. More...
 
 Tuple (const Schema &s)
 Construct a tuple of the specified schema. More...
 
 ~Tuple ()
 Destructor. More...
 
const Tupleoperator= (const Tuple &rhs)
 
bool operator== (const Tuple &rhs) const
 
void verify () const
 verify that the tuple is valid Throws StreamBaseException on invalid tuple More...
 
void clear ()
 null all fields in the tuple More...
 
const SchemagetSchema () const
 
void setSchema (const Schema &)
 set the schema More...
 
size_t getNumFields () const
 
size_t getSize () const
 
template<typename T >
get (const Field &f) const
 Return the value of the given field of type T. More...
 
template<typename T >
get (size_t i) const
 
template<typename T >
get (const std::string &field_name) const
 
template<typename T >
void set (const Field &field, T value)
 Set a field to a specific value. More...
 
template<typename T >
void set (int fieldNum, T value)
 
template<typename T >
void set (const std::string &field_name, T value)
 
bool isNull (const Field &f) const
 Test the null setting for field f. More...
 
bool isNull (size_t i) const
 
bool isNull (const std::string &n) const
 
void setNull (const Field &f)
 Set the null setting for field f. More...
 
void setNull (size_t i)
 
void setNull (const std::string &n)
 
bool getBool (const Field &f) const
 Return the value of a Boolean field. More...
 
bool getBool (size_t i) const
 
bool getBool (const std::string &n) const
 
void setBool (const Field &f, bool v)
 Set the value of a Boolean field. More...
 
void setBool (size_t i, bool v)
 
void setBool (const std::string &n, bool v)
 
int getInt (const Field &f) const
 Return the value of an int field. More...
 
int getInt (size_t i) const
 
int getInt (const std::string &n) const
 
void setInt (const Field &f, int v)
 Set the value of an integer field. More...
 
void setInt (size_t i, int v)
 
void setInt (const std::string &n, int v)
 
long long getLong (const Field &f) const
 Return the value of a long field. More...
 
long long getLong (size_t i) const
 
long long getLong (const std::string &n) const
 
void setLong (const Field &f, long long v)
 Set the value of a long field. More...
 
void setLong (size_t i, long long v)
 
void setLong (const std::string &n, long long v)
 
double getDouble (const Field &f) const
 Return the value of a double field. More...
 
double getDouble (size_t i) const
 
double getDouble (const std::string &n) const
 
void setDouble (const Field &f, double v)
 Set the value of a double field. More...
 
void setDouble (size_t i, double v)
 
void setDouble (const std::string &n, double v)
 
Timestamp getTimestamp (const Field &f) const
 Return the value of a Timestamp field. More...
 
Timestamp getTimestamp (size_t i) const
 
Timestamp getTimestamp (const std::string &n) const
 
void setTimestamp (const Field &f, const Timestamp &v)
 Set the value of a Timestamp field. More...
 
void setTimestamp (size_t i, const Timestamp &v)
 
void setTimestamp (const std::string &n, const Timestamp &v)
 
const std::string & getBlobBuffer (const Field &f) const
 Return the value of a BLOB field. More...
 
const std::string & getBlobBuffer (size_t i) const
 
const std::string & getBlobBuffer (const std::string &n) const
 
void setBlobBuffer (const Field &f, const std::string &v)
 Set the value of a BLOB field. More...
 
void setBlobBuffer (size_t i, const std::string &v)
 
void setBlobBuffer (const std::string &n, const std::string &v)
 
const std::vector< FieldValue > & getList (const Schema::Field &f) const
 Return the value of a LIST field. More...
 
const std::vector< FieldValue > & getList (size_t i) const
 
const std::vector< FieldValue > & getList (const std::string &n) const
 
void setList (const Schema::Field &f, const std::vector< FieldValue > &v)
 Set the value of a LIST field. More...
 
void setList (size_t i, const std::vector< FieldValue > &v)
 
void setList (const std::string &n, const std::vector< FieldValue > &v)
 
const std::string & getString (const Field &f) const
 Return the value of a string field. More...
 
const std::string & getString (size_t i) const
 
const std::string & getString (const std::string &n) const
 
void setString (const Field &field, const std::string &value, Flags flags=NONE)
 Set the value of a string field. More...
 
void setString (size_t field, const char *data, size_t len, Flags flags=NONE)
 
void setString (const std::string &field, const char *data, size_t len, Flags flags=NONE)
 
void setString (const Field &field, const char *data, size_t len, Flags flags=NONE)
 
void setString (size_t field_index, const std::string &value, Flags flags=NONE)
 
void setString (const std::string &field_name, const std::string &value, Flags flags=NONE)
 
const TuplegetTuple (const Field &f) const
 Return the value of a nested tuple field. More...
 
const TuplegetTuple (size_t i) const
 
const TuplegetTuple (const std::string &n) const
 
const Function & getFunction (const Field &f) const
 Return the value of a function field. More...
 
const Function & getFunction (size_t i) const
 
const Function & getFunction (const std::string &n) const
 
void setTuple (const Field &f, const Tuple &v)
 Set the value of a nested tuple field. More...
 
void setTuple (size_t i, const Tuple &v)
 
void setTuple (const std::string &n, const Tuple &v)
 
void setFunction (const Field &f, const Function &v)
 Set the value of a function field. More...
 
void setFunction (size_t i, const Function &v)
 
void setFunction (const std::string &n, const Function &v)
 
FieldValuegetFieldValue (const Field &f)
 Takes a field with a path and returns the field at the target of that path. More...
 
const FieldValuegetFieldValue (const Schema::Field &f) const
 Takes a field with a path and returns the field at the target of that path. More...
 
FieldValuegetFieldValue (size_t field_num)
 Takes the index of a field in this tuple's schema, returns the corresponding field value. More...
 
const FieldValuegetFieldValue (size_t field_num) const
 Takes the index of a field in this tuple's schema, returns the corresponding field value. More...
 
FieldValuegetFieldValue (const std::string &field_name)
 Takes the name of a field in this tuple's schema, returns the corresponding field value. More...
 
const FieldValuegetFieldValue (const std::string &field_name) const
 Takes the name of a field in this tuple's schema, returns the corresponding field value. More...
 
void setFieldValue (const Field &f, const FieldValue &fv)
 Takes a field with a path and sets the value of the field at the target of that path to that of the provided FieldValue. More...
 
void setFieldValue (size_t field_num, const FieldValue &fv)
 Takes the index of a field in this tuple's schema and sets the corresponding field value. More...
 
void setFieldValue (const std::string &field_name, const FieldValue &fv)
 Takes the name of a field in this tuple's schema and sets the corresponding field value. More...
 
bool hasHeader () const
 
unsigned int getId () const
 
void setId (unsigned int tid)
 set the id More...
 
std::string as_string () const
 Return a human-readable string value representing this tuple in its entirety (including all header values, if applicable). More...
 
std::string as_string_external (char delimiter=',', const std::string &null_string=getNullString()) const
 Return a human-readable string value representing this tuple. More...
 
std::string toDelimitedString (const std::string &delimiter, const std::string &null_string=getNullString(), bool include_names=false, bool quote_all_strings=false) const
 Return a string value representing this tuple, separated by the given delimiter. More...
 

Static Public Member Functions

static const std::string & getNullString ()
 Return the default string used to represent null, i.e., null. More...
 

Detailed Description

Tuples are value types that can be copied and modified separately thus.

t2 = t1;
t2.setId(0); // does not modify t1

They will only make copies of the underlying data as needed, so they are relatively cheap to pass around by value

Member Enumeration Documentation

◆ Flags

Flags that can be passed to setString().

TRUNCATE: starting in StreamBase 6.3 the string type does not have a declared length and strings are never truncated.

Constructor & Destructor Documentation

◆ Tuple() [1/2]

sb::Tuple::Tuple ( const Tuple t)

Copy constructor.

◆ Tuple() [2/2]

sb::Tuple::Tuple ( const Schema s)

Construct a tuple of the specified schema.

◆ ~Tuple()

sb::Tuple::~Tuple ( )

Destructor.

Member Function Documentation

◆ as_string()

std::string sb::Tuple::as_string ( ) const

Return a human-readable string value representing this tuple in its entirety (including all header values, if applicable).

Returns
the string value.

◆ as_string_external()

std::string sb::Tuple::as_string_external ( char  delimiter = ',',
const std::string &  null_string = getNullString() 
) const

Return a human-readable string value representing this tuple.

It compares to as_string by allowing a user-specified delimiter between fields, making the header timestamp stand out, and omitting the TupleId header field. null_string is written out for any null field.

Returns
the string value

◆ clear()

void sb::Tuple::clear ( )
inline

null all fields in the tuple

◆ get()

template<typename T >
T sb::Tuple::get ( const Field f) const
inline

Return the value of the given field of type T.

T must be one of string, int, double, bool, long, or Timestamp, and correspond to the field's actual type.

The Field objects used to set and get Tuple field values must be obtained via the Tuple's Schema object. A Schema.Field object that has been created by the user or retrieved from a different Schema may not work.

Returns
the value of the field.

◆ getBlobBuffer()

const std::string & sb::Tuple::getBlobBuffer ( const Field f) const

Return the value of a BLOB field.

The Field objects used to set and get Tuple field values must be obtained via the Tuple's Schema object. A Schema.Field object that has been created by the user or retrieved from a different Schema may not work.

Returns
the BLOB value.

◆ getBool()

bool sb::Tuple::getBool ( const Field f) const

Return the value of a Boolean field.

The Field objects used to set and get Tuple field values must be obtained via the Tuple's Schema object. A Schema.Field object that has been created by the user or retrieved from a different Schema may not work.

Returns
the Boolean value.

◆ getDouble()

double sb::Tuple::getDouble ( const Field f) const

Return the value of a double field.

The Field objects used to set and get Tuple field values must be obtained via the Tuple's Schema object. A Schema.Field object that has been created by the user or retrieved from a different Schema may not work.

Returns
the double value.

◆ getFieldValue() [1/6]

FieldValue & sb::Tuple::getFieldValue ( const Field f)

Takes a field with a path and returns the field at the target of that path.

◆ getFieldValue() [2/6]

const FieldValue & sb::Tuple::getFieldValue ( const Schema::Field f) const

Takes a field with a path and returns the field at the target of that path.

◆ getFieldValue() [3/6]

FieldValue & sb::Tuple::getFieldValue ( const std::string &  field_name)

Takes the name of a field in this tuple's schema, returns the corresponding field value.

◆ getFieldValue() [4/6]

const FieldValue & sb::Tuple::getFieldValue ( const std::string &  field_name) const

Takes the name of a field in this tuple's schema, returns the corresponding field value.

◆ getFieldValue() [5/6]

FieldValue & sb::Tuple::getFieldValue ( size_t  field_num)

Takes the index of a field in this tuple's schema, returns the corresponding field value.

◆ getFieldValue() [6/6]

const FieldValue & sb::Tuple::getFieldValue ( size_t  field_num) const

Takes the index of a field in this tuple's schema, returns the corresponding field value.

◆ getFunction()

const Function & sb::Tuple::getFunction ( const Field f) const

Return the value of a function field.

The Field objects used to set and get Tuple field values must be obtained via the Tuple's Schema object. A Schema.Field object that has been created by the user or retrieved from a different Schema may not work.

Returns
the function value.

◆ getId()

unsigned int sb::Tuple::getId ( ) const
Returns
The id for this tuple

◆ getInt()

int sb::Tuple::getInt ( const Field f) const

Return the value of an int field.

The Field objects used to set and get Tuple field values must be obtained via the Tuple's Schema object. A Schema.Field object that has been created by the user or retrieved from a different Schema may not work.

Returns
the int value.

◆ getList()

const std::vector< FieldValue > & sb::Tuple::getList ( const Schema::Field f) const

Return the value of a LIST field.

The Schema::Field objects used to set and get Tuple field values must be obtained via the Tuple's Schema object. A Schema.Field object that has been created by the user or retrieved from a different Schema may not work.

Returns
the LIST value.

◆ getLong()

long long sb::Tuple::getLong ( const Field f) const

Return the value of a long field.

The Field objects used to set and get Tuple field values must be obtained via the Tuple's Schema object. A Schema.Field object that has been created by the user or retrieved from a different Schema may not work.

Returns
the long value.

◆ getNullString()

static const std::string & sb::Tuple::getNullString ( )
inlinestatic

Return the default string used to represent null, i.e., null.

◆ getNumFields()

size_t sb::Tuple::getNumFields ( ) const
inline
Returns
the number of fields in the tuple's schema

References sb::Schema::getNumFields().

◆ getSchema()

const Schema & sb::Tuple::getSchema ( ) const
Returns
the schema

◆ getSize()

size_t sb::Tuple::getSize ( ) const
Returns
the serialized size of this tuple

◆ getString()

const std::string & sb::Tuple::getString ( const Field f) const

Return the value of a string field.

The Field objects used to set and get Tuple field values must be obtained via the Tuple's Schema object. A Schema.Field object that has been created by the user or retrieved from a different Schema may not work.

Returns
the string value.

◆ getTimestamp()

Timestamp sb::Tuple::getTimestamp ( const Field f) const

Return the value of a Timestamp field.

The Field objects used to set and get Tuple field values must be obtained via the Tuple's Schema object. A Schema.Field object that has been created by the user or retrieved from a different Schema may not work.

Returns
the Timestamp value.

◆ getTuple()

const Tuple & sb::Tuple::getTuple ( const Field f) const

Return the value of a nested tuple field.

The Field objects used to set and get Tuple field values must be obtained via the Tuple's Schema object. A Schema.Field object that has been created by the user or retrieved from a different Schema may not work.

Returns
the nested tuple value.

◆ hasHeader()

bool sb::Tuple::hasHeader ( ) const
inline
Returns
true if tuple has a header, false otherwise

◆ isNull()

bool sb::Tuple::isNull ( const Field f) const

Test the null setting for field f.

The Field objects used to set and get Tuple field values must be obtained via the Tuple's Schema object. A Schema.Field object that has been created by the user or retrieved from a different Schema may not work.

Returns
true if field is null, false otherwise

◆ set()

template<typename T >
void sb::Tuple::set ( const Field field,
value 
)
inline

Set a field to a specific value.

Supported values are string, int, double, bool and Timestamp. field must be a of a matching DataType.

The Field objects used to set and get Tuple field values must be obtained via the Tuple's Schema object. A Schema.Field object that has been created by the user or retrieved from a different Schema may not work.

◆ setBlobBuffer()

void sb::Tuple::setBlobBuffer ( const Field f,
const std::string &  v 
)

Set the value of a BLOB field.

The Field objects used to set and get Tuple field values must be obtained via the Tuple's Schema object. A Schema.Field object that has been created by the user or retrieved from a different Schema may not work.

◆ setBool()

void sb::Tuple::setBool ( const Field f,
bool  v 
)

Set the value of a Boolean field.

The Field objects used to set and get Tuple field values must be obtained via the Tuple's Schema object. A Schema.Field object that has been created by the user or retrieved from a different Schema may not work.

◆ setDouble()

void sb::Tuple::setDouble ( const Field f,
double  v 
)

Set the value of a double field.

The Field objects used to set and get Tuple field values must be obtained via the Tuple's Schema object. A Schema.Field object that has been created by the user or retrieved from a different Schema may not work.

◆ setFieldValue() [1/3]

void sb::Tuple::setFieldValue ( const Field f,
const FieldValue fv 
)

Takes a field with a path and sets the value of the field at the target of that path to that of the provided FieldValue.

◆ setFieldValue() [2/3]

void sb::Tuple::setFieldValue ( const std::string &  field_name,
const FieldValue fv 
)

Takes the name of a field in this tuple's schema and sets the corresponding field value.

◆ setFieldValue() [3/3]

void sb::Tuple::setFieldValue ( size_t  field_num,
const FieldValue fv 
)

Takes the index of a field in this tuple's schema and sets the corresponding field value.

◆ setFunction()

void sb::Tuple::setFunction ( const Field f,
const Function &  v 
)

Set the value of a function field.

The Field objects used to set and get Tuple field values must be obtained via the Tuple's Schema object. A Schema.Field object that has been created by the user or retrieved from a different Schema may not work.

◆ setId()

void sb::Tuple::setId ( unsigned int  tid)

set the id

◆ setInt()

void sb::Tuple::setInt ( const Field f,
int  v 
)

Set the value of an integer field.

The Field objects used to set and get Tuple field values must be obtained via the Tuple's Schema object. A Schema.Field object that has been created by the user or retrieved from a different Schema may not work.

◆ setList()

void sb::Tuple::setList ( const Schema::Field f,
const std::vector< FieldValue > &  v 
)

Set the value of a LIST field.

The Schema::Field objects used to set and get Tuple field values must be obtained via the Tuple's Schema object. A Schema.Field object that has been created by the user or retrieved from a different Schema may not work.

◆ setLong()

void sb::Tuple::setLong ( const Field f,
long long  v 
)

Set the value of a long field.

The Field objects used to set and get Tuple field values must be obtained via the Tuple's Schema object. A Schema.Field object that has been created by the user or retrieved from a different Schema may not work.

◆ setNull()

void sb::Tuple::setNull ( const Field f)

Set the null setting for field f.

The Field objects used to set and get Tuple field values must be obtained via the Tuple's Schema object. A Schema.Field object that has been created by the user or retrieved from a different Schema may not work.

◆ setSchema()

void sb::Tuple::setSchema ( const Schema )

set the schema

◆ setString()

void sb::Tuple::setString ( const Field field,
const std::string &  value,
Flags  flags = NONE 
)

Set the value of a string field.

The Field objects used to set and get Tuple field values must be obtained via the Tuple's Schema object. A Schema.Field object that has been created by the user or retrieved from a different Schema may not work.

◆ setTimestamp()

void sb::Tuple::setTimestamp ( const Field f,
const Timestamp v 
)

Set the value of a Timestamp field.

The Field objects used to set and get Tuple field values must be obtained via the Tuple's Schema object. A Schema.Field object that has been created by the user or retrieved from a different Schema may not work.

◆ setTuple()

void sb::Tuple::setTuple ( const Field f,
const Tuple v 
)

Set the value of a nested tuple field.

The Field objects used to set and get Tuple field values must be obtained via the Tuple's Schema object. A Schema.Field object that has been created by the user or retrieved from a different Schema may not work.

◆ toDelimitedString()

std::string sb::Tuple::toDelimitedString ( const std::string &  delimiter,
const std::string &  null_string = getNullString(),
bool  include_names = false,
bool  quote_all_strings = false 
) const

Return a string value representing this tuple, separated by the given delimiter.

Parameters
delimiterthe string to put between fields
null_stringthe string used to represent null values
include_nameswhether to preface each field with "<name>="
quote_all_stringswhether to put quotes around all strings, regardless of need
Returns
the result string

◆ verify()

void sb::Tuple::verify ( ) const

verify that the tuple is valid Throws StreamBaseException on invalid tuple


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