From 26293db40f8ac62f3971e0e9dbbc0bf3439e61c0 Mon Sep 17 00:00:00 2001 From: Vasile Vilvoiu Date: Tue, 29 Dec 2020 19:33:03 +0200 Subject: Initial commit --- src/input-parser.hpp | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 src/input-parser.hpp (limited to 'src/input-parser.hpp') diff --git a/src/input-parser.hpp b/src/input-parser.hpp new file mode 100644 index 0000000..8df72ab --- /dev/null +++ b/src/input-parser.hpp @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2020-2021 Vasile Vilvoiu + * + * specgram is free software; you can redistribute it and/or modify + * it under the terms of the MIT license. See LICENSE for details. + */ +#ifndef _INPUT_PARSER_HPP_ +#define _INPUT_PARSER_HPP_ + +#include +#include +#include + +/* Input data type */ +enum class DataType { + /* signed integer */ + kSignedInt8, + kSignedInt16, + kSignedInt32, + kSignedInt64, + + /* unsigned integer */ + kUnsignedInt8, + kUnsignedInt16, + kUnsignedInt32, + kUnsignedInt64, + + /* floating point */ + kFloat32, + kFloat64 +}; + +/* Complex type that we normalize everything to */ +typedef std::complex Complex; + +/* Window of real numbers */ +typedef std::vector RealWindow; + +/* Window of complex numbers */ +typedef std::vector ComplexWindow; + +/* + * Input parser base class + */ +class InputParser { +protected: + double prescale_factor_; + bool is_complex_; + std::vector values_; + + InputParser() = delete; + explicit InputParser(double prescale, bool is_complex); + +public: + InputParser(const InputParser &c) = delete; + InputParser(InputParser &&) = delete; + InputParser & operator=(const InputParser&) = delete; + virtual ~InputParser() = default; + + static std::unique_ptr FromDataType(DataType dtype, double prescale, bool is_complex); + + std::size_t GetBufferedValueCount() const; + + std::vector PeekValues(std::size_t count) const; + void RemoveValues(std::size_t count); + + virtual std::size_t ParseBlock(const std::vector &block) = 0; + virtual std::size_t GetDataTypeSize() const = 0; + virtual bool IsSigned() const = 0; + virtual bool IsFloatingPoint() const = 0; + virtual bool IsComplex() const { return is_complex_; }; +}; + +/* + * Integer input parser + */ +template +class IntegerInputParser : public InputParser { +public: + IntegerInputParser() = delete; + explicit IntegerInputParser(double prescale, bool is_complex); + + std::size_t ParseBlock(const std::vector &block) override; + + std::size_t GetDataTypeSize() const override; + bool IsSigned() const override { return std::numeric_limits::is_signed; }; + bool IsFloatingPoint() const override { return false; }; +}; + +/* + * Floating point input parser + */ +template +class FloatInputParser : public InputParser { +public: + FloatInputParser() = delete; + explicit FloatInputParser(double prescale, bool is_complex); + + std::size_t ParseBlock(const std::vector &block) override; + + std::size_t GetDataTypeSize() const override; + bool IsSigned() const override { return true; }; + bool IsFloatingPoint() const override { return true; }; +}; + +#endif \ No newline at end of file -- cgit v1.2.3