Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // ./spho_test.sh
0002 
0003 
0004 #include <iostream>
0005 #include "spho.h"
0006 
0007 void test_gen()
0008 {
0009      spho p = {} ;
0010      p.id = 101 ;
0011      std::cout << p.desc() << std::endl ;
0012 
0013      for(unsigned i=0 ; i < 256 ; i++)
0014      {
0015          if( i == 10 ) p.uc4.w = 214 ;
0016 
0017          p = p.make_nextgen();
0018          std::cout << p.desc() << std::endl ;
0019      }
0020 
0021 
0022 
0023      p.set_gen(1);
0024      std::cout
0025          << p.desc() << " "
0026          << " p.set_gen(1) "
0027          << std::endl
0028          ;
0029 
0030      p.set_gen(0);
0031      p.set_flg(1);
0032 
0033      std::cout
0034          << p.desc() << " "
0035          << "p.set_gen(0), p.set_flg(1) "
0036          << std::endl
0037          ;
0038 
0039 
0040      p.set_gen(1);
0041      p.set_flg(1);
0042      std::cout
0043          << p.desc() << " "
0044          << "p.set_gen(1), p.set_flg(1) "
0045          << std::endl
0046          ;
0047 }
0048 
0049 
0050 void test_u4c()
0051 {
0052      spho p = {} ;
0053 
0054      p.uc4.x = 1 ;
0055      p.uc4.y = 1 ;
0056      p.uc4.z = 1 ;
0057      p.uc4.w = 1 ;
0058      std::cout
0059          << p.desc() << " "
0060          << "p.uc4.x = 1, p.uc4.y = 1, p.uc4.z = 1, p.uc4.w = 1 "
0061          << std::endl
0062          ;
0063 
0064 
0065 
0066      p.uc4.x = 0xff ;
0067      p.uc4.y = 0xff ;
0068      p.uc4.z = 0xff ;
0069      p.uc4.w = 0xff ;
0070      std::cout
0071          << p.desc() << " "
0072          << "p.uc4.x = 0xff, p.uc4.y = 0xff, p.uc4.z = 0xff, p.uc4.w = 0xff "
0073          << std::endl
0074          ;
0075 
0076      p.uc4.x = 'A' ;
0077      p.uc4.y = 'a' ;
0078      p.uc4.z = '?' ;
0079      p.uc4.w = '_' ;
0080      std::cout
0081          << p.desc() << " "
0082          << "p.uc4.x = 'A' p.uc4.y = 'a' p.uc4.z = '?'  p.uc4.w = '_'  "
0083          << std::endl
0084          ;
0085 
0086 
0087      p.uc4.x = 'Z' ;
0088      p.uc4.y = 'z' ;
0089      p.uc4.z = ' ' ;
0090      p.uc4.w = '_' ;
0091      std::cout
0092          << p.desc() << " "
0093          << "p.uc4.x = 'Z' p.uc4.y = 'z' p.uc4.z = ' '  p.uc4.w = '_'  "
0094          << std::endl
0095          ;
0096 }
0097 
0098 void test_serialize_load()
0099 {
0100     spho p = { 1, 2, 3, {'a', 'b', 'c', 'd' } };
0101 
0102     std::cout << "p " << p << std::endl;
0103 
0104     std::array<int,4> a ;
0105     p.serialize(a) ;
0106 
0107     spho q = {} ;
0108     q.load(a) ;
0109 
0110     std::cout << "q " << q << std::endl ;
0111 
0112 }
0113 
0114 /**
0115 
0116 ::
0117 
0118     In [6]: np.array( [1684234849], dtype=np.uint32 ).view("|S4")
0119     Out[6]: array([b'abcd'], dtype='|S4')
0120 
0121 **/
0122 
0123 void test_uc4packed()
0124 {
0125     spho p = { 1, 2, 3, {'a', 'b', 'c', 'd' } };
0126 
0127     unsigned u4pk = p.uc4packed() ;
0128     std::cout << " u4pk " << u4pk << std::endl ;
0129 }
0130 
0131 
0132 void test_inplace()
0133 {
0134     // inplace modify the p object via another object with only int* data connection between them
0135 
0136     spho p = { 1, 2, 3, {'a', 'b', 'c', 'd' } };
0137     std::cout << "p0 " << p << std::endl ;
0138     int* d = p.data(); // d points into p
0139 
0140 
0141     spho& q = reinterpret_cast<spho&>(*d);
0142     std::cout << "q  " << q << std::endl ;
0143 
0144     // changing q also changes p
0145     q.uc4.x = 'A' ;
0146     q.uc4.y = 'B' ;
0147     q.uc4.z = 'C' ;
0148     q.uc4.w = 'D' ;
0149     q.gs = 10 ;
0150     q.ix = 20 ;
0151     q.id = 30 ;
0152 
0153     std::cout << "p1 " << p << std::endl ;
0154     std::cout << "q  " << q << "(q and p share same data)" << std::endl ;
0155 }
0156 
0157 
0158 int main()
0159 {
0160      /*
0161      test_gen();
0162      test_uc4();
0163      test_serialize_load();
0164      test_uc4packed();
0165      */
0166      test_inplace();
0167 
0168      return 0 ;
0169 }