--- Represent/Represent.cpp 2004/12/23 09:40:10 384 +++ Represent/Represent.cpp 2004/12/24 05:01:12 385 @@ -9,8 +9,6 @@ #include -Environment env; - int Main(const app::Options& options) { Represent represent; @@ -29,10 +27,17 @@ Represent::Represent() headings(xhtml); form(xhtml); - - // + output(xhtml); } +struct Represent::Item +{ + DataType type; + ext::String data; + Input input; + Item(const DataType& type, const ext::String& data, Input input) : type(type), data(data), input(input) {} +}; + void Represent::parse() { ext::String query(env.get("QUERY_STRING")); @@ -107,14 +112,14 @@ void Represent::form(xml::TextWriter& xh { xml::ScopeElement td(xhtml, "td"), select(xhtml, "select"); - ext::String inputs[] = { "Binary", "Hexadecimal", "std::istream", "ios::PrintReader" }; - unsigned input(cgi.find("input") != cgi.end() ? lexical_cast(cgi.find("input")->second) : 0); + ext::String inputs[] = { "Normal", "Binary", "Hexadecimal" }; + Input input(cgi.find("input") != cgi.end() ? Input(lexical_cast(cgi.find("input")->second)) : INPUT_Normal); - _foru (input_, 0, sizeof (inputs) / sizeof (ext::String)) + _foru (input_, INPUT_Normal, INPUT_Hexadecimal + 1) { xml::ScopeElement option(xhtml, "option"); - if (input_ == input) xhtml.SetAttribute("selected", "selected"); + if (Input(input_) == input) xhtml.SetAttribute("selected", "selected"); xhtml.SetAttribute("value", lexical_cast(input_)); xhtml.OutputText(inputs[input_]); @@ -126,3 +131,43 @@ void Represent::form(xml::TextWriter& xh xhtml.SetAttribute("type", "submit"); xhtml.SetAttribute("value", "Store"); } + +void Represent::output(xml::TextWriter& xhtml) +{ + typedef std::multimap::size_type MultiMapSize; + + std::set > count; + ext::String names[] = { "type", "data", "input" }; + + _foru (index, 0, sizeof (names) / sizeof (ext::String)) count.insert(cgi.count(names[index])); + + typedef std::multimap::const_iterator MultiMapConstIterator; + + 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")); + ext::Vector items; + + _foru (index, 0, *count.begin()) + { + Item item(type != type_ ? DataType::Type(lexical_cast(type->second)) : DataType::TYPE_bool, data != data_ ? data->second : std::string(), input != input_ ? Input(lexical_cast(input->second)) : INPUT_Normal); + + items.InsertLast(item); + + if (type != type_) ++type; + if (data != data_) ++data; + if (input != input_) ++input; + } + + _rfor (MultiMapConstIterator, delete_, cgi.lower_bound("delete"), cgi.upper_bound("delete")) items.RemoveAt(lexical_cast(delete_->second)); + + _foreach (ext::Vector, item, items) switch (item->type) + { + case DataType::TYPE_bool: + output(xhtml, *item); + + break; + case DataType::TYPE_char: + output(xhtml, *item); + + break; + } +}