Annotation of parser3/src/doc/ClassExample2.dox, revision 1.5
1.5 ! paf 1: /** @page ClassExample2 Sample of creating simple class (with fields only)
1.1 paf 2:
1.5 ! paf 3: To create the class of your own, which does not contain methods [like 'env', see VEnv],
! 4: one need to create a derivate from Value, where override Value::type,
! 5: and also Value::get_element and/or Value::put_element.
1.1 paf 6:
1.5 ! paf 7: File pa_vexample2.h in types/ directory:
1.1 paf 8: @code
9: #define EXAMPLE2_CLASS_NAME "example2"
10:
11: /// env class
12: class VExample2 : public Value {
13: public: // Value
14:
15: const char *type() const { return "example2"; }
16:
1.3 paf 17: /// VEnv: field
1.1 paf 18: Value *get_element(const String& aname) {
1.5 ! paf 19: // device information
1.2 paf 20: double temperature=25;
1.1 paf 21: return NEW VDouble(temperature);
22: }
23:
24: public: // usage
25:
26: VExample2(Pool& apool) : Value(apool) {
27: }
28:
29: };
30: @endcode
31:
1.5 ! paf 32: Register your class in Request::classes(), by adding it to Request constructor [in pa_request.C file]:
1.1 paf 33:
1.2 paf 34: @code
35: /// methodless
36: // example2 class
37: classes().put(*NEW String(pool(), EXAMPLE2_CLASS_NAME), &example2);
38: @endcode
1.1 paf 39:
1.5 ! paf 40: User could then read temperature like:
1.4 paf 41: @verbatim
42: $example2:test
43: @endverbatim
44:
1.1 paf 45: */
E-mail: