ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/Represent/Represent.cpp
Revision: 384
Committed: 2004-12-23T01:40:10-08:00 (20 years, 6 months ago) by douglas
File size: 3026 byte(s)
Log Message:
Underscore.

File Contents

# Content
1 // Represent
2 //
3 // Douglas Thrift
4 //
5 // $Id$
6
7 #include "Hexadecimal.hpp"
8 #include "DataType.hpp"
9
10 #include <menes-app/simple.hpp>
11
12 Environment env;
13
14 int Main(const app::Options& options)
15 {
16 Represent represent;
17
18 return 0;
19 }
20
21 Represent::Represent()
22 {
23 parse();
24
25 api::Cout << "Content-Type: text/html; charset=UTF-8\r\n\r\n" << ios::Flush;
26
27 xml::TextWriter xhtml(api::Cout);
28 xml::ScopeElement table(xhtml, "table");
29
30 headings(xhtml);
31 form(xhtml);
32
33 //
34 }
35
36 void Represent::parse()
37 {
38 ext::String query(env.get("QUERY_STRING"));
39
40 if (env.get("REQUEST_METHOD") == "POST")
41 {
42 ext::Buffer content(lexical_cast<size_t>(env.get("CONTENT_LENGTH")));
43
44 api::Cin.ReadFully(content.Begin(), content.GetSize());
45
46 query = content;
47 }
48
49 ext::Vector<ext::String> pairs(query.Split('&'));
50
51 _foreach (ext::Vector<ext::String>, pair, pairs)
52 {
53 ext::String::ConstIterator equal(pair->FindFirst('='));
54 ext::String name(pair->Begin(), equal), value(equal != pair->End() ? equal + 1 : equal, pair->End());
55
56 cgi.insert(std::pair<std::string, std::string>(name, value));
57 }
58 }
59
60 void Represent::headings(xml::TextWriter& xhtml)
61 {
62 xml::ScopeElement tr(xhtml, "tr");
63 ext::String headings[] = { "Data Type", "Data Representation", "Input", "Storage" };
64
65 _foru (index, 0, sizeof (headings) / sizeof (ext::String))
66 {
67 xml::ScopeElement th(xhtml, "th");
68
69 xhtml.OutputText(headings[index]);
70 }
71 }
72
73 void Represent::form(xml::TextWriter& xhtml)
74 {
75 xml::ScopeElement tr(xhtml, "tr");
76
77 {
78 xml::ScopeElement td(xhtml, "td"), select(xhtml, "select");
79
80 xhtml.SetAttribute("name", "type");
81
82 DataType type(cgi.find("type") != cgi.end() ? DataType::Type(lexical_cast<unsigned>(cgi.find("type")->second)) : DataType::TYPE_bool);
83
84 _foreach (ext::Vector<DataType>, type_, DataType::enumerate())
85 {
86 xml::ScopeElement option(xhtml, "option");
87
88 if (*type_ == type) xhtml.SetAttribute("selected", "selected");
89
90 xhtml.SetAttribute("value", lexical_cast<ext::String>(DataType::Type(*type_)));
91 xhtml.OutputText(*type_);
92 }
93 }
94
95 {
96 xml::ScopeElement td(xhtml, "td"), input(xhtml, "input");
97
98 xhtml.SetAttribute("name", "data");
99 xhtml.SetAttribute("size", "64");
100 xhtml.SetAttribute("type", "text");
101
102 ext::String data(cgi.find("data") != cgi.end() ? cgi.find("data")->second : std::string());
103
104 xhtml.SetAttribute("value", data);
105 }
106
107 {
108 xml::ScopeElement td(xhtml, "td"), select(xhtml, "select");
109
110 ext::String inputs[] = { "Binary", "Hexadecimal", "std::istream", "ios::PrintReader" };
111 unsigned input(cgi.find("input") != cgi.end() ? lexical_cast<unsigned>(cgi.find("input")->second) : 0);
112
113 _foru (input_, 0, sizeof (inputs) / sizeof (ext::String))
114 {
115 xml::ScopeElement option(xhtml, "option");
116
117 if (input_ == input) xhtml.SetAttribute("selected", "selected");
118
119 xhtml.SetAttribute("value", lexical_cast<ext::String>(input_));
120 xhtml.OutputText(inputs[input_]);
121 }
122 }
123
124 xml::ScopeElement td(xhtml, "td"), input(xhtml, "input");
125
126 xhtml.SetAttribute("type", "submit");
127 xhtml.SetAttribute("value", "Store");
128 }

Properties

Name Value
svn:eol-style native
svn:keywords Id