Last change
on this file since 79 was
75,
checked in by rosiere, 17 years ago
|
Update all component (except front_end) to :
- new statistics model
- no namespace std
|
File size:
1.1 KB
|
Line | |
---|
1 | #ifndef morpheo_ToBase2 |
---|
2 | #define morpheo_ToBase2 |
---|
3 | |
---|
4 | /* |
---|
5 | * $Id$ |
---|
6 | * |
---|
7 | * [ Description ] |
---|
8 | * |
---|
9 | */ |
---|
10 | |
---|
11 | #include <sstream> |
---|
12 | |
---|
13 | namespace morpheo { |
---|
14 | |
---|
15 | template<typename T> inline std::string toBase2 (const T& value, const uint32_t & size) |
---|
16 | { |
---|
17 | std::ostringstream res; |
---|
18 | T mask = 1<<(size-1); |
---|
19 | |
---|
20 | while (mask != 0) |
---|
21 | { |
---|
22 | res << ((value&mask)?'1':'0'); |
---|
23 | mask >>= 1; |
---|
24 | } |
---|
25 | |
---|
26 | return res.str(); |
---|
27 | } |
---|
28 | |
---|
29 | inline std::string toBase2 (const bool & value) |
---|
30 | { |
---|
31 | return toBase2<bool > (value, 1); |
---|
32 | } |
---|
33 | |
---|
34 | inline std::string toBase2 (const uint8_t & value, const uint32_t & size) |
---|
35 | { |
---|
36 | return toBase2<uint8_t> (value, size); |
---|
37 | } |
---|
38 | |
---|
39 | inline std::string toBase2 (const uint16_t& value, const uint32_t & size) |
---|
40 | { |
---|
41 | return toBase2<uint16_t> (value, size); |
---|
42 | } |
---|
43 | |
---|
44 | inline std::string toBase2 (const uint32_t& value, const uint32_t & size) |
---|
45 | { |
---|
46 | return toBase2<uint32_t> (value, size); |
---|
47 | } |
---|
48 | |
---|
49 | inline std::string toBase2 (const uint64_t& value, const uint32_t & size) |
---|
50 | { |
---|
51 | return toBase2<uint64_t> (value, size); |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | }; // end namespace morpheo |
---|
56 | |
---|
57 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.