File: Configurators_example.cxx

package info (click to toggle)
clam 1.4.0-6
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 17,836 kB
  • ctags: 20,981
  • sloc: cpp: 92,504; python: 9,721; ansic: 1,602; xml: 444; sh: 239; makefile: 153; perl: 54; asm: 15
file content (206 lines) | stat: -rw-r--r-- 5,358 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
 * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
 *                         UNIVERSITAT POMPEU FABRA
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

/**
 * @example Configurators_example.cxx
 * This example shows how the diferent values inside a dinamic type
 * can be shown and edited using the Qt and FLTK configurator widgets.
 * The kind of attributes that are shown are:
 * - Boolean
 * - std::string and CLAM::Text (the latter allows spaces)
 * - Integer numbers
 * - Double numbers
 * - Filenames
 * - Another dynamic type
 * - Enumerations (limited set of values)
 */


#include "XMLStorage.hxx"
#include "ProcessingConfig.hxx"
#include "Enum.hxx"
#include "Filename.hxx"
#include "BPF.hxx"


namespace CLAMTest
{

	// Firstly we will define the objects that we want to modify.

	// The enumeration must be defined as a class.
	class EDummy : public CLAM::Enum {
	public:
		static tEnumValue sEnumValues[];
		static tValue sDefault;
		EDummy() : Enum(sEnumValues, sDefault) {}
		EDummy(tValue v) : Enum(sEnumValues, v) {};
		EDummy(std::string s) : Enum(sEnumValues, s) {};
		virtual ~EDummy() {};
		Component * Species() const { return new EDummy;};

		typedef enum {
			zero=0,
			dos=2,
			cent=100,
			mil=1000
		} tEnum;
		static void TestClass ();
	};
	CLAM::Enum::tEnumValue EDummy::sEnumValues[] = {
		{EDummy::zero,"zero"},
		{EDummy::dos,"dos"},
		{EDummy::cent,"cent"},
		{EDummy::mil,"mil"},
		{0,NULL}
	};

	CLAM::Enum::tValue EDummy::sDefault = EDummy::dos;


	// Also the sub configuration, a configuration object
	// inside the main one.

	class DummySubConfig : public CLAM::ProcessingConfig
	{
	public:
		DYNAMIC_TYPE_USING_INTERFACE (DummySubConfig,6,ProcessingConfig);
		DYN_ATTRIBUTE(0,public,std::string,Name);
		DYN_ATTRIBUTE(1,public,std::string,ThatIsAString);
		DYN_ATTRIBUTE(2,public,CLAM::TData,ThatIsATData);
		DYN_ATTRIBUTE(3,public,CLAM::TSize,ThatIsATSize);
		DYN_ATTRIBUTE(4,public,EDummy, ThatIsAEDummy);
		DYN_ATTRIBUTE(5,public,bool, ThatIsABool);
	private:

		void DefaultInit() {
			AddAll();
			UpdateData();
			DefaultValues();
		}
		void DefaultValues() {
		}

	public:
		~DummySubConfig(){};
	};

	// A not suported type, and see what is happening
	class NotSupportedType : public CLAM::Component {
		void StoreOn(CLAM::Storage &) const { }
		void LoadFrom(CLAM::Storage &) { }
		const char * GetClassName() const { return "NotSupportedType"; }
	};

	// And at last, the main configuration class
	// including all the above and more
	class DummyConfig : public CLAM::ProcessingConfig
	{
	public:
		DYNAMIC_TYPE_USING_INTERFACE (DummyConfig,11,ProcessingConfig);
		DYN_ATTRIBUTE(0,public,std::string,Name);
		DYN_ATTRIBUTE(1,public,std::string,ThisisAString);
		DYN_ATTRIBUTE(2,public,CLAM::TData,ThisIsATData);
		DYN_ATTRIBUTE(3,public,CLAM::TSize,ThisIsATSize);
		DYN_ATTRIBUTE(4,public,EDummy, ThisIsAEDummy);
		DYN_ATTRIBUTE(5,public,NotSupportedType, ThisIsNotSupportedType);
		DYN_ATTRIBUTE(6,public,DummySubConfig, ThisIsASubConfig);
		DYN_ATTRIBUTE(7,public,bool, ThisIsABool);
		DYN_ATTRIBUTE(8,public,DummySubConfig, ThisIsDifferentSubConfig);
		DYN_ATTRIBUTE(9,public,CLAM::Filename, ThisIsAFilename);
		DYN_ATTRIBUTE(10,public,CLAM::BPF, ThisIsABPF);


	private:

		void DefaultInit() {
			AddAll();
			UpdateData();
			DefaultValues();
		}
		void DefaultValues() {
		}
	public:
		~DummyConfig(){};
	};


}

using namespace CLAMTest;

#ifdef FLTK_library_removed
#include <FL/Fl.H>
#include "FLTKConfigurator.hxx"
int DisplayFLTKConfigurator(DummyConfig & config)
{
	CLAM::FLTKConfigurator * configurator = new CLAM::FLTKConfigurator;
	configurator->SetConfig(config);
	configurator->show();
	return Fl::run();
}
#endif

#include "QTConfigurator.hxx"
#include <qapplication.h>



int DisplayQTConfigurator(DummyConfig & config, int argc, char**argv)
{
	QApplication a(argc,argv);
	CLAM::QTConfigurator configurator;
	configurator.SetConfig(config);
	configurator.show();
	a.setMainWidget( &configurator );
	return a.exec();
}

int main(int argc, char** argv)
{
	const char * xmlfilename="config.xml";
	DummyConfig config;

	// If it is present, load the xml file
	try
	{
		CLAM::XmlStorage::Restore(config, xmlfilename);
	}
	catch (...)
	{
		std::cout 
			<< "Could not read the file '" << xmlfilename <<  "'. " 
			<< "Working with a default configuration." << std::endl;
	}

	// Use the configurators
	DisplayQTConfigurator(config,argc,argv);
#ifdef FLTK_library_removed
	DisplayFLTKConfigurator(config);
#endif
	// Display and store the results
	CLAM::XmlStorage::Dump(config,"DummyConfig", xmlfilename);
	CLAM::XmlStorage::Dump(config,"DummyConfig", std::cout);
	std::cout << std::endl;

	return 0;	
}