X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/d656f9465e7b1c36319f86eeafdcec58fe9551a4..4f4afa70b8cc31bd39d3ab5dbaf7ae899c77b34b:/include/xbt/string.hpp diff --git a/include/xbt/string.hpp b/include/xbt/string.hpp index c0126b4da6..7af6d332c1 100644 --- a/include/xbt/string.hpp +++ b/include/xbt/string.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2015-2017. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2015-2018. 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. */ @@ -54,16 +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. */ -XBT_PUBLIC_CLASS string : private string_data { - static const char NUL; +class XBT_PUBLIC string : private string_data { + static char NUL; + public: // Types typedef std::size_t size_type; - typedef std::ptrdiff_t difference_type; typedef char& reference; typedef const char& const_reference; - typedef char* pointer; - typedef const char* const_pointer; typedef char* iterator; typedef const char* const_iterator; @@ -79,7 +77,7 @@ public: { if (size == 0) { string_data::len = 0; - string_data::data = const_cast(&NUL); + string_data::data = &NUL; } else { string_data::len = size; string_data::data = new char[string_data::len + 1]; @@ -87,17 +85,17 @@ public: string_data::data[string_data::len] = '\0'; } } - string() : string (const_cast(&NUL), 0) {} - string(const char* s) : string(s, strlen(s)) {} + 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) { 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(&NUL); + s.string_data::data = &NUL; } - string(std::string const& s) : string(s.c_str(), s.size()) {} + explicit string(std::string const& s) : string(s.c_str(), s.size()) {} // Assign void assign(const char* s, size_t size) @@ -136,7 +134,7 @@ public: 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; } @@ -180,7 +178,7 @@ public: void clear() { string_data::len = 0; - string_data::data = const_cast(&NUL); + string_data::data = &NUL; } bool equals(const char* data, std::size_t len) const @@ -299,14 +297,13 @@ typedef std::string string; * * @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 */ -std::string string_vprintf(const char *fmt, va_list ap); - +XBT_PUBLIC std::string string_vprintf(const char* fmt, va_list ap); } }