Beispiel #1
0
void print::operator()(object_t const &m) const
{
  using namespace std;
  
  if(mode_) {
    if(depth_)
      (*os_) << "\n";
    PRINT_SPACE(depth_, *os_);
  }

  (*os_) << "{";
  if(mode_) (*os_) << "\n";
  object_t::const_iterator i = m.begin();
  object_t::const_iterator j = m.begin();
  ++depth_;
  while(i != m.end()){
    if(mode_) PRINT_SPACE(depth_, *os_);
    (*this)(i->first);
    (*os_) << " : ";
    boost::apply_visitor(*this, i->second);
    if(++i != m.end()) {
      (*os_) << ",";
      if(mode_) (*os_) << "\n";
    }
  }
  depth_--;
  if(mode_) {
    (*os_) << "\n";
    PRINT_SPACE(depth_, *os_);
  }
  (*os_) << "}";
  if(mode_ && !depth_) 
    (*os_) << "\n";

}
Beispiel #2
0
S32 LLSDJSONParser::parseObject( object_t obj, LLSD& data ) const
{
	S32					object_count = 0;
	iterator_t			iter	= obj.begin();
	const iterator_t	end		= obj.end();
	//
	for( ; iter != end; ++iter )
	{
		std::string name = iter->first;
		variant_t var = iter->second;
		//
		if( var->type() == typeid(std::string) )
		{
			data[name] = boost::any_cast<std::string>(*var);
			object_count++;
		}
		else if( var->type() == typeid(bool) )
		{
			data[name] = boost::any_cast<bool>(*var);
			object_count++;
		}
		else if( var->type() == typeid(int) )
		{
			data[name] = boost::any_cast<int>(*var);
			object_count++;
		}
		else if( var->type() == typeid(double) )
		{
			data[name] = boost::any_cast<double>(*var);
			object_count++;
		}
		else if( var->type() == typeid(object_t) )
		{
			object_count += parseObject( boost::any_cast<object_t>(*var), data[name] );
		}
		else
		{
			data[name] = "null";
			object_count++;
		}
	}

	return object_count;
}
Beispiel #3
0
    static void extract(const object_t &json, char* json_ptr, const char *key, const std::size_t &len, T &value)
    {
        jsonpack::key k;
        k._bytes = len;
        k._ptr = key;

        object_t::const_iterator found = json.find(k);
        if( found != json.end() )    // exist the current key
        {
            if( match_token_type(found->second) )
            {
                extract(found->second, json_ptr, value);
            }
            else
            {
                std::string msg = derived::invalid_value_msg();
                throw type_error( msg.data() );
            }
        }
    }
Beispiel #4
0
    static void extract(const object_t &json, char* json_ptr, const char *key, const std::size_t &len, Seq &value)
    {
        jsonpack::key k;
        k._bytes = len;
        k._ptr = key;

        object_t::const_iterator found = json.find(k);
        if( found != json.end() )    // exist the current key
        {
            if(found->second._field == _ARR )
            {
                extract(found->second, json_ptr, value);
            }
            else
            {
                std::string msg = "Invalid array value for key: ";
                msg += key;
                throw type_error( msg.data() );
            }
        }
    }