Streaming C++ API
sb::Schema Class Reference

A type of tuple, containing zero or more fields (each encapsulated as a Schema::Field object). More...

#include <Schema.hpp>

Public Types

enum  Flags { NO_HEADER = 1 }
 Flags for creating a schema.
More...
 
typedef sb::Field Field
 

Public Member Functions

 Schema ()
 Creates an uninitialized Schema. More...
 
 Schema (const Schema &schema)
 Copy constructor. More...
 
Schemaoperator= (const Schema &)
 Assignment operator. More...
 
template<typename Iterator >
 Schema (std::string name, Iterator begin, Iterator end, Flags flags=Flags())
 Constructs a Schema from a sequence of Field objects. More...
 
template<typename Iterator >
 Schema (Iterator begin, Iterator end, Flags flags=Flags())
 Constructs a Schema from a sequence of Field objects. More...
 
 Schema (std::string name, const std::vector< Field > &fields, Flags flags=Flags())
 Constructs a Schema from a vector of Field objects. More...
 
 Schema (const std::vector< Field > &fields, Flags flags=Flags())
 Constructs a Schema from a vector of Field objects. More...
 
 operator const void * () const
 Returns a non-null value if the object was not created with the no-argument constructor, i.e., this is a meaningful Schema. More...
 
bool hasHeader () const
 Return true if the schema has space for a header, false otherwise. More...
 
size_t getHeaderSize () const
 Return the size of the header. More...
 
const FieldgetField (size_t field_num) const
 Return the Fields object description of a field in the schema. More...
 
const FieldgetField (const std::string &pathName) const
 Return the Fields object description of a field in the schema. More...
 
const bool hasField (const std::string &pathName) const
 Returns true if a field of a given path name is present, otherwise it returns false. More...
 
const std::vector< Field > & getFields () const
 Returns a reference to a vector of all fields in the schema. More...
 
int indexOfField (const std::string &name) const
 Returns the index of the field with a particular name (note: not path name), or -1 if there is no such field. More...
 
const std::string & getName () const
 Returns the name of the schema or empty string at runtime. More...
 
size_t getNumFields () const
 Returns the number of fields in the schema. More...
 
std::string as_string () const
 Returns a string representation of the schema. More...
 
bool sameFieldTypes (const Schema &other) const
 Returns true if this schema has the same field types in the same order as another Schema. More...
 
bool sameFields (const Schema &other) const
 Returns true if this schema has the same field Names and Types in the same order as another Schema. More...
 
bool operator== (const Schema &other) const
 
bool operator!= (const Schema &other) const
 

Static Public Member Functions

static Schema fromXml (const std::string &input, Flags flags=Flags())
 Parse and return a schema from an XML string. More...
 

Static Public Attributes

static const Schema EMPTY_SCHEMA
 

Detailed Description

A type of tuple, containing zero or more fields (each encapsulated as a Schema::Field object).

Schemas are immutable: once constructed they may not be changed.

Member Enumeration Documentation

◆ Flags

Flags for creating a schema.

Enumerator
NO_HEADER 
Deprecated:
ignored

Constructor & Destructor Documentation

◆ Schema() [1/6]

sb::Schema::Schema ( )

Creates an uninitialized Schema.

This should NOT be used to create a Schema with no fields; to construct such a Schema use one of the other overloads and pass an empty list of fields.

◆ Schema() [2/6]

sb::Schema::Schema ( const Schema schema)

Copy constructor.

◆ Schema() [3/6]

template<typename Iterator >
sb::Schema::Schema ( std::string  name,
Iterator  begin,
Iterator  end,
Flags  flags = Flags() 
)

Constructs a Schema from a sequence of Field objects.

◆ Schema() [4/6]

template<typename Iterator >
sb::Schema::Schema ( Iterator  begin,
Iterator  end,
Flags  flags = Flags() 
)

Constructs a Schema from a sequence of Field objects.

◆ Schema() [5/6]

sb::Schema::Schema ( std::string  name,
const std::vector< Field > &  fields,
Flags  flags = Flags() 
)

Constructs a Schema from a vector of Field objects.

If the vector is empty the Schema will contain no fields.

◆ Schema() [6/6]

sb::Schema::Schema ( const std::vector< Field > &  fields,
Flags  flags = Flags() 
)

Constructs a Schema from a vector of Field objects.

If the vector is empty the Schema will contain no fields.

Member Function Documentation

◆ as_string()

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

Returns a string representation of the schema.

◆ fromXml()

static Schema sb::Schema::fromXml ( const std::string &  input,
Flags  flags = Flags() 
)
static

Parse and return a schema from an XML string.

The root tag must be <schema>.

◆ getField() [1/2]

const Field & sb::Schema::getField ( const std::string &  pathName) const

Return the Fields object description of a field in the schema.

Parameters
pathNamethe path name of the field to fetch.
Exceptions
NoSuchFieldExceptionif field is not found.

◆ getField() [2/2]

const Field & sb::Schema::getField ( size_t  field_num) const

Return the Fields object description of a field in the schema.

Parameters
field_numthe zero-relative index of the field.
Exceptions
NoSuchFieldExceptionif field_num is too large

◆ getFields()

const std::vector< Field > & sb::Schema::getFields ( ) const

Returns a reference to a vector of all fields in the schema.

◆ getHeaderSize()

size_t sb::Schema::getHeaderSize ( ) const
inline

Return the size of the header.

◆ getName()

const std::string & sb::Schema::getName ( ) const

Returns the name of the schema or empty string at runtime.

◆ getNumFields()

size_t sb::Schema::getNumFields ( ) const

Returns the number of fields in the schema.

Referenced by sb::Tuple::getNumFields().

◆ hasField()

const bool sb::Schema::hasField ( const std::string &  pathName) const

Returns true if a field of a given path name is present, otherwise it returns false.

Parameters
pathNamethe path name of the field to fetch.

◆ hasHeader()

bool sb::Schema::hasHeader ( ) const
inline

Return true if the schema has space for a header, false otherwise.

Deprecated:

◆ indexOfField()

int sb::Schema::indexOfField ( const std::string &  name) const

Returns the index of the field with a particular name (note: not path name), or -1 if there is no such field.

◆ operator const void *()

sb::Schema::operator const void * ( ) const
inline

Returns a non-null value if the object was not created with the no-argument constructor, i.e., this is a meaningful Schema.

Useful in the following manner:

Schema td = callSomeMethod();
if (td) {
    cout << "someMethod returned a valid Schema: " << td << endl;
} else {
    cout << "no such Schema" << endl;
}

◆ operator=()

Schema & sb::Schema::operator= ( const Schema )

Assignment operator.

◆ sameFields()

bool sb::Schema::sameFields ( const Schema other) const

Returns true if this schema has the same field Names and Types in the same order as another Schema.

◆ sameFieldTypes()

bool sb::Schema::sameFieldTypes ( const Schema other) const

Returns true if this schema has the same field types in the same order as another Schema.


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