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 373 by douglas, 2004-12-22T17:27:28-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-app/simple.hpp>
10  
11 < /*template <typename Type>
14 < std::string binary(const Type& type)
11 > int Main(const app::Options& options)
12   {
13 <        std::ostringstream string;
13 >        Represent represent;
14  
15 <        _rforu (index, 0, 8 * sizeof (type))
16 <        {
20 <                bool bit(1 & type >> index);
21 <
22 <                string << bit;
23 <        }
24 <
25 <        return string.str();
26 < }*/
15 >        return 0;
16 > }
17  
18 < class Binary
18 > Represent::Represent()
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 >        api::Cerr << Binary("Hello, World!") << " = " << Hexadecimal("Hello, World") << " = Hello, World!" << ios::NewLine;
21  
22 < Binary::Binary(const std::string& string)
40 < {
41 <        throw;
42 < }
22 >        std::string hello("Hello, World!");
23  
24 < template <typename Type>
45 < Binary::Binary(const Type& type) : bytes(sizeof (type))
46 < {
47 <        char* type_(reinterpret_cast<char*>(const_cast<Type*>(&type)));
24 >        api::Cerr << Binary(hello) << " = " << Hexadecimal(hello) << " = " << ext::String(hello) << ios::NewLine;
25  
26 <        _mforeach (std::vector<char>, byte, bytes) *byte = *type_++;
50 < }
26 >        _sforeach (std::string, atom, hello) api::Cerr << Binary(*atom) << " = " << Hexadecimal(*atom) << " = " << ext::String(atom, 1) << ios::NewLine;
27  
28 < Binary::operator std::string() const
53 < {
54 <        std::string string;
28 >        ext::String hello_(hello);
29  
30 <        _rforeach (std::vector<char>, byte, bytes)
57 <        {
58 <                _rfor (char, bit, 0, 8)
59 <                {
60 <                        string += 1 & *byte >> bit ? '1' : '0';
61 <                }
62 <        }
30 >        api::Cerr << Binary(hello_) << " = " << Hexadecimal(hello_) << " = " << hello_ << ios::NewLine;
31  
32 <        return string;
65 < }
32 >        _foreach (ext::String, atom, hello_) api::Cerr << Binary(*atom) << " = " << Hexadecimal(*atom) << " = " << ext::String(*atom) << ios::NewLine;
33  
34 < std::ostream& operator<<(std::ostream& out, const Binary& binary)
68 < {
69 <        return out << std::string(binary);
70 < }
34 >        _fori (index, -10, 11) api::Cerr << Binary(index) << " = " << Hexadecimal(index) << " = " << index << ios::NewLine;
35  
36 < int main(int argc, char* argv[])
73 < {
74 <        std::string hello("Hello, World!");
36 >        _foru (index, 0xFFFFFFF6, 11) api::Cerr << Binary(index) << " = " << Hexadecimal(index) << " = " << index << ios::NewLine;
37  
38 <        _foreach (std::string, atom, hello)
77 <        {
78 <                std::cout << Binary(*atom) << " = " << *atom << std::endl;
79 <        }
80 <
81 <        _fori (index, -10, 11)
82 <        {
83 <                std::cout << Binary(index) << " = " << index << std::endl;
84 <        }
85 <
86 <        _foru (index, -10, 11)
87 <        {
88 <                std::cout << Binary(index) << " = " << index << std::endl;
89 <        }
90 <
91 <        for (float index(-1.0); index < 1.0; index += 0.1)
92 <        {
93 <                std::cout << Binary(index) << " = " << index << std::endl;
94 <        }
95 <
96 <        for (double index(-1.0); index < 1.0; index += 0.1)
97 <        {
98 <                std::cout << Binary(index) << " = " << index << std::endl;
99 <        }
38 >        for (float index(-1); index < 1.1; index += 0.1) api::Cerr << Binary(index) << " = " << Hexadecimal(index) << " = " << index << ios::NewLine;
39  
40 <        return 0;
40 >        for (double index(-1); index < 1.1; index += 0.1) api::Cerr << Binary(index) << " = " << Hexadecimal(index) << " = " << index << ios::NewLine;
41   }

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

# Line 0 | Line 1
1 + Id

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines