1 | /* |
---|
2 | * ---------------------------------------------------------------------- |
---|
3 | * Rappture 2.0 AxisMarker Object Source |
---|
4 | * |
---|
5 | * ====================================================================== |
---|
6 | * AUTHOR: Derrick Kearney, Purdue University |
---|
7 | * Copyright (c) 2004-2012 HUBzero Foundation, LLC |
---|
8 | * |
---|
9 | * See the file "license.terms" for information on usage and |
---|
10 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
11 | * ====================================================================== |
---|
12 | */ |
---|
13 | |
---|
14 | #include "RpAxisMarker.h" |
---|
15 | |
---|
16 | using namespace Rappture; |
---|
17 | |
---|
18 | AxisMarker::AxisMarker() |
---|
19 | : Object(), |
---|
20 | _axisName(NULL), |
---|
21 | _style(NULL), |
---|
22 | _at(0.0) |
---|
23 | {} |
---|
24 | |
---|
25 | AxisMarker::AxisMarker(const char *axisName, const char *label, |
---|
26 | const char *style, double at) |
---|
27 | : Object(), |
---|
28 | _axisName(NULL), |
---|
29 | _style(NULL), |
---|
30 | _at(0.0) |
---|
31 | { |
---|
32 | this->axisName(axisName); |
---|
33 | this->label(label); |
---|
34 | this->style(style); |
---|
35 | this->at(at); |
---|
36 | } |
---|
37 | |
---|
38 | AxisMarker::AxisMarker(const AxisMarker &o) |
---|
39 | : Object(), |
---|
40 | _axisName(NULL), |
---|
41 | _style(NULL), |
---|
42 | _at(0.0) |
---|
43 | { |
---|
44 | this->axisName(o.axisName()); |
---|
45 | this->label(o.label()); |
---|
46 | this->style(o.style()); |
---|
47 | this->at(o.at()); |
---|
48 | } |
---|
49 | |
---|
50 | AxisMarker::~AxisMarker() |
---|
51 | { |
---|
52 | if (_axisName != NULL) { |
---|
53 | delete[] _axisName; |
---|
54 | } |
---|
55 | |
---|
56 | if (_style != NULL) { |
---|
57 | delete[] _style; |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | |
---|
62 | void |
---|
63 | AxisMarker::axisName (const char *a) |
---|
64 | { |
---|
65 | size_t len = 0; |
---|
66 | |
---|
67 | if (a == NULL) { |
---|
68 | return; |
---|
69 | } |
---|
70 | |
---|
71 | if (_axisName != NULL) { |
---|
72 | delete[] _axisName; |
---|
73 | } |
---|
74 | |
---|
75 | len = strlen(a); |
---|
76 | char *tmp = new char[len+1]; |
---|
77 | |
---|
78 | strncpy(tmp,a,len+1); |
---|
79 | |
---|
80 | _axisName = tmp; |
---|
81 | |
---|
82 | return; |
---|
83 | } |
---|
84 | |
---|
85 | const char * |
---|
86 | AxisMarker::axisName (void) const |
---|
87 | { |
---|
88 | return _axisName; |
---|
89 | } |
---|
90 | |
---|
91 | void |
---|
92 | AxisMarker::style (const char *s) |
---|
93 | { |
---|
94 | size_t len = 0; |
---|
95 | |
---|
96 | if (s == NULL) { |
---|
97 | return; |
---|
98 | } |
---|
99 | |
---|
100 | if (_style != NULL) { |
---|
101 | delete[] _style; |
---|
102 | } |
---|
103 | |
---|
104 | len = strlen(s); |
---|
105 | char *tmp = new char[len+1]; |
---|
106 | |
---|
107 | strncpy(tmp,s,len+1); |
---|
108 | |
---|
109 | _style = tmp; |
---|
110 | |
---|
111 | return; |
---|
112 | } |
---|
113 | |
---|
114 | const char * |
---|
115 | AxisMarker::style (void) const |
---|
116 | { |
---|
117 | return _style; |
---|
118 | } |
---|
119 | |
---|
120 | void |
---|
121 | AxisMarker::at (double a) |
---|
122 | { |
---|
123 | _at = a; |
---|
124 | return; |
---|
125 | } |
---|
126 | |
---|
127 | double |
---|
128 | AxisMarker::at (void) const |
---|
129 | { |
---|
130 | return _at; |
---|
131 | } |
---|
132 | |
---|
133 | /**********************************************************************/ |
---|
134 | // METHOD: xml() |
---|
135 | /// Return the xml of the object |
---|
136 | /** |
---|
137 | * Return the xml of the object |
---|
138 | */ |
---|
139 | |
---|
140 | const char * |
---|
141 | AxisMarker::xml(size_t indent, size_t tabstop) |
---|
142 | { |
---|
143 | size_t l1width = indent + tabstop; |
---|
144 | const char *sp = ""; |
---|
145 | |
---|
146 | _tmpBuf.clear(); |
---|
147 | |
---|
148 | _tmpBuf.appendf( |
---|
149 | "%6$*4$s<marker>\n\ |
---|
150 | %6$*5$s<at>%1$g</at>\n\ |
---|
151 | %6$*5$s<label>%2$s</label>\n\ |
---|
152 | %6$*5$s<style>%3$s</style>\n\ |
---|
153 | %6$*4$s<marker>\n", |
---|
154 | _at,label(),_style,indent,l1width,sp); |
---|
155 | |
---|
156 | _tmpBuf.append("\0",1); |
---|
157 | |
---|
158 | return _tmpBuf.bytes(); |
---|
159 | } |
---|
160 | |
---|
161 | /**********************************************************************/ |
---|
162 | // METHOD: is() |
---|
163 | /// what kind of object is this |
---|
164 | /** |
---|
165 | * return hex value telling what kind of object this is. |
---|
166 | */ |
---|
167 | |
---|
168 | const int |
---|
169 | AxisMarker::is() const |
---|
170 | { |
---|
171 | // return "mark" in hex |
---|
172 | return 0x6D61726B; |
---|
173 | } |
---|
174 | |
---|
175 | // -------------------------------------------------------------------- // |
---|
176 | |
---|