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 379 by douglas, 2004-12-22T20:42:52-08:00

# Line 4 | Line 4
4   //
5   // $Id$
6  
7 < #include <iostream>
8 < #include <string>
9 < #include <vector>
7 > #include "Hexadecimal.hpp"
8  
9 < #include <foreach.hpp>
9 > #include <menes-api/environment.hpp>
10 > #include <menes-app/simple.hpp>
11  
12 < /*template <typename Type>
14 < std::string binary(const Type& type)
12 > struct Environment
13   {
14 <        std::ostringstream string;
14 >        ext::String get(const ext::String& name) { try { return api::TheEnvironment.Get(name); } catch (ext::Exception) { return ext::String(); } }
15 > } env;
16  
17 <        _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
17 > int Main(const app::Options& options)
18   {
19 < 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 < };
19 >        Represent represent;
20  
21 < Binary::Binary(const std::string& string)
40 < {
41 <        throw;
21 >        return 0;
22   }
23  
24 < template <typename Type>
45 < Binary::Binary(const Type& type) : bytes(sizeof (type))
24 > Represent::Represent()
25   {
26 <        char* type_(reinterpret_cast<char*>(const_cast<Type*>(&type)));
26 >        parse();
27  
28 <        _mforeach (std::vector<char>, byte, bytes) *byte = *type_++;
50 < }
28 >        api::Cout << "Content-Type: text/html; charset=UTF-8\r\n\r\n" << ios::Flush;
29  
30 < Binary::operator std::string() const
31 < {
54 <        std::string string;
30 >        xml::TextWriter xhtml(api::Cout);
31 >        xml::ScopeElement table(xhtml, "table");
32  
56        _rforeach (std::vector<char>, byte, bytes)
33          {
34 <                _rfor (char, bit, 0, 8)
34 >                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 <                        string += 1 & *byte >> bit ? '1' : '0';
39 >                        xml::ScopeElement th(xhtml, "th");
40 >
41 >                        xhtml.OutputText(headings[index]);
42                  }
43          }
63
64        return string;
44   }
45  
46 < std::ostream& operator<<(std::ostream& out, const Binary& binary)
46 > void Represent::parse()
47   {
48 <        return out << std::string(binary);
70 < }
71 <
72 < int main(int argc, char* argv[])
73 < {
74 <        std::string hello("Hello, World!");
48 >        ext::String query(env.get("QUERY_STRING"));
49  
50 <        _foreach (std::string, atom, hello)
50 >        if (env.get("REQUEST_METHOD") == "POST")
51          {
52 <                std::cout << Binary(*atom) << " = " << *atom << std::endl;
79 <        }
52 >                ext::Buffer content(lexical_cast<size_t>(env.get("CONTENT_LENGTH")));
53  
54 <        _fori (index, -10, 11)
82 <        {
83 <                std::cout << Binary(index) << " = " << index << std::endl;
84 <        }
54 >                api::Cin.ReadFully(content.Begin(), content.GetSize());
55  
56 <        _foru (index, -10, 11)
87 <        {
88 <                std::cout << Binary(index) << " = " << index << std::endl;
56 >                query = content;
57          }
58  
59 <        for (float index(-1.0); index < 1.0; index += 0.1)
92 <        {
93 <                std::cout << Binary(index) << " = " << index << std::endl;
94 <        }
59 >        ext::Vector<ext::String> pairs(query.Split('&'));
60  
61 <        for (double index(-1.0); index < 1.0; index += 0.1)
61 >        _foreach (ext::Vector<ext::String>, pair, pairs)
62          {
63 <                std::cout << Binary(index) << " = " << index << std::endl;
64 <        }
63 >                ext::String::ConstIterator equal(pair->FindFirst('='));
64 >                ext::String name(pair->Begin(), equal), value(equal != pair->End() ? equal + 1 : equal, pair->End());
65  
66 <        return 0;
66 >                cgi.insert(std::pair<std::string, std::string>(name, value));
67 >        }
68   }

Comparing Represent/represent.cpp (property svn:eol-style):
Revision 362 by douglas, 2004-12-21T01:12:18-08:00 vs.
Revision 379 by douglas, 2004-12-22T20:42:52-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 379 by douglas, 2004-12-22T20:42:52-08:00

# Line 0 | Line 1
1 + Id

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines