Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef WAVEPACKET_VGFX_REQUEST_H__
00035 #define WAVEPACKET_VGFX_REQUEST_H__
00036
00037
00038 #include "vgfx.h"
00039
00040 #include <sstream>
00041
00042
00043 namespace vgfx {
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 class Request {
00059 public:
00060 Request(void) : m_closed(false) {
00061 m_stream << "request {\n";
00062 }
00063
00064 void close(void) {
00065 if (!m_closed) {
00066 m_stream << "}";
00067 m_closed = true;
00068 }
00069 }
00070
00071 std::string get(void) {
00072 this->close();
00073 return m_stream.str();
00074 }
00075
00076 void addBezier(IN const char * id,
00077 IN float x0, IN float ax, IN float bx, IN float cx,
00078 IN float y0, IN float ay, IN float by, IN float cy) {
00079 ASSERT(!m_closed, "request is closed");
00080 m_stream << "add bezier id " << id;
00081 m_stream << " x0 " << x0 << " ax " << ax;
00082 m_stream << " bx " << bx << " cx " << cx;
00083 m_stream << " y0 " << y0 << " ay " << ay;
00084 m_stream << " by " << by << " cy " << cy;
00085 m_stream << "\n";
00086 }
00087
00088 void addQuadBezier(IN const char * id, IN const point_t& p0,
00089 IN const point_t& p1, IN const point_t& p2) {
00090 ASSERT(!m_closed, "request is closed");
00091
00092 m_stream << "add quad id " << id;
00093 m_stream << " x0 " << p0.x << " y0 " << p0.y;
00094 m_stream << " x1 " << p1.x << " y1 " << p1.y;
00095 m_stream << " x2 " << p2.x << " y2 " << p2.y;
00096 m_stream << "\n";
00097 }
00098
00099 void addRect(IN const char * id,
00100 IN float left, IN float top,
00101 IN float right, IN float bottom,
00102 IN bool fill) {
00103 ASSERT(!m_closed, "request is closed");
00104 m_stream << "add rect id " << id << " left " << left;
00105 m_stream << " top " << top;
00106 m_stream << " right " << right << " bottom " << bottom;
00107 if (fill) {
00108 m_stream << " fill true";
00109 }
00110 m_stream << "\n";
00111 }
00112
00113 void addSimpleRect(IN const char * id,
00114 IN float width, IN float height, IN bool fill) {
00115 this->addRect(id, 0, 0, width, height, fill);
00116 }
00117
00118 void addText(IN const char * id, IN const char * text) {
00119 ASSERT(!m_closed, "request is closed");
00120 m_stream << "add text id " << id;
00121 m_stream << " text \"" << text << "\"\n";
00122 }
00123
00124 void addSimpleGroup(IN const char * id) {
00125 ASSERT(!m_closed, "request is closed");
00126 m_stream << "add group {\n";
00127 m_stream << "\tid\t" << id << "\n";
00128 m_stream << "\t}\n";
00129 }
00130
00131 void addMeta(IN const char * group_id,
00132 IN const char * name,
00133 IN const char * value) {
00134 ASSERT(!m_closed, "request is closed");
00135 m_stream << "set " << group_id << ".meta." << name;
00136 m_stream << "\t" << name << " \"" << value << "\"\n";
00137 }
00138
00139 void addObject(IN const char * group_id, IN const char * tag,
00140 IN const char * ref,
00141 IN float x, IN float y,
00142 IN float z, IN float phi = 0.0) {
00143 ASSERT(!m_closed, "request is closed");
00144 m_stream << "set " << group_id << ".object." << tag;
00145 m_stream << "\ttag " << tag << "\tid " << ref;
00146 m_stream << "\tx " << x << "\ty " << y;
00147 m_stream << "\tz " << z;
00148 m_stream << "\tphi " << phi << "\n";
00149 }
00150
00151 void setDictionary(IN const char * path, IN const dictionary_t& data) {
00152 ASSERT(!m_closed, "request is closed");
00153 m_stream << "set " << path;
00154 for (dictionary_t::const_iterator i = data.begin();
00155 i != data.end(); ++i) {
00156 m_stream << " " << i->first << " \"";
00157 m_stream << i->second << "\"";
00158 }
00159 m_stream << "\n";
00160 }
00161
00162 void removeObject(IN const char * path) {
00163 ASSERT(!m_closed, "request is closed");
00164 m_stream << "remove " << path << "\n";
00165 }
00166
00167 std::ostream& getStream(void) {
00168 ASSERT(!m_closed, "request is closed");
00169 return m_stream;
00170 }
00171
00172 private:
00173 std::ostringstream m_stream;
00174 bool m_closed;
00175 };
00176
00177
00178 };
00179
00180
00181 #endif // WAVEPACKET_VGFX_REQUEST_H__
00182