5#ifndef STREAMBASE_COMPLETEDATATYPE_HPP_
6#define STREAMBASE_COMPLETEDATATYPE_HPP_
8#include "StreamBase.hpp"
10#include "DataType.hpp"
40 CompleteDataType(
const Schema &schema) : _type(DataType::TUPLE), _schema(
new Schema(schema)), _name(
""), _cdt(0), _argumentSchema(0), _returnType(0) { }
46 assert(!schema || type == DataType::TUPLE);
54 _type(type), _schema(0), _name(
""), _cdt(
new CompleteDataType(elementType)), _argumentSchema(0), _returnType(0) {
55 assert(type == DataType::LIST);
63 _type(type), _schema(0), _name(
""), _cdt(
new CompleteDataType(elementCDT)), _argumentSchema(0), _returnType(0) {
64 assert(type == DataType::LIST);
71 _type(type), _schema(0), _name(name), _cdt(0), _argumentSchema(0), _returnType(0) {
72 assert(type == DataType::CAPTURE);
79 _type(type), _schema(0), _name(
""), _cdt(0), _argumentSchema(
new Schema(argumentSchema)), _returnType(
new CompleteDataType(returnType)) {
80 assert(type == DataType::FUNCTION);
85#ifndef DOXYGEN_INTERNAL_ONLY
87 CompleteDataType() : _type(DataType::NONE), _schema(0), _cdt(0), _argumentSchema(0), _returnType(0) {}
92 _schema(cdt._schema ? new
Schema(*(cdt._schema)) : 0),
95 _argumentSchema(cdt._argumentSchema ? new
Schema(*(cdt._argumentSchema)) : 0),
109 bool operator==(
const CompleteDataType& t)
const {
return compare(t) == 0; }
110 bool operator!=(
const CompleteDataType& t)
const {
return compare(t) != 0; }
111 bool operator<(
const CompleteDataType& t)
const {
return compare(t) < 0; }
112 bool operator>(
const CompleteDataType& t)
const {
return compare(t) > 0; }
113 bool operator<=(
const CompleteDataType& t)
const {
return compare(t) <= 0; }
114 bool operator>=(
const CompleteDataType& t)
const {
return compare(t) >= 0; }
117 operator const void *()
const {
return this; }
170 return _type == DataType::TUPLE;
177 return _schema ? *_schema : Schema::EMPTY_SCHEMA;
184 return _cdt ? _cdt->getType() != DataType::NONE :
false;
191 return _cdt ? *_cdt : EMPTY_DATATYPE;
198 return _returnType ? *_returnType : EMPTY_DATATYPE;
206 return _argumentSchema ? *_argumentSchema : Schema::EMPTY_SCHEMA;
209 std::string getCaptureTypeName()
const {
222 case DataType::DOUBLE:
223 case DataType::TIMESTAMP:
224 case DataType::STRING:
226 return NMSTL::to_string(_type);
227 case DataType::TUPLE:
228 return NMSTL::to_string(_type) +
" (" + NMSTL::to_string(getSchema()) +
")";
230 return NMSTL::to_string(_type) +
" (" + NMSTL::to_string(getElementCompleteType()) +
")";
231 case DataType::CAPTURE:
233 case DataType::FUNCTION:
234 assert (_argumentSchema && _returnType);
235 return _argumentSchema->as_string() +
" -> " + _returnType->as_string();
238 NMSTL_ASSERT_UNREACHABLE();
An object containing all the information about a data type – the primitive DataType; for DataType::TU...
Definition: CompleteDataType.hpp:29
const CompleteDataType & getReturnType() const
If this CompleteDataType is a function, return its return type.
Definition: CompleteDataType.hpp:197
static const CompleteDataType & forDouble()
Return a CompleteDataType of type DataType::DOUBLE.
Definition: CompleteDataType.hpp:137
static const CompleteDataType & forString()
Return a CompleteDataType of type DataType::STRING.
Definition: CompleteDataType.hpp:141
int compare(const CompleteDataType &fv) const
Compare the current CompleteDataType against the provided CompleteDataType by base type (eg DataType:...
const Schema getSchema() const
If this CompleteDataType has a nested tuple, return its Schema.
Definition: CompleteDataType.hpp:176
static const CompleteDataType & forBlob()
Return a CompleteDataType of type DataType::BLOB.
Definition: CompleteDataType.hpp:143
bool hasElementType() const
Returns true if this CompleteDataType has an element CompleteDataType (eg it is a DataType::LIST of D...
Definition: CompleteDataType.hpp:183
const CompleteDataType & getElementCompleteType() const
If this CompleteDataType has an element type, returns the element CompleteDataType.
Definition: CompleteDataType.hpp:190
CompleteDataType(const CompleteDataType &cdt)
Copy constructor.
Definition: CompleteDataType.hpp:91
static const CompleteDataType forFunction(const Schema &argumentSchema, const CompleteDataType &returnType)
Return a CompleteDataType of type DataType::FUNCTION with the given argument schema and return type.
Definition: CompleteDataType.hpp:151
static const CompleteDataType & forTimestamp()
Return a CompleteDataType of type DataType::TIMESTAMP.
Definition: CompleteDataType.hpp:139
const Schema & getArgumentSchema() const
If this CompleteDataType is a function, return its argument schema.
Definition: CompleteDataType.hpp:205
~CompleteDataType()
Destructor.
Definition: CompleteDataType.hpp:103
static const CompleteDataType forTuple(const Schema &s)
Return a CompleteDataType of type DataType::TUPLE with the given Schema.
Definition: CompleteDataType.hpp:145
static const CompleteDataType forList(const CompleteDataType &elemType)
Return a CompleteDataType of type DataType::LIST with the given CompleteDataType as the type of its e...
Definition: CompleteDataType.hpp:147
std::string as_string() const
Returns a string representation of this CompleteDataType.
Definition: CompleteDataType.hpp:216
static const CompleteDataType & forBool()
Return a CompleteDataType of type DataType::BOOL.
Definition: CompleteDataType.hpp:131
static const CompleteDataType forCapture(const std::string &captureName)
Return a CompleteDataType of type DataType::CAPTURE with the given capture type name.
Definition: CompleteDataType.hpp:149
const DataType & getType() const
Return the primitive DataType of the CompleteDataType.
Definition: CompleteDataType.hpp:162
static const CompleteDataType forSimpleType(const DataType &type)
Convenience method.
bool hasSchema()
Returns true if this CompleteDataType contains a Schema (eg it is a DataType::TUPLE).
Definition: CompleteDataType.hpp:169
CompleteDataType & operator=(const CompleteDataType &cdt)
Assignment operator.
static const CompleteDataType & forLong()
Return a CompleteDataType of type DataType::LONG.
Definition: CompleteDataType.hpp:135
static const CompleteDataType & forInt()
Return a CompleteDataType of type DataType::INT.
Definition: CompleteDataType.hpp:133
A type of data in a tuple.
Definition: DataType.hpp:29
A type of tuple, containing zero or more fields (each encapsulated as a Schema::Field object).
Definition: Schema.hpp:62