A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge pull request #302 from mpoquet/rename-s4u-synchro-examples
[simgrid.git]
/
include
/
xbt
/
string.hpp
diff --git
a/include/xbt/string.hpp
b/include/xbt/string.hpp
index
f37e189
..
9400d3d
100644
(file)
--- a/
include/xbt/string.hpp
+++ b/
include/xbt/string.hpp
@@
-1,4
+1,4
@@
-/* Copyright (c) 2015-201
7
. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2015-201
8
. The SimGrid Team. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
@@
-6,19
+6,19
@@
#ifndef SIMGRID_XBT_STRING_HPP
#define SIMGRID_XBT_STRING_HPP
#ifndef SIMGRID_XBT_STRING_HPP
#define SIMGRID_XBT_STRING_HPP
-#include <simgrid
_
config.h>
+#include <simgrid
/
config.h>
-#include <string>
#include <cstdarg>
#include <cstdarg>
-#include <stdlib.h>
+#include <cstdlib>
+#include <string>
#if SIMGRID_HAVE_MC
#if SIMGRID_HAVE_MC
-#include <
stdexcept
>
+#include <
algorithm
>
#include <cstddef>
#include <cstddef>
-#include <cstdlib>
#include <cstring>
#include <iterator>
#include <cstring>
#include <iterator>
+#include <stdexcept>
#include <xbt/sysdep.h>
#include <xbt/sysdep.h>
@@
-54,17
+54,14
@@
struct string_data {
* * the [C++11-conforming implementation](https://gcc.gnu.org/gcc-5/changes.html)
* does not use refcouting/COW but has a small string optimization.
*/
* * the [C++11-conforming implementation](https://gcc.gnu.org/gcc-5/changes.html)
* does not use refcouting/COW but has a small string optimization.
*/
-XBT_PUBLIC_CLASS string : private string_data {
- static const char NUL;
-public:
+class XBT_PUBLIC string : private string_data {
+ static char NUL;
+public:
// Types
typedef std::size_t size_type;
// Types
typedef std::size_t size_type;
- typedef std::ptrdiff_t difference_type;
typedef char& reference;
typedef const char& const_reference;
typedef char& reference;
typedef const char& const_reference;
- typedef char* pointer;
- typedef const char* const_pointer;
typedef char* iterator;
typedef const char* const_iterator;
typedef char* iterator;
typedef const char* const_iterator;
@@
-72,7
+69,7
@@
public:
~string()
{
if (string_data::data != &NUL)
~string()
{
if (string_data::data != &NUL)
-
std::free(string_data::data)
;
+
delete[] string_data::data
;
}
// Ctors
}
// Ctors
@@
-80,15
+77,15
@@
public:
{
if (size == 0) {
string_data::len = 0;
{
if (size == 0) {
string_data::len = 0;
- string_data::data =
const_cast<char*>(&NUL)
;
+ string_data::data =
&NUL
;
} else {
string_data::len = size;
} else {
string_data::len = size;
- string_data::data =
static_cast<char*>(std::malloc(string_data::len + 1))
;
-
memcpy(string_data::data, s, string_data::len
);
+ string_data::data =
new char[string_data::len + 1]
;
+
std::copy_n(s, string_data::len, string_data::data
);
string_data::data[string_data::len] = '\0';
}
}
string_data::data[string_data::len] = '\0';
}
}
- string() : string
(const_cast<char*>(&NUL)
, 0) {}
+ string() : string
(&NUL
, 0) {}
explicit string(const char* s) : string(s, strlen(s)) {}
string(string const& s) : string(s.c_str(), s.size()) {}
string(string&& s)
explicit string(const char* s) : string(s, strlen(s)) {}
string(string const& s) : string(s.c_str(), s.size()) {}
string(string&& s)
@@
-96,7
+93,7
@@
public:
string_data::len = s.string_data::len;
string_data::data = s.string_data::data;
s.string_data::len = 0;
string_data::len = s.string_data::len;
string_data::data = s.string_data::data;
s.string_data::len = 0;
- s.string_data::data =
const_cast<char*>(&NUL)
;
+ s.string_data::data =
&NUL
;
}
explicit string(std::string const& s) : string(s.c_str(), s.size()) {}
}
explicit string(std::string const& s) : string(s.c_str(), s.size()) {}
@@
-104,14
+101,14
@@
public:
void assign(const char* s, size_t size)
{
if (string_data::data != &NUL) {
void assign(const char* s, size_t size)
{
if (string_data::data != &NUL) {
-
std::free(string_data::data)
;
+
delete[] string_data::data
;
string_data::data = nullptr;
string_data::len = 0;
}
if (size != 0) {
string_data::len = size;
string_data::data = nullptr;
string_data::len = 0;
}
if (size != 0) {
string_data::len = size;
- string_data::data =
(char*) std::malloc(string_data::len + 1)
;
- std::
memcpy(string_data::data, s, string_data::len
);
+ string_data::data =
new char[string_data::len + 1]
;
+ std::
copy_n(s, string_data::len, string_data::data
);
string_data::data[string_data::len] = '\0';
}
}
string_data::data[string_data::len] = '\0';
}
}
@@
-137,7
+134,7
@@
public:
size_t size() const { return len; }
size_t length() const { return len; }
bool empty() const { return len != 0; }
size_t size() const { return len; }
size_t length() const { return len; }
bool empty() const { return len != 0; }
- void shrink_to_fit() {}
+ void shrink_to_fit() {
/* Being there, but doing nothing */
}
// Alement access
char* data() { return string_data::data; }
// Alement access
char* data() { return string_data::data; }
@@
-165,7
+162,8
@@
public:
return data()[i];
}
// Conversion
return data()[i];
}
// Conversion
- explicit operator std::string() const { return std::string(this->c_str(), this->size()); }
+ static string_data& to_string_data(string& s) { return s; }
+ operator std::string() const { return std::string(this->c_str(), this->size()); }
// Iterators
iterator begin() { return data(); }
// Iterators
iterator begin() { return data(); }
@@
-180,7
+178,7
@@
public:
void clear()
{
string_data::len = 0;
void clear()
{
string_data::len = 0;
- string_data::data =
const_cast<char*>(&NUL)
;
+ string_data::data =
&NUL
;
}
bool equals(const char* data, std::size_t len) const
}
bool equals(const char* data, std::size_t len) const
@@
-299,14
+297,13
@@
typedef std::string string;
*
* @ingroup XBT_str
*/
*
* @ingroup XBT_str
*/
-
std::string string_printf(const char *
fmt, ...);
+
XBT_PUBLIC std::string string_printf(const char*
fmt, ...);
/** Create a C++ string from a C-style format
*
* @ingroup XBT_str
*/
/** Create a C++ string from a C-style format
*
* @ingroup XBT_str
*/
-std::string string_vprintf(const char *fmt, va_list ap);
-
+XBT_PUBLIC std::string string_vprintf(const char* fmt, va_list ap);
}
}
}
}