/* 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. */
-#ifndef SIMGRIC_XBT_STRING_HPP
-#define SIMGRIC_XBT_STRING_HPP
+#ifndef SIMGRID_XBT_STRING_HPP
+#define SIMGRID_XBT_STRING_HPP
-#ifdef HAVE_MC
+#include <simgrid_config.h>
+
+#include <string>
+#include <cstdarg>
+
+#if HAVE_MC
#include <stdexcept>
#include <cstddef>
#include <cstdlib>
#include <cstring>
-#include <string>
#include <iterator>
#include <xbt/sysdep.h>
+#endif
+
namespace simgrid {
namespace xbt {
+#if HAVE_MC
+
/** POD structure representation of a string
*/
struct string_data {
std::size_t len;
};
-/** A std::string with well-known representation
+/** A std::string-like with well-known representation
+ *
+ * HACK, this is a (incomplete) replacement for `std::string`.
+ * It has a fixed POD representation (`simgrid::xbt::string_data`)
+ * which can be used to easily read the string content from another
+ * process.
*
- * This is a (incomplete) drop-in replacement for std::string.
+ * The internal representation of a `std::string` is private.
+ * We could add some code to read this for a given implementation.
+ * However, even if we focus on GNU libstdc++ with Itanium ABI
+ * GNU libstdc++ currently has two different ABIs
*
- * This is used for cross-process access to strings
- * (when the MC is enabled).
+ * * the pre-C++11 is a pointer to a ref-counted
+ * string-representation (with support for COW);
+ *
+ * * 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;
return b <= a;
}
-}
-}
-
#else
-#include <string>
+typedef std::string string;
-namespace simgrid {
-namespace xbt {
+#endif
-typedef std::string string;
+std::string string_vprintf(const char *fmt, va_list ap);
+std::string string_printf(const char *fmt, ...);
}
}
#endif
-
-#endif
\ No newline at end of file