Exemple #1
0
void iterateArray(Value::ConstValueIterator& itr,
		Value::ConstValueIterator& itrEnd, StringBuffer *buffer,
		Writer<StringBuffer> *writer, stringstream& ss) {
	for (; itr != itrEnd; itr++) {
		if (itr->IsObject()) {
			Value::ConstMemberIterator itr_ = itr->MemberBegin();
			Value::ConstMemberIterator itrEnd_ = itr->MemberEnd();
			iterateObject(itr_, itrEnd_, buffer, writer, ss);
		} else if (itr->IsArray()) {
			Value::ConstValueIterator itr_ = itr->Begin();
			Value::ConstValueIterator itrEnd_ = itr->End();
			iterateArray(itr_, itrEnd_, buffer, writer, ss);
		} else if (itr->IsBool()) {
			ss << DELIM << itr->GetBool();
		} else if (itr->IsInt()) {
			ss << DELIM << itr->GetInt();
		} else if (itr->IsInt64()) {
			ss << DELIM << itr->GetInt64();
		} else if (itr->IsDouble()) {
			ss << DELIM << itr->GetDouble();
		} else if (itr->IsString()) {
			ss << DELIM << "\"" << itr->GetString() << "\"";
		} else {
			throw runtime_error(string("Case missing from tokenizer"));
		}
	}
}
/* ****************************************************************************
*
* parseContextAttributeCompoundValue - 
*/
std::string parseContextAttributeCompoundValue
(
  const Value::ConstValueIterator&   node,
  ContextAttribute*                  caP,
  orion::CompoundValueNode*          parent
)  
{
  if (node->IsObject())
  {
    int counter  = 0;

    for (Value::ConstMemberIterator iter = node->MemberBegin(); iter != node->MemberEnd(); ++iter)
    {
      std::string                nodeType = jsonParseTypeNames[iter->value.GetType()];
      orion::CompoundValueNode*  cvnP     = new orion::CompoundValueNode();

      cvnP->valueType  = stringToCompoundType(nodeType);

      cvnP->name       = iter->name.GetString();
      cvnP->container  = parent;
      cvnP->rootP      = parent->rootP;
      cvnP->level      = parent->level + 1;
      cvnP->siblingNo  = counter;
      cvnP->path       = parent->path + cvnP->name;

      if (nodeType == "String")
      {
        cvnP->stringValue       = iter->value.GetString();
      }
      else if (nodeType == "Number")
      {
        cvnP->numberValue = iter->value.GetDouble();
      }
      else if ((nodeType == "True") || (nodeType == "False"))
      {
        cvnP->boolValue   = (nodeType == "True")? true : false;
      }
      else if (nodeType == "Null")
      {
        cvnP->valueType = orion::ValueTypeNone;
      }
      else if (nodeType == "Object")
      {
        cvnP->path += "/";
        cvnP->valueType = orion::ValueTypeObject;
      }
      else if (nodeType == "Array")
      {
        cvnP->path += "/";
        cvnP->valueType = orion::ValueTypeVector;
      }

      parent->childV.push_back(cvnP);
        
      //
      // Recursive call if Object or Array
      //
      if ((nodeType == "Object") || (nodeType == "Array"))
      {
        parseContextAttributeCompoundValue(iter, caP, cvnP);
      }

      ++counter;
    }
  }
  else if (node->IsArray())
  {
    int counter  = 0;

    for (Value::ConstValueIterator iter = node->Begin(); iter != node->End(); ++iter)
    {
      std::string                nodeType  = jsonParseTypeNames[iter->GetType()];
      orion::CompoundValueNode*  cvnP      = new orion::CompoundValueNode();
      char                       itemNo[4];

      snprintf(itemNo, sizeof(itemNo), "%03d", counter);

      cvnP->valueType  = stringToCompoundType(nodeType);
      cvnP->container  = parent;
      cvnP->rootP      = parent->rootP;
      cvnP->level      = parent->level + 1;
      cvnP->siblingNo  = counter;
      cvnP->path       = parent->path + "[" + itemNo + "]";


      if (nodeType == "String")
      {
        cvnP->stringValue       = iter->GetString();
      }
      else if (nodeType == "Number")
      {
        cvnP->numberValue = iter->GetDouble();
      }
      else if ((nodeType == "True") || (nodeType == "False"))
      {
        cvnP->boolValue   = (nodeType == "True")? true : false;
      }
      else if (nodeType == "Null")
      {
        cvnP->valueType = orion::ValueTypeNone;
      }
      else if (nodeType == "Object")
      {
        cvnP->path += "/";
        cvnP->valueType = orion::ValueTypeObject;
      }
      else if (nodeType == "Array")
      {
        cvnP->path += "/";
        cvnP->valueType = orion::ValueTypeVector;
      }

      parent->childV.push_back(cvnP);

      //
      // Recursive call if Object or Array
      //
      if ((nodeType == "Object") || (nodeType == "Array"))
      {
        parseContextAttributeCompoundValue(iter, caP, cvnP);
      }

      ++counter;
    }
  }


  return "OK";
}
std::vector<SlotType>
MtgJsonAllSetsData::getBoosterSlots( const std::string& code ) const
{
    std::vector<SlotType> boosterSlots;

    if( mBoosterSetCodes.count(code) == 0 )
    {
        mLogger->warn( "No booster member in set {}, returning empty booster slots", code );
        return boosterSlots;
    }

    // In parse() this was vetted to be safe and yield an Array-type value.
    const Value& boosterValue = mDoc[code]["booster"];

    mLogger->debug( "{:-^40}", "assembling booster slots" );
    for( Value::ConstValueIterator iter = boosterValue.Begin(); iter != boosterValue.End(); ++iter )
    {
        if( iter->IsArray() )
        {
            // create a set of any strings in the array
            std::set<std::string> slotArraySet;
            for( unsigned i = 0; i < iter->Size(); ++i )
            {
                const Value& val = (*iter)[i];
                if( val.IsString() )
                {
                    slotArraySet.insert( val.GetString() );
                    mLogger->debug( "booster slot array[{}]: {}", i, val.GetString() );
                }
                else
                {
                    mLogger->warn( "Non-string in booster slot array, ignoring!" );
                }
            }
            const std::set<std::string> rareMythicRareSlot { "rare", "mythic rare" };
            if( slotArraySet == rareMythicRareSlot )
                boosterSlots.push_back( SLOT_RARE_OR_MYTHIC_RARE );
            else
                mLogger->warn( "Unrecognized booster slot array, ignoring!" );
        }
        else if( iter->IsString() )
        {
            std::string slotStr( iter->GetString() );
            mLogger->debug( "booster slot string: {}", slotStr );
            if( slotStr == "common" )
                boosterSlots.push_back( SLOT_COMMON );
            else if( slotStr == "uncommon" )
                boosterSlots.push_back( SLOT_UNCOMMON );
            else if( slotStr == "rare" )
                boosterSlots.push_back( SLOT_RARE );
            else if( slotStr == "timeshifted purple" )
                boosterSlots.push_back( SLOT_TIMESHIFTED_PURPLE );
            else if( slotStr == "land" )      { /* do nothing */ }
            else if( slotStr == "marketing" ) { /* do nothing */ }
            else
                mLogger->warn( "Unrecognized booster slot type {}, ignoring!", slotStr );
        }
        else
        {
            mLogger->warn( "Non-string booster slot type, ignoring!" );
        }
    }
    return boosterSlots;
}