Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:15

0001 #include <csignal>
0002 #include "OPTICKS_LOG.hh"
0003 #include "SBit.hh"
0004 
0005 void test_FromString_0()
0006 {
0007     unsigned long long ull_0 = SBit::FromString("0b11111111") ; 
0008     LOG(info) << " ull_0 " << ull_0 ; 
0009 
0010     bool ull_0_expect = ull_0 == 255 ;
0011     assert( ull_0_expect ); 
0012     if(!ull_0_expect) std::raise(SIGINT); 
0013 
0014     unsigned long long ull_1 = SBit::FromString("0xff") ; 
0015     bool ull_1_expect = ull_1 == 255 ;
0016     assert( ull_1_expect ); 
0017     if(!ull_1_expect) std::raise(SIGINT); 
0018 
0019     unsigned long long ull_2 = SBit::FromString("255") ; 
0020     bool ull_2_expect = ull_2 == 255 ;
0021     assert( ull_2_expect ); 
0022     if(!ull_2_expect) std::raise(SIGINT); 
0023 
0024     unsigned long long ull_3 = SBit::FromString("0,1,2,3,4,5,6,7") ; 
0025     LOG(info) << " ull_3 " << ull_3 ; 
0026     bool ull_3_expect = ull_3 == 255 ;
0027     assert( ull_3_expect ); 
0028     if(!ull_3_expect) std::raise(SIGINT); 
0029 
0030 
0031 
0032 }
0033 
0034 
0035 
0036 const char* EXAMPLES  = R"LITERAL(
0037 
0038 0p
0039 ,
0040 0
0041 0d0
0042 0x0
0043 0x000000000
0044 0b0
0045 0b00000000
0046 
0047 0,
0048 0p0
0049 1
0050 0x1
0051 0b1
0052 0b000000001
0053 
0054 1,
0055 0p1
0056 2
0057 0x2
0058 0b10
0059 0b0010
0060 
0061 0,1
0062 0p0,1
0063 3
0064 0d3
0065 0x3
0066 0b11
0067 0b0000011
0068 
0069 2,
0070 0p2
0071 4
0072 0d4
0073 0x4
0074 0b100
0075 0b0000100
0076 
0077 
0078 0,2
0079 0p0,2
0080 5
0081 0d5
0082 0x5
0083 0b101
0084 0b00000101
0085 
0086 
0087 # Complemented zero : ie all 64 bits set  
0088 
0089 ~0
0090 
0091 
0092 # PosString setting only the comma delimited bitpos ranging from 0 to 15
0093 
0094 0,
0095 1,
0096 2,
0097 3,
0098 4,
0099 5,
0100 6,
0101 7,
0102 8,
0103 9,
0104 10,
0105 11,
0106 12,
0107 13,
0108 14,
0109 15,
0110 
0111 # PosString all bits set other than the comma delimited bitpos ranging from 0 to 15
0112 
0113 ~0,
0114 ~1,
0115 ~2,
0116 ~3,
0117 ~4,
0118 ~5,
0119 ~6,
0120 ~7,
0121 ~8,
0122 ~9,
0123 ~10,
0124 ~11,
0125 ~12,
0126 ~13,
0127 ~14,
0128 ~15,
0129 
0130 
0131 # alt tilde avoiding shell escaping
0132 
0133 t0,
0134 t1,
0135 
0136 2
0137 0d2
0138 0x2
0139 ~0b1101
0140 0b0010
0141 1,
0142 0p1,
0143 
0144 t0b1101
0145 
0146 t1,
0147 t0p1
0148 
0149 ~8,8
0150 
0151 
0152 )LITERAL";
0153 
0154 void test_FromString_(const char* str)
0155 {
0156     if(strlen(str) == 0)
0157     {
0158         std::cout << std::endl ; 
0159     }
0160     else if(str[0] == '#')
0161     {
0162         std::cout << str << std::endl ; 
0163     }
0164     else
0165     {
0166         unsigned long long ull = SBit::FromString(str) ; 
0167         std::cout
0168             << std::setw(15) << str 
0169             << " : "
0170             << " "      << std::setw(20) << SBit::String(ull)
0171             << " (0p) " << std::setw(10) << SBit::PosString(ull)
0172             << " (0x) " << std::setw(16) << SBit::HexString(ull) 
0173             << " (0d) " << std::setw(20) << SBit::DecString(ull)
0174             << " (0b) " << std::setw(20) << SBit::BinString(ull)
0175             << std::endl  
0176             ;
0177     }
0178 }
0179 
0180 
0181 void test_FromString()
0182 {
0183     LOG(info); 
0184     std::stringstream ss ; 
0185     ss.str(EXAMPLES); 
0186     std::string s;
0187     while (std::getline(ss, s, '\n')) 
0188     {
0189         const char* str = s.c_str(); 
0190         test_FromString_(str); 
0191     }
0192 }
0193 
0194 void test_FromString_args(int argc, char** argv)
0195 {
0196     LOG(info) << " from arguments argc " << argc ;  
0197     for(int i=1 ; i < argc ; i++) std::cout << std::setw(5) << i << " : " << argv[i] << std::endl  ; 
0198     for(int i=1 ; i < argc ; i++) test_FromString_(argv[i]) ; 
0199 }
0200 
0201 void test_FromEString()
0202 {
0203     unsigned long long emm = SBit::FromEString("EMM"); 
0204     LOG(info) << " emm " << SBit::HexString(emm) << " 0x" << std::hex << emm << std::dec << std::endl ; 
0205 }
0206 
0207 
0208 int main(int argc, char** argv)
0209 {
0210     OPTICKS_LOG(argc, argv); 
0211 
0212     /*
0213     test_FromString();  
0214     test_FromString_args(argc, argv);  
0215     */ 
0216 
0217     test_FromEString();  
0218 
0219 
0220     return 0 ; 
0221 }
0222