2013-12-06 22:29:25 +01:00
|
|
|
#include "concordia/common/utils.hpp"
|
|
|
|
|
|
|
|
Utils::Utils() {
|
|
|
|
}
|
|
|
|
|
|
|
|
Utils::~Utils() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void Utils::writeIndexCharacter(ofstream & file,
|
|
|
|
INDEX_CHARACTER_TYPE character) {
|
|
|
|
file.write(reinterpret_cast<char *>(&character), sizeof(character));
|
|
|
|
}
|
|
|
|
|
2014-02-20 10:49:17 +01:00
|
|
|
void Utils::writeMarker(ofstream & file,
|
|
|
|
SUFFIX_MARKER_TYPE marker) {
|
|
|
|
file.write(reinterpret_cast<char *>(&marker), sizeof(marker));
|
|
|
|
}
|
|
|
|
|
2013-12-06 22:29:25 +01:00
|
|
|
INDEX_CHARACTER_TYPE Utils::readIndexCharacter(ifstream & file) {
|
|
|
|
INDEX_CHARACTER_TYPE character;
|
|
|
|
file.read(reinterpret_cast<char *>(&character), sizeof(character));
|
|
|
|
return character;
|
|
|
|
}
|
|
|
|
|
2014-02-20 10:49:17 +01:00
|
|
|
SUFFIX_MARKER_TYPE Utils::readMarker(ifstream & file) {
|
|
|
|
SUFFIX_MARKER_TYPE marker;
|
|
|
|
file.read(reinterpret_cast<char *>(&marker), sizeof(marker));
|
|
|
|
return marker;
|
|
|
|
}
|
|
|
|
|
2013-12-06 22:29:25 +01:00
|
|
|
sauchar_t * Utils::indexVectorToSaucharArray(
|
2013-12-14 15:23:17 +01:00
|
|
|
boost::shared_ptr<vector<INDEX_CHARACTER_TYPE> > input) {
|
|
|
|
const int kArraySize = input->size()*sizeof(INDEX_CHARACTER_TYPE);
|
2013-12-06 22:29:25 +01:00
|
|
|
sauchar_t * patternArray =
|
|
|
|
new sauchar_t[kArraySize];
|
|
|
|
int pos = 0;
|
2013-12-14 15:23:17 +01:00
|
|
|
for (vector<INDEX_CHARACTER_TYPE>::iterator it = input->begin();
|
|
|
|
it != input->end(); ++it) {
|
|
|
|
_insertCharToSaucharArray(patternArray, *it, pos);
|
2013-12-06 22:29:25 +01:00
|
|
|
pos += sizeof(INDEX_CHARACTER_TYPE);
|
|
|
|
}
|
|
|
|
return patternArray;
|
|
|
|
}
|
|
|
|
|
2014-06-24 18:23:46 +02:00
|
|
|
boost::shared_ptr<std::vector<sauchar_t> > Utils::indexVectorToSaucharVector(
|
|
|
|
boost::shared_ptr<vector<INDEX_CHARACTER_TYPE> > input) {
|
2014-06-24 18:33:02 +02:00
|
|
|
boost::shared_ptr<std::vector<sauchar_t> > result =
|
|
|
|
boost::shared_ptr<std::vector<sauchar_t> >(new std::vector<sauchar_t>);
|
|
|
|
|
2014-06-24 18:23:46 +02:00
|
|
|
for (vector<INDEX_CHARACTER_TYPE>::iterator it = input->begin();
|
|
|
|
it != input->end(); ++it) {
|
|
|
|
appendCharToSaucharVector(result, *it);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-12-14 15:23:17 +01:00
|
|
|
void Utils::appendCharToSaucharVector(
|
|
|
|
boost::shared_ptr<std::vector<sauchar_t> > vector,
|
|
|
|
INDEX_CHARACTER_TYPE character) {
|
|
|
|
sauchar_t * characterArray = reinterpret_cast<sauchar_t *>(&character);
|
|
|
|
for (int i = 0; i < sizeof(character); i++) {
|
|
|
|
vector->push_back(characterArray[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Utils::_insertCharToSaucharArray(sauchar_t * array,
|
2013-12-06 22:29:25 +01:00
|
|
|
INDEX_CHARACTER_TYPE character, int pos) {
|
|
|
|
sauchar_t * characterArray = reinterpret_cast<sauchar_t *>(&character);
|
|
|
|
for (int i = pos; i < pos+sizeof(character); i++) {
|
|
|
|
array[i] = characterArray[i-pos];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|