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

# User Rev Content
1 douglas 362 // Represent
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7 douglas 371 #include "Hexadecimal.hpp"
8 douglas 380 #include "DataType.hpp"
9 douglas 362
10 douglas 370 #include <menes-app/simple.hpp>
11 douglas 362
12 douglas 384 Environment env;
13 douglas 379
14 douglas 370 int Main(const app::Options& options)
15 douglas 362 {
16 douglas 370 Represent represent;
17 douglas 362
18 douglas 370 return 0;
19 douglas 362 }
20    
21 douglas 370 Represent::Represent()
22 douglas 362 {
23 douglas 379 parse();
24 douglas 371
25 douglas 379 api::Cout << "Content-Type: text/html; charset=UTF-8\r\n\r\n" << ios::Flush;
26 douglas 371
27 douglas 379 xml::TextWriter xhtml(api::Cout);
28     xml::ScopeElement table(xhtml, "table");
29 douglas 371
30 douglas 380 headings(xhtml);
31     form(xhtml);
32 douglas 371
33 douglas 380 //
34 douglas 379 }
35 douglas 373
36 douglas 379 void Represent::parse()
37     {
38     ext::String query(env.get("QUERY_STRING"));
39 douglas 373
40 douglas 379 if (env.get("REQUEST_METHOD") == "POST")
41     {
42     ext::Buffer content(lexical_cast<size_t>(env.get("CONTENT_LENGTH")));
43 douglas 373
44 douglas 379 api::Cin.ReadFully(content.Begin(), content.GetSize());
45 douglas 373
46 douglas 379 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 douglas 362 }
59 douglas 380
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