示例#1
0
std::string GD_API VariableStructureToJSON(const gd::Variable & variable)
{
    if ( !variable.IsStructure() ) {
        if ( variable.IsNumber() )
            return ToString(variable.GetValue());
        else
            return StringToQuotedJSONString(variable.GetString().c_str());
    }

    std::string str = "{";
    bool firstChild = true;
    for(std::map<std::string, gd::Variable>::const_iterator i = variable.GetAllChildren().begin();
        i != variable.GetAllChildren().end();++i)
    {
        if ( !firstChild ) str += ",";
        str += StringToQuotedJSONString(i->first.c_str())+": "+VariableStructureToJSON(i->second);

        firstChild = false;
    }

    str += "}";
    return str;
}
示例#2
0
unsigned int RuntimeObject::GetVariableChildCount(gd::Variable &variable) {
  if (variable.IsStructure() == false) return 0;
  return variable.GetChildrenCount();
}
示例#3
0
文件: Variable.cpp 项目: 4ian/GD
#include <algorithm>
#include <initializer_list>
#include <map>

#include "GDCore/CommonTools.h"
#include "GDCore/Project/VariablesContainer.h"

TEST_CASE("Variable", "[common][variables]") {
  SECTION("Basics") {
    gd::Variable variable;
    variable.SetValue(50);
    REQUIRE(variable.GetValue() == 50);
    REQUIRE(variable == 50);
    REQUIRE(variable.IsNumber() == true);
    REQUIRE(variable.IsStructure() == false);

    variable.SetString("MyString");
    REQUIRE(variable.GetString() == "MyString");
    REQUIRE(variable == "MyString");
    REQUIRE(variable.IsNumber() == false);
    REQUIRE(variable.IsStructure() == false);
  }
  SECTION("Conversions") {
    gd::Variable variable;
    variable.SetValue(50);
    REQUIRE(variable.GetString() == "50");  // Used as a string...
    REQUIRE(variable.IsNumber() == false);  //...so consider as a string

    variable.SetString("MyString");
    REQUIRE(variable.GetValue() == 0);     // Used as a number...
示例#4
0
unsigned int GD_API GetVariableChildCount(gd::Variable & variable)
{
    if (variable.IsStructure() == false) return 0;

    return variable.GetAllChildren().size();
}