//CAST
any bitset_descriptor::cast (const any& value) const
{
    if (value.desc() != this)
    {
        any destination;
        std::string svalue;
        return this->stoa(value.desc()->atos(value), destination);
    }

    return any(value);
}
// RAW VALUE SERIALIZATION
void bitset_descriptor::set(void* ptr, const any& value)  const
{
    boost::dynamic_bitset<>* destination = (boost::dynamic_bitset<>*) ptr;
    if (value.desc() != this)
    {
        any a = destination;
        std::string svalue = std::move(value.desc()->atos(value));
        this->stoa(svalue, a);
        *destination = *anycast<boost::dynamic_bitset<>*>(a);
    }
    else
    {
        *destination = *anycast<boost::dynamic_bitset<>*>(value);
    }
}
Exemple #3
0
// USeless ?
bool serial_manager::remove_object(any object)
{
    const descriptor* d = object.desc();
    any serial_value;
    d->serial().get(object, serial_value);
    return this->remove(serial_value.tos());
}
// TO/FROM STRING SERIALIZATION 
std::string any_descriptor::atos(const any& value) const
{
	const descriptor* cd = value.desc();
	if (!cd)
	{
		throw LAURENA_NULL_POINTER_EXCEPTION("unknow class descriptor");
	}
	return cd->atos(value);

}
    static void impl(CONTAINER* c, const descriptor* element_descriptor, any& element)
    {
        if ( element.desc()->has(descriptor::Flags::ATOMIC))
	    {
		    element = element_descriptor->cast(element);
		    c->push_back(anycast<ELEMENT>(element));
	    }
	    else
	    {
		    ELEMENT* e = anycast<ELEMENT*>(element);
		    c->push_back(*e);
	    }
    }
void oarchive_json::serializeObject(const any& value)
{
const descriptor* cd = value.desc();

    if ( !cd)
    {
        throw new LAURENA_NULL_POINTER_EXCEPTION("any& value do have nullptr descriptor.");
    }

    word32 backup = this->_nb_fields;
    this->_nb_fields = 0;

	std::string opening = "{";
	std::string ending = "}" ;

	if (cd->hasFeature(Feature::CONTAINER))
	{
		opening = "[" ;
		ending = "]" ;
	}

    // opening
	if (this->_compact) 
		this->_data << opening ;
	else
	{
		this->_data << this->_tab << opening << std::endl;
		this->_tab.increase();
	}


    if (cd->has(descriptor::Flags::FIELDS))
        this->serializeFields(*cd,value);   

    if (cd->hasFeature(Feature::CONTAINER))
        this->serializeElements(*cd,value);

	if (this->_compact)
		this->_data << ending ;
	else 
	{
		this->_data << std::endl << this->_tab.decrease() << ending ;
	}

    this->_nb_fields = backup;
}
Exemple #7
0
void iarchive_xml::readObject(const std::string& tag, any& object)
{
token t;
std::string keyword;
const descriptor* d = object.desc();

    // READ ATTRIBUTES
    this->readAttributes(object);

    // End of section
    t = std::move(this->read_token(XML::TOKEN_INFERIOR_SLASH, XML::TOKEN_SUPERIOR));


    while(true)
    {
        std::string content = this->_tokenizer.readUntil("<",true);
        if (*this->_tokenizer._ptr == '/')
        {
            // Check that incoming keyword is same than the last one
            this->read_token(XML::TOKEN_SLASH);
            t = std::move(this->read_token( XML::TOKEN_KEYWORD));

            std::string keyword = anycast<std::string>(t);
            if (keyword == tag)
            {
                this->read_token(XML::TOKEN_SUPERIOR);
                //object.desc()->stoa(content, object);
                return;
            }
            else
                this->error_tag_not_expected(tag, keyword);
        }
        else
        {
            // check content is tabs
            if (!const_charsets<>::TABS.validate(content))
            {
                throw LAURENA_FAILED_PARSING_EXCEPTION("Syntax error",this->_tokenizer._ptr);
            }

            // read keyword
            t=std::move(this->read_token(XML::TOKEN_KEYWORD));
            std::string keyword = anycast<std::string>(t);

            // Identification of keyword
	        if (d->has(descriptor::Flags::FIELDS))
	        {
		        const field* f = d->findField(keyword); 
                if (f)
                {
                    this->readField(*f, keyword, object);
                    continue;
                }
            }
            
            std::ostringstream ss;
            ss << keyword << " : unknow child for class " << d->name();
            throw LAURENA_FAILED_PARSING_EXCEPTION(ss.str().c_str(),this->_tokenizer._ptr);
            
        }

    }
}