Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages   Examples  

util_types.h

00001 #ifndef UTIL_TYPES_H
00002 #define UTIL_TYPES_H
00003 
00004 #include <vector>
00005 #include <iostream>
00006 #include <hash_set> //to get std::hash
00007 #include <numeric>  //to_get accumulate
00008 #include "SmartPtr.h"
00009 
00010 namespace fpoller {
00011 
00012   namespace util_types {
00014     typedef std::vector<char> vec;
00016     typedef Loki::SmartPtr<vec> svec;
00017 
00019     template<typename T, typename U>
00020     struct hashing_accumulator{
00021       //pretty much what the sgi hash<const char *> does
00022       T operator()(T t,U u){
00023         return 5*t+u;
00024       }
00025     };
00026     
00028     struct svec_hash {
00029       size_t operator()(const svec &s) const{
00030         return std::accumulate(s->begin(),s->end(),0,hashing_accumulator<size_t,char>());
00031       }
00032     };
00033     
00035     inline const char *pcc(const svec &s){
00036       return &((*s)[0]);
00037     }
00038 
00040     inline vec * new_vec_from_cstring(const char * pc){
00041       return new vec(pc,pc+strlen(pc));
00042     }
00043 
00044 
00045     inline void to_cerr(const svec & s, char c = ' '){
00046 #ifdef DEBUG
00047       std::ostream_iterator<char> out(std::cerr);
00048       copy(s->begin(),s->end(),out);
00049       *out++ = c;
00050 #endif
00051     }
00052 
00054     inline bool equals(const svec & s, const char * c){
00055       size_t matched = 0;
00056       for(vec::iterator i = s->begin();(*c) && i != s->end() && *i++ == *c++;matched++);
00057       return matched == s->size();
00058     }
00059 
00061     inline bool equals(const char * c,const svec & s){
00062       return equals(s,c);
00063     }
00064     
00065 
00066   }// namespace util_types
00067 
00068 }//namespace fpoller
00069 
00070 namespace std {
00072   inline std::ostream & operator<<(std::ostream &o, const fpoller::util_types::vec &v){
00073     return o.write(&v[0],v.size());
00074   }
00075 }
00076 #endif

Generated at Wed Oct 16 16:02:39 2002 for fpoller by doxygen1.2.9.1 written by Dimitri van Heesch, © 1997-2001