diff --git a/.gitmodules b/.gitmodules index d9c0b91..d81c7b0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,9 +4,6 @@ [submodule "glm"] path = glm url = https://github.com/g-truc/glm.git -[submodule "picojson"] - path = picojson - url = https://github.com/kazuho/picojson.git [submodule "ebcl"] path = ebcl url = ssh://git@git.nocternity.net:44/u/tseeker/libs/corelib diff --git a/.vim.local/ycm_extra_conf.py b/.vim.local/ycm_extra_conf.py index b4ecac1..3fb74bd 100644 --- a/.vim.local/ycm_extra_conf.py +++ b/.vim.local/ycm_extra_conf.py @@ -47,7 +47,6 @@ flags = [ '-I','.', '-I','imgui', '-I','glm', - '-I','picojson', '-I','ebcl/include', '-I','/usr/include/SDL2' , '-D','GLM_ENABLE_EXPERIMENTAL', diff --git a/Makefile b/Makefile index 4434f8b..d45d2ed 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ OUTDIR = output CXXFLAGS += $(shell sdl2-config --cflags) -std=c++14 -Wall -g CFLAGS += $(shell sdl2-config --cflags) CPPFLAGS += -I. -I$(OUTDIR) \ - -Iimgui -Iglm -Ipicojson -Iebcl/include \ + -Iimgui -Iglm -Iebcl/include \ -DREAL_BUILD -DGLM_ENABLE_EXPERIMENTAL LIBS += $(shell sdl2-config --libs) -lGL -lGLEW -ldl \ $(LIBEBCL) -latomic diff --git a/externals.hh b/externals.hh index 617ffff..ec70fdd 100644 --- a/externals.hh +++ b/externals.hh @@ -32,9 +32,6 @@ using std::swap; #include #include -// PicoJSON -#include - // EBCL #include #include diff --git a/picojson b/picojson deleted file mode 160000 index 1ebfc7b..0000000 --- a/picojson +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 1ebfc7b998fed25c48b4c14c0907bda74ead42c5 diff --git a/utilities.cc b/utilities.cc index cb41ace..0461844 100644 --- a/utilities.cc +++ b/utilities.cc @@ -69,93 +69,3 @@ T_String GetParentPath( free( rp ); return rv; } - - -/*= JSON =====================================================================*/ - -template void jsonAdd< double >( - T_JSONObject& object , - std::string const& key , - double const& v ); -template void jsonAdd< T_JSONObject >( - T_JSONObject& object , - std::string const& key , - T_JSONObject const& v ); -template void jsonAdd< T_JSONArray >( - T_JSONObject& object , - std::string const& key , - T_JSONArray const& v ); -template void jsonAdd< std::string >( - T_JSONObject& object , - std::string const& key , - std::string const& v ); - -template< > -void jsonAdd< picojson::value >( - T_JSONObject& object , - std::string const& key , - picojson::value const& v ) -{ - using T_Entry = std::pair< std::string , picojson::value >; - object.insert( T_Entry( key , v ) ); -} - -template< > -void jsonAdd< int >( - T_JSONObject& object , - std::string const& key , - int const& v ) -{ - using T_Entry = std::pair< std::string , picojson::value >; - object.insert( T_Entry( key , picojson::value( double( v ) ) ) ); -} - -template< > -void jsonAdd< unsigned >( - T_JSONObject& object , - std::string const& key , - unsigned const& v ) -{ - using T_Entry = std::pair< std::string , picojson::value >; - object.insert( T_Entry( key , picojson::value( double( v ) ) ) ); -} - -/*----------------------------------------------------------------------------*/ - -picojson::value jsonVector( float const* vector , const int nComponents ) -{ - using namespace picojson; - value::array a; - for ( auto i = 0 ; i < nComponents ; i ++ ) { - a.push_back( value( vector[ i ] ) ); - } - return value( a ); -} - -/*----------------------------------------------------------------------------*/ - -void jsonGetVectorOpt( - float* vector , - const size_t size , - T_JSONObject const& object , - char const* key ) -{ - using namespace picojson; - auto const* ptr( jsonGetOpt< array >( object , key ) ); - if ( !ptr ) { - return; - } - - auto const& a( *ptr ); - if ( a.size( ) != size ) { - throw X_JsonGetFailed( ); - } - - int i = 0; - for ( auto const& av : a ) { - if ( !av.is< double >( ) ) { - throw X_JsonGetFailed( ); - } - vector[ i ++ ] = float( av.get< double >( ) ); - } -} diff --git a/utilities.hh b/utilities.hh index 0d3f881..20cabfe 100644 --- a/utilities.hh +++ b/utilities.hh @@ -76,199 +76,3 @@ std::string GetAbsolutePath( // Get the absolute parent path for a (possibly relative) path std::string GetParentPath( std::string const& path ); - - -/*= JSON utilities ===========================================================*/ - -using T_JSONObject = picojson::value::object; -using T_JSONArray = picojson::value::array; - -// Convert a vector to a JSON array -picojson::value jsonVector( - float const* vector , - const int nComponents ); - -// Convert a GLM vec3 to a JSON array -inline picojson::value jsonVector( - glm::vec3 const& vector ) -{ - return jsonVector( &vector.x , 3 ); -} - -// Add an entry to a JSON object -template< typename T > -inline void jsonAdd( - T_JSONObject& object , - std::string const& key , - T const& v ) -{ - using T_Entry = std::pair< std::string , picojson::value >; - object.insert( T_Entry( key , picojson::value( v ) ) ); -} - -extern template void jsonAdd< double >( - T_JSONObject& object , - std::string const& key , - double const& v ); -extern template void jsonAdd< T_JSONObject >( - T_JSONObject& object , - std::string const& key , - T_JSONObject const& v ); -extern template void jsonAdd< T_JSONArray >( - T_JSONObject& object , - std::string const& key , - T_JSONArray const& v ); -extern template void jsonAdd< std::string >( - T_JSONObject& object , - std::string const& key , - std::string const& v ); - -template< > -void jsonAdd< picojson::value >( - T_JSONObject& object , - std::string const& key , - picojson::value const& v ); -template< > -void jsonAdd< int >( - T_JSONObject& object , - std::string const& key , - int const& v ); -template< > -void jsonAdd< unsigned >( - T_JSONObject& object , - std::string const& key , - unsigned const& v ); - -/*----------------------------------------------------------------------------*/ - -// JSON read type error -class X_JsonGetFailed : public std::exception { }; - -// Get a JSON object field; throws X_JsonGetFailed if the type is incorrect or -// if the field is missing. -template< typename T > -inline T const& jsonGet( - T_JSONObject const& object , - char const* const key ) -{ - const std::string k( key ); - if ( object.find( k ) == object.end( ) ) { - throw X_JsonGetFailed( ); - } - - picojson::value const& v( object.at( k ) ); - if ( !v.is< T >( ) ) { - throw X_JsonGetFailed( ); - } - return v.get< T >( ); -} - -// Get a pointer to a JSON object field, or nullptr if the field doesn't exist. -// Throws X_JsonGetFailed if the type is incorrect. -template< typename T > -inline T const* jsonGetOpt( - T_JSONObject const& object , - char const* const key ) -{ - const std::string k( key ); - if ( object.find( k ) == object.end( ) ) { - return nullptr; - } - - picojson::value const& v( object.at( k ) ); - if ( !v.is< T >( ) ) { - throw X_JsonGetFailed( ); - } - return &v.get< T >( ); -} - -// Read a value from a JSON object, if the value actually exists. Fails with -// X_JsonGetFailed if the type is wrong -template< typename T > -inline bool jsonSetFromOpt( - T& out , - T_JSONObject const& object , - char const* const key ) -{ - T const* ptr( jsonGetOpt< T >( object , key ) ); - if ( ptr ) { - out = *ptr; - } - return ptr; -} - -// Integer specialization of the above -template< > -inline bool jsonSetFromOpt< int >( - int& out , - T_JSONObject const& object , - char const* const key ) -{ - double const* ptr( jsonGetOpt< double >( object , key ) ); - if ( ptr ) { - out = int( *ptr ); - } - return ptr; -} - -// Unsigned integer specialization of the above -template< > -inline bool jsonSetFromOpt< unsigned >( - unsigned& out , - T_JSONObject const& object , - char const* const key ) -{ - double const* ptr( jsonGetOpt< double >( object , key ) ); - if ( ptr ) { - out = unsigned( *ptr ); - } - return ptr; -} - -// 32-bit float specialization of the above -template< > -inline bool jsonSetFromOpt< float >( - float& out , - T_JSONObject const& object , - char const* const key ) -{ - double const* ptr( jsonGetOpt< double >( object , key ) ); - if ( ptr ) { - out = float( *ptr ); - } - return ptr; -} - -// Read a vector from a JSON array of numbers -void jsonGetVectorOpt( - float* vector , - const size_t size , - T_JSONObject const& object , - char const* key ); - -// Read a GLM vec3 from a JSON array of numbers -inline void jsonGetVectorOpt( - glm::vec3& vector , - T_JSONObject const& object , - char const* key ) -{ - jsonGetVectorOpt( &vector.x , 3 , object , key ); -} - -// Try to load some object using its "bool load( jsonobject )" method. -template< typename T > -inline bool jsonLoadOpt( - T& out , - T_JSONObject const& object , - char const* key ) -{ - try { - auto const* sub( jsonGetOpt< T_JSONObject >( object , key ) ); - if ( sub ) { - return out.load( *sub ); - } - return true; - } catch ( X_JsonGetFailed const& ) { - return false; - } -}