ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/Represent/Represent.cpp
(Generate patch)

Comparing Represent/Represent.cpp (file contents):
Revision 380 by douglas, 2004-12-23T01:07:33-08:00 vs.
Revision 386 by douglas, 2004-12-23T21:08:56-08:00

# Line 7 | Line 7
7   #include "Hexadecimal.hpp"
8   #include "DataType.hpp"
9  
10 < #include <menes-api/environment.hpp>
11 < #include <menes-app/simple.hpp>
10 > #ifdef _WIN32
11 > #pragma warning(disable:4267)
12 > #endif
13  
14 < struct Environment
14 < {
15 <        ext::String get(const ext::String& name) { try { return api::TheEnvironment.Get(name); } catch (ext::Exception) { return ext::String(); } }
16 < } env;
14 > #include <menes-app/simple.hpp>
15  
16   int Main(const app::Options& options)
17   {
# Line 33 | Line 31 | Represent::Represent()
31  
32          headings(xhtml);
33          form(xhtml);
34 <
37 <        //
34 >        output(xhtml);
35   }
36  
37 + struct Represent::Item
38 + {
39 +        DataType type;
40 +        ext::String data;
41 +        Input input;
42 +        Item(const DataType& type, const ext::String& data, Input input) : type(type), data(data), input(input) {}
43 + };
44 +
45   void Represent::parse()
46   {
47          ext::String query(env.get("QUERY_STRING"));
# Line 111 | Line 116 | void Represent::form(xml::TextWriter& xh
116          {
117                  xml::ScopeElement td(xhtml, "td"), select(xhtml, "select");
118  
119 <                ext::String inputs[] = { "Binary", "Hexadecimal", "std::istream", "ios::PrintReader" };
120 <                unsigned input(cgi.find("input") != cgi.end() ? lexical_cast<unsigned>(cgi.find("input")->second) : 0);
119 >                ext::String inputs[] = { "Normal", "Binary", "Hexadecimal" };
120 >                Input input(cgi.find("input") != cgi.end() ? Input(lexical_cast<unsigned>(cgi.find("input")->second)) : INPUT_Normal);
121  
122 <                _foru (input_, 0, sizeof (inputs) / sizeof (ext::String))
122 >                _foru (input_, INPUT_Normal, INPUT_Hexadecimal + 1)
123                  {
124                          xml::ScopeElement option(xhtml, "option");
125  
126 <                        if (input_ == input) xhtml.SetAttribute("selected", "selected");
126 >                        if (Input(input_) == input) xhtml.SetAttribute("selected", "selected");
127  
128                          xhtml.SetAttribute("value", lexical_cast<ext::String>(input_));
129                          xhtml.OutputText(inputs[input_]);
# Line 130 | Line 135 | void Represent::form(xml::TextWriter& xh
135          xhtml.SetAttribute("type", "submit");
136          xhtml.SetAttribute("value", "Store");
137   }
138 +
139 + void Represent::output(xml::TextWriter& xhtml)
140 + {
141 +        typedef std::multimap<std::string, std::string>::size_type MultiMapSize;
142 +
143 +        std::set<MultiMapSize, std::greater<MultiMapSize> > count;
144 +        ext::String names[] = { "type", "data", "input" };
145 +
146 +        _foru (index, 0, sizeof (names) / sizeof (ext::String)) count.insert(cgi.count(names[index]));
147 +
148 +        typedef std::multimap<std::string, std::string>::const_iterator MultiMapConstIterator;
149 +
150 +        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"));
151 +        ext::Vector<Item> items;
152 +
153 +        _foru (index, 0, *count.begin())
154 +        {
155 +                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);
156 +
157 +                items.InsertLast(item);
158 +
159 +                if (type != type_) ++type;
160 +                if (data != data_) ++data;
161 +                if (input != input_) ++input;
162 +        }
163 +
164 +        _rfor (MultiMapConstIterator, delete_, cgi.lower_bound("delete"), cgi.upper_bound("delete")) items.RemoveAt(lexical_cast<size_t>(delete_->second));
165 +
166 +        _foreach (ext::Vector<Item>, item, items) switch (item->type)
167 +        {
168 +        case DataType::TYPE_bool:
169 +                output<bool>(xhtml, *item);
170 +
171 +                break;
172 +        case DataType::TYPE_char:
173 +                output<char>(xhtml, *item);
174 +
175 +                break;
176 +        }
177 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines