3#ifndef STREAMBASE_SCHEMA_H
4#define STREAMBASE_SCHEMA_H
6#if !(defined(WIN32) || defined(__APPLE__))
10#include "StreamBase.hpp"
14#include "Exceptions.hpp"
15#include "SBHashMap.hpp"
17SB_INTERNAL_FWD(SchemaUtil);
18SB_INTERNAL_FWD(Errors);
42 size_t operator()(
const std::string &str)
const
44 const std::string::value_type *buffer = str.data();
46 for (
unsigned int i = 0; i < str.size(); i++)
49 hashcode = (37 * hashcode) + *(buffer++);
65 static const int HASH_LENGTH = 16;
72 static const int HEADER_SIZE = 4;
77 static const Schema EMPTY_SCHEMA;
98 template <
typename Iterator>
102 template <
typename Iterator>
117 typedef QUALIFIED_SB_HASH_MAP<std::string, int, StringHashFunc> FieldIndexMap;
118 typedef QUALIFIED_SB_HASH_MAP<std::string, Field, StringHashFunc> FieldPathMap;
135 operator const void *()
const {
return _isInitialized ? _rep.get() : (
const void*) NULL; }
150 size_t getNullMaskSize()
const;
153 size_t getNullMaskOffset()
const {
177 const bool hasField(
const std::string &pathName)
const;
201 std::string as_xml(std::string name = std::string(),
bool aAddUUID =
true)
const;
216 bool operator == (
const Schema& other)
const;
217 bool operator != (
const Schema& other)
const {
218 return !(*
this == other);
224 void addField(
const Field& f);
228 template <
typename Iterator>
229 void addFields(Iterator begin, Iterator end) {
231 addField(*(begin++));
234 void resolveFieldPathName(
const std::string& pathName, std::vector<Field>& fields)
const;
237 std::shared_ptr<SchemaRep> _rep;
239 friend class sb_internal::SchemaUtil;
240 friend class SchemaRep;
245inline std::ostream& operator << (std::ostream& os,
const sb::Schema& schema) {
Information (name, type, and optionally size) about a field in a Schema.
Definition: Field.hpp:40
No field found with the given name or index.
Definition: Schema.hpp:32
Field path name contained an not-leaf segment whose type was not TUPLE.
Definition: Schema.hpp:35
A type of tuple, containing zero or more fields (each encapsulated as a Schema::Field object).
Definition: Schema.hpp:62
Schema(std::string name, const std::vector< Field > &fields, Flags flags=Flags())
Constructs a Schema from a vector of Field objects.
static Schema fromXml(const std::string &input, Flags flags=Flags())
Parse and return a schema from an XML string.
Schema(const std::vector< Field > &fields, Flags flags=Flags())
Constructs a Schema from a vector of Field objects.
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.
Schema & operator=(const Schema &)
Assignment operator.
const Field & getField(const std::string &pathName) const
Return the Fields object description of a field in the schema.
size_t getHeaderSize() const
Return the size of the header.
Definition: Schema.hpp:144
size_t getNumFields() const
Returns the number of fields in the schema.
Schema(std::string name, Iterator begin, Iterator end, Flags flags=Flags())
Constructs a Schema from a sequence of Field objects.
const bool hasField(const std::string &pathName) const
Returns true if a field of a given path name is present, otherwise it returns false.
Flags
Flags for creating a schema.
Definition: Schema.hpp:80
bool hasHeader() const
Return true if the schema has space for a header, false otherwise.
Definition: Schema.hpp:139
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 suc...
Schema(Iterator begin, Iterator end, Flags flags=Flags())
Constructs a Schema from a sequence of Field objects.
bool sameFieldTypes(const Schema &other) const
Returns true if this schema has the same field types in the same order as another Schema.
const std::vector< Field > & getFields() const
Returns a reference to a vector of all fields in the schema.
const std::string & getName() const
Returns the name of the schema or empty string at runtime.
Schema()
Creates an uninitialized Schema.
Schema(const Schema &schema)
Copy constructor.
std::string as_string() const
Returns a string representation of the schema.
const Field & getField(size_t field_num) const
Return the Fields object description of a field in the schema.
Error parsing a tuple as a delimited string.
Definition: Schema.hpp:29