variant::variant(const std::string& str) : type_(TYPE_STRING) { string_ = new variant_string; string_->str = str; increment_refcount(); }
variant(const variant& v) { type_ = v.type_; value_ = v.value_; if(type_ > VARIANT_TYPE_INT) { increment_refcount(); } }
variant::variant(std::map<variant,variant>* map) : type_(TYPE_MAP) { assert(map); map_ = new variant_map; map_->elements.swap(*map); increment_refcount(); }
variant::variant(std::vector<variant>* array) : type_(TYPE_LIST) { assert(array); list_ = new variant_list; list_->elements.swap(*array); increment_refcount(); }
const variant& variant::operator=(const variant& v) { if(&v != this) { release(); memcpy(this, &v, sizeof(v)); increment_refcount(); } return *this; }
variant::variant(const game_logic::formula_callable* callable) : type_(TYPE_CALLABLE), callable_(callable) { if(callable == NULL) { type_ = TYPE_NULL; return; } increment_refcount(); }
variant::variant(game_logic::const_formula_ptr fml, const std::vector<std::string>& args, const game_logic::formula_callable& callable) : type_(TYPE_FUNCTION) { fn_ = new variant_fn; if(args.empty()) { fn_->begin_args = fn_->end_args = NULL; } else { fn_->begin_args = &args[0]; fn_->end_args = fn_->begin_args + args.size(); } fn_->fn = fml; fn_->callable = &callable; increment_refcount(); }
const variant& variant::operator=(const variant& v) { if(&v != this) { if(type_ > TYPE_INT) { release(); } type_ = v.type_; value_ = v.value_; if(type_ > TYPE_INT) { increment_refcount(); } } return *this; }
std::vector<variant>& variant::initialize_list() { if(type_ == TYPE_LIST) { if(list_->refcount == 1) { list_->elements.clear(); return list_->elements; } release(); } else { release(); type_ = TYPE_LIST; } list_ = new variant_list; increment_refcount(); return list_->elements; }
variant::variant(const variant& v) : type_(v.type_) { memcpy(this, &v, sizeof(v)); increment_refcount(); }
variant::variant(const game_logic::formula_callable* callable) : type_(TYPE_CALLABLE), callable_(callable) { assert(callable_); increment_refcount(); }