当前位置: 首页>>代码示例>>C++>>正文


C++ JSONNode::as_float方法代码示例

本文整理汇总了C++中JSONNode::as_float方法的典型用法代码示例。如果您正苦于以下问题:C++ JSONNode::as_float方法的具体用法?C++ JSONNode::as_float怎么用?C++ JSONNode::as_float使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JSONNode的用法示例。


在下文中一共展示了JSONNode::as_float方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: switch

HQLOperand::HQLOperand(const JSONNode &n, OPERAND_TYPE ot)
{
    // ot == ID -> auto
    switch(n.type()){
    case JSON_NULL:
        type = NIL;
        break;
    case JSON_STRING:
        {
            if(ot == ID){
                type = ID;
                data.str = new string(n.as_string());
            }else{
                type = STRING;
                data.str = new string(string("\"") + n.as_string() + "\"");
            }
            break;
        }
    case JSON_NUMBER:
        {
            type = NUM;
            data.num = n.as_float();
            break;
        }
    case JSON_BOOL:
        {
            type = BOOL;
            data.boolean = n.as_bool();
            break;
        }
    case JSON_ARRAY:
    case JSON_NODE:
        {
            //TODO
            break;
        }
    default:
        type = NIL;
    }
}
开发者ID:appwilldev,项目名称:HQL,代码行数:40,代码来源:ast.cpp

示例2: TestInspectors

void TestSuite::TestInspectors(void){
    UnitTest::SetPrefix("TestInspectors.cpp - Inspectors");
    JSONNode test = JSONNode(JSON_NULL);
    #ifdef JSON_CASTABLE
	   assertEquals(test.as_string(), JSON_TEXT(""));
	   assertEquals(test.as_int(), 0);
	   assertEquals(test.as_float(), 0.0f);
	   assertEquals(test.as_bool(), false);
    #endif

    test = 15.5f;
    assertEquals(test.type(), JSON_NUMBER);
  #ifdef JSON_CASTABLE
    assertEquals(test.as_string(), JSON_TEXT("15.5"));
  #endif
    assertEquals(test.as_int(), 15);
    assertEquals(test.as_float(), 15.5f);
    #ifdef JSON_CASTABLE
	   assertEquals(test.as_bool(), true);
    #endif

    test = 0.0f;
    assertEquals(test.type(), JSON_NUMBER);
  #ifdef JSON_CASTABLE
    assertEquals(test.as_string(), JSON_TEXT("0"));
  #endif
    assertEquals(test.as_int(), 0);
    assertEquals(test.as_float(), 0.0f);
    #ifdef JSON_CASTABLE
	   assertEquals(test.as_bool(), false);
    #endif

    test = true;
    assertEquals(test.type(), JSON_BOOL);
    #ifdef JSON_CASTABLE
	   assertEquals(test.as_string(), JSON_TEXT("true"));
	   assertEquals(test.as_int(), 1);
	   assertEquals(test.as_float(), 1.0f);
    #endif
    assertEquals(test.as_bool(), true);

    test = false;
    assertEquals(test.type(), JSON_BOOL);
    #ifdef JSON_CASTABLE
	   assertEquals(test.as_string(), JSON_TEXT("false"));
	   assertEquals(test.as_int(), 0);
	   assertEquals(test.as_float(), 0.0f);
    #endif
    assertEquals(test.as_bool(), false);

    #ifdef JSON_CASTABLE
	   test.cast(JSON_NODE);
    #else
	   test = JSONNode(JSON_NODE);
    #endif
    assertEquals(test.type(), JSON_NODE);
    assertEquals(test.size(), 0);
    test.push_back(JSONNode(JSON_TEXT("hi"), JSON_TEXT("world")));
    test.push_back(JSONNode(JSON_TEXT("hello"), JSON_TEXT("mars")));
    test.push_back(JSONNode(JSON_TEXT("salut"), JSON_TEXT("france")));
    assertEquals(test.size(), 3);
    TestSuite::testParsingItself(test);

    #ifdef JSON_CASTABLE
	   JSONNode casted = test.as_array();
	   #ifdef JSON_UNIT_TEST
		  assertNotEquals(casted.internal, test.internal);
	   #endif
	   assertEquals(casted.type(), JSON_ARRAY);
	   assertEquals(test.type(), JSON_NODE);
	   assertEquals(test.size(), 3);
	   assertEquals(casted.size(), 3);
	   TestSuite::testParsingItself(casted);
    #endif

    UnitTest::SetPrefix("TestInspectors.cpp - Location");

    try {
	   #ifdef JSON_CASTABLE
		  assertEquals(casted.at(0), JSON_TEXT("world"));
		  assertEquals(casted.at(1), JSON_TEXT("mars"));
		  assertEquals(casted.at(2), JSON_TEXT("france"));
		  assertEquals(casted.at(0).name(), JSON_TEXT(""));
		  assertEquals(casted.at(1).name(), JSON_TEXT(""));
		  assertEquals(casted.at(2).name(), JSON_TEXT(""));
	   #endif
	   assertEquals(test.at(0), JSON_TEXT("world"));
	   assertEquals(test.at(1), JSON_TEXT("mars"));
	   assertEquals(test.at(2), JSON_TEXT("france"));
	   assertEquals(test.at(0).name(), JSON_TEXT("hi"));
	   assertEquals(test.at(1).name(), JSON_TEXT("hello"));
	   assertEquals(test.at(2).name(), JSON_TEXT("salut"));
    } catch (std::out_of_range){
	   FAIL("exception caught");
    }

    try {
	   assertEquals(test.at(JSON_TEXT("hi")), JSON_TEXT("world"));
	   assertEquals(test.at(JSON_TEXT("hello")), JSON_TEXT("mars"));
	   assertEquals(test.at(JSON_TEXT("salut")), JSON_TEXT("france"));
//.........这里部分代码省略.........
开发者ID:NatalieWolfe,项目名称:libjson,代码行数:101,代码来源:TestInspectors.cpp

示例3: predicate

bool HQLOperand::predicate(const HQLOperand &o, const JSONNode &n)
{
    if(type != COOP){
        return false;
    }

    switch(data.coop){
    case COND_OPER::EQ:
        return CompareHQLOperandAndJSONNode<COND_OPER::EQ>(o, n);
        break;
    case COND_OPER::GT:
        return CompareHQLOperandAndJSONNode<COND_OPER::GT>(o, n);
        break;
    case COND_OPER::LT:
        return CompareHQLOperandAndJSONNode<COND_OPER::LT>(o, n);
        break;
    case COND_OPER::GE:
        return CompareHQLOperandAndJSONNode<COND_OPER::GE>(o, n);
        break;
    case COND_OPER::LE:
        return CompareHQLOperandAndJSONNode<COND_OPER::LE>(o, n);
        break;
    case COND_OPER::IN:
        {
            if(o.get_type()==NUM_ARRAY){
                if(n.type()==JSON_NUMBER){
                    string ns=num2str(n.as_int());
                    vector<string>::const_iterator it=o.as_str_array()->begin();
                    for(;it!=o.as_str_array()->end();it++){
                        if(ns==*it)return true;
                    }
                    return false;
                }
                return false;
            }else if(o.get_type()==STR_ARRAY){
                if(n.type()==JSON_STRING){
                    string ns=n.as_string();
                    vector<string>::const_iterator it=o.as_str_array()->begin();
                    for(;it!=o.as_str_array()->end();it++){
                        if(ns==*it)return true;
                    }
                    return false;
                }
                return false;
            }
            return false;
            break;
        }
    case COND_OPER::CONTAINS:
        {
            string val = o.as_str_array()->at(0);
            string sep = o.as_str_array()->at(1);
            string ns=n.as_string();
            string unit;
            string::size_type start = 0, end = 0;
            while(end!=string::npos){
                end = ns.find_first_of(sep, start);
                if(end==string::npos){
                    unit = ns.substr(start);
                }else{
                    unit = ns.substr(start, end-start);
                }
                start = end + 1;
                if(val == "\"" + unit + "\""){
                    return true;
                }
            }
            return false;
            break;
        }
    case COND_OPER::TIME_IN:
        {
            if(n.type()!=JSON_NUMBER) return false;
            if(o.get_type()!=NUM) return false;
            time_t now = time(NULL);
            return now-o.as_num() <= n.as_float();
            break;
        }
    default:
        return false;
    }
    return false;
}
开发者ID:appwilldev,项目名称:HQL,代码行数:83,代码来源:ast.cpp


注:本文中的JSONNode::as_float方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。