src/DataTypeReaderBase.h
author František Kučera <franta-hg@frantovo.cz>
Sat, 25 Aug 2018 18:16:53 +0200
branchv_0
changeset 14 e8de089f95dd
parent 13 543f1613c2da
child 18 e11f1ad20826
permissions -rw-r--r--
refactoring, move files, use TypeId instead of integer_t

#pragma once

#include <string>
#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() {
	};

	/**
	 * @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;

	/**
	 * @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;
	}
};

}
}