builds with cmake 3.7.2 (e.g. on Debian GNU/Linux 9.6)
/**
* Relational pipes (library)
* Copyright © 2018 František Kučera (Frantovo.cz, GlobalCode.info)
*
* This program 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 3 of the License, or (at your option) any later version;
* or (at your option)
* - 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/>.
*/
#pragma once
#include <string>
#include <functional>
#include "../include/relpipe/reader/TypeId.h"
#include "../include/relpipe/reader/typedefs.h"
namespace relpipe {
namespace reader {
/**
* This class contains common features that are independent from particular data type (generic/template type)
*/
class DataTypeReaderBase {
private:
const TypeId typeId;
const string_t typeCode;
public:
DataTypeReaderBase(const TypeId typeId, const string_t typeCode) :
typeId(typeId), typeCode(typeCode) {
}
virtual ~DataTypeReaderBase() {
};
/**
* TODO: delete, use handler?
*
* @param input input stream, should be at position where the value is to be read; the stream will not be closed afred reading
* @return read value in form of the string representation of given data type.
* E.g. integer 123 is returned as a character string "123",
* boolean true is returned as a character string "true".
* See Relational pipes format specification for details.
*/
virtual string_t readString(std::istream &input) = 0;
/**
* The value is read from the input and then passed to the handler.
*
* @param input
* @param handler
*/
virtual void read(std::istream &input, std::function<void(const void *, const std::type_info&) > handler) = 0;
/**
* TODO: documentation
*
* @param input
* @param handler
*/
virtual void read(std::istream &input, std::function<void(const string_t&, const void *, const std::type_info&) > handler) = 0;
/**
* @param dataType data type code as defined in DDP L0
* @return whether this class supports conversions of this type
*/
virtual bool supports(const TypeId &dataType) {
return dataType == typeId;
}
/**
* @param dataType data type name as defined in DDP L0
* @return whether this class supports conversions of this type
*/
virtual bool supports(const string_t &dataType) {
return dataType == typeCode;
}
TypeId getTypeId() {
return typeId;
}
string_t getTypeCode() {
return typeCode;
}
};
}
}