24 #include <boost/typeof/typeof.hpp> 25 #include <boost/algorithm/string.hpp> 26 #include <boost/functional/hash.hpp> 39 : value_(
"OPTIONAL"), type_(no_default_optional_type), storage_(NULL)
45 boost::algorithm::trim(
value_);
56 boost::hash_combine(seed,
"Default");
57 boost::hash_combine(seed,
type_);
58 boost::hash_combine(seed,
value_);
71 istringstream is(
"[\n" +
value_ +
"\n]");
76 }
catch ( Input::ReaderInternalBase::ExcNotJSONFormat &e ) {
77 THROW( ExcWrongDefaultJSON() << EI_DefaultStr(
value_ ) << EI_TypeName(type->type_name())
79 }
catch ( Input::ReaderInternalBase::ExcInputError &e ) {
80 THROW( ExcWrongDefault() << EI_DefaultStr(
value_ ) << EI_TypeName(type->type_name())
125 boost::hash_combine(seed,
"Record");
126 data_->content_hash(seed);
133 ASSERT(
data_->auto_conversion_key_idx == -1)(from_key).error(
"auto conversion key is already set");
134 data_->auto_conversion_key_idx = 0;
135 data_->auto_conversion_key=from_key;
147 if (
data_->keys.size() && it->key_ ==
"TYPE") it++;
150 for(
KeyIter pit=origin.
data_->keys.begin(); pit != origin.
data_->keys.end(); ++pit) {
158 if (tmp_key.
key_==
"TYPE")
163 if (kit !=
data_->key_to_index.end()) {
166 Key *k = &(
data_->keys[kit->second+n_inserted]);
178 it =
data_->keys.insert(it, tmp_key)+1;
182 for (
unsigned int i=0; i<
data_->keys.size(); i++) {
183 if (
data_->keys[i].key_.compare(
"") == 0) {
187 data_->keys[i].key_index = i;
198 .error(
"Derived record must have defined TYPE key!");
202 for (
auto &parent :
data_->parent_vec_) {
209 data_->parent_vec_.push_back( std::make_shared<Abstract>(parent) );
226 return data_->finish_status_;
236 return data_->closed_;
256 if (
it->key_ !=
"TYPE") {
257 if (
typeid( *(
it->type_.get()) ) ==
typeid(
Instance)) {
259 it->type_ =
it->type_->make_instance().first;
262 THROW( ExcGenericWithoutInstance()
263 << EI_Object(
it->type_->type_name())
265 it->type_->finish(finish_type);
266 ASSERT(
it->type_->is_finished()).error();
272 it->default_.check_validity(
it->type_);
273 }
catch (ExcWrongDefaultJSON & e) {
274 e << EI_KeyName(
it->key_);
276 }
catch (ExcWrongDefault & e) {
277 e << EI_KeyName(
it->key_);
285 if (
data_->auto_conversion_key_idx != -1 ) {
290 const string &other_key =
it->key_;
291 ASSERT(!
it->default_.is_obligatory() || (int)(
it->key_index) ==
data_->auto_conversion_key_idx)
292 (
data_->auto_conversion_key_iter()->key_)(other_key)
293 .error(
"Finishing auto convertible Record from given key, but other obligatory key has no default value.");
297 data_->finish_status_ = finish_type;
298 return (
data_->finish_status_);
306 for (
auto &parent :
data_->parent_vec_) {
307 parent->add_child(rec);
316 return data_->type_name_;
328 {
return typeid(*this) ==
typeid(other) &&
335 return data_->auto_conversion_key_iter();
363 return std::make_pair( std::make_shared<Record>(rec.
close()), parameter_map );
370 if ( key_it->key_ !=
"TYPE" ) {
372 key_it->type_ = inst.first;
374 parameter_map.insert(other_map.begin(), other_map.end());
387 rec.
data_ = std::make_shared<Record::RecordData>(*this->
data_);
388 rec.
data_->closed_ =
false;
431 :description_(description),
432 type_name_(type_name_in),
436 auto_conversion_key_idx(-1)
444 else return keys.end();
450 std::shared_ptr<TypeBase> type,
452 const string &description,
465 Key tmp_key = { (
unsigned int)
keys.size(), key, description, type, default_value,
false, key_attributes };
466 keys.push_back(tmp_key);
468 ASSERT(
keys[it->second].derived )(key)(
type_name_).error(
"Re-declaration of the key in Record");
469 Key tmp_key = { it->second, key, description, type, default_value,
false};
470 keys[ it->second ] = tmp_key;
480 if (key.key_ !=
"TYPE") {
481 boost::hash_combine(seed, key.key_);
482 boost::hash_combine(seed, key.description_);
483 boost::hash_combine(seed, key.type_->content_hash() );
484 boost::hash_combine(seed, key.default_.content_hash() );
491 const Default &default_value,
const string &description,
494 data_->declare_key(key, type, default_value, description, key_attributes);
499 template <
class KeyType>
501 const Default &default_value,
const string &description,
507 std::shared_ptr<TypeBase> type_copy = std::make_shared<KeyType>(type);
508 return declare_key(key, type_copy, default_value, description, key_attributes);
513 template <
class KeyType>
515 const string &description,
525 #define RECORD_DECLARE_KEY(TYPE) \ 526 template Record & Record::declare_key<TYPE>(const string &key, const TYPE &type, const Default &default_value, const string &description, TypeBase::attribute_map key_attributes); \ 527 template Record & Record::declare_key<TYPE>(const string &key, const TYPE &type, const string &description, TypeBase::attribute_map key_attributes)
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
static constexpr bool value
EI_Nested make_nested_ei(Exc &e)
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.