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 365 by douglas, 2004-12-21T03:21:00-08:00 vs.
Revision 369 by douglas, 2004-12-21T03:32:17-08:00

# Line 25 | Line 25 | public:
25  
26   Binary::Binary(std::string& string, bool signed_) : bytes(string.size() / 8, 0)
27   {
28 +        if (string.find_first_not_of("01") != std::string::npos) throw;
29 +
30          std::string::size_type off(string.size() % 8);
31  
32          if (off != 0)
33          {
34 <                bytes.push_back(0);
34 >                bytes.push_back(0);
35                  string.insert(0, 8 - off, signed_ && string[0] == '1' ? '1' : '0');
36          }
37  
38          std::string::size_type index(0);
39  
40 <        _rmforeach (std::vector<char>, byte, bytes)
39 <        {
40 <                _rfor (char, bit, 0, 8)
41 <                {
42 <                        *byte |= (string[index++] == '1') << bit;
43 <                }
44 <        }
40 >        _rmforeach (std::vector<char>, byte, bytes) _rfor (char, bit, 0, 8) *byte |= (string[index++] == '1') << bit;
41   }
42  
43   template <typename Type>
# Line 84 | Line 80 | int main(int argc, char* argv[])
80   {
81          std::string hello("Hello, World!");
82  
83 <        _foreach (std::string, atom, hello)
88 <        {
89 <                std::cout << Binary(*atom) << " = " << *atom << std::endl;
90 <        }
83 >        _foreach (std::string, atom, hello) std::cout << Binary(*atom) << " = " << *atom << std::endl;
84  
85 <        _fori (index, -10, 11)
93 <        {
94 <                std::cout << Binary(index) << " = " << index << std::endl;
95 <        }
85 >        _fori (index, -10, 11) std::cout << Binary(index) << " = " << index << std::endl;
86  
87 <        _foru (index, -10, 11)
98 <        {
99 <                std::cout << Binary(index) << " = " << index << std::endl;
100 <        }
87 >        _foru (index, -10, 11) std::cout << Binary(index) << " = " << index << std::endl;
88  
89 <        for (float index(-1.0); index < 1.0; index += 0.1)
103 <        {
104 <                std::cout << Binary(index) << " = " << index << std::endl;
105 <        }
89 >        for (float index(-1.0); index < 1.0; index += 0.1) std::cout << Binary(index) << " = " << index << std::endl;
90  
91 <        for (double index(-1.0); index < 1.0; index += 0.1)
108 <        {
109 <                std::cout << Binary(index) << " = " << index << std::endl;
110 <        }
91 >        for (double index(-1.0); index < 1.0; index += 0.1) std::cout << Binary(index) << " = " << index << std::endl;
92  
93          std::string string("101001101001");
94          Binary binary(string, true);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines