18 #ifndef INCLUDE_SF_STRING_HPP 19 #define INCLUDE_SF_STRING_HPP 23 #include <type_traits> 25 #include <RCF/Tools.hpp> 26 #include <SF/Archive.hpp> 27 #include <SF/Stream.hpp> 32 template<
typename C,
typename T,
typename A>
33 inline void serializeString(
SF::Archive & ar, std::basic_string<C,T,A> & s)
37 std::uint32_t count = 0;
44 std::size_t minSerializedLength =
sizeof(C);
45 if (ar.verifyAgainstArchiveSize(count*minSerializedLength))
47 if (count > s.capacity())
53 std::uint32_t charsRemaining = count;
54 const std::uint32_t BufferSize = 512;
56 while (charsRemaining)
58 std::uint32_t charsToRead = RCF_MIN(BufferSize, charsRemaining);
59 std::uint32_t bytesToRead = charsToRead*
sizeof(C);
61 if ( is.read((
char *)buffer, bytesToRead) != bytesToRead )
67 s.append(buffer, charsToRead);
68 charsRemaining -= charsToRead;
73 std::uint32_t count =
static_cast<std::uint32_t
>(s.length());
75 ar.getOstream()->writeRaw(
82 RCF_EXPORT
bool getCurrentNativeWstringSerialization();
84 template<
typename C,
typename T,
typename A>
85 inline void serializeEncodedString(
SF::Archive & ar, std::basic_string<C,T,A> & ws)
89 serializeString(ar, ws);
99 if (encodingType == 8)
104 ws = RCF::stringToWstring(s);
110 if ( encodingType !=
sizeof(
wchar_t) )
112 RCF::Exception e(RCF::RcfError_WcharSizeMismatch,
sizeof(
wchar_t), encodingType);
116 serializeString(ar, ws);
125 int encodingType = 8;
126 bool useNativeWstringSerialization = getCurrentNativeWstringSerialization();
127 if ( useNativeWstringSerialization )
129 encodingType =
sizeof(wchar_t);
134 if (encodingType == 8)
137 std::string s = RCF::wstringToString(ws);
144 if ( encodingType !=
sizeof(
wchar_t) )
146 RCF::Exception e(RCF::RcfError_WcharSizeMismatch,
sizeof(
wchar_t), encodingType);
150 serializeString(ar, ws);
155 template<
typename C,
typename T,
typename A>
156 inline void serializeEncodedStringOrNot(
SF::Archive & ar, std::basic_string<C, T, A> & t, std::true_type *)
158 serializeEncodedString(ar, t);
161 template<
typename C,
typename T,
typename A>
162 inline void serializeEncodedStringOrNot(
SF::Archive & ar, std::basic_string<C, T, A> & t, std::false_type *)
164 serializeString(ar, t);
168 template<
typename C,
typename T,
typename A>
169 inline void serialize_vc6(
SF::Archive & ar, std::basic_string<C,T,A> & t,
const unsigned int)
171 typedef typename std::is_same<C, wchar_t>::type type;
172 serializeEncodedStringOrNot(ar, t, (type *) NULL);
177 #endif // ! INCLUDE_SF_STRING_HPP Represents an archive, in which serialized objects are stored.
Definition: Archive.hpp:31
int getRuntimeVersion()
Gets the RCF runtime version associated with this archive.
Base class for all RCF exceptions.
Definition: Exception.hpp:67
Definition: ByteBuffer.hpp:188
bool isWrite() const
Returns true if this archive is being written to.
bool isRead() const
Returns true if this archive is being read from.
Base class for input streams using SF serialization. Use operator >>() to deserialize objects from th...
Definition: Stream.hpp:137