reSIProcate/stack  9694
TransactionMap.hxx
Go to the documentation of this file.
00001 #if !defined(RESIP_TRANSACTIONMAP_HXX)
00002 #define RESIP_TRANSACTIONMAP_HXX
00003 
00004 #include "rutil/Data.hxx"
00005 #include "rutil/HashMap.hxx"
00006 
00007 namespace resip
00008 {
00009   class TransactionState;
00010 
00014 class TransactionMap 
00015 {
00016   public:
00017      ~TransactionMap();
00018      
00019      TransactionState* find( const Data& transactionId ) const;
00020      void add( const Data& transactionId, TransactionState* state  );
00021      void erase( const Data& transactionId );
00022      int size() const;
00023      
00024   private:
00025 
00026 #if  defined(__INTEL_COMPILER ) || (defined(WIN32) && defined(_MSC_VER) && (_MSC_VER >= 1310))  // !slg! not sure if this works on __INTEL_COMPILER 
00027 
00030       class BranchCompare
00031       {
00032          public:
00033             enum { bucket_size = 4, min_buckets = 8 };
00034 
00035             inline size_t operator()(const Data& branch) const
00036             {
00037                return branch.caseInsensitiveTokenHash();
00038             }
00039 
00040             inline bool operator()(const Data& branch1, const Data& branch2) const
00041             {
00042                return isLessThanNoCase(branch1,branch2);
00043             }
00044       };
00045 #elif defined(HASH_MAP_NAMESPACE)
00046 
00049       class BranchHasher
00050       {
00051          public:
00052             inline size_t operator()(const Data& branch) const
00053             {
00054                return branch.caseInsensitiveTokenHash();
00055             }
00056       };
00057 
00061       class BranchEqual
00062       {
00063          public:
00064             inline bool operator()(const Data& branch1, const Data& branch2) const
00065             {
00066                return isEqualNoCase(branch1,branch2);
00067             }
00068       };
00069 #else
00070 
00073       class BranchCompare
00074       {
00075          public:
00076             inline bool operator()(const Data& branch1, const Data& branch2) const
00077             {
00078                return isLessThanNoCase(branch1,branch2);
00079             }
00080       };
00081 #endif
00082 
00083       // .bwc. If rutil/HashMap.hxx fails to find a hash_map impl for the 
00084       // platform we're using, it will #define HashMap to a std::map, which
00085       // takes different template args. We try to compensate for this here.
00086 #if  defined(__INTEL_COMPILER ) || (defined(WIN32) && defined(_MSC_VER) && (_MSC_VER >= 1310))
00087      typedef HashMap<Data, TransactionState*, BranchCompare> Map;
00088 #elif defined(HASH_MAP_NAMESPACE)
00089      typedef HashMap<Data, TransactionState*, BranchHasher, BranchEqual> Map;
00090 #else
00091      typedef std::map<Data, TransactionState*, BranchCompare> Map;
00092 #endif
00093 
00094      Map mMap;
00095      typedef Map::iterator MapIterator;
00096      typedef Map::const_iterator MapConstIterator;
00097 };
00098 }
00099 
00100 #endif
00101 
00102 /* ====================================================================
00103  * The Vovida Software License, Version 1.0 
00104  * 
00105  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00106  * 
00107  * Redistribution and use in source and binary forms, with or without
00108  * modification, are permitted provided that the following conditions
00109  * are met:
00110  * 
00111  * 1. Redistributions of source code must retain the above copyright
00112  *    notice, this list of conditions and the following disclaimer.
00113  * 
00114  * 2. Redistributions in binary form must reproduce the above copyright
00115  *    notice, this list of conditions and the following disclaimer in
00116  *    the documentation and/or other materials provided with the
00117  *    distribution.
00118  * 
00119  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00120  *    and "Vovida Open Communication Application Library (VOCAL)" must
00121  *    not be used to endorse or promote products derived from this
00122  *    software without prior written permission. For written
00123  *    permission, please contact vocal@vovida.org.
00124  *
00125  * 4. Products derived from this software may not be called "VOCAL", nor
00126  *    may "VOCAL" appear in their name, without prior written
00127  *    permission of Vovida Networks, Inc.
00128  * 
00129  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00130  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00131  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00132  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00133  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00134  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00135  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00136  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00137  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00138  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00139  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00140  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00141  * DAMAGE.
00142  * 
00143  * ====================================================================
00144  * 
00145  * This software consists of voluntary contributions made by Vovida
00146  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00147  * Inc.  For more information on Vovida Networks, Inc., please see
00148  * <http://www.vovida.org/>.
00149  *
00150  */