Inferno  0.2
standard.hpp
Go to the documentation of this file.
00001 #ifndef STANDARD_HPP
00002 #define STANDARD_HPP
00003 
00004 #include <assert.h>
00005 #include <stdio.h>
00006 #include <vector>
00007 #include <stack>
00008 #include <map>
00009 #include <set>
00010 using namespace std;
00011 #include <stdarg.h> 
00012 
00013 #include <boost/shared_ptr.hpp>
00014 #include <boost/weak_ptr.hpp>
00015 using namespace boost;
00016 
00017 // JSG we now use boost's FOREACH which means we depend on Boost 1.34 (I think)
00018 #include <boost/foreach.hpp>
00019 #define FOREACH BOOST_FOREACH
00020 
00021 // How many members in an array
00022 #define COUNTOF( array ) ( sizeof( array )/sizeof( array[0] ) )
00023 
00024 // sprintf into a std::string
00025 string SSPrintf(const char *fmt, ...);
00026 
00027 // Pushes element t of type T onto stack s, then pops again in destructor
00028 template< typename T >
00029 class AutoPush
00030 {
00031 public:
00032     AutoPush( stack<T> &s, const T &t ) : st(s)
00033     {
00034         st.push(t);
00035     }    
00036     ~AutoPush()
00037     {
00038         st.pop();
00039     }
00040     
00041 private:
00042     std::stack<T> &st;
00043 };
00044 
00045 // Find out whether an element exists in the map, without the pain of iterators
00046 template< typename KEY, typename DATA >
00047 class Map : public map<KEY, DATA>
00048 {
00049 public:
00050     inline bool IsExist( const KEY &k ) const 
00051     {
00052         return map<KEY, DATA>::find( k ) != map<KEY, DATA>::end();
00053     }
00054 };
00055 
00056 template< typename KEY >
00057 class Set : public set<KEY>
00058 {
00059 public:
00060     inline bool IsExist( const KEY &k ) const 
00061     {
00062         return set<KEY>::find( k ) != set<KEY>::end();
00063     }
00064 };
00065 
00066 void CommonTest();
00067 
00068 class Traceable
00069 {
00070 public:
00071     static string CPPFilt( string s );
00072     virtual string GetName() const; // used by parse, render etc
00073     virtual string GetAddr() const; // used by parse, render etc
00074     virtual operator string() const; // used for debug
00075 };
00076 
00077 #endif