opp_pooledstring.h Source File

API: opp_pooledstring.h Source File
API
opp_pooledstring.h
1//==========================================================================
2// OPP_POOLEDSTRING.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_OPP_POOLEDSTRING_H
17#define __OMNETPP_OPP_POOLEDSTRING_H
18
19#include <cstring>
20#include <string>
21#include "simkerneldefs.h"
22
23namespace omnetpp {
24
29class SIM_API opp_staticpooledstring
30{
31 private:
32 const char *p;
33 public:
34 opp_staticpooledstring();
35 opp_staticpooledstring(const char *s);
36 opp_staticpooledstring(const std::string& s) : opp_staticpooledstring(s.c_str()) {}
37 opp_staticpooledstring(const opp_staticpooledstring&) = default;
38 opp_staticpooledstring(opp_staticpooledstring&&) = default;
39 opp_staticpooledstring& operator=(const opp_staticpooledstring&) = default;
40 opp_staticpooledstring& operator=(opp_staticpooledstring&&) = default;
41 bool empty() const {return !p || !*p;}
42 std::string str() const {return p;}
43 const char *c_str() const {return p;}
44 static const char *get(const char *s);
45 bool operator==(const opp_staticpooledstring& ps) const {return p == ps.p;}
46 bool operator!=(const opp_staticpooledstring& ps) const {return p != ps.p;}
47 bool operator==(const char *s) const {return strcmp(p,s) == 0;}
48 bool operator!=(const char *s) const {return strcmp(p,s) != 0;}
49 bool operator==(const std::string& s) const {return strcmp(p,s.c_str()) == 0;}
50 bool operator!=(const std::string& s) const {return strcmp(p,s.c_str()) != 0;}
51};
52
53inline bool operator==(const char *s, const opp_staticpooledstring& ps) {return ps == s;}
54inline bool operator!=(const char *s, const opp_staticpooledstring& ps) {return ps != s;}
55inline bool operator==(const std::string& s, const opp_staticpooledstring& ps) {return ps == s;}
56inline bool operator!=(const std::string& s, const opp_staticpooledstring& ps) {return ps != s;}
57
58
63class SIM_API opp_pooledstring
64{
65 private:
66 const char *p;
67 public:
68 opp_pooledstring();
69 opp_pooledstring(const char *s);
70 opp_pooledstring(const std::string& s) : opp_pooledstring(s.c_str()) {}
71 opp_pooledstring(const opp_pooledstring& ps) : opp_pooledstring(ps.c_str()) {}
72 opp_pooledstring(opp_pooledstring&& ps) {p = ps.p; ps.p = nullptr;}
73 ~opp_pooledstring();
74 opp_pooledstring& operator=(const opp_pooledstring& ps);
75 opp_pooledstring& operator=(opp_pooledstring&& ps);
76 bool empty() const {return !p || !*p;}
77 std::string str() const {return p;}
78 const char *c_str() const {return p;}
79 bool operator==(const opp_pooledstring& ps) const {return p == ps.p;}
80 bool operator!=(const opp_pooledstring& ps) const {return p != ps.p;}
81 bool operator==(const char *s) const {return strcmp(p,s) == 0;}
82 bool operator!=(const char *s) const {return strcmp(p,s) != 0;}
83 bool operator==(const std::string& s) const {return strcmp(p,s.c_str()) == 0;}
84 bool operator!=(const std::string& s) const {return strcmp(p,s.c_str()) != 0;}
85};
86
87inline bool operator==(const char *s, const opp_pooledstring& ps) {return ps == s;}
88inline bool operator!=(const char *s, const opp_pooledstring& ps) {return ps != s;}
89inline bool operator==(const std::string& s, const opp_pooledstring& ps) {return ps == s;}
90inline bool operator!=(const std::string& s, const opp_pooledstring& ps) {return ps != s;}
91
92} // namespace omnetpp
93
94
95#endif
96
97
Definition opp_pooledstring.h:64
Definition opp_pooledstring.h:30