/usr/include/apertium-3.4/apertium/serialiser.h is in apertium-dev 3.4.2~r68466-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | // Copyright (C) 2005 Universitat d'Alacant / Universidad de Alicante
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
#ifndef SERIALISER_H
#define SERIALISER_H
#include "a.h"
#include "basic_exception_type.h"
#include "analysis.h"
#include "exception.h"
#include "i.h"
#include "lemma.h"
#include "morpheme.h"
#include "tag.h"
#include <cstddef>
#include <ios>
#include <limits>
#include <map>
#include <ostream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
namespace Apertium {
template <typename SerialisedType>
static unsigned char compressedSize(const SerialisedType &SerialisedType_) {
unsigned char compressedSize_ = 0;
for (; static_cast<unsigned char>(SerialisedType_ >>
std::numeric_limits<unsigned char>::digits *
compressedSize_) != 0;
++compressedSize_) {
}
return compressedSize_;
}
template <typename SerialisedType> class Serialiser;
template <> class Serialiser<a> {
public:
inline static void serialise(const a &StreamedType_, std::ostream &Stream_);
};
template <> class Serialiser<Analysis> {
public:
inline static void serialise(const Analysis &SerialisedType_,
std::ostream &Stream_);
};
template <> class Serialiser<i> {
public:
inline static void serialise(const i &StreamedType_, std::ostream &Stream_);
};
template <> class Serialiser<Lemma> {
public:
inline static void serialise(const Lemma &StreamedType_,
std::ostream &Stream_);
};
template <> class Serialiser<Morpheme> {
public:
inline static void serialise(const Morpheme &SerialisedType_,
std::ostream &Stream_);
};
template <> class Serialiser<Tag> {
public:
inline static void serialise(const Tag &SerialisedType_,
std::ostream &Stream_);
};
template <typename value_type>
class Serialiser<std::basic_string<value_type> > {
public:
inline static void
serialise(const std::basic_string<value_type> &SerialisedType_,
std::ostream &Stream_);
};
template <typename key_type, typename mapped_type>
class Serialiser<std::map<key_type, mapped_type> > {
public:
inline static void
serialise(const std::map<key_type, mapped_type> &SerialisedType_,
std::ostream &Stream_);
};
template <typename first_type, typename second_type>
class Serialiser<std::pair<first_type, second_type> > {
public:
inline static void
serialise(const std::pair<first_type, second_type> &SerialisedType_,
std::ostream &Stream_);
};
template <> class Serialiser<std::size_t> {
public:
inline static void serialise(const std::size_t &SerialisedType_,
std::ostream &Stream_);
};
template <typename value_type> class Serialiser<std::vector<value_type> > {
public:
inline static void serialise(const std::vector<value_type> &SerialisedType_,
std::ostream &Stream_);
};
template <> class Serialiser<wchar_t> {
public:
inline static void serialise(const wchar_t &SerialisedType_,
std::ostream &Stream_);
};
void Serialiser<a>::serialise(const a &StreamedType_, std::ostream &Stream_) {
Serialiser<std::vector<Tag> >::serialise(StreamedType_.TheTags, Stream_);
Serialiser<std::vector<Morpheme> >::serialise(StreamedType_.TheMorphemes,
Stream_);
}
void Serialiser<Analysis>::serialise(const Analysis &SerialisedType_,
std::ostream &Stream_) {
Serialiser<std::vector<Morpheme> >::serialise(SerialisedType_.TheMorphemes,
Stream_);
}
void Serialiser<i>::serialise(const i &StreamedType_, std::ostream &Stream_) {
Serialiser<std::vector<Tag> >::serialise(StreamedType_.TheTags, Stream_);
}
void Serialiser<Lemma>::serialise(const Lemma &StreamedType_,
std::ostream &Stream_) {
Serialiser<std::wstring>::serialise(StreamedType_.TheLemma, Stream_);
}
void Serialiser<Morpheme>::serialise(const Morpheme &SerialisedType_,
std::ostream &Stream_) {
Serialiser<std::wstring>::serialise(SerialisedType_.TheLemma, Stream_);
Serialiser<std::vector<Tag> >::serialise(SerialisedType_.TheTags, Stream_);
}
void Serialiser<Tag>::serialise(const Tag &SerialisedType_,
std::ostream &Stream_) {
Serialiser<std::wstring>::serialise(SerialisedType_.TheTag, Stream_);
}
template <typename value_type>
void Serialiser<std::basic_string<value_type> >::serialise(
const std::basic_string<value_type> &SerialisedType_,
std::ostream &Stream_) {
Serialiser<std::size_t>::serialise(SerialisedType_.size(), Stream_);
for (typename std::basic_string<value_type>::const_iterator
SerialisedType_iterator = SerialisedType_.begin();
// Call .end() each iteration to save memory.
SerialisedType_iterator != SerialisedType_.end();
++SerialisedType_iterator) {
Serialiser<value_type>::serialise(*SerialisedType_iterator, Stream_);
}
}
template <typename key_type, typename mapped_type>
void Serialiser<std::map<key_type, mapped_type> >::serialise(
const std::map<key_type, mapped_type> &SerialisedType_,
std::ostream &Stream_) {
Serialiser<std::size_t>::serialise(SerialisedType_.size(), Stream_);
for (typename std::map<key_type, mapped_type>::const_iterator
SerialisedType_iterator = SerialisedType_.begin();
// Call .end() each iteration to save memory.
SerialisedType_iterator != SerialisedType_.end();
++SerialisedType_iterator) {
Serialiser<std::pair<key_type, mapped_type> >::serialise(
*SerialisedType_iterator, Stream_);
}
}
template <typename first_type, typename second_type>
void Serialiser<std::pair<first_type, second_type> >::serialise(
const std::pair<first_type, second_type> &SerialisedType_,
std::ostream &Stream_) {
Serialiser<first_type>::serialise(SerialisedType_.first, Stream_);
Serialiser<second_type>::serialise(SerialisedType_.second, Stream_);
}
void Serialiser<std::size_t>::serialise(const std::size_t &SerialisedType_,
std::ostream &Stream_) {
try {
Stream_.put(compressedSize(SerialisedType_));
if (!Stream_) {
std::stringstream what_;
what_ << "can't serialise size " << std::hex
<< /* [1] */ +compressedSize(SerialisedType_) << std::dec;
throw Exception::Serialiser::not_Stream_good(what_);
}
for (unsigned char CompressedSize = compressedSize(SerialisedType_);
CompressedSize != 0; Stream_.put(static_cast<unsigned char>(
SerialisedType_ >>
std::numeric_limits<unsigned char>::digits * --CompressedSize))) {
if (!Stream_) {
std::stringstream what_;
what_ << "can't serialise byte " << std::hex
<< /* [1] */ +static_cast<unsigned char>(
SerialisedType_ >>
std::numeric_limits<unsigned char>::digits *
CompressedSize) << std::dec;
throw Exception::Serialiser::not_Stream_good(what_);
}
}
} catch (const basic_ExceptionType &basic_ExceptionType_) {
std::stringstream what_;
what_ << "can't serialise const std::size_t & : "
<< basic_ExceptionType_.what();
throw Exception::Serialiser::size_t_(what_);
}
}
template <typename value_type>
void Serialiser<std::vector<value_type> >::serialise(
const std::vector<value_type> &SerialisedType_, std::ostream &Stream_) {
Serialiser<std::size_t>::serialise(SerialisedType_.size(), Stream_);
for (typename std::vector<value_type>::const_iterator value_type_ =
SerialisedType_.begin();
// Call .end() each iteration to save memory.
value_type_ != SerialisedType_.end(); ++value_type_) {
Serialiser<value_type>::serialise(*value_type_, Stream_);
}
}
void Serialiser<wchar_t>::serialise(const wchar_t &SerialisedType_,
std::ostream &Stream_) {
try {
Stream_.put(compressedSize(SerialisedType_));
if (!Stream_) {
std::stringstream what_;
what_ << "can't serialise size " << std::hex
<< /* [1] */ +compressedSize(SerialisedType_);
throw Exception::Serialiser::not_Stream_good(what_);
}
for (unsigned char CompressedSize = compressedSize(SerialisedType_);
CompressedSize != 0; Stream_.put(static_cast<unsigned char>(
static_cast<unsigned wchar_t>(SerialisedType_) >>
std::numeric_limits<unsigned char>::digits * --CompressedSize))) {
if (!Stream_) {
std::stringstream what_;
what_ << "can't serialise byte " << std::hex
<< /* [1] */ +(static_cast<unsigned wchar_t>(SerialisedType_) >>
std::numeric_limits<unsigned char>::digits *
CompressedSize);
throw Exception::Serialiser::not_Stream_good(what_);
}
}
} catch (const basic_ExceptionType &basic_ExceptionType_) {
std::stringstream what_;
what_ << "can't serialise const wchar_t & : "
<< basic_ExceptionType_.what();
throw Exception::Serialiser::wchar_t_(what_);
}
}
}
// [1] operator+ promotes its operand to a printable integral type.
#endif // SERIALISER_H
|