OMNeT++ API 6.1
Discrete Event Simulation Library
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 
23 namespace omnetpp {
24 
30 {
31  private:
32  const char *p;
33  public:
35  opp_staticpooledstring(const char *s);
36  opp_staticpooledstring(const std::string& s) : opp_staticpooledstring(s.c_str()) {}
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 
53 inline bool operator==(const char *s, const opp_staticpooledstring& ps) {return ps == s;}
54 inline bool operator!=(const char *s, const opp_staticpooledstring& ps) {return ps != s;}
55 inline bool operator==(const std::string& s, const opp_staticpooledstring& ps) {return ps == s;}
56 inline bool operator!=(const std::string& s, const opp_staticpooledstring& ps) {return ps != s;}
57 
58 
63 class SIM_API opp_pooledstring
64 {
65  private:
66  const char *p;
67  public:
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;}
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 
87 inline bool operator==(const char *s, const opp_pooledstring& ps) {return ps == s;}
88 inline bool operator!=(const char *s, const opp_pooledstring& ps) {return ps != s;}
89 inline bool operator==(const std::string& s, const opp_pooledstring& ps) {return ps == s;}
90 inline bool operator!=(const std::string& s, const opp_pooledstring& ps) {return ps != s;}
91 
92 } // namespace omnetpp
93 
94 
95 #endif
96 
97 
omnetpp::opp_staticpooledstring
Definition: opp_pooledstring.h:29
omnetpp::opp_pooledstring
Definition: opp_pooledstring.h:63