| # Gaudi Framework, version v21r9 |

Home |  | Generated: 3 May 2010

# KeyedTraits.h

Go to the documentation of this file.

    00001 // $Id: KeyedTraits.h,v 1.3 2006/12/10 20:29:17 leggett Exp $
    00002 #ifndef GAUDIKERNEL_KEYEDTRAITS_H
    00003 #define GAUDIKERNEL_KEYEDTRAITS_H
    00004
    00005 #define CHECK_KEYED_CONTAINER
    00006
    00007 // Include files
    00008 #include <vector>
    00009
    00010 // Forward declarations
    00011 template <class K>          class KeyedObject;
    00012 template <class T, class M> class KeyedContainer;
    00013
    00014 /*
    00015   Namespace for Key classes used by the Keyed Container
    00016 */
    00017 namespace Containers    {
    00018
    00019   // Status enumeration
    00020   enum {
    00021     OBJ_NOT_FOUND,
    00022     OBJ_DELETED,
    00023     OBJ_ERASED,
    00024     OBJ_INSERTED,
    00025     OBJ_CANNOT_INSERT
    00026   };
    00027
    00028   // Forward declarations
    00029
    00031   template <class CONTAINER, class DATATYPE>  struct traits;
    00033   template <class KEY>                        struct key_traits;
    00035   template <class SETUP>                      class  KeyedObjectManager;
    00036
    00039   GAUDI_API void cannotInsertToContainer();
    00040
    00043   GAUDI_API void containerIsInconsistent();
    00044
    00048   GAUDI_API void invalidContainerOperation();
    00049
    00051   GAUDI_API void cannotAssignObjectKey();
    00052
    00064   template < class KEY > struct key_traits   {
    00066     typedef KEY                   key_type;
    00068     typedef KeyedObject<key_type> obj_type;
    00073     static key_type makeKey(long k)                    {return key_type(k); }
    00074     static key_type makeKey(int k)                     {return key_type(k); }
    00076     static long identifier(const key_type& k)          {return k;           }
    00078     static long hash(const key_type& key_value)        {return key_value;   }
    00080     static void setKey(obj_type* v, const key_type& k) {if(v)v->setKey(k);  }
    00085     static bool checkKey(obj_type* v,const key_type& k) {
    00086 #ifdef CHECK_KEYED_CONTAINER
    00087       return (v) ? (hash(v->key())==hash(k)) : false;
    00088 #else
    00089       return true;
    00090 #endif
    00091     }
    00093     static long addRef(obj_type* v)      {   return (v) ? v->addRef()  : 0; }
    00095     static long release(obj_type* v)     {   return (v) ? v->release() : 0; }
    00096   };
    00097
    00106   template < class CONTAINER, class DATATYPE >
    00107   struct traits : public key_traits < typename DATATYPE::key_type >
    00108   {
    00110     static bool checkBounds(const std::vector<DATATYPE*>* cnt,
    00111                             const typename DATATYPE::key_type& k) {
    00112 #ifdef CHECK_KEYED_CONTAINER
    00113       return size_t(cnt->size()) > size_t(traits::hash(k));
    00114 #else
    00115       return true;
    00116 #endif
    00117     }
    00118   };
    00119 }
    00120 #endif  // GAUDIKERNEL_KEYEDTRAITS_H
    00121