Commit 58360c22 authored by hlgr's avatar hlgr
Browse files

throwing on invalid casts/attribute extraction

parent b9bee4ac
#pragma once
#include <valarray>
#include <variant>
#include <array>
#include <map>
#include <vector>
#include <variant>
#include <any>
#include <string>
#include <iostream>
#include <functional>
#include <memory>
#include "Storage.hpp"
using namespace std;
#include <valarray>
#include <variant>
#include <array>
#include <map>
#include <vector>
#include <variant>
#include <any>
#include <string>
#include <iostream>
#include <functional>
#include <memory>
#include "Storage.hpp"
using namespace std;
struct SupportedDatatype : public variant<long, double, string> { // <- supported datatypes
// All of this stuff is convenience functions
......@@ -58,7 +58,13 @@ struct SupportedDatatype : public variant<long, double, string> { // <- supporte
}
bool operator>(SupportedDatatype const& t) const { return !(*this == t || *this < t); }
template <typename T> explicit operator T() { return get_if<T>(this) ? *get_if<T>(this) : T{}; }
template <typename T> explicit operator T() const {
if(!get_if<T>(this))
throw logic_error(string("attribute does not hold a value of the requested type: ") +
typeid(T).name());
return *get_if<T>(this);
}
friend ostream& operator<<(ostream& stream, SupportedDatatype const& v) {
if(get_if<long>(&v))
stream << *get_if<long>(&v);
......@@ -117,7 +123,7 @@ struct Tuple : valarray<SupportedDatatype> {
}
friend ostream& operator<<(ostream& stream, Tuple const& t) {
for (auto it = begin(t); it != prev(end(t)); ++it)
for(auto it = begin(t); it != prev(end(t)); ++it)
cout << *it << ", ";
return stream << *prev(end(t));
}
......@@ -348,7 +354,7 @@ struct BufferedGroupBy : BufferedScan {
nextGroupOperatorID++;
}
Tuple& getHashTableEntry(size_t id, Tuple const& groupKeys);
size_t hashTableEntrySize(Tuple const& groupKeys) const ;
size_t hashTableEntrySize(Tuple const& groupKeys) const;
void open();
......@@ -364,4 +370,4 @@ size_t hashTableEntrySize(Tuple const& groupKeys) const ;
child->close();
}
};
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment