1 /* 2 3 Copyright (C) 2012 Grame 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Lesser General Public 7 License as published by the Free Software Foundation; either 8 version 2.1 of the License, or (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Lesser General Public License for more details. 14 15 You should have received a copy of the GNU Lesser General Public 16 License along with this library; if not, write to the Free Software 17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 19 Grame Research Laboratory, 9 rue du Garet, 69001 Lyon - France 20 research@grame.fr 21 22 */ 23 24 25 #ifndef __jsonfactory__ 26 #define __jsonfactory__ 27 28 #include <stack> 29 #include <string> 30 31 #include "jsonroot.h" 32 #include "jsoncontrol.h" 33 34 namespace httpdfaust 35 { 36 37 class jsonnode; 38 typedef SMARTP<jsonnode> Sjsonnode; 39 40 //-------------------------------------------------------------------------- 41 /*! 42 \brief a factory to build a OSC UI hierarchy 43 44 Actually, makes use of a stack to build the UI hierarchy. 45 It includes a pointer to a OSCIO controler, but just to give it to the root node. 46 */ 47 class jsonfactory 48 { 49 std::stack<Sjsonnode> fNodes; ///< maintains the current hierarchy level 50 jsonroot fRoot; ///< keep track of the root node 51 52 void addnode(Sjsonnode node, const char* label); 53 54 public: 55 jsonfactory(const char * name,const char * address,int port)56 jsonfactory(const char* name, const char* address, int port) : fRoot(name, address, port) {} ~jsonfactory()57 virtual ~jsonfactory() {} 58 addnode(const char * type,const char * label,C min,C max,const TMetas & m)59 template <typename C> void addnode (const char* type, const char* label, C min, C max, const TMetas& m) { 60 addnode(jsoncontrol<C>::create (label, type, min, max, m), label); 61 } 62 addnode(const char * type,const char * label,C init,C min,C max,C step,const TMetas & m)63 template <typename C> void addnode (const char* type, const char* label, C init, C min, C max, C step, const TMetas& m) { 64 addnode(jsoncontrol<C>::create (label, type, init, min, max, step, m), label); 65 } 66 addnode(const char * type,const char * label,const TMetas & m)67 template <typename C> void addnode (const char* type, const char* label, const TMetas& m) { 68 addnode(jsoncontrol<C>::create (label, type, m), label); 69 } 70 71 void opengroup(const char* type, const char* label, const TMetas& m); 72 void closegroup(); 73 root()74 jsonroot& root() { return fRoot; } 75 }; 76 77 } // end namespoace 78 79 #endif 80