Example #1
0
variant::variant(const std::string& str)
	: type_(TYPE_STRING)
{
	string_ = new variant_string;
	string_->str = str;
	increment_refcount();
}
Example #2
0
	variant(const variant& v) {
		type_ = v.type_;
		value_ = v.value_;
		if(type_ > VARIANT_TYPE_INT) {
			increment_refcount();
		}
	}
Example #3
0
variant::variant(std::map<variant,variant>* map)
    : type_(TYPE_MAP)
{
	assert(map);
	map_ = new variant_map;
	map_->elements.swap(*map);
	increment_refcount();
}
Example #4
0
variant::variant(std::vector<variant>* array)
    : type_(TYPE_LIST)
{
	assert(array);
	list_ = new variant_list;
	list_->elements.swap(*array);
	increment_refcount();
}
Example #5
0
const variant& variant::operator=(const variant& v)
{
	if(&v != this) {
		release();
		memcpy(this, &v, sizeof(v));
		increment_refcount();
	}
	return *this;
}
Example #6
0
variant::variant(const game_logic::formula_callable* callable)
	: type_(TYPE_CALLABLE), callable_(callable)
{
	if(callable == NULL) {
		type_ = TYPE_NULL;
		return;
	}
	increment_refcount();
}
Example #7
0
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();
}
Example #8
0
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;
}
Example #9
0
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;
}
Example #10
0
variant::variant(const variant& v)
    : type_(v.type_)
{
	memcpy(this, &v, sizeof(v));
	increment_refcount();
}
Example #11
0
variant::variant(const game_logic::formula_callable* callable)
	: type_(TYPE_CALLABLE), callable_(callable)
{
	assert(callable_);
	increment_refcount();
}