Skip to content

Commit

Permalink
Move picojson back into its own namespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenlovegrove committed Mar 24, 2017
1 parent 1115175 commit 7ea6e53
Show file tree
Hide file tree
Showing 38 changed files with 216 additions and 218 deletions.
12 changes: 6 additions & 6 deletions include/pangolin/log/packet_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ class PacketIndex: std::map<PacketStreamSourceId, std::map<size_t, std::streampo
{
}

PacketIndex(const json::array& source)
PacketIndex(const picojson::array& source)
{
for (size_t src = 0; src < source.size(); ++src)
{
const json::array& row = source[src].get<json::array>();
const picojson::array& row = source[src].get<picojson::array>();
for (size_t frame = 0; frame < row.size(); ++frame)
add(src, frame, row[frame].get<int64_t>());
}
Expand Down Expand Up @@ -75,15 +75,15 @@ class PacketIndex: std::map<PacketStreamSourceId, std::map<size_t, std::streampo
}
}

json::array json() const
picojson::array json() const
{
json::array index;
picojson::array index;
for (const auto& src : *this)
{
json::array positions;
picojson::array positions;
for (const auto& frame : src.second)
{
positions.push_back(json::value(frame.second));
positions.push_back(picojson::value(frame.second));
}
index.push_back(positions);
}
Expand Down
2 changes: 1 addition & 1 deletion include/pangolin/log/packetstream_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class PANGOLIN_EXPORT PacketStreamReader
int64_t time;
size_t size;
size_t sequence_num;
json::value meta;
picojson::value meta;

// The 'frame' includes the json and the packet.
std::streampos frame_streampos;
Expand Down
4 changes: 2 additions & 2 deletions include/pangolin/log/packetstream_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct PANGOLIN_EXPORT PacketStreamSource
std::string driver;
size_t id;
std::string uri;
json::value info;
picojson::value info;
int64_t version;
int64_t data_alignment_bytes;
std::string data_definitions;
Expand All @@ -25,7 +25,7 @@ struct PANGOLIN_EXPORT PacketStreamSource
PacketStreamSource(
const std::string& source_driver,
const std::string& source_uri,
const json::value& json_header = json::value(),
const picojson::value& json_header = picojson::value(),
const size_t packet_size_bytes = 0,
const std::string& packet_definitions = ""
) : driver(source_driver), id(static_cast<PacketStreamSourceId>(-1)), uri(source_uri), info(json_header), version(1), data_alignment_bytes(1), data_definitions(packet_definitions), data_size_bytes(packet_size_bytes)
Expand Down
4 changes: 2 additions & 2 deletions include/pangolin/log/packetstream_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class PANGOLIN_EXPORT PacketStreamWriter

void WriteSourcePacket(
PacketStreamSourceId src, const char* source,
size_t sourcelen, const json::value& meta = json::value()
size_t sourcelen, const picojson::value& meta = picojson::value()
);

// For stream read/write synchronization. Note that this is NOT the same as
Expand All @@ -121,7 +121,7 @@ class PANGOLIN_EXPORT PacketStreamWriter
private:
void WriteHeader();
void Write(const PacketStreamSource&);
void WriteMeta(PacketStreamSourceId src, const json::value& data);
void WriteMeta(PacketStreamSourceId src, const picojson::value& data);

threadedfilebuf _buffer;
std::ostream _stream;
Expand Down
104 changes: 51 additions & 53 deletions include/pangolin/utils/picojson.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ extern "C" {
#define PICOJSON_FALSE_TEMPLATE_TYPE ((void*)0)
#endif

namespace pangolin {
namespace json {
namespace picojson {

enum {
null_type,
Expand Down Expand Up @@ -1102,20 +1101,19 @@ inline bool operator!=(const value& x, const value& y) {
}

} // namespace json
} // namespace pangolin

inline std::istream& operator>>(std::istream& is, pangolin::json::value& x)
inline std::istream& operator>>(std::istream& is, picojson::value& x)
{
pangolin::json::set_last_error(std::string());
std::string err = pangolin::json::parse(x, is);
picojson::set_last_error(std::string());
std::string err = picojson::parse(x, is);
if (! err.empty()) {
pangolin::json::set_last_error(err);
picojson::set_last_error(err);
is.setstate(std::ios::failbit);
}
return is;
}

inline std::ostream& operator<<(std::ostream& os, const pangolin::json::value& x)
inline std::ostream& operator<<(std::ostream& os, const picojson::value& x)
{
x.serialize(std::ostream_iterator<char>(os));
return os;
Expand Down Expand Up @@ -1174,7 +1172,7 @@ int main(void)

// constructors
#define TEST(expr, expected) \
is(pangolin::json::value expr .serialize(), string(expected), "pangolin::json::value" #expr)
is(picojson::value expr .serialize(), string(expected), "picojson::value" #expr)

TEST( (true), "true");
TEST( (false), "false");
Expand All @@ -1186,10 +1184,10 @@ int main(void)
{
double a = 1;
for (int i = 0; i < 1024; i++) {
pangolin::json::value vi(a);
picojson::value vi(a);
std::stringstream ss;
ss << vi;
pangolin::json::value vo;
picojson::value vo;
ss >> vo;
double b = vo.get<double>();
if ((i < 53 && a != b) || fabs(a - b) / b > 1e-8) {
Expand All @@ -1202,9 +1200,9 @@ int main(void)
#undef TEST

#define TEST(in, type, cmp, serialize_test) { \
pangolin::json::value v; \
picojson::value v; \
const char* s = in; \
string err = pangolin::json::parse(v, s, s + strlen(s)); \
string err = picojson::parse(v, s, s + strlen(s)); \
ok(err.empty(), in " no error"); \
ok(v.is<type>(), in " check type"); \
is<type>(v.get<type>(), cmp, in " correct output"); \
Expand Down Expand Up @@ -1232,24 +1230,24 @@ int main(void)
#undef TEST

#define TEST(type, expr) { \
pangolin::json::value v; \
picojson::value v; \
const char *s = expr; \
string err = pangolin::json::parse(v, s, s + strlen(s)); \
string err = picojson::parse(v, s, s + strlen(s)); \
ok(err.empty(), "empty " #type " no error"); \
ok(v.is<pangolin::json::type>(), "empty " #type " check type"); \
ok(v.get<pangolin::json::type>().empty(), "check " #type " array size"); \
ok(v.is<picojson::type>(), "empty " #type " check type"); \
ok(v.get<picojson::type>().empty(), "check " #type " array size"); \
}
TEST(array, "[]");
TEST(object, "{}");
#undef TEST

{
pangolin::json::value v;
picojson::value v;
const char *s = "[1,true,\"hello\"]";
string err = pangolin::json::parse(v, s, s + strlen(s));
string err = picojson::parse(v, s, s + strlen(s));
ok(err.empty(), "array no error");
ok(v.is<pangolin::json::array>(), "array check type");
is(v.get<pangolin::json::array>().size(), size_t(3), "check array size");
ok(v.is<picojson::array>(), "array check type");
is(v.get<picojson::array>().size(), size_t(3), "check array size");
ok(v.contains(0), "check contains array[0]");
ok(v.get(0).is<double>(), "check array[0] type");
is(v.get(0).get<double>(), 1.0, "check array[0] value");
Expand All @@ -1263,12 +1261,12 @@ int main(void)
}

{
pangolin::json::value v;
picojson::value v;
const char *s = "{ \"a\": true }";
string err = pangolin::json::parse(v, s, s + strlen(s));
string err = picojson::parse(v, s, s + strlen(s));
ok(err.empty(), "object no error");
ok(v.is<pangolin::json::object>(), "object check type");
is(v.get<pangolin::json::object>().size(), size_t(1), "check object size");
ok(v.is<picojson::object>(), "object check type");
is(v.get<picojson::object>().size(), size_t(1), "check object size");
ok(v.contains("a"), "check contains property");
ok(v.get("a").is<bool>(), "check bool property exists");
is(v.get("a").get<bool>(), true, "check bool property value");
Expand All @@ -1277,9 +1275,9 @@ int main(void)
}

#define TEST(json, msg) do { \
pangolin::json::value v; \
picojson::value v; \
const char *s = json; \
string err = pangolin::json::parse(v, s, s + strlen(s)); \
string err = picojson::parse(v, s, s + strlen(s)); \
is(err, string("syntax error at line " msg), msg); \
} while (0)
TEST("falsoa", "1 near: oa");
Expand All @@ -1289,92 +1287,92 @@ int main(void)
#undef TEST

{
pangolin::json::value v1, v2;
picojson::value v1, v2;
const char *s;
string err;
s = "{ \"b\": true, \"a\": [1,2,\"three\"], \"d\": 2 }";
err = pangolin::json::parse(v1, s, s + strlen(s));
err = picojson::parse(v1, s, s + strlen(s));
s = "{ \"d\": 2.0, \"b\": true, \"a\": [1,2,\"three\"] }";
err = pangolin::json::parse(v2, s, s + strlen(s));
err = picojson::parse(v2, s, s + strlen(s));
ok((v1 == v2), "check == operator in deep comparison");
}

{
pangolin::json::value v1, v2;
picojson::value v1, v2;
const char *s;
string err;
s = "{ \"b\": true, \"a\": [1,2,\"three\"], \"d\": 2 }";
err = pangolin::json::parse(v1, s, s + strlen(s));
err = picojson::parse(v1, s, s + strlen(s));
s = "{ \"d\": 2.0, \"a\": [1,\"three\"], \"b\": true }";
err = pangolin::json::parse(v2, s, s + strlen(s));
err = picojson::parse(v2, s, s + strlen(s));
ok((v1 != v2), "check != operator for array in deep comparison");
}

{
pangolin::json::value v1, v2;
picojson::value v1, v2;
const char *s;
string err;
s = "{ \"b\": true, \"a\": [1,2,\"three\"], \"d\": 2 }";
err = pangolin::json::parse(v1, s, s + strlen(s));
err = picojson::parse(v1, s, s + strlen(s));
s = "{ \"d\": 2.0, \"a\": [1,2,\"three\"], \"b\": false }";
err = pangolin::json::parse(v2, s, s + strlen(s));
err = picojson::parse(v2, s, s + strlen(s));
ok((v1 != v2), "check != operator for object in deep comparison");
}

{
pangolin::json::value v1, v2;
picojson::value v1, v2;
const char *s;
string err;
s = "{ \"b\": true, \"a\": [1,2,\"three\"], \"d\": 2 }";
err = pangolin::json::parse(v1, s, s + strlen(s));
pangolin::json::object& o = v1.get<pangolin::json::object>();
err = picojson::parse(v1, s, s + strlen(s));
picojson::object& o = v1.get<picojson::object>();
o.erase("b");
pangolin::json::array& a = o["a"].get<pangolin::json::array>();
pangolin::json::array::iterator i;
i = std::remove(a.begin(), a.end(), pangolin::json::value(std::string("three")));
picojson::array& a = o["a"].get<picojson::array>();
picojson::array::iterator i;
i = std::remove(a.begin(), a.end(), picojson::value(std::string("three")));
a.erase(i, a.end());
s = "{ \"a\": [1,2], \"d\": 2 }";
err = pangolin::json::parse(v2, s, s + strlen(s));
err = picojson::parse(v2, s, s + strlen(s));
ok((v1 == v2), "check erase()");
}

ok(pangolin::json::value(3.0).serialize() == "3",
ok(picojson::value(3.0).serialize() == "3",
"integral number should be serialized as a integer");

{
const char* s = "{ \"a\": [1,2], \"d\": 2 }";
pangolin::json::null_parse_context ctx;
picojson::null_parse_context ctx;
string err;
pangolin::json::_parse(ctx, s, s + strlen(s), &err);
picojson::_parse(ctx, s, s + strlen(s), &err);
ok(err.empty(), "null_parse_context");
}

{
pangolin::json::value v;
picojson::value v;
const char *s = "{ \"a\": 1, \"b\": [ 2, { \"b1\": \"abc\" } ], \"c\": {}, \"d\": [] }";
string err;
err = pangolin::json::parse(v, s, s + strlen(s));
err = picojson::parse(v, s, s + strlen(s));
ok(err.empty(), "parse test data for prettifying output");
ok(v.serialize() == "{\"a\":1,\"b\":[2,{\"b1\":\"abc\"}],\"c\":{},\"d\":[]}", "non-prettifying output");
ok(v.serialize(true) == "{\n \"a\": 1,\n \"b\": [\n 2,\n {\n \"b1\": \"abc\"\n }\n ],\n \"c\": {},\n \"d\": []\n}\n", "prettifying output");
}

try {
pangolin::json::value v(std::numeric_limits<double>::quiet_NaN());
picojson::value v(std::numeric_limits<double>::quiet_NaN());
ok(false, "should not accept NaN");
} catch (std::overflow_error e) {
ok(true, "should not accept NaN");
}

try {
pangolin::json::value v(std::numeric_limits<double>::infinity());
picojson::value v(std::numeric_limits<double>::infinity());
ok(false, "should not accept infinity");
} catch (std::overflow_error e) {
ok(true, "should not accept infinity");
}

try {
pangolin::json::value v(123.);
picojson::value v(123.);
ok(! v.is<bool>(), "is<wrong_type>() should return false");
v.get<bool>();
ok(false, "get<wrong_type>() should raise an error");
Expand All @@ -1384,7 +1382,7 @@ int main(void)

#ifdef PICOJSON_USE_INT64
{
pangolin::json::value v1((int64_t)123);
picojson::value v1((int64_t)123);
ok(v1.is<int64_t>(), "is int64_t");
ok(v1.is<double>(), "is double as well");
ok(v1.serialize() == "123", "serialize the value");
Expand All @@ -1395,7 +1393,7 @@ int main(void)
ok(v1.is<double>(), "and is still a double");

const char *s = "-9223372036854775809";
ok(pangolin::json::parse(v1, s, s + strlen(s)).empty(), "parse underflowing int64_t");
ok(picojson::parse(v1, s, s + strlen(s)).empty(), "parse underflowing int64_t");
ok(! v1.is<int64_t>(), "underflowing int is not int64_t");
ok(v1.is<double>(), "underflowing int is double");
ok(v1.get<double>() + 9.22337203685478e+18 < 65536, "double value is somewhat correct");
Expand Down
4 changes: 2 additions & 2 deletions include/pangolin/video/drivers/debayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ class PANGOLIN_EXPORT DebayerVideo :
std::vector<bayer_method_t> methods;
color_filter_t tile;

json::value device_properties;
json::value frame_properties;
picojson::value device_properties;
picojson::value frame_properties;
};

}
10 changes: 5 additions & 5 deletions include/pangolin/video/drivers/depthsense.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ class PANGOLIN_EXPORT DepthSenseVideo :
bool GrabNewest( unsigned char* image, bool wait = true );

//! Implement VideoInput::DeviceProperties()
const json::value& DeviceProperties() const {
const picojson::value& DeviceProperties() const {
return device_properties;
}

//! Implement VideoInput::DeviceProperties()
const json::value& FrameProperties() const {
const picojson::value& FrameProperties() const {
return frame_properties;
}
protected:
Expand All @@ -101,9 +101,9 @@ class PANGOLIN_EXPORT DepthSenseVideo :
double GetDeltaTime() const;

std::vector<StreamInfo> streams;
json::value device_properties;
json::value frame_properties;
json::value* streams_properties;
picojson::value device_properties;
picojson::value frame_properties;
picojson::value* streams_properties;


DepthSense::Device device;
Expand Down
4 changes: 2 additions & 2 deletions include/pangolin/video/drivers/ffmpeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ class PANGOLIN_EXPORT FfmpegVideoOutput
~FfmpegVideoOutput();

const std::vector<StreamInfo>& Streams() const;
void SetStreams(const std::vector<StreamInfo>& streams, const std::string& uri, const json::value& properties);
int WriteStreams(const unsigned char* data, const json::value& frame_properties) override;
void SetStreams(const std::vector<StreamInfo>& streams, const std::string& uri, const picojson::value& properties);
int WriteStreams(const unsigned char* data, const picojson::value& frame_properties) override;
bool IsPipe() const;

protected:
Expand Down
Loading

0 comments on commit 7ea6e53

Please sign in to comment.