16#ifndef __OMNETPP_OPP_STRING_H
17#define __OMNETPP_OPP_STRING_H
23#include "simkerneldefs.h"
44 static char *opp_strdup(
const char *s) {
45 if (!s || !s[0])
return nullptr;
46 char *p =
new char[strlen(s)+1];
51 static int opp_strcmp(
const char *s1,
const char *s2) {
53 return s2 ? strcmp(s1,s2) : (*s1 ? 1 : 0);
55 return (s2 && *s2) ? -1 : 0;
72 opp_string(
const char *s,
int n) {buf =
new char[n+1]; strncpy(buf, s?s:
"", n); buf[n] =
'\0';}
77 opp_string(
const std::string& s) {buf = opp_strdup(s.c_str());}
97 const char *
c_str()
const {
return buf ? buf :
"";}
102 std::string
str()
const {
return buf ? buf :
"";}
107 bool empty()
const {
return !buf || !buf[0];}
119 int size()
const {
return buf ? strlen(buf) : 0;}
130 const char *
operator=(
const char *s) {
delete[] buf;buf=opp_strdup(s);
return buf;}
189inline std::ostream& operator<<(std::ostream& out,
const opp_string& s)
191 out << s.c_str();
return out;
203class SIM_API opp_string_vector :
public std::vector<opp_string>
206 opp_string_vector() {}
207 opp_string_vector(
const opp_string_vector& other) =
default;
219class SIM_API opp_string_map :
public std::map<opp_string,opp_string>
223 opp_string_map(
const opp_string_map& other) =
default;
const char * c_str() const
Definition opp_string.h:97
opp_string & operator=(const opp_string &s)
Definition opp_string.h:135
opp_string()
Definition opp_string.h:62
bool operator!=(const opp_string &s) const
Definition opp_string.h:155
opp_string(const char *s)
Definition opp_string.h:67
bool operator<(const opp_string &s) const
Definition opp_string.h:145
bool empty() const
Definition opp_string.h:107
opp_string(opp_string &&s)
Definition opp_string.h:87
opp_string(const std::string &s)
Definition opp_string.h:77
char * buffer()
Definition opp_string.h:114
opp_string & operator+=(const std::string &s)
Definition opp_string.h:170
opp_string operator+(const char *s)
Definition opp_string.h:175
char * reserve(unsigned size)
Definition opp_string.h:124
opp_string(const char *s, int n)
Definition opp_string.h:72
opp_string operator+(const opp_string &s)
Definition opp_string.h:180
const char * operator=(const char *s)
Definition opp_string.h:130
opp_string & operator=(const std::string &s)
Definition opp_string.h:140
opp_string operator+(const std::string &s)
Definition opp_string.h:185
bool operator==(const opp_string &s) const
Definition opp_string.h:150
opp_string & operator+=(const opp_string &s)
Definition opp_string.h:165
std::string str() const
Definition opp_string.h:102
opp_string(const opp_string &s)
Definition opp_string.h:82
opp_string & operator+=(const char *s)
Definition opp_string.h:160
int size() const
Definition opp_string.h:119
~opp_string()
Definition opp_string.h:92