Statistics
| Branch: | Revision:

root / include / cstringpool.h @ fbe00e73

History | View | Annotate | Download (1.9 KB)

1
//==========================================================================
2
//  CSTRINGPOOL.H - part of
3
//                     OMNeT++/OMNEST
4
//            Discrete System Simulation in C++
5
//
6
//==========================================================================
7

    
8
/*--------------------------------------------------------------*
9
  Copyright (C) 1992-2008 Andras Varga
10
  Copyright (C) 2006-2008 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 __CSTRINGPOOL_H
17
#define __CSTRINGPOOL_H
18

    
19
#include <string>
20
#include "simkerneldefs.h"
21
#include "simutil.h"
22

    
23
NAMESPACE_BEGIN
24

    
25
/**
26
 * For saving memory on the storage of (largely) constant strings that occur in
27
 * many instances during runtime: module names, gate names, property names,
28
 * keys and values, etc. These strings can be stored in a cStringPool as one
29
 * shared instance. Strings in the cStringPool are refcounted.
30
 * (See Flyweight GoF pattern.)
31
 *
32
 * @ingroup internals
33
 */
34
class cStringPool
35
{
36
  protected:
37

    
38
    std::string name;
39

    
40
  public:
41
    /**
42
     * Returns pointer to the pooled copy of the given string, and increments
43
     * its reference count. get() and release() must occur in pairs.
44
     * Passing NULL is OK.
45
     */
46
    virtual const char *get(const char *s) = 0;
47

    
48
    /**
49
     * Returns pointer to the pooled copy of the given string, or NULL.
50
     * Reference count is not incremented. Passing NULL is OK.
51
     */
52
    virtual const char *peek(const char *s) const = 0;
53

    
54
    /**
55
     * The parameter must a pointer returned by get(). It decrements the
56
     * reference count and frees the pooled string if it reaches zero.
57
     * Passing NULL is OK.
58
     */
59
    virtual void release(const char *s) = 0;
60

    
61
    /**
62
     * For debug purposes.
63
     */
64
    virtual void dump() const = 0;
65
};
66

    
67
NAMESPACE_END
68

    
69

    
70
#endif
71

    
72