示例#1
0
    // canvas::draw overridable
    virtual void draw( HELEMENT he, graphics& gx, UINT width, UINT height )
    { 
      if( !data.is_array() )
      {
        draw_message( gx, width, height, const_wchars(L"Data not found") );
        return; 
      }

      color black(0,0,0);

       // x axis
      gx.line_cap(LINE_CAP_BUTT);
      gx.line_color(black);
      gx.line( 0.5, height - 0.5, width - 0.5, height - 0.5 ); // 0.5 - to draw line in the middle of the pixel

      for( int n = 0; n < data.length(); ++n )
      {
        json::value bar_def = data[n];
        json::value color_v = bar_def.k2v(L"color"); 
        json::value value_v = bar_def.k2v(L"value");
        if( color_v.is_undefined() || value_v.is_undefined())
        {
          draw_message( gx, width, height, const_wchars(L"Bad data structure") );
          return; 
        }
        draw_bar(gx, width, height, n, data.length(), color(color_v.get(0)), value_v.get(1.0));
      }
    }
示例#2
0
inline void __print_close_brace (string & result, json::value const & v, print_spec const & pspec)
{
    if (v.is_array()) {
        result.append(pspec.close_array_brace);
    } else {
        result.append(pspec.close_object_brace);
    }
}
示例#3
0
void GoogleSearchClient::flattenJsonInnerLoop(json::value const & val, FlatJsonObject & json_map) {
  // input : Body of the google search response as json::value
  // This recursive function parse the Json raw value to a C++ multimap
  if (!val.is_null() && val.is_object()) {
    for (auto const &iter : val.as_object()) {
      //iter on each element for Json object type. Return a vect<string_t,json::value>
      const auto &mapKey = iter.first;
      const auto &content = iter.second;
      json_map.insert(std::pair<utility::string_t, utility::string_t>(mapKey, content.serialize()));
      flattenJsonInnerLoop(content, json_map);
    }
  } else if (val.is_array()) {
    for (auto const &content : val.as_array()) {
      //iter on each element for Json array type. Return a json::value
      flattenJsonInnerLoop(content, json_map);
    }
  }
}
示例#4
0
    // Constructing with a float should produce number values
    REQUIRE( json::value{33.2f}.is_number() );
    REQUIRE( json::value{33.2f}.number<float>() == Approx(33.2f) );
    REQUIRE( json::value{33.2f}.get_kind() == json::kind::number );
    REQUIRE( json::value{33.2f}.get_contents() == "33.2" );

    // Constructing with a char should produce number values (so that int8_t/uint8_t work correctly)
    REQUIRE( json::value{'A'}.is_number() );
    REQUIRE( json::value{'A'}.number<char>() == 'A' );
    REQUIRE( json::value{'A'}.get_kind() == json::kind::number );
    REQUIRE( json::value{'A'}.get_contents() == "65" );

    // Constructing with a json::array should produce array values
    json::value array_value = json::array{2,3.14f,"foo",false,nullptr};
    REQUIRE( array_value.is_array() );
    REQUIRE( array_value.get_array().size() == 5 );
    REQUIRE( array_value[0] == 2 );
    REQUIRE( array_value[1] == 3.14f );
    REQUIRE( array_value[2] == "foo" );
    REQUIRE( array_value[3] == false );
    REQUIRE( array_value[4] == nullptr );
    REQUIRE( array_value.get_kind() == json::kind::array );

    // Constructing with a json::object should produce object values
    json::value object_value = json::object{{"a",2},{"b",3.14f},{"c","foo"},{"d",false},{"e",nullptr}};
    REQUIRE( object_value.is_object() );
    REQUIRE( object_value.get_object().size() == 5 );
    REQUIRE( object_value["a"] == 2 );
    REQUIRE( object_value["b"] == 3.14f );
    REQUIRE( object_value["c"] == "foo" );