File indexing completed on 2026-04-09 07:49:18
0001 #include <cstring>
0002 #include <csignal>
0003 #include "OPTICKS_LOG.hh"
0004 #include "SLabelCache.hh"
0005
0006 struct Surf
0007 {
0008 const char* name ;
0009 int index ;
0010 Surf(const char* name_, int index_) : name(strdup(name_)), index(index_) {}
0011 };
0012
0013 struct Turf
0014 {
0015 const char* name ;
0016 int index ;
0017 Turf(const char* name_, int index_) : name(strdup(name_)), index(index_) {}
0018 };
0019
0020
0021 inline std::ostream& operator<<(std::ostream& os, const Surf& s){ os << "Surf " << s.index << " " << s.name ; return os; }
0022 inline std::ostream& operator<<(std::ostream& os, const Turf& s){ os << "Turf " << s.index << " " << s.name ; return os; }
0023
0024
0025 int main(int argc, char** argv)
0026 {
0027 OPTICKS_LOG(argc, argv);
0028 LOG(info) ;
0029
0030
0031 Surf* r = new Surf("red", 100);
0032 Surf* g = new Surf("green", 200);
0033 Surf* b = new Surf("blue", 300);
0034
0035 Turf* c = new Turf("cyan", 1000);
0036 Turf* m = new Turf("magenta", 2000);
0037 Turf* y = new Turf("yellow", 3000);
0038 Turf* k = new Turf("black", 4000);
0039
0040 std::vector<const void*> oo = {r,g,b,c,m,y,k} ;
0041
0042
0043 for(unsigned i=0 ; i < 3 ; i++) std::cout << *(Surf*)oo[i] << std::endl ;
0044 for(unsigned i=3 ; i < oo.size() ; i++) std::cout << *(Turf*)oo[i] << std::endl ;
0045
0046
0047 SLabelCache<int> cache(-1);
0048
0049 for(unsigned i=0 ; i < oo.size() ; i++)
0050 {
0051 const void* o = oo[i] ;
0052 cache.add(o, int(i));
0053 int idx = cache.find(o);
0054 bool idx_expect = idx == int(i) ;
0055 assert( idx_expect );
0056 if(!idx_expect) std::raise(SIGINT);
0057 }
0058
0059 const void* anon = (const void*)m ;
0060 int idx_m = cache.find(anon) ;
0061 bool idx_m_expect = idx_m == 4 ;
0062 assert( idx_m_expect );
0063 if(!idx_m_expect) std::raise(SIGINT);
0064
0065 return 0 ;
0066 }
0067
0068