--- Represent/represent.cpp 2004/12/21 09:15:40 363 +++ Represent/Represent.cpp 2004/12/23 04:42:52 379 @@ -4,84 +4,65 @@ // // $Id$ -#include -#include -#include +#include "Hexadecimal.hpp" -#include +#include +#include -class Binary +struct Environment { -private: - std::vector bytes; -public: - Binary(const std::string& string); - template - Binary(const Type& type); - operator std::string() const; -}; + ext::String get(const ext::String& name) { try { return api::TheEnvironment.Get(name); } catch (ext::Exception) { return ext::String(); } } +} env; -Binary::Binary(const std::string& string) +int Main(const app::Options& options) { - throw; + Represent represent; + + return 0; } -template -Binary::Binary(const Type& type) : bytes(sizeof (type)) +Represent::Represent() { - char* type_(reinterpret_cast(const_cast(&type))); + parse(); - _mforeach (std::vector, byte, bytes) *byte = *type_++; -} + api::Cout << "Content-Type: text/html; charset=UTF-8\r\n\r\n" << ios::Flush; -Binary::operator std::string() const -{ - std::string string; + xml::TextWriter xhtml(api::Cout); + xml::ScopeElement table(xhtml, "table"); - _rforeach (std::vector, byte, bytes) { - _rfor (char, bit, 0, 8) + xml::ScopeElement tr(xhtml, "tr"); + ext::String headings[] = { "Type", "Data Representation", "Storage" }; + + _foru (index, 0, sizeof (headings) / sizeof (ext::String)) { - string += 1 & *byte >> bit ? '1' : '0'; + xml::ScopeElement th(xhtml, "th"); + + xhtml.OutputText(headings[index]); } } - - return string; -} - -std::ostream& operator<<(std::ostream& out, const Binary& binary) -{ - return out << std::string(binary); } -int main(int argc, char* argv[]) +void Represent::parse() { - std::string hello("Hello, World!"); + ext::String query(env.get("QUERY_STRING")); - _foreach (std::string, atom, hello) + if (env.get("REQUEST_METHOD") == "POST") { - std::cout << Binary(*atom) << " = " << *atom << std::endl; - } + ext::Buffer content(lexical_cast(env.get("CONTENT_LENGTH"))); - _fori (index, -10, 11) - { - std::cout << Binary(index) << " = " << index << std::endl; - } + api::Cin.ReadFully(content.Begin(), content.GetSize()); - _foru (index, 4294967286, 11) - { - std::cout << Binary(index) << " = " << index << std::endl; + query = content; } - for (float index(-1.0); index < 1.0; index += 0.1) - { - std::cout << Binary(index) << " = " << index << std::endl; - } + ext::Vector pairs(query.Split('&')); - for (double index(-1.0); index < 1.0; index += 0.1) + _foreach (ext::Vector, pair, pairs) { - std::cout << Binary(index) << " = " << index << std::endl; - } + ext::String::ConstIterator equal(pair->FindFirst('=')); + ext::String name(pair->Begin(), equal), value(equal != pair->End() ? equal + 1 : equal, pair->End()); - return 0; + cgi.insert(std::pair(name, value)); + } }