19 #ifndef avro_GenericDatum_hh__    20 #define avro_GenericDatum_hh__    27 #if __cplusplus >= 201703L    30 #include "boost/any.hpp"    33 #include "LogicalType.hh"    35 #include "ValidSchema.hh"    65 #if __cplusplus >= 201703L    72         : type_(t), logicalType_(LogicalType::NONE) { }
    75         : type_(t), logicalType_(logicalType) { }
    79         : type_(t), logicalType_(logicalType), value_(v) { }
    81     void init(
const NodePtr& schema);
    98     template<
typename T> 
const T& value() 
const;
   109     template<
typename T> T& value();
   120     size_t unionBranch() 
const;
   126     void selectBranch(
size_t branch);
   176         type_(schema->type()), logicalType_(schema->logicalType()) {
   178 #if __cplusplus >= 201703L   179         *std::any_cast<T>(&value_) = v;
   181         *boost::any_cast<T>(&value_) = v;
   199     static void assertType(
const NodePtr& schema, 
Type type);
   243         if (curBranch_ != branch) {
   270     std::vector<GenericDatum> fields_;
   282         return fields_.size();
   290         if (!schema()->nameIndex(name, index)) {
   291             throw Exception(
"Invalid field name: " + name);
   302         return schema()->nameIndex(name, index);
   309         return fieldAt(fieldIndex(name));
   317         return fieldAt(fieldIndex(name));
   352     typedef std::vector<GenericDatum> 
Value;
   386     typedef std::vector<std::pair<std::string, GenericDatum> > 
Value;
   418     static size_t index(
const NodePtr& schema, 
const std::string& symbol) {
   420         if (schema->nameIndex(symbol, result)) {
   435     GenericEnum(
const NodePtr& schema, 
const std::string& symbol) :
   444         if (n < schema()->names()) {
   445             return schema()->nameAt(n);
   454     size_t index(
const std::string& symbol)
 const {
   455         return index(schema(), symbol);
   461     size_t set(
const std::string& symbol) {
   462         return value_ = index(symbol);
   469         if (n < schema()->names()) {
   487         return schema()->nameAt(value_);
   495     std::vector<uint8_t> value_;
   502         value_.resize(schema->fixedSize());
   505     GenericFixed(
const NodePtr& schema, 
const std::vector<uint8_t>& v) :
   511     const std::vector<uint8_t>& 
value()
 const {
   525 #if __cplusplus >= 201703L   528         boost::any_cast<
GenericUnion>(&value_)->datum().type() :
   539 #if __cplusplus >= 201703L   540         std::any_cast<
GenericUnion>(&value_)->datum().value<T>() :
   541         *std::any_cast<T>(&value_);
   543         boost::any_cast<
GenericUnion>(&value_)->datum().value<T>() :
   544         *boost::any_cast<T>(&value_);
   550 #if __cplusplus >= 201703L   551         std::any_cast<
GenericUnion>(&value_)->datum().value<T>() :
   552         *std::any_cast<T>(&value_);
   554         boost::any_cast<
GenericUnion>(&value_)->datum().value<T>() :
   555         *boost::any_cast<T>(&value_);
   560 #if __cplusplus >= 201703L   561     return std::any_cast<
GenericUnion>(&value_)->currentBranch();
   563     return boost::any_cast<GenericUnion>(&value_)->currentBranch();
   568 #if __cplusplus >= 201703L   569     std::any_cast<
GenericUnion>(&value_)->selectBranch(branch);
   571     boost::any_cast<GenericUnion>(&value_)->selectBranch(branch);
   576 #endif // avro_GenericDatum_hh__ std::vector< uint8_t > & value()
Returns the reference to the contents of this fixed. 
Definition: GenericDatum.hh:518
 
GenericArray(const NodePtr &schema)
Constructs a generic array corresponding to the given schema schema, which should be of Avro type arr...
Definition: GenericDatum.hh:358
 
size_t currentBranch() const
Returns the index of the current branch. 
Definition: GenericDatum.hh:236
 
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:331
 
size_t unionBranch() const
Returns the index of the current branch, if this is a union. 
Definition: GenericDatum.hh:559
 
const Value & value() const
Returns the contents of this array. 
Definition: GenericDatum.hh:364
 
The generic container for Avro maps. 
Definition: GenericDatum.hh:381
 
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:30
 
Generic container for Avro enum. 
Definition: GenericDatum.hh:415
 
const std::string & symbol() const
Returns the symbol for the current value of this enum. 
Definition: GenericDatum.hh:486
 
GenericDatum(double v)
Makes a new AVRO_DOUBLE datum whose value is of type double. 
Definition: GenericDatum.hh:148
 
const NodePtr & schema() const
Returns the schema for this object. 
Definition: GenericDatum.hh:210
 
bool isUnion() const
Returns true if and only if this datum is a union. 
Definition: GenericDatum.hh:114
 
GenericDatum(const std::string &v)
Makes a new AVRO_STRING datum whose value is of type std::string. 
Definition: GenericDatum.hh:152
 
size_t fieldIndex(const std::string &name) const
Returns index of the field with the given name name. 
Definition: GenericDatum.hh:288
 
The generic container for Avro arrays. 
Definition: GenericDatum.hh:347
 
const std::string & symbol(size_t n)
Returns the symbol corresponding to the cardinal n. 
Definition: GenericDatum.hh:443
 
size_t index(const std::string &symbol) const
Returns the cardinal for the given symbol symbol. 
Definition: GenericDatum.hh:454
 
Value & value()
Returns the reference to the contents of this map. 
Definition: GenericDatum.hh:405
 
std::vector< std::pair< std::string, GenericDatum > > Value
The contents type for the map. 
Definition: GenericDatum.hh:386
 
GenericContainer(Type type, const NodePtr &s)
Constructs a container corresponding to the given schema. 
Definition: GenericDatum.hh:204
 
const GenericDatum & fieldAt(size_t pos) const
Returns the field at the given position pos. 
Definition: GenericDatum.hh:323
 
void setFieldAt(size_t pos, const GenericDatum &v)
Replaces the field at the given position pos with v. 
Definition: GenericDatum.hh:338
 
Value & value()
Returns the reference to the contents of this array. 
Definition: GenericDatum.hh:371
 
const T & value() const
Returns the value held by this datum. 
Definition: GenericDatum.hh:548
 
GenericDatum(const std::vector< uint8_t > &v)
Makes a new AVRO_BYTES datum whose value is of type std::vector<uint8_t>. 
Definition: GenericDatum.hh:157
 
GenericMap(const NodePtr &schema)
Constructs a generic map corresponding to the given schema schema, which should be of Avro type map...
Definition: GenericDatum.hh:392
 
GenericDatum(const NodePtr &schema, const T &v)
Constructs a datum corresponding to the given avro type and set the value. 
Definition: GenericDatum.hh:175
 
size_t value() const
Returns the cardinal for the current value of this enum. 
Definition: GenericDatum.hh:479
 
GenericEnum(const NodePtr &schema)
Constructs a generic enum corresponding to the given schema schema, which should be of Avro type enum...
Definition: GenericDatum.hh:431
 
GenericDatum()
Makes a new AVRO_NULL datum. 
Definition: GenericDatum.hh:129
 
GenericDatum(float v)
Makes a new AVRO_FLOAT datum whose value is of type float. 
Definition: GenericDatum.hh:144
 
GenericDatum(int32_t v)
Makes a new AVRO_INT datum whose value is of type int32_t. 
Definition: GenericDatum.hh:136
 
GenericDatum & datum()
Returns the datum corresponding to the currently selected branch in this union. 
Definition: GenericDatum.hh:253
 
Definition: LogicalType.hh:28
 
LogicalType logicalType() const
The avro logical type that augments the main data type this datum holds. 
Definition: GenericDatum.hh:533
 
The generic container for Avro records. 
Definition: GenericDatum.hh:269
 
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:316
 
void selectBranch(size_t branch)
Selects a new branch. 
Definition: GenericDatum.hh:242
 
size_t fieldCount() const
Returns the number of fields in the current record. 
Definition: GenericDatum.hh:281
 
GenericDatum(bool v)
Makes a new AVRO_BOOL datum whose value is of type bool. 
Definition: GenericDatum.hh:132
 
std::vector< GenericDatum > Value
The contents type for the array. 
Definition: GenericDatum.hh:352
 
void selectBranch(size_t branch)
Selects a new branch in the union if this is a union. 
Definition: GenericDatum.hh:567
 
const GenericDatum & datum() const
Returns the datum corresponding to the currently selected branch in this union. 
Definition: GenericDatum.hh:261
 
Wrapper for std::runtime_error that provides convenience constructor for boost::format objects...
Definition: Exception.hh:31
 
Type type() const
The avro data type this datum holds. 
Definition: GenericDatum.hh:523
 
A ValidSchema is basically a non-mutable Schema that has passed some minumum of sanity checks...
Definition: ValidSchema.hh:40
 
const GenericDatum & field(const std::string &name) const
Returns the field with the given name name. 
Definition: GenericDatum.hh:308
 
The base class for all generic type for containers. 
Definition: GenericDatum.hh:197
 
Generic container for Avro fixed. 
Definition: GenericDatum.hh:494
 
Generic container for unions. 
Definition: GenericDatum.hh:218
 
const Value & value() const
Returns the contents of this map. 
Definition: GenericDatum.hh:398
 
const std::vector< uint8_t > & value() const
Returns the contents of this fixed. 
Definition: GenericDatum.hh:511
 
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:300
 
GenericDatum(int64_t v)
Makes a new AVRO_LONG datum whose value is of type int64_t. 
Definition: GenericDatum.hh:140
 
GenericFixed(const NodePtr &schema)
Constructs a generic enum corresponding to the given schema schema, which should be of Avro type fixe...
Definition: GenericDatum.hh:501
 
Generic datum which can hold any Avro type. 
Definition: GenericDatum.hh:61
 
GenericUnion(const NodePtr &schema)
Constructs a generic union corresponding to the given schema schema, and the given value...
Definition: GenericDatum.hh:228