void AnimationBuilder::interpolateFrame(ParamsFile &pnew, int frameno)
{
	for(auto itP = A.begin(); itP != A.end(); itP ++){
		if((*itP).second.lastSetIndex >= (*itP).second.F.size() - 1){
			continue;
		}

		int nextFrameIndex = (*itP).second.lastSetIndex + 1;
		KeyFrame nextFrame = (*itP).second.F[nextFrameIndex];

		if(nextFrame.frameno == frameno){
			*((*itP).second.jsonPtr) = nextFrame.val;

			(*itP).second.lastSetIndex = nextFrameIndex;
		}else if(nextFrame.interp != "none"){
			int fi = (*itP).second.F[(*itP).second.lastSetIndex].frameno;
			int ff = nextFrame.frameno;
			Json::Value i = (*itP).second.F[(*itP).second.lastSetIndex].val;
			Json::Value f = nextFrame.val;

			if((*itP).second.pType == SVT_INT){
				*((*itP).second.jsonPtr) =
					animationInterpolate(nextFrame.interp, frameno, fi, ff, i.asInt(), f.asInt());
			}else if((*itP).second.pType == SVT_REAL){
				*((*itP).second.jsonPtr) =
					animationInterpolate(nextFrame.interp, frameno, fi, ff, i.asDouble(), f.asDouble());
			}else if((*itP).second.pType == SVT_COLOR){
				Json::Value arr = Json::Value(Json::ValueType::arrayValue);
				arr.resize(3);
				arr[0] = animationInterpolate(nextFrame.interp, frameno, fi, ff,
							i[0].asDouble(), f[0].asDouble());
				arr[1] = animationInterpolate(nextFrame.interp, frameno, fi, ff,
							i[1].asInt(), f[1].asInt());
				arr[2] = animationInterpolate(nextFrame.interp, frameno, fi, ff,
							i[2].asInt(), f[2].asInt());
				*((*itP).second.jsonPtr) = arr;
			}else if((*itP).second.pType == SVT_COMPLEX){
				std::complex<double> zi = getComplexValueFromString(i.asString());
				std::complex<double> zf = getComplexValueFromString(f.asString());
				std::complex<double> z = animationInterpolate(nextFrame.interp, frameno, fi, ff, zi, zf);
				std::string res = concat("", z.real()) + concat("+", z.imag()) + "i";
				*((*itP).second.jsonPtr) = res;
			}
		}
	}
}
Example #2
0
		int readInt(std::string key, int def)
		{
			Json::Value val = root.get(key, def);
			if (val.isInt())
				return val.asInt();
			else
				return def;
		}
void GetBuyedListRequest::decode_from_json_object(const Json::Value &root)
{
    Json::Value tmp;

    
    if ( root.isObject() && root.isMember("data") ) {
        tmp = root["data"];
        if ( !tmp.isNull() )
        {
            data.decode_from_json_object(tmp);
        }
    }

    
    if ( root.isObject() && root.isMember("status") ) {
        tmp = root["status"];
        if ( !tmp.isNull() )
        {
            status = tmp.asInt();
        }
    }

    
    if ( root.isObject() && root.isMember("total") ) {
        tmp = root["total"];
        if ( !tmp.isNull() )
        {
            total = tmp.asInt();
        }
    }

    
    if ( root.isObject() && root.isMember("errMsg") ) {
        tmp = root["errMsg"];
        if ( !tmp.isNull() )
        {
            errMsg = tmp.asString();
        }
    }

    
    
    
    
}
 bool Deserialize ( const Json::Value& json_val, int& obj_val )
 {
     if ( json_val.isInt () )
     {
         obj_val = json_val.asInt ();
         return true;
     }
     return false;
 }
Example #5
0
int Response::getUserID() const {
    try {
        Json::Value json = root["result"][0U]["value"];
        return json.asInt();
    } catch (...) {
        return ERROR;
    }
    return ERROR;
}
Example #6
0
void JsonTree::init( const string &key, const Json::Value &value, bool setType, NodeType nodeType, ValueType valueType )
{
    mKey = key;
	mNodeType = nodeType;
	mParent = 0;
	mValue = "";
	mValueType = valueType;

	if( ! value.isNull() && ( value.isArray() || value.isObject() ) ) {
        if( value.isArray() ) {
            mNodeType = NODE_ARRAY;
            for ( uint32_t i = 0; i < value.size(); i++ ) {
                pushBack( JsonTree( "", value[ i ] ) );
            }
        }
		else if( value.isObject() ) {
            mNodeType = NODE_OBJECT;
            Json::Value::Members members = value.getMemberNames();
            for( Json::Value::Members::const_iterator memberIt = members.begin(); memberIt != members.end(); ++memberIt ) {
				string key = *memberIt;
                pushBack( JsonTree( key, value[ key ] ) );
            }
        }
    }
	else {
		if( value.isBool() ) {
			mValue = toString( value.asBool() );
			if( setType ) {
				mValueType = VALUE_BOOL;
			}
		}
		else if ( value.isDouble() ) { 
			mValue = toString( value.asDouble() );
			if ( setType ) {
				mValueType = VALUE_DOUBLE;
			}
		}
		else if ( value.isInt() ) { 
			mValue = toString( value.asInt() );
			if ( setType ) {
				mValueType = VALUE_INT;
			}
		}
		else if ( value.isString() ) { 
			mValue = toString( value.asString() );
			if ( setType ) {
				mValueType = VALUE_STRING;
			}
		}
		else if ( value.isUInt() ) { 
			mValue = toString( value.asUInt() );
			if ( setType ) {
				mValueType = VALUE_UINT;
			}
		}
	}
}
Example #7
0
void leer_datos_iniciales(int &ancho, int &alto, std::string &ip, int &puerto){
  Json::Value datos;
  Json::Value aux;
  Json::Reader reader;
  
  std::string configuracion = CONFIG;
  std::ifstream archivo_datos(configuracion.c_str(), std::ifstream::binary | std::ifstream::in);
  reader.parse(archivo_datos, datos, false);
  
  aux = datos.get("ancho", aux);
  ancho = aux.asInt();
  aux = datos.get("alto", aux);
  alto = aux.asInt();
  aux = datos.get("ip", aux);
  ip = aux.asString();
  aux = datos.get("puerto", aux);
  puerto = aux.asInt();
}
Example #8
0
		int getnetworkhashps(){
			string command="getnetworkhashps()";
			Json::Value params;
			Json::Value result;
			//params.append(account);
			result=this->sendcommand(command,params);
			int hashps=result.asInt();
			return hashps;
		}
bool QSanProtocol::Utils::tryParse(const Json::Value &arg, double &result) {
    if (arg.isDouble())
        result = arg.asDouble();
    else if (arg.isInt())
        result = arg.asInt();
    else
        return false;
    return true;
}
Example #10
0
bool GetInt32(const Json::Value& value, int32_t* out) {
  if (value.isNull()) {
    return false;
  }
  if (!value.isInt()) {
    return false;
  }
  *out = value.asInt();
  return true;
}
Example #11
0
bool JSON_Type2Type(const Json::Value &subNode, int &value)
{
	if (Json::intValue == subNode.type())
	{
		value = subNode.asInt();
		return true;
	}
	ASSERT_C(false);
	return false;
}
Example #12
0
int GetJsonInt(const Json::Value& _jsValue)
{
	if ( _jsValue.type() == Json::intValue)
		return _jsValue.asInt();
	else if (_jsValue.type() == Json::stringValue)
		return atoi(_jsValue.asCString());
	else if (_jsValue.isBool())
		return (int)_jsValue.asBool();
	return 0;
}
Example #13
0
int Utils::GetIntFromJsonValue(Json::Value &value, int defaultValue) {
    int res = defaultValue;

    // some json responses have ints formated as strings
    if (value.isString())
        res = StringToInt(value.asString());
    else if (value.isInt())
        res = value.asInt();

    return res;
}
Example #14
0
File: main.cpp Project: tuita/DOMQ
static void
printValueTree( FILE *fout, Json::Value &value, const std::string &path = "." )
{
   switch ( value.type() )
   {
   case Json::nullValue:
      fprintf( fout, "%s=null\n", path.c_str() );
      break;
   case Json::intValue:
      fprintf( fout, "%s=%ld\n", path.c_str(), value.asInt() );
      break;
   case Json::uintValue:
      fprintf( fout, "%s=%lu\n", path.c_str(), value.asUInt() );
      break;
   case Json::realValue:
      fprintf( fout, "%s=%.16g\n", path.c_str(), value.asDouble() );
      break;
   case Json::stringValue:
      fprintf( fout, "%s=\"%s\"\n", path.c_str(), value.asString().c_str() );
      break;
   case Json::booleanValue:
      fprintf( fout, "%s=%s\n", path.c_str(), value.asBool() ? "true" : "false" );
      break;
   case Json::arrayValue:
      {
         fprintf( fout, "%s=[]\n", path.c_str() );
         int size = value.size();
         for ( int index =0; index < size; ++index )
         {
            static char buffer[16];
            sprintf( buffer, "[%d]", index );
            printValueTree( fout, value[index], path + buffer );
         }
      }
      break;
   case Json::objectValue:
      {
         fprintf( fout, "%s={}\n", path.c_str() );
         Json::Value::Members members( value.getMemberNames() );
         std::sort( members.begin(), members.end() );
         std::string suffix = *(path.end()-1) == '.' ? "" : ".";
         for ( Json::Value::Members::iterator it = members.begin(); 
               it != members.end(); 
               ++it )
         {
            const std::string &name = *it;
            printValueTree( fout, value[name], path + suffix + name );
         }
      }
      break;
   default:
      break;
   }
}
Example #15
0
int getParamVal(std::string param, Json::Value const& item, int defvalue) {
  Json::Value nnType = item[param];
  if (!nnType.empty())
  {
    int n = nnType.asInt();
    console->info("{0}={1}", param, n);
    return n;
  }
  else  
    return  defvalue;
  }
Example #16
0
int Response::getUserID(std::string &s) const {
    Json::Value root;
    stringToJson(s, root);
    try {
        Json::Value json = root["result"][0U]["value"];
        return json.asInt();
    } catch (...) {
        return ERROR;
    }
    return ERROR;
}
Example #17
0
std::string BTSyncInterface::jsonValueToString_(Json::Value jsonValue) {
  std::string stringValue;

  // May need to check for more types in the future
  if (jsonValue.type() == Json::ValueType::intValue)
    stringValue = std::to_string(jsonValue.asInt());
  else 
    stringValue = jsonValue.asString();

  return stringValue;
}
Example #18
0
    int JsonUtils::asInt(const Json::Value &value, int defaultValue)
    {
        int returned = defaultValue;

        if(value.isString())
            returned = Ogre::StringConverter::parseInt(value.asString(), defaultValue);

        if(value.isIntegral())
            returned = value.asInt();

        return returned;
    }
Example #19
0
WidgetKey::WidgetKey(LCDCore *v, std::string n, Json::Value *section) :
    Widget(v, n, section, 0, 0, 0, WIDGET_TYPE_KEYPAD) {

    Json::Value *val = v->CFG_Fetch_Raw(section, "expression", new Json::Value(""));
    code_ = val->asString();
    delete val;

    val = v->CFG_Fetch(section, "key", new Json::Value(-1));
    key_ = val->asInt();
    delete val;

    started_ = false;
}
Example #20
0
void GetOrdinal(Json::Value& config, Ord* setting)
{
	if (config.isNull())
		return;

	Ord value;
	if (config.isString())
		value = lookupFunction(config.asString());
	else
		value = (Ord) config.asInt();

	*setting = value;
}
Example #21
0
WidgetBignums::WidgetBignums(LCDCore *v, std::string n, Json::Value *section, 
    int row, int col, int layer) : Widget(v, n, section, row, col, layer,
    WIDGET_TYPE_BIGNUMS | WIDGET_TYPE_RC | WIDGET_TYPE_SPECIAL) {

    if(lcd_type_ == LCD_TEXT)
        Draw = TextBignumsDraw;
    else if(lcd_type_ == LCD_GRAPHIC)
        Draw = GraphicBignumsDraw;
    else
        Draw = NULL;

    expression_ = new Property(v, section, "expression", new Json::Value("0"));
    expr_min_ = new Property(v, section, "min", NULL);
    expr_max_ = new Property(v, section, "max", NULL);

    Json::Value *val = v->CFG_Fetch(section, "layer", new Json::Value(0));
    layer_ = val->asInt();
    delete val;

    val = v->CFG_Fetch(section, "update", new Json::Value(500));
    update_ = val->asInt();
    delete val;

    fg_valid_ = WidgetColor(section, "foreground", &fg_color_);
    bg_valid_ = WidgetColor(section, "background", &bg_color_);

    min_ = max_ = 0.0;

/*
    timer_ = new QTimer();
    timer_->setSingleShot(false);
    timer_->setInterval(update_);
    QObject::connect(timer_, SIGNAL(timeout()), this, SLOT(Update()));

    QObject::connect(visitor_->GetWrapper(), SIGNAL(_ResizeLCD(int, int, int, int)),
        this, SLOT(Resize(int, int, int, int)));
*/
}
int JsonParser::GetInt(const char* pName)
{
	if(!pName|| (m_pRoot == NULL))
	{
		return 0;
	}

	Json::Value *pChild = GetChildByName(string(pName));
	if( pChild  == NULL)
	{
		return 0;
	}

	return pChild->asInt();
}
int JsonParser::GetInt(const int nIndex)
{
	if((nIndex < 0) || (m_pRoot == NULL))
	{
		return 0;
	}

	Json::Value *pChild = GetChildByIndex(nIndex);
	if( pChild  == NULL)
	{
		return 0;
	}

	return pChild->asInt();
}
Example #24
0
bool deserialize(const Json::Value& node, uint8_t& val)
{
	if (node.empty())
	{
		std::cout << "Node is empty." << std::endl;
		return false;
	}
	if (!node.isNumeric())
	{
		std::cout << "Node data type is not numeric." << std::endl;
		return false;
	}
	val = (uint8_t)node.asInt();
	return true;
}
void BaseResponseRequest::decode_from_json_object(const Json::Value &root)
{
    Json::Value tmp;

    
    if ( root.isObject() && root.isMember("status") ) {
        tmp = root["status"];
        if ( !tmp.isNull() )
        {
            status = tmp.asInt();
        }
    }

    
}
Example #26
0
void util::PrintJSONValue( Json::Value val ){
	if( val.isString() ) {
		printf( "string(%s)", val.asString().c_str() ); 
	} else if( val.isBool() ) {
		printf( "bool(%d)", val.asBool() ); 
	} else if( val.isInt() ) {
		printf( "int(%d)", val.asInt() ); 
	} else if( val.isUInt() ) {
		printf( "uint(%u)", val.asUInt() ); 
	} else if( val.isDouble() ) {
		printf( "double(%f)", val.asDouble() ); 
	} else {
		printf( "unknown type=[%d]", val.type() ); 
	}
}
Example #27
0
WidgetTimer::WidgetTimer(LCDCore *v, std::string n, Json::Value *section) :
    Widget(v, n, section, 0, 0, 0, WIDGET_TYPE_TIMER) {

    expression_ = new Property(v, section, "expression", new Json::Value(""));

    Json::Value *val = v->CFG_Fetch(section, "update", new Json::Value(-1));
    update_ = val->asInt();
    delete val;

/*
    timer_ = new QTimer();
    timer_->setSingleShot(false);
    timer_->setInterval(update_);
    //QObject::connect(timer_, SIGNAL(timeout()), this, SLOT(Update()));
*/
}
 int JsonHelper::ToInt( const Json::Value& value, int defaultResult )
 {
     if ( value.isInt() )
     {
         return value.asInt();
     }
     if ( value.isDouble() )
     {
         return (int) value.asDouble();
     }
     if ( value.isString() )
     {
         return Core::Convert::ToInt( value.asString() );
     }
     return defaultResult;
 }
 float JsonHelper::ToFloat( const Json::Value& value, float defaultResult )
 {
     if ( value.isDouble() )
     {
         return (float) value.asDouble();
     }
     if ( value.isInt() )
     {
         return (float) value.asInt();
     }
     if ( value.isString() )
     {
         return Convert::ToFloat( value.asString() );
     }        
     return defaultResult;
 }
 std::string JsonHelper::ToString( const Json::Value& value, const std::string& defaultResult )
 {
     if ( value.isString() )
     {
         return value.asString();
     }
     if ( value.isInt() )
     {
         return Convert::ToString( value.asInt() );
     }
     if ( value.isDouble() )
     {
         return Convert::ToString( (float)value.asDouble() );
     }
     return defaultResult;
 }