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 362 by douglas, 2004-12-21T01:12:18-08:00 vs.
Revision 380 by douglas, 2004-12-23T01:07:33-08:00

# Line 4 | Line 4
4   //
5   // $Id$
6  
7 < #include <iostream>
8 < #include <string>
9 < #include <vector>
7 > #include "Hexadecimal.hpp"
8 > #include "DataType.hpp"
9  
10 < #include <foreach.hpp>
10 > #include <menes-api/environment.hpp>
11 > #include <menes-app/simple.hpp>
12  
13 < /*template <typename Type>
14 < std::string binary(const Type& type)
13 > struct Environment
14   {
15 <        std::ostringstream string;
15 >        ext::String get(const ext::String& name) { try { return api::TheEnvironment.Get(name); } catch (ext::Exception) { return ext::String(); } }
16 > } env;
17  
18 <        _rforu (index, 0, 8 * sizeof (type))
19 <        {
20 <                bool bit(1 & type >> index);
21 <
22 <                string << bit;
23 <        }
24 <
25 <        return string.str();
26 < }*/
27 <
28 < class Binary
18 > int Main(const app::Options& options)
19   {
20 < private:
31 <        std::vector<char> bytes;
32 < public:
33 <        Binary(const std::string& string);
34 <        template <typename Type>
35 <        Binary(const Type& type);
36 <        operator std::string() const;
37 < };
20 >        Represent represent;
21  
22 < Binary::Binary(const std::string& string)
40 < {
41 <        throw;
22 >        return 0;
23   }
24  
25 < template <typename Type>
45 < Binary::Binary(const Type& type) : bytes(sizeof (type))
25 > Represent::Represent()
26   {
27 <        char* type_(reinterpret_cast<char*>(const_cast<Type*>(&type)));
27 >        parse();
28 >
29 >        api::Cout << "Content-Type: text/html; charset=UTF-8\r\n\r\n" << ios::Flush;
30 >
31 >        xml::TextWriter xhtml(api::Cout);
32 >        xml::ScopeElement table(xhtml, "table");
33  
34 <        _mforeach (std::vector<char>, byte, bytes) *byte = *type_++;
34 >        headings(xhtml);
35 >        form(xhtml);
36 >
37 >        //
38   }
39  
40 < Binary::operator std::string() const
40 > void Represent::parse()
41   {
42 <        std::string string;
42 >        ext::String query(env.get("QUERY_STRING"));
43  
44 <        _rforeach (std::vector<char>, byte, bytes)
44 >        if (env.get("REQUEST_METHOD") == "POST")
45          {
46 <                _rfor (char, bit, 0, 8)
47 <                {
48 <                        string += 1 & *byte >> bit ? '1' : '0';
49 <                }
46 >                ext::Buffer content(lexical_cast<size_t>(env.get("CONTENT_LENGTH")));
47 >
48 >                api::Cin.ReadFully(content.Begin(), content.GetSize());
49 >
50 >                query = content;
51          }
52  
53 <        return string;
65 < }
53 >        ext::Vector<ext::String> pairs(query.Split('&'));
54  
55 < std::ostream& operator<<(std::ostream& out, const Binary& binary)
56 < {
57 <        return out << std::string(binary);
55 >        _foreach (ext::Vector<ext::String>, pair, pairs)
56 >        {
57 >                ext::String::ConstIterator equal(pair->FindFirst('='));
58 >                ext::String name(pair->Begin(), equal), value(equal != pair->End() ? equal + 1 : equal, pair->End());
59 >
60 >                cgi.insert(std::pair<std::string, std::string>(name, value));
61 >        }
62   }
63  
64 < int main(int argc, char* argv[])
64 > void Represent::headings(xml::TextWriter& xhtml)
65   {
66 <        std::string hello("Hello, World!");
66 >        xml::ScopeElement tr(xhtml, "tr");
67 >        ext::String headings[] = { "Data Type", "Data Representation", "Input", "Storage" };
68  
69 <        _foreach (std::string, atom, hello)
69 >        _foru (index, 0, sizeof (headings) / sizeof (ext::String))
70          {
71 <                std::cout << Binary(*atom) << " = " << *atom << std::endl;
79 <        }
71 >                xml::ScopeElement th(xhtml, "th");
72  
73 <        _fori (index, -10, 11)
82 <        {
83 <                std::cout << Binary(index) << " = " << index << std::endl;
73 >                xhtml.OutputText(headings[index]);
74          }
75 + }
76 +
77 + void Represent::form(xml::TextWriter& xhtml)
78 + {
79 +        xml::ScopeElement tr(xhtml, "tr");
80  
86        _foru (index, -10, 11)
81          {
82 <                std::cout << Binary(index) << " = " << index << std::endl;
82 >                xml::ScopeElement td(xhtml, "td"), select(xhtml, "select");
83 >
84 >                xhtml.SetAttribute("name", "type");
85 >
86 >                DataType type(cgi.find("type") != cgi.end() ? DataType::Type(lexical_cast<unsigned>(cgi.find("type")->second)) : DataType::TYPE_bool);
87 >
88 >                _foreach (ext::Vector<DataType>, type_, DataType::enumerate())
89 >                {
90 >                        xml::ScopeElement option(xhtml, "option");
91 >
92 >                        if (*type_ == type) xhtml.SetAttribute("selected", "selected");
93 >
94 >                        xhtml.SetAttribute("value", lexical_cast<ext::String>(DataType::Type(*type_)));
95 >                        xhtml.OutputText(*type_);
96 >                }
97          }
98  
91        for (float index(-1.0); index < 1.0; index += 0.1)
99          {
100 <                std::cout << Binary(index) << " = " << index << std::endl;
100 >                xml::ScopeElement td(xhtml, "td"), input(xhtml, "input");
101 >
102 >                xhtml.SetAttribute("name", "data");
103 >                xhtml.SetAttribute("size", "64");
104 >                xhtml.SetAttribute("type", "text");
105 >
106 >                ext::String data(cgi.find("data") != cgi.end() ? cgi.find("data")->second : std::string());
107 >
108 >                xhtml.SetAttribute("value", data);
109          }
110  
96        for (double index(-1.0); index < 1.0; index += 0.1)
111          {
112 <                std::cout << Binary(index) << " = " << index << std::endl;
112 >                xml::ScopeElement td(xhtml, "td"), select(xhtml, "select");
113 >
114 >                ext::String inputs[] = { "Binary", "Hexadecimal", "std::istream", "ios::PrintReader" };
115 >                unsigned input(cgi.find("input") != cgi.end() ? lexical_cast<unsigned>(cgi.find("input")->second) : 0);
116 >
117 >                _foru (input_, 0, sizeof (inputs) / sizeof (ext::String))
118 >                {
119 >                        xml::ScopeElement option(xhtml, "option");
120 >
121 >                        if (input_ == input) xhtml.SetAttribute("selected", "selected");
122 >
123 >                        xhtml.SetAttribute("value", lexical_cast<ext::String>(input_));
124 >                        xhtml.OutputText(inputs[input_]);
125 >                }
126          }
127  
128 <        return 0;
128 >        xml::ScopeElement td(xhtml, "td"), input(xhtml, "input");
129 >
130 >        xhtml.SetAttribute("type", "submit");
131 >        xhtml.SetAttribute("value", "Store");
132   }

Comparing Represent/represent.cpp (property svn:eol-style):
Revision 362 by douglas, 2004-12-21T01:12:18-08:00 vs.
Revision 380 by douglas, 2004-12-23T01:07:33-08:00

# Line 0 | Line 1
1 + native

Comparing Represent/represent.cpp (property svn:keywords):
Revision 362 by douglas, 2004-12-21T01:12:18-08:00 vs.
Revision 380 by douglas, 2004-12-23T01:07:33-08:00

# Line 0 | Line 1
1 + Id

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines