UniSet  2.6.0
ujson.h
00001 /*
00002  * Copyright (c) 2015 Pavel Vainerman.
00003  *
00004  * This program is free software: you can redistribute it and/or modify
00005  * it under the terms of the GNU Lesser General Public License as
00006  * published by the Free Software Foundation, version 2.1.
00007  *
00008  * This program is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00011  * Lesser General Lesser Public License for more details.
00012  *
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00015  */
00016 // --------------------------------------------------------------------------
00017 #ifndef jsonHelpers_H_
00018 #define jsonHelpers_H_
00019 // --------------------------------------------------------------------------
00020 #ifndef DISABLE_REST_API
00021 #include <Poco/JSON/Object.h>
00022 // --------------------------------------------------------------------------
00023 namespace uniset
00024 {
00025 namespace json
00026 {
00027 Poco::JSON::Object::Ptr make_object( const std::string& key, const Poco::Dynamic::Var& val );
00028 Poco::JSON::Object::Ptr make_object( const std::string& key, const Poco::Dynamic::Var&& val );
00029 Poco::JSON::Object::Ptr make_child( Poco::JSON::Object::Ptr& root, const std::string& key );
00030 Poco::JSON::Array::Ptr make_child_array( Poco::JSON::Object::Ptr& root, const std::string& key );
00031 
00032 namespace help
00033 {
00034 
00035 class item
00036 {
00037     public:
00038 
00039         item( Poco::JSON::Object::Ptr& ptr );
00040         item( const std::string& description );
00041 
00042         void param(const std::string& name, const std::string& description );
00043         Poco::JSON::Object::Ptr get();
00044 
00045         operator Poco::JSON::Object::Ptr();
00046         operator Poco::Dynamic::Var();
00047 
00048     private:
00049         Poco::JSON::Object::Ptr root;
00050         Poco::JSON::Array::Ptr params;
00051 };
00052 
00053 class object
00054 {
00055     public:
00056         object( const std::string& name );
00057         object( const std::string& name, Poco::JSON::Object::Ptr ptr );
00058 
00059         void add( item& i );
00060 
00061         Poco::JSON::Object::Ptr get();
00062 
00063         operator Poco::JSON::Object::Ptr();
00064         operator Poco::Dynamic::Var();
00065 
00066     private:
00067         Poco::JSON::Object::Ptr root;
00068         Poco::JSON::Array::Ptr cmdlist;
00069 };
00070 
00071 } // end of namespace help
00072 } // end of namespace json
00073 // --------------------------------------------------------------------------
00074 } // end of namespace uniset
00075 // --------------------------------------------------------------------------
00076 #endif // end of #ifndef DISABLE_REST_API
00077 // --------------------------------------------------------------------------
00078 #endif // end of _jsonHelpers_H_