1 /*
2 
3   Copyright (C) 2011 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 #ifndef __jsonnode__
25 #define __jsonnode__
26 
27 #include <string>
28 #include <vector>
29 #include <map>
30 
31 #include "smartpointer.h"
32 
33 namespace httpdfaust
34 {
35 
36 class jsonnode;
37 typedef SMARTP<jsonnode>	Sjsonnode;
38 
39 typedef std::map<std::string, std::string>	TMetas;
40 
41 //______________________________________________________________________________
42 /*!
43 \internal
44 \brief to be used in place of std::endl
45 	to provide indentation of the json output.
46 */
47 class jsonendl {
48 	private:
49 		int fIndent;
50 	public:
jsonendl()51 				 jsonendl() : fIndent(0) {}
~jsonendl()52 		virtual ~jsonendl() {}
53 
54 		//! increase the indentation
55 		jsonendl& operator++ (int)  { fIndent++; return *this; }	// prefix
56 		jsonendl& operator++ ()		{ fIndent++; return *this; }	// postfix
57 		//! decrease the indentation
58 		jsonendl& operator-- (int)  { fIndent--; return *this; }	// prefix
59 		jsonendl& operator-- ()		{ fIndent--; return *this; }	// postfix
60 		//! reset the indentation to none
61 		void print(std::ostream& os) const;
62 };
63 std::ostream& operator<< (std::ostream& os, const jsonendl& eol);
64 
65 //--------------------------------------------------------------------------
66 /*!
67 	\brief a faust node is a terminal node and represents a faust parameter controler
68 */
69 class jsonnode : public smartable
70 {
71 	std::string fAddress;
72 	public:
~jsonnode()73 		virtual ~jsonnode() {}
74 
add(const Sjsonnode & node)75 		virtual void	add (const Sjsonnode& node)		{}
76 		virtual void	print(std::ostream& out, jsonendl& eol) const = 0;
getAddress()77 		virtual const std::string&	getAddress() const							{ return fAddress; }
setAddress(const std::string & address)78 		virtual void				setAddress( const std::string& address) 	{ fAddress = address; }
79 };
80 
81 } // end namespoace
82 
83 #endif
84