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 379 by douglas, 2004-12-22T20:42:52-08:00 vs.
Revision 384 by douglas, 2004-12-23T01:40:10-08:00

# Line 5 | Line 5
5   // $Id$
6  
7   #include "Hexadecimal.hpp"
8 + #include "DataType.hpp"
9  
9 #include <menes-api/environment.hpp>
10   #include <menes-app/simple.hpp>
11  
12 < struct Environment
13 < {
14 <        ext::String get(const ext::String& name) { try { return api::TheEnvironment.Get(name); } catch (ext::Exception) { return ext::String(); } }
15 < } env;
12 > Environment env;
13  
14   int Main(const app::Options& options)
15   {
# Line 30 | Line 27 | Represent::Represent()
27          xml::TextWriter xhtml(api::Cout);
28          xml::ScopeElement table(xhtml, "table");
29  
30 <        {
31 <                xml::ScopeElement tr(xhtml, "tr");
35 <                ext::String headings[] = { "Type", "Data Representation", "Storage" };
36 <
37 <                _foru (index, 0, sizeof (headings) / sizeof (ext::String))
38 <                {
39 <                        xml::ScopeElement th(xhtml, "th");
30 >        headings(xhtml);
31 >        form(xhtml);
32  
33 <                        xhtml.OutputText(headings[index]);
42 <                }
43 <        }
33 >        //
34   }
35  
36   void Represent::parse()
# Line 66 | Line 56 | void Represent::parse()
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 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines