19 #ifndef avro_GenericDatum_hh__
20 #define avro_GenericDatum_hh__
27 #include <boost/any.hpp>
30 #include "ValidSchema.hh"
64 void init(
const NodePtr& schema);
78 template<
typename T>
const T&
value()
const {
79 return *boost::any_cast<T>(&value_);
91 template<
typename T> T&
value() {
92 return *boost::any_cast<T>(&value_);
104 size_t unionBranch()
const;
110 void selectBranch(
size_t branch);
154 type_(schema->type()) {
173 static void assertType(
const NodePtr& schema,
Type type);
216 if (curBranch_ != branch) {
243 std::vector<GenericDatum> fields_;
255 return fields_.size();
263 if (!schema()->nameIndex(name, index)) {
264 throw Exception(
"Invalid field name: " + name);
275 return schema()->nameIndex(name, index);
282 return fieldAt(fieldIndex(name));
290 return fieldAt(fieldIndex(name));
325 typedef std::vector<GenericDatum>
Value;
359 typedef std::vector<std::pair<std::string, GenericDatum> >
Value;
391 static size_t index(
const NodePtr& schema,
const std::string& symbol) {
393 if (schema->nameIndex(symbol, result)) {
408 GenericEnum(
const NodePtr& schema,
const std::string& symbol) :
417 if (n < schema()->names()) {
418 return schema()->nameAt(n);
427 size_t index(
const std::string& symbol)
const {
428 return index(schema(), symbol);
434 size_t set(
const std::string& symbol) {
435 return value_ = index(symbol);
442 if (n < schema()->names()) {
460 return schema()->nameAt(value_);
468 std::vector<uint8_t> value_;
475 value_.resize(schema->fixedSize());
478 GenericFixed(
const NodePtr& schema,
const std::vector<uint8_t>& v) :
484 const std::vector<uint8_t>&
value()
const {
497 return boost::any_cast<
GenericUnion>(&value_)->currentBranch();
505 #endif // avro_GenericDatum_hh__
std::vector< uint8_t > & value()
Returns the reference to the contents of this fixed.
Definition: GenericDatum.hh:491
GenericArray(const NodePtr &schema)
Constructs a generic array corresponding to the given schema schema, which should be of Avro type arr...
Definition: GenericDatum.hh:331
GenericDatum & fieldAt(size_t pos)
Returns the reference to the field at the given position pos, which can be used to change the content...
Definition: GenericDatum.hh:304
size_t index(const std::string &symbol) const
Returns the cardinal for the given symbol symbol.
Definition: GenericDatum.hh:427
The generic container for Avro maps.
Definition: GenericDatum.hh:354
Type
The "type" for the schema.
Definition: Types.hh:31
A bunch of templates and specializations for encoding and decoding specific types.
Definition: AvroParse.hh:31
void set(size_t n)
Set the value for this enum corresponding to the given cardinal n.
Definition: GenericDatum.hh:441
Generic container for Avro enum.
Definition: GenericDatum.hh:388
GenericDatum(double v)
Makes a new AVRO_DOUBLE datum whose value is of type double.
Definition: GenericDatum.hh:128
size_t fieldIndex(const std::string &name) const
Returns index of the field with the given name name.
Definition: GenericDatum.hh:261
GenericDatum(const std::string &v)
Makes a new AVRO_STRING datum whose value is of type std::string.
Definition: GenericDatum.hh:131
const Value & value() const
Returns the contents of this array.
Definition: GenericDatum.hh:337
const T & value() const
Returns the value held by this datum.
Definition: GenericDatum.hh:78
The generic container for Avro arrays.
Definition: GenericDatum.hh:320
const GenericDatum & field(const std::string &name) const
Returns the field with the given name name.
Definition: GenericDatum.hh:281
const std::string & symbol(size_t n)
Returns the symbol corresponding to the cardinal n.
Definition: GenericDatum.hh:416
Value & value()
Returns the reference to the contents of this map.
Definition: GenericDatum.hh:378
std::vector< std::pair< std::string, GenericDatum > > Value
The contents type for the map.
Definition: GenericDatum.hh:359
GenericContainer(Type type, const NodePtr &s)
Constructs a container corresponding to the given schema.
Definition: GenericDatum.hh:178
void setFieldAt(size_t pos, const GenericDatum &v)
Replaces the field at the given position pos with v.
Definition: GenericDatum.hh:311
T & value()
Returns the reference to the value held by this datum, which can be used to change the contents...
Definition: GenericDatum.hh:91
Value & value()
Returns the reference to the contents of this array.
Definition: GenericDatum.hh:344
const Value & value() const
Returns the contents of this map.
Definition: GenericDatum.hh:371
size_t unionBranch() const
Returns the index of the current branch, if this is a union.
Definition: GenericDatum.hh:496
GenericDatum(const std::vector< uint8_t > &v)
Makes a new AVRO_BYTES datum whose value is of type std::vector.
Definition: GenericDatum.hh:135
GenericMap(const NodePtr &schema)
Constructs a generic map corresponding to the given schema schema, which should be of Avro type map...
Definition: GenericDatum.hh:365
GenericDatum(const NodePtr &schema, const T &v)
Constructs a datum corresponding to the given avro type and set the value.
Definition: GenericDatum.hh:153
size_t set(const std::string &symbol)
Set the value for this enum corresponding to the given symbol symbol.
Definition: GenericDatum.hh:434
const std::vector< uint8_t > & value() const
Returns the contents of this fixed.
Definition: GenericDatum.hh:484
GenericEnum(const NodePtr &schema)
Constructs a generic enum corresponding to the given schema schema, which should be of Avro type enum...
Definition: GenericDatum.hh:404
GenericDatum()
Makes a new AVRO_NULL datum.
Definition: GenericDatum.hh:113
GenericDatum(float v)
Makes a new AVRO_FLOAT datum whose value is of type float.
Definition: GenericDatum.hh:125
GenericDatum(int32_t v)
Makes a new AVRO_INT datum whose value is of type int32_t.
Definition: GenericDatum.hh:119
GenericDatum & datum()
Returns the datum corresponding to the currently selected branch in this union.
Definition: GenericDatum.hh:226
The generic container for Avro records.
Definition: GenericDatum.hh:242
GenericDatum & field(const std::string &name)
Returns the reference to the field with the given name name, which can be used to change the contents...
Definition: GenericDatum.hh:289
void selectBranch(size_t branch)
Selects a new branch.
Definition: GenericDatum.hh:215
GenericDatum(bool v)
Makes a new AVRO_BOOL datum whose value is of type bool.
Definition: GenericDatum.hh:116
std::vector< GenericDatum > Value
The contents type for the array.
Definition: GenericDatum.hh:325
void selectBranch(size_t branch)
Selects a new branch in the union if this is a union.
Definition: GenericDatum.hh:500
size_t value() const
Returns the cardinal for the current value of this enum.
Definition: GenericDatum.hh:452
size_t currentBranch() const
Returns the index of the current branch.
Definition: GenericDatum.hh:209
Wrapper for std::runtime_error that provides convenience constructor for boost::format objects...
Definition: Exception.hh:31
const GenericDatum & fieldAt(size_t pos) const
Returns the field at the given position pos.
Definition: GenericDatum.hh:296
A ValidSchema is basically a non-mutable Schema that has passed some minumum of sanity checks...
Definition: ValidSchema.hh:40
size_t fieldCount() const
Returns the number of fields in the current record.
Definition: GenericDatum.hh:254
const GenericDatum & datum() const
Returns the datum corresponding to the currently selected branch in this union.
Definition: GenericDatum.hh:234
Type type() const
The avro data type this datum holds.
Definition: GenericDatum.hh:69
const NodePtr & schema() const
Returns the schema for this object.
Definition: GenericDatum.hh:184
The base class for all generic type for containers.
Definition: GenericDatum.hh:171
Generic container for Avro fixed.
Definition: GenericDatum.hh:467
Generic container for unions.
Definition: GenericDatum.hh:192
const std::string & symbol() const
Returns the symbol for the current value of this enum.
Definition: GenericDatum.hh:459
GenericDatum(int64_t v)
Makes a new AVRO_LONG datum whose value is of type int64_t.
Definition: GenericDatum.hh:122
GenericFixed(const NodePtr &schema)
Constructs a generic enum corresponding to the given schema schema, which should be of Avro type fixe...
Definition: GenericDatum.hh:474
bool hasField(const std::string &name) const
Returns true if a field with the given name name is located in this r false otherwise.
Definition: GenericDatum.hh:273
bool isUnion() const
Returns true if and only if this datum is a union.
Definition: GenericDatum.hh:98
Generic datum which can hold any Avro type.
Definition: GenericDatum.hh:55
GenericUnion(const NodePtr &schema)
Constructs a generic union corresponding to the given schema schema, and the given value...
Definition: GenericDatum.hh:202