<commit_before>/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* Copyright (C) 2015, IGG Group, ICube, University of Strasbourg, France       *
*                                                                              *
* This library is free software; you can redistribute it and/or modify it      *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your     *
* option) any later version.                                                   *
*                                                                              *
* This library 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 Lesser General Public License  *
* for more details.                                                            *
*                                                                              *
* You should have received a copy of the GNU Lesser General Public License     *
* along with this library; if not, write to the Free Software Foundation,      *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
*                                                                              *
* Web site: http://cgogn.unistra.fr/                                           *
* Contact information: <EMAIL>                                        *
*                                                                              *
*******************************************************************************/

#ifndef CORE_SERIALIZATION_H_
#define CORE_SERIALIZATION_H_

#include <utils/assert.h>

#include <iostream>
#include <vector>
#include <list>
#include <array>
#include <utils/dll.h>

namespace cgogn
{

namespace serialization
{

template <typename T>
void load(std::istream& istream, T* dest, std::size_t quantity)
{
	cgogn_assert(dest != nullptr);
	istream.read(reinterpret_cast<char*>(dest), static_cast<std::streamsize>(quantity*sizeof(T)));
}

template <typename T>
void save(std::ostream& ostream, T const* src, std::size_t quantity)
{
	cgogn_assert(src != nullptr);
	ostream.write(reinterpret_cast<const char*>(src), static_cast<std::streamsize>(quantity*sizeof(T)));
}

template <typename T>
std::size_t data_length(T const* /*src*/, std::size_t quantity)
{
	return quantity*sizeof(T);
}

// data size is known or not ?
template <typename T>
bool known_size(T const* /*src*/)
{
	return true;
}

template <>
CGOGN_UTILS_API bool known_size<std::string>(std::string const* /*src*/);

template <typename U>
bool known_size(std::vector<U> const* /*src*/)
{
	return false;
}

template <typename U>
bool known_size(std::list<U> const* /*src*/)
{
	return false;
}

// first step : declare all overrides of load and save
template <typename U>
void load(std::istream& istream, std::vector<U>* dest, std::size_t quantity);

template <typename U>
void save(std::ostream& ostream, std::vector<U> const* src, std::size_t quantity);

template <typename U>
std::size_t data_length(std::vector<U> const* src, std::size_t quantity);


template <typename U>
void load(std::istream& istream, std::list<U>* dest, std::size_t quantity);

template <typename U>
void save(std::ostream& ostream, std::list<U> const* src, std::size_t quantity);<commit_msg>added missing specialization of known_size method for std::array<commit_after>/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* Copyright (C) 2015, IGG Group, ICube, University of Strasbourg, France       *
*                                                                              *
* This library is free software; you can redistribute it and/or modify it      *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your     *
* option) any later version.                                                   *
*                                                                              *
* This library 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 Lesser General Public License  *
* for more details.                                                            *
*                                                                              *
* You should have received a copy of the GNU Lesser General Public License     *
* along with this library; if not, write to the Free Software Foundation,      *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
*                                                                              *
* Web site: http://cgogn.unistra.fr/                                           *
* Contact information: <EMAIL>                                        *
*                                                                              *
*******************************************************************************/

#ifndef CORE_SERIALIZATION_H_
#define CORE_SERIALIZATION_H_

#include <utils/assert.h>

#include <iostream>
#include <vector>
#include <list>
#include <array>
#include <utils/dll.h>

namespace cgogn
{

namespace serialization
{

template <typename T>
void load(std::istream& istream, T* dest, std::size_t quantity)
{
	cgogn_assert(dest != nullptr);
	istream.read(reinterpret_cast<char*>(dest), static_cast<std::streamsize>(quantity*sizeof(T)));
}

template <typename T>
void save(std::ostream& ostream, T const* src, std::size_t quantity)
{
	cgogn_assert(src != nullptr);
	ostream.write(reinterpret_cast<const char*>(src), static_cast<std::streamsize>(quantity*sizeof(T)));
}

template <typename T>
std::size_t data_length(T const* /*src*/, std::size_t quantity)
{
	return quantity*sizeof(T);
}

// data size is known or not ?
template <typename T>
bool known_size(T const* /*src*/)
{
	return true;
}

template <>
CGOGN_UTILS_API bool known_size<std::string>(std::string const* /*src*/);

template <typename U>
bool known_size(std::vector<U> const* /*src*/)
{
	return false;
}

template <typename U>
bool known_size(std::list<U> const* /*src*/)
{
	return false;
}

template <typename U, std::size_t size>
bool known_size(std::array<U, size> const* /*src*/)
{
	return false;
}

// first step : declare all overrides of load and save
template <typename U>
void load(std::istream& istream, std::vector<U>* dest, std::size_t quantity);

template <typename U>
void save(std::ostream& ostream, std::vector<U> const* src, std::size_t quantity);

template <typename U>
std::size_t data_length(std::vector<U> const* src, std::size_t quantity);


template <typename U>
void load(std::istream& istream, std::list<U>* dest, std::size_t quantity);

template <typename U>
void save(std::ostream& ostream, std::list<U> const* src, std::size_t quantity);
{'fraction_non_alphanumeric': 0.1454898157129001, 'fraction_numerical': 0.004711098794512956, 'mean_word_length': 2.4111531190926274, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 42, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7431308', 'n_tokens_mistral': 1898, 'n_tokens_neox': 1846, 'n_words': 622}