9 |
|
|
10 |
|
#include <menes-app/simple.hpp> |
11 |
|
|
12 |
– |
Environment env; |
13 |
– |
|
12 |
|
int Main(const app::Options& options) |
13 |
|
{ |
14 |
|
Represent represent; |
27 |
|
|
28 |
|
headings(xhtml); |
29 |
|
form(xhtml); |
30 |
< |
|
33 |
< |
// |
30 |
> |
output(xhtml); |
31 |
|
} |
32 |
|
|
33 |
+ |
struct Represent::Item |
34 |
+ |
{ |
35 |
+ |
DataType type; |
36 |
+ |
ext::String data; |
37 |
+ |
Input input; |
38 |
+ |
Item(const DataType& type, const ext::String& data, Input input) : type(type), data(data), input(input) {} |
39 |
+ |
}; |
40 |
+ |
|
41 |
|
void Represent::parse() |
42 |
|
{ |
43 |
|
ext::String query(env.get("QUERY_STRING")); |
112 |
|
{ |
113 |
|
xml::ScopeElement td(xhtml, "td"), select(xhtml, "select"); |
114 |
|
|
115 |
< |
ext::String inputs[] = { "Binary", "Hexadecimal", "std::istream", "ios::PrintReader" }; |
116 |
< |
unsigned input(cgi.find("input") != cgi.end() ? lexical_cast<unsigned>(cgi.find("input")->second) : 0); |
115 |
> |
ext::String inputs[] = { "Normal", "Binary", "Hexadecimal" }; |
116 |
> |
Input input(cgi.find("input") != cgi.end() ? Input(lexical_cast<unsigned>(cgi.find("input")->second)) : INPUT_Normal); |
117 |
|
|
118 |
< |
_foru (input_, 0, sizeof (inputs) / sizeof (ext::String)) |
118 |
> |
_foru (input_, INPUT_Normal, INPUT_Hexadecimal + 1) |
119 |
|
{ |
120 |
|
xml::ScopeElement option(xhtml, "option"); |
121 |
|
|
122 |
< |
if (input_ == input) xhtml.SetAttribute("selected", "selected"); |
122 |
> |
if (Input(input_) == input) xhtml.SetAttribute("selected", "selected"); |
123 |
|
|
124 |
|
xhtml.SetAttribute("value", lexical_cast<ext::String>(input_)); |
125 |
|
xhtml.OutputText(inputs[input_]); |
131 |
|
xhtml.SetAttribute("type", "submit"); |
132 |
|
xhtml.SetAttribute("value", "Store"); |
133 |
|
} |
134 |
+ |
|
135 |
+ |
void Represent::output(xml::TextWriter& xhtml) |
136 |
+ |
{ |
137 |
+ |
typedef std::multimap<std::string, std::string>::size_type MultiMapSize; |
138 |
+ |
|
139 |
+ |
std::set<MultiMapSize, std::greater<MultiMapSize> > count; |
140 |
+ |
ext::String names[] = { "type", "data", "input" }; |
141 |
+ |
|
142 |
+ |
_foru (index, 0, sizeof (names) / sizeof (ext::String)) count.insert(cgi.count(names[index])); |
143 |
+ |
|
144 |
+ |
typedef std::multimap<std::string, std::string>::const_iterator MultiMapConstIterator; |
145 |
+ |
|
146 |
+ |
MultiMapConstIterator type(cgi.lower_bound("type")), type_(cgi.upper_bound("type")), data(cgi.lower_bound("data")), data_(cgi.upper_bound("data")), input(cgi.lower_bound("input")), input_(cgi.upper_bound("input")); |
147 |
+ |
ext::Vector<Item> items; |
148 |
+ |
|
149 |
+ |
_foru (index, 0, *count.begin()) |
150 |
+ |
{ |
151 |
+ |
Item item(type != type_ ? DataType::Type(lexical_cast<unsigned>(type->second)) : DataType::TYPE_bool, data != data_ ? data->second : std::string(), input != input_ ? Input(lexical_cast<unsigned>(input->second)) : INPUT_Normal); |
152 |
+ |
|
153 |
+ |
items.InsertLast(item); |
154 |
+ |
|
155 |
+ |
if (type != type_) ++type; |
156 |
+ |
if (data != data_) ++data; |
157 |
+ |
if (input != input_) ++input; |
158 |
+ |
} |
159 |
+ |
|
160 |
+ |
_rfor (MultiMapConstIterator, delete_, cgi.lower_bound("delete"), cgi.upper_bound("delete")) items.RemoveAt(lexical_cast<size_t>(delete_->second)); |
161 |
+ |
|
162 |
+ |
_foreach (ext::Vector<Item>, item, items) switch (item->type) |
163 |
+ |
{ |
164 |
+ |
case DataType::TYPE_bool: |
165 |
+ |
output<bool>(xhtml, *item); |
166 |
+ |
|
167 |
+ |
break; |
168 |
+ |
case DataType::TYPE_char: |
169 |
+ |
output<char>(xhtml, *item); |
170 |
+ |
|
171 |
+ |
break; |
172 |
+ |
} |
173 |
+ |
} |