Statistics
| Branch: | Revision:

root / src / sim / cdummystringpool.cc @ e26d3d25

History | View | Annotate | Download (1.99 KB)

1
//==========================================================================
2
//  CDUMMYSTRINGPOOL.CC - part of
3
//                     Horizon/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
  Copyright (C) 2011 Simon Tenbusch, Georg Kunz
12

13
  This file is distributed WITHOUT ANY WARRANTY. See the file
14
  `license' for details on this and other legal matters.
15
*--------------------------------------------------------------*/
16

    
17
#include "cdummystringpool.h"
18
#include "cownedobject.h"
19
#include "stringutil.h"
20

    
21
USING_NAMESPACE
22

    
23
cDummyStringPool::cDummyStringPool(const char *poolName)
24
{
25
    // nothing to do here
26
}
27

    
28
cDummyStringPool::~cDummyStringPool()
29
{
30
    // allocated strings need to deleted by respective calls of release
31
}
32

    
33
void cDummyStringPool::dump() const
34
{
35
    fprintf(stderr, "ERROR: cDummyStringPool::dump() -- string pooling is disabled (Horizon)");
36
}
37

    
38
const char *cDummyStringPool::get(const char *s)
39
{
40
    if (!cStaticFlag::isSet())
41
        {fprintf(stderr, "ERROR: cDummyStringPool::get(\"%s\") invoked outside main() -- please do not use cStringPool from global objects", s); return opp_strdup(s);}
42

    
43
    if (!s)
44
        return NULL;
45

    
46
    char *str = new char[strlen(s)+1];
47
    strcpy(str, s);
48
    return str;
49
}
50

    
51
const char *cDummyStringPool::peek(const char *s) const
52
{
53
    if (!cStaticFlag::isSet())
54
        {fprintf(stderr, "ERROR: cDummyStringPool::peek(\"%s\") invoked outside main() -- please do not use cStringPool from global objects", s); return false;}
55
    if (!s)
56
        return NULL;
57

    
58
    return s;
59
}
60

    
61
void cDummyStringPool::release(const char *s)
62
{
63
    if (!s)
64
        return;
65

    
66
    if (!cStaticFlag::isSet())
67
        {fprintf(stderr, "Warning: cDummyStringPool::release(): string \"%s\" released too late, after main() already exited\n", s); return;}
68

    
69
    delete[] s;
70
}