void json2tvalue(QVariant & output, const rapidjson::Value & input, int itype)
    {
        if(input.IsNull())
        {
            output.clear();
        }
        else if(input.IsInt64())
        {
            output = QVariant(input.GetInt64());
        }
        else if(input.IsInt())
        {
            output = QVariant(input.GetInt());
        }
        else if(input.IsDouble())
        {
            output = QVariant(input.GetDouble());
        }
        else if(input.IsBool())
        {
            output = QVariant(input.GetBool());
        }
        else if(input.IsString())
        {
            output = QVariant(QString(input.GetString()));
        }
        else if(input.IsArray())
        {
            switch(itype)
            {
            case QVariant::Point:
            {
                assert(input.Size() == 2);
                output = QPoint(input[0u].GetDouble(), input[1].GetDouble());
                break;
            }
            case QVariant::PointF:
            {
                assert(input.Size() == 2);
                output = QPointF(input[0u].GetDouble(), input[1].GetDouble());
                break;
            }
            case QVariant::Size:
            {
                assert(input.Size() == 2);
                output = QSize(input[0u].GetDouble(), input[1].GetDouble());
                break;
            }
            case QVariant::SizeF:
            {
                assert(input.Size() == 2);
                output = QSizeF(input[0u].GetDouble(), input[1].GetDouble());
                break;
            }
            case QVariant::Rect:
            {
                assert(input.Size() == 4);
                output = QRect(input[0u].GetDouble(), input[1].GetDouble(), input[2].GetDouble(), input[3].GetDouble());
                break;
            }
            case QVariant::RectF:
            {
                assert(input.Size() == 4);
                output = QRectF(input[0u].GetDouble(), input[1].GetDouble(), input[2].GetDouble(), input[3].GetDouble());
                break;
            }
            case QVariant::Vector2D:
            {
                assert(input.Size() == 2);
                output = QVector2D(input[0u].GetDouble(), input[1].GetDouble());
                break;
            }
            case QVariant::Vector3D:
            {
                assert(input.Size() == 3);
                output = QVector3D(input[0u].GetDouble(), input[1].GetDouble(), input[2].GetDouble());
                break;
            }
            case QVariant::Vector4D:
            {
                assert(input.Size() == 4);
                output = QVector4D(input[0u].GetDouble(), input[1].GetDouble(), input[2].GetDouble(), input[3].GetDouble());
                break;
            }
            case QVariant::Color:
            {
                assert(input.Size() == 4);
                output = QColor(input[0u].GetDouble(), input[1].GetDouble(), input[2].GetDouble(), input[3].GetDouble());
                break;
            }
            case QVariant::StringList:
            {
                QStringList list;
                list.reserve(input.Size());

                for(rapidjson::Value::ConstValueIterator it = input.Begin(); it != input.End(); ++it)
                {
                    QString tmp(it->GetString());
                    list.append(tmp);
                }
                output = list;
                break;
            }
            case QVariant::List:
            default:
            {
                QList<QVariant> list;
                list.reserve(input.Size());

                for(rapidjson::SizeType i = 0; i < input.Size(); ++i)
                {
                    QVariant tmp;
                    json2tvalue(tmp, input[i], QVariant::Invalid);
                    list.append(tmp);
                }
                output = list;
                break;
            }
            }
        }
        else if(input.IsObject())
        {
            QMap<QString, QVariant> map;

            for(rapidjson::Value::ConstMemberIterator it= input.MemberBegin();
                it != input.MemberEnd(); ++it)
            {
                QString qstring(QLatin1String(it->name.GetString(), it->name.GetStringLength()));
                QVariant qvalue;
                json2tvalue(qvalue, it->value, QVariant::Invalid);

                map.insert(qstring, qvalue);
            }

            output = map;
        }
        else
        {
            output.clear();
            assert(false && "shouldn't execute to here.");
        }
    }
bool MultitypeVar::readFromValue(const rapidjson::Value& obj)
{
    if (obj.IsNull())
    {
        mType = MultitypeNull;
    }
    else if (obj.IsBool())
    {
        mType = MultitypeBool;
        mBool = obj.GetBool();
    }
    else if (obj.IsNumber())
    {
        mType = MultitypeNumber;
        mNumber = obj.GetDouble();
    }
    else if (obj.IsString())
    {
        mType = MultitypeNumber;
        mString = obj.GetString();
    }
    else
    {
        mType = MultitypeNull;
        return false;
    }
    return true;
}
Exemple #3
0
SPGREchoSequence::SPGREchoSequence(const rapidjson::Value &json) {
    if (json.IsNull())
        QI::Fail("Could not read sequence: {}", name());
    TR = GetMember(json, "TR").GetDouble();
    TE = GetMember(json, "TE").GetDouble();
    FA = ArrayFromJSON(json, "FA", M_PI / 180);
}
Exemple #4
0
tws::geoarray::spatial_extent_t
tws::geoarray::read_spatial_extent(const rapidjson::Value& jspatial_extent)
{
  if(!jspatial_extent.IsObject() || jspatial_extent.IsNull())
    throw tws::parse_error() << tws::error_description("error parsing spatial extent in metadata.");

  spatial_extent_t sp_extent;

  const rapidjson::Value& jextent = jspatial_extent["extent"];

  sp_extent.extent = read_extent(jextent);

  const rapidjson::Value& jres = jspatial_extent["resolution"];

  sp_extent.resolution = read_spatial_resolution(jres);

  //const rapidjson::Value& jcrs = jspatial_extent["crs"];

  //if(!jcrs.IsString() || jcrs.IsNull())
    //throw tws::parse_error() << tws::error_description("error in CRS in metadata.");

  //std::string crs = jcrs.GetString();

  //std::pair<std::string,unsigned int> crs_id = te::srs::SpatialReferenceSystemManager::getInstance().getIdFromP4Txt(crs);

  const rapidjson::Value& jsrid = jspatial_extent["srid"];

  if(!jsrid.IsInt() || jsrid.IsNull())
    throw tws::parse_error() << tws::error_description("error reading geoarray srid.");

  sp_extent.crs_code = jsrid.GetUint();

  return sp_extent;
}
Exemple #5
0
/*
 * Regularly spaced sequence
 */
MultiEchoSequence::MultiEchoSequence(const rapidjson::Value &json) {
    if (json.IsNull())
        QI::Fail("Could not read sequence: {}", name());
    TR  = GetMember(json, "TR").GetDouble();
    TE1 = GetMember(json, "TE1").GetDouble();
    ESP = GetMember(json, "ESP").GetDouble();
    ETL = GetMember(json, "ETL").GetInt();
    TE  = Eigen::ArrayXd::LinSpaced(ETL, TE1, TE1 + ESP * (ETL - 1));
}
bool DictionaryHelper::checkObjectExist_json(const rapidjson::Value &root)
{
    bool bRet = false;
    do {
        CC_BREAK_IF(root.IsNull());
        bRet = true;
    } while (0);
    
    return bRet;
}
bool DictionaryHelper::checkObjectExist_json(const rapidjson::Value &root,const char* key)
{
    bool bRet = false;
    do {
        CC_BREAK_IF(root.IsNull());
        bRet = root.HasMember(key);
    } while (0);
    
    return bRet;
}
int DictionaryHelper::getArrayCount_json(const rapidjson::Value& root, const char* key, int def)
{
    int nRet = def;
    do {
        CC_BREAK_IF(root.IsNull());
        CC_BREAK_IF(root[key].IsNull());
        nRet = (int)(root[key].Size());
    } while (0);
    
    return nRet;
}
int DictionaryHelper::getIntValue_json(const rapidjson::Value& root, const char* key, int def)
{
    int nRet = def;
    do {
        CC_BREAK_IF(root.IsNull());
        CC_BREAK_IF(root[key].IsNull());
        nRet = root[key].GetInt();
    } while (0);
    
    return nRet;
}
float DictionaryHelper::getFloatValue_json(const rapidjson::Value& root,const char* key, float def)
{
	float fRet = def;
    do {
        CC_BREAK_IF(root.IsNull());
        CC_BREAK_IF(root[key].IsNull());
        fRet = (float)root[key].GetDouble();
    } while (0);
    
    return fRet;
}
bool DictionaryHelper::getBooleanValue_json(const rapidjson::Value& root,const char* key, bool def)
{
    bool bRet = def;
    do {
        CC_BREAK_IF(root.IsNull());
        CC_BREAK_IF(root[key].IsNull());
        bRet = root[key].GetBool();
    } while (0);
    
    return bRet;
}
bool DictionaryHelper::getBoolValueFromArray_json(const rapidjson::Value& root,const char* arrayKey,int idx, bool def)
{
	bool bRet = def;
    do {
        CC_BREAK_IF(root.IsNull());
        CC_BREAK_IF(root[arrayKey].IsNull());
        CC_BREAK_IF(root[arrayKey][idx].IsNull());
        bRet = root[arrayKey][idx].GetBool();
    } while (0);
    
    return bRet;
}
bool DictionaryHelper::checkObjectExist_json(const rapidjson::Value &root, int index)
{
    bool bRet = false;
    do {   
        CC_BREAK_IF(root.IsNull());
        CC_BREAK_IF(!root.IsArray());
        CC_BREAK_IF(index < 0 || root.Size() <= (unsigned int )index);
        bRet = true;
    } while (0);

    return bRet;
}
float DictionaryHelper::getFloatValueFromArray_json(const rapidjson::Value& root,const char* arrayKey,int idx, float def)
{
    float fRet = def;
    do {
        CC_BREAK_IF(root.IsNull());
        CC_BREAK_IF(root[arrayKey].IsNull());
        CC_BREAK_IF(root[arrayKey][idx].IsNull());
        fRet = (float)root[arrayKey][idx].GetDouble();
    } while (0);
    
    return fRet;
}
int DictionaryHelper::getIntValueFromArray_json(const rapidjson::Value& root,const char* arrayKey,int idx, int def)
{
    int nRet = def;
    do {
        CC_BREAK_IF(root.IsNull());
        CC_BREAK_IF(!root.HasMember(arrayKey));
        CC_BREAK_IF(root[arrayKey].IsNull());
        CC_BREAK_IF(root[arrayKey][idx].IsNull());
        nRet = root[arrayKey][idx].GetInt();
    } while (0);

    return nRet;
}
Exemple #16
0
void Json_Parser::read_print_for_array(rapidjson::Value &va,int i){
    
    if (va.IsBool()) {
        const bool flag=va.GetBool();
        
        CCLOG("%d:%d",i,flag);
    }
    else if (va.IsDouble()) {
        const double flag=va.GetDouble();
        CCLOG("%d:%f",i,flag);
    }
    else if (va.IsInt()) {
        const int flag=va.GetInt();
        CCLOG("%d:%d",i,flag);
    }
    else if (va.IsString()) {
        const std::string flag=va.GetString();
        CCLOG("%d:%s",i,flag.c_str());
    }
    else if (va.IsNull()) {
        
        CCLOG("%d:null",i);
    }
    else if(va.IsObject())
    {
        CCLOG("obj----------%d",i);
        auto it=va.MemberBegin();
        for (;it!=va.MemberEnd();it++) {
            if (va.HasMember(it->name)) {
                read_print(va,it->name.GetString());
                
            }
        }
        
    }
    else if(va.IsArray())
    {
        CCLOG("array-------%d",i);
        for (int i=0; i<va.Size();i++) {
            
            read_print_for_array(va[i],i);
            
            
        }
        
    }
    
}
Exemple #17
0
tws::geoarray::attribute_t
tws::geoarray::read_array_attribute(const rapidjson::Value& jattribute)
{
  if(!jattribute.IsObject() || jattribute.IsNull())
    throw tws::parse_error() << tws::error_description("error parsing array attribute in metadata.");

  attribute_t attr;

  const rapidjson::Value& jname = jattribute["name"];

  if(!jname.IsString() || jname.IsNull())
    throw tws::parse_error() << tws::error_description("error in attribute name entry in metadata.");

  attr.name = jname.GetString();

  const rapidjson::Value& jdescription = jattribute["description"];

  if(jdescription.IsString() || !jdescription.IsNull())
    attr.description = jdescription.GetString();

  const rapidjson::Value& jdatatype = jattribute["datatype"];

  if(!jdatatype.IsString() || jdatatype.IsNull())
    throw tws::parse_error() << tws::error_description("error in attribute datatype entry in metadata.");

  attr.datatype = datatype_t::from_string(jdatatype.GetString());

  const rapidjson::Value& jvalid_range = jattribute["valid_range"];

  attr.valid_range = read_numeric_range(jvalid_range);

  const rapidjson::Value& jscale_factor = jattribute["scale_factor"];

  if(!jscale_factor.IsNumber() || jscale_factor.IsNull())
    throw tws::parse_error() << tws::error_description("error in attribute scale_factor entry in metadata.");

  attr.scale_factor = jscale_factor.GetDouble();

  const rapidjson::Value& jmissing_value = jattribute["missing_value"];

  if(!jmissing_value.IsNumber() || jmissing_value.IsNull())
    throw tws::parse_error() << tws::error_description("error in attribute missing_value entry in metadata.");

  attr.missing_value = jmissing_value.GetDouble();

  return attr;
}
Exemple #18
0
void Json_Parser::read_to_map_for_array(cocos2d::ValueVector &temp,rapidjson::Value &va,int i){
     CCLOG("dex:%d",i);
    if (va.IsBool()) {
        const bool flag=va.GetBool();
          temp.push_back(Value(flag));
    }
    else if (va.IsDouble()) {
        const double flag=va.GetDouble();
         temp.push_back(Value(flag));
    }
    else if (va.IsInt()) {
        const int flag=va.GetInt();
          temp.push_back(Value(flag));
    }
    else if (va.IsString()) {
        const std::string flag=va.GetString();
        temp.push_back(Value(flag));
       // CCLOG("++:%d",temp.size());
    }
    else if (va.IsNull()) {
      
           temp.push_back(Value(nullptr));
        
    }
    else if(va.IsObject())
    {
        cocos2d::ValueMap temp2;
        auto it=va.MemberBegin();
        for (;it!=va.MemberEnd();it++) {
            if (va.HasMember(it->name)) {
                read_to_map(temp2,va,it->name.GetString());
            }
        }
           temp.push_back(Value(temp2));
        // CCLOG("mapinvectro层:%lu",temp2.size());
    }
    else if(va.IsArray())
    {
        cocos2d::ValueVector temp2;
        for (int i=0; i<va.Size();i++) {
            read_to_map_for_array(temp2,va[i],i);
        }
         temp.push_back(Value(temp2));
        // CCLOG("vectorinvectro层:%lu",temp.size());
    }
    
}
Exemple #19
0
tws::geoarray::geo_extent_t
tws::geoarray::read_geo_extent(const rapidjson::Value& jgeo_extent)
{
  if(!jgeo_extent.IsObject() || jgeo_extent.IsNull())
    throw tws::parse_error() << tws::error_description("error parsing geographical extent in metadata.");

  geo_extent_t geo_extent;

  const rapidjson::Value& jspatial = jgeo_extent["spatial"];

  geo_extent.spatial = read_spatial_extent(jspatial);

  const rapidjson::Value& jtemporal = jgeo_extent["temporal"];

  geo_extent.temporal = read_temporal_extent(jtemporal);

  return geo_extent;
}
Exemple #20
0
tws::geoarray::dimension_t
tws::geoarray::read_dimension(const rapidjson::Value& jdim)
{
  if(!jdim.IsObject() || jdim.IsNull())
    throw tws::parse_error() << tws::error_description("error parsing array dimension in metadata.");

  dimension_t dim;

  const rapidjson::Value& jname = jdim["name"];

  if(!jname.IsString() || jname.IsNull())
    throw tws::parse_error() << tws::error_description("error in dimension name entry in metadata.");

  dim.name = jname.GetString();

  const rapidjson::Value& jdescription = jdim["description"];

  if(jdescription.IsString() || !jdescription.IsNull())
    dim.description = jdescription.GetString();

  const rapidjson::Value& jdim_min = jdim["min_idx"];

  if(!jdim_min.IsNumber() || jdim_min.IsNull())
    throw tws::parse_error() << tws::error_description("error in dimension min_idx entry in metadata.");

  dim.min_idx = jdim_min.GetInt64();

  const rapidjson::Value& jdim_max = jdim["max_idx"];

  if(!jdim_max.IsNumber() || jdim_max.IsNull())
    throw tws::parse_error() << tws::error_description("error in dimension max_idx entry in metadata.");

  dim.max_idx = jdim_max.GetInt64();

  const rapidjson::Value& jdim_pos = jdim["pos"];

  if(!jdim_pos.IsNumber() || jdim_pos.IsNull())
    throw tws::parse_error() << tws::error_description("error in dimension position entry in metadata.");

  dim.pos = jdim_pos.GetUint();

  return dim;
}
Exemple #21
0
int JsonValidator::getType(rapidjson::Value& jsonValue) {
	if (jsonValue.IsNull()) {
		return kJsonTypeNull;
	} else if (jsonValue.IsBool()) {
		return kJsonTypeBoolean;
	} else if (jsonValue.IsObject()) {
		return kJsonTypeObject;
	} else if (jsonValue.IsArray()) {
		return kJsonTypeArray;
	} else if (jsonValue.IsString()) {
		return kJsonTypeString;
	} else if (jsonValue.IsInt() || jsonValue.IsInt64() ||
	           jsonValue.IsUint() || jsonValue.IsUint64()) {
		return kJsonTypeInteger;
	} else if (jsonValue.IsDouble()) {
		return kJsonTypeDouble;
	} else {
		return kJsonTypeUnknown;
	}
}
bool JSASTNode::ParseLoc(const rapidjson::Value& value)
{
    // SpiderMonkey can have this for loc :/
    if (value.IsNull())
        return true;

    assert(value.IsObject());

    const Value::Member* mstart = value.FindMember("start");
    assert(mstart);

    const Value::Member* mend = value.FindMember("end");
    assert(mend);

    loc_.startLine_ = mstart->value["line"].GetInt();
    loc_.startColumn_ = mstart->value["column"].GetInt();
    loc_.endLine_ = mend->value["line"].GetInt();
    loc_.endColumn_ = mend->value["column"].GetInt();

    return true;
}
Exemple #23
0
std::vector<tws::geoarray::attribute_t>
tws::geoarray::read_array_attributes(const rapidjson::Value& jattributes)
{
  if(!jattributes.IsArray() || jattributes.IsNull())
    throw tws::parse_error() << tws::error_description("error parsing array attributes in metadata.");

  std::vector<attribute_t> attributes;

  const rapidjson::SizeType nelements = jattributes.Size();

  for(rapidjson::SizeType i = 0; i != nelements; ++i)
  {
    const rapidjson::Value& jattribute = jattributes[i];

    if(jattribute.IsNull())
      continue;

    attributes.push_back(read_array_attribute(jattribute));
  }

  return attributes;
}
Exemple #24
0
std::vector<tws::geoarray::dimension_t>
tws::geoarray::read_dimensions(const rapidjson::Value& jdims)
{
  if(!jdims.IsArray() || jdims.IsNull())
    throw tws::parse_error() << tws::error_description("error parsing array dimensions in metadata.");

  std::vector<dimension_t> dims;

  const rapidjson::SizeType nelements = jdims.Size();

  for(rapidjson::SizeType i = 0; i != nelements; ++i)
  {
    const rapidjson::Value& jdim = jdims[i];

    if(jdim.IsNull())
      continue;

    dims.push_back(read_dimension(jdim));
  }

  return dims;
}
Exemple #25
0
tws::geoarray::extent_t
tws::geoarray::read_extent(const rapidjson::Value& jextent)
{
  if(!jextent.IsObject() || jextent.IsNull())
    throw tws::parse_error() << tws::error_description("error parsing spatial extent in metadata.");

  extent_t extent;

  const rapidjson::Value& jxmin = jextent["xmin"];

  if(!jxmin.IsNumber() || jxmin.IsNull())
    throw tws::parse_error() << tws::error_description("error in spatial extent 'xmin' entry in metadata.");

  extent.xmin = jxmin.GetDouble();

  const rapidjson::Value& jymin = jextent["ymin"];

  if(!jymin.IsNumber() || jymin.IsNull())
    throw tws::parse_error() << tws::error_description("error in spatial extent 'ymin' entry in metadata.");

  extent.ymin = jymin.GetDouble();

  const rapidjson::Value& jxmax = jextent["xmax"];

  if(!jxmax.IsNumber() || jxmax.IsNull())
    throw tws::parse_error() << tws::error_description("error in spatial extent 'xmax' entry in metadata.");

  extent.xmax = jxmax.GetDouble();

  const rapidjson::Value& jymax = jextent["ymax"];

  if(!jymax.IsNumber() || jymax.IsNull())
    throw tws::parse_error() << tws::error_description("error in spatial extent 'ymax' entry in metadata.");

  extent.ymax = jymax.GetDouble();

  return extent;
}
Exemple #26
0
tws::geoarray::spatial_resolution_t
tws::geoarray::read_spatial_resolution(const rapidjson::Value& jresolution)
{
  if(!jresolution.IsObject() || jresolution.IsNull())
    throw tws::parse_error() << tws::error_description("error parsing spatial resolution in metadata.");

  spatial_resolution_t resolution;

  const rapidjson::Value& jx = jresolution["x"];

  if(!jx.IsNumber() || jx.IsNull())
    throw tws::parse_error() << tws::error_description("error in spatial resolution 'x' entry in metadata.");

  resolution.x = jx.GetDouble();

  const rapidjson::Value& jy = jresolution["y"];

  if(!jy.IsNumber() || jy.IsNull())
    throw tws::parse_error() << tws::error_description("error in spatial resolution 'y' entry in metadata.");

  resolution.y = jy.GetDouble();

  return resolution;
}
Exemple #27
0
tws::geoarray::numeric_range_t
tws::geoarray::read_numeric_range(const rapidjson::Value& jrange)
{
  if(!jrange.IsObject() || jrange.IsNull())
    throw tws::parse_error() << tws::error_description("error parsing attribute range in metadata.");

  numeric_range_t r;

  const rapidjson::Value& jmin_val = jrange["min"];

  if(!jmin_val.IsNumber() || jmin_val.IsNull())
    throw tws::parse_error() << tws::error_description("error in attribute range entry in metadata.");

  r.min_val = jmin_val.GetDouble();

  const rapidjson::Value& jmax_val = jrange["max"];

  if(!jmax_val.IsNumber() || jmax_val.IsNull())
    throw tws::parse_error() << tws::error_description("error in attribute range entry in metadata.");

  r.max_val = jmax_val.GetDouble();

  return r;
}
Exemple #28
0
tws::geoarray::time_interval_t
tws::geoarray::read_time_interval(const rapidjson::Value& jinterval)
{
  if(!jinterval.IsObject() || jinterval.IsNull())
    throw tws::parse_error() << tws::error_description("error parsing temporal interval in metadata.");

  time_interval_t ti;

  const rapidjson::Value& jstart_val = jinterval["start"];

  if(!jstart_val.IsString() || jstart_val.IsNull())
    throw tws::parse_error() << tws::error_description("error parsing temporal interval in metadata.");

  ti.start = jstart_val.GetString();

  const rapidjson::Value& jend_val = jinterval["end"];

  if(!jend_val.IsString() || jend_val.IsNull())
    throw tws::parse_error() << tws::error_description("error parsing temporal interval in metadata.");

  ti.end = jend_val.GetString();

  return ti;
}
Exemple #29
0
tws::geoarray::temporal_extent_t
tws::geoarray::read_temporal_extent(const rapidjson::Value& jtemporal_extent)
{
  if(!jtemporal_extent.IsObject() || jtemporal_extent.IsNull())
    throw tws::parse_error() << tws::error_description("error parsing temporal extent in metadata.");

  temporal_extent_t t_ext;

  const rapidjson::Value& jti = jtemporal_extent["interval"];

  t_ext.time_interval = read_time_interval(jti);

  const rapidjson::Value& jres = jtemporal_extent["resolution"];

  t_ext.resolution = jres.GetUint64();

  const rapidjson::Value& junit = jtemporal_extent["unit"];

  const std::string sunit = junit.GetString();

  t_ext.unit = unit_t::from_string(sunit);

  return t_ext;
}
Exemple #30
0
/*
 * Irregularly spaced sequence
 */
MultiEchoFlexSequence::MultiEchoFlexSequence(const rapidjson::Value &json) {
    if (json.IsNull())
        QI::Fail("Could not read sequence: {}", name());
    TR = GetMember(json, "TR").GetDouble();
    TE = ArrayFromJSON(json, "TE");
}