예제 #1
0
void GoodStock::load( const VariantList& stream )
{
  if( stream.size() < 3 )
    return;

  VariantList::const_iterator it=stream.begin();
  _type = (Good::Type)(*it).toInt(); it++;
  _maxQty = (*it).toInt(); it++;
  _currentQty = math::clamp( (*it).toInt(), 0, _maxQty );
}
예제 #2
0
void SimpleGoodStore::load( const VariantMap& stream )
{
    _goodStockList.clear();

    GoodStore::load( stream );
    _maxQty = (int)stream.get( "max" );

    VariantList stockSave = stream.get( "stock" ).toList();
    for( VariantList::iterator it=stockSave.begin(); it!=stockSave.end(); it++ )
    {
        GoodStock restored;
        restored.load( (*it).toList() );
        _goodStockList.push_back( restored );
    }
}
예제 #3
0
VariantList proxyProcessList( const VariantList &args, const JSAPIImplPtr& self, const JSAPIImplPtr& proxy )
{
    VariantList newArgs;
    for (VariantList::const_iterator it = args.begin();
        it != args.end(); ++it) {
        if (it->is_of_type<JSAPIPtr>() && it->convert_cast<JSAPIPtr>() == self) {
            newArgs.push_back(proxy);
        } else if (it->is_of_type<VariantList>()) {
            newArgs.push_back(proxyProcessList(it->convert_cast<VariantList>(), self, proxy));
        } else if (it->is_of_type<VariantMap>()) {
            newArgs.push_back(proxyProcessMap(it->convert_cast<VariantMap>(), self, proxy));
        } else {
            newArgs.push_back(*it);
        }
    }
    return newArgs;
}
예제 #4
0
    void load( const VariantList& stream )
    {
      if( stream.size() != 9 )
      {
        StringHelper::debug( 0xff, "%s [%s %d]", "Incorrect argument number in ", __FILE__, __LINE__ );
        return;
      }

      VariantList::const_iterator it=stream.begin();
      sellPrice = it->toUInt(); it++;
      buyPrice = it->toUInt(); it++;
      exportLimit = it->toUInt(); it++;
      importLimit = it->toUInt(); it++;
      soldGoods = it->toUInt(); it++;
      bougthGoods = it->toUInt(); it++;
      stacking = it->toBool(); it++;
      order = (CityTradeOptions::Order)it->toInt(); it++;
      vendor = it->toBool();
    }
예제 #5
0
    void load( const VariantList& stream )
    {
      if( stream.size() != 9 )
      {
        Logger::warning( "%s [%s %d]", "Incorrect argument number in ", __FILE__, __LINE__ );
        return;
      }

      VariantList::const_iterator it=stream.begin();
      sellPrice = it->toUInt(); ++it;
      buyPrice = it->toUInt(); ++it;
      exportLimit = it->toUInt(); ++it;
      importLimit = it->toUInt(); ++it;
      soldGoods = it->toUInt(); ++it;
      bougthGoods = it->toUInt(); ++it;
      stacking = it->toBool(); ++it;
      order = (trade::Order)it->toInt(); ++it;
      vendor = it->toBool();
    }
예제 #6
0
std::string Json::serialize(const Variant &data, bool &success, const std::string& tab)
{
  std::string str;
  success = true;

  if( !data.isValid() ) // invalid or null?
  {
    str = "null";
  }

  else if( (data.type() == Variant::List) || (data.type() == Variant::NStringArray) ) // variant is a list?
  {
    StringArray values;
    const VariantList rlist = data.toList();
    for( VariantList::const_iterator it = rlist.begin(); it != rlist.end(); it++)
    {
      std::string serializedValue = serialize( *it, "" );
      if( serializedValue.empty() )
      {
          success = false;
          break;
      }

      values.push_back( serializedValue );
    }

    str = "[ " + join( values, ", " ) + " ]";
  }
// 	else if(data.type() == Variant::Hash) // variant is a hash?
// 	{
// 		const VariantHash vhash = data.toHash();
// 		QHashIterator<std::string, Variant> it( vhash );
// 		str = "{ ";
// 		QList<QByteArray> pairs;
// 
// 		while(it.hasNext())
// 		{
// 			it.next();
//               QByteArray serializedValue = serialize(it.value(), "");
// 
// 			if(serializedValue.isNull())
// 			{
// 				success = false;
// 				break;
// 			}
// 
//               pairs << tab.toAscii() + sanitizeString(it.key()).toUtf8() + " : " + serializedValue;
// 		}
// 
// 		str += join(pairs, ", ");
// 		str += " }";
// 	}
    else if(data.type() == Variant::Map) // variant is a map?
    {
      VariantMap vmap = data.toMap();
      
      str = "{ \n";
      StringArray pairs;
      for( VariantMap::iterator it = vmap.begin(); it != vmap.end(); it++ )
      {        
        std::string serializedValue = serialize( it->second, tab + "  ");
        if( serializedValue.empty())
        {
                //success = false;
          pairs.push_back( tab + sanitizeString( it->first ) + std::string( " : \"nonSerializableValue\"" ) );
          continue;
        }
        pairs.push_back( tab + sanitizeString( it->first ) + " : " + serializedValue );
      }
      str += join(pairs, ",\n");
      std::string rtab( tab );
      rtab.resize( std::max<int>( 0, tab.size() - 2 ) );
      str += std::string( "\n" ) + rtab + "}";
    }
    else if((data.type() == Variant::String) || (data.type() == Variant::NByteArray)) // a string or a byte array?
    {
            str = sanitizeString( data.toString() );
    }
    else if(data.type() == Variant::Double || data.type() == Variant::Float) // double?
    {
      str = StringHelper::format( 0xff, "\"%f\"", data.toDouble() );
      if( str.find(".") == std::string::npos && str.find("e") == std::string::npos )
      {
         str += ".0";
      }
    }
    else if( data.type() == Variant::NTilePos)
    {
      TilePos pos = data.toTilePos();
      str = StringHelper::format( 0xff, "[ %d, %d ]", pos.getI(), pos.getJ() );
    }
    else if( data.type() == Variant::NSize)
    {
      Size size = data.toSize();
      str = StringHelper::format( 0xff, "[ %d, %d ]", size.getWidth(), size.getHeight() );
    }
    else if( data.type() == Variant::NPoint)
    {
      Point pos = data.toPoint();
      str = StringHelper::format( 0xff, "[ %d, %d ]", pos.getX(), pos.getY() );
    }
    else if( data.type() == Variant::NPointF)
    {
      PointF pos = data.toPointF();
      str = StringHelper::format( 0xff, "[ \"%f\", \"%f\" ]", pos.getX(), pos.getY() );
    }
    else if (data.type() == Variant::Bool) // boolean value?
    {
      str = data.toBool() ? "true" : "false";
    }
    else if (data.type() == Variant::ULongLong) // large unsigned number?
    {
      str = StringHelper::format( 0xff, "%u", data.toULongLong() );
    }
    else if ( data.canConvert( Variant::LongLong ) ) // any signed number?
    {
      str = StringHelper::format( 0xff, "%d", data.toLongLong() );
    }
    else if (data.canConvert( Variant::Long ))
    {
      str = StringHelper::format( 0xff, "%d", data.toLongLong() );
    }
    else if (data.canConvert( Variant::String ) ) // can value be converted to string?
    {
      // this will catch Date, DateTime, Url, ...
      str = sanitizeString( data.toString() );
    }
    else
    {
      success = false;
    }

    if (success)
    {
            return str;
    }
    else
    {
      return std::string();
    }
}