OMNeT++ Simulation Library  5.6.1
cstringpool.h
1 //==========================================================================
2 // CSTRINGPOOL.H - part of
3 // OMNeT++/OMNEST
4 // Discrete System Simulation in C++
5 //
6 //==========================================================================
7 
8 /*--------------------------------------------------------------*
9  Copyright (C) 1992-2017 Andras Varga
10  Copyright (C) 2006-2017 OpenSim Ltd.
11 
12  This file is distributed WITHOUT ANY WARRANTY. See the file
13  `license' for details on this and other legal matters.
14 *--------------------------------------------------------------*/
15 
16 #ifndef __OMNETPP_CSTRINGPOOL_H
17 #define __OMNETPP_CSTRINGPOOL_H
18 
19 #include <string>
20 #include <map>
21 #include "simkerneldefs.h"
22 #include "simutil.h"
23 
24 namespace omnetpp {
25 
37 {
38  protected:
39  struct strless {
40  bool operator()(const char *s1, const char *s2) const {
41  int d0 = *s1 - *s2;
42  if (d0<0) return true; else if (d0>0) return false;
43  return strcmp(s1,s2) < 0; // note: (s1+1,s2+1) not good because either strings may be empty
44  }
45  };
46  std::string name;
47  typedef std::map<char *,int,strless> StringIntMap;
48  StringIntMap pool; // map<string,refcount>
49  bool alive; // useful when stringpool is a global variable
50 
51  public:
55  cStringPool(const char *poolName=nullptr);
56 
60  ~cStringPool();
61 
67  const char *get(const char *s);
68 
73  const char *peek(const char *s) const;
74 
80  void release(const char *s);
81 
85  void dump() const;
86 };
87 
88 } // namespace omnetpp
89 
90 
91 #endif
92 
93 
void release(const char *s)
Definition: cabstracthistogram.h:21
const char * peek(const char *s) const
cStringPool(const char *poolName=nullptr)
Reference-counted storage for strings.
Definition: cstringpool.h:36