cstringpool.h

00001 //==========================================================================
00002 //  CSTRINGPOOL.H - part of
00003 //                     OMNeT++/OMNEST
00004 //            Discrete System Simulation in C++
00005 //
00006 //==========================================================================
00007 
00008 /*--------------------------------------------------------------*
00009   Copyright (C) 1992-2008 Andras Varga
00010   Copyright (C) 2006-2008 OpenSim Ltd.
00011 
00012   This file is distributed WITHOUT ANY WARRANTY. See the file
00013   `license' for details on this and other legal matters.
00014 *--------------------------------------------------------------*/
00015 
00016 #ifndef __CSTRINGPOOL_H
00017 #define __CSTRINGPOOL_H
00018 
00019 #include <string>
00020 #include <map>
00021 #include "simkerneldefs.h"
00022 #include "simutil.h"
00023 
00024 NAMESPACE_BEGIN
00025 
00035 class cStringPool
00036 {
00037   protected:
00038     struct strless {
00039         bool operator()(const char *s1, const char *s2) const {
00040             int d0 = *s1 - *s2;
00041             if (d0<0) return true; else if (d0>0) return false;
00042             return strcmp(s1,s2) < 0;  // note: (s1+1,s2+1) not good because either strings may be empty
00043         }
00044     };
00045     std::string name;
00046     typedef std::map<char *,int,strless> StringIntMap;
00047     StringIntMap pool; // map<string,refcount>
00048     bool alive; // useful when stringpool is a global variable
00049 
00050   public:
00051     cStringPool(const char *poolName=NULL);
00052     ~cStringPool();
00053 
00059     const char *get(const char *s);
00060 
00065     const char *peek(const char *s) const;
00066 
00072     void release(const char *s);
00073 
00077     void dump() const;
00078 };
00079 
00080 NAMESPACE_END
00081 
00082 
00083 #endif
00084 
00085 
Generated on Tue Dec 2 11:16:27 2014 for OMNeT++ Simulation Library by  doxygen 1.6.3