From 49f8bc71859b280520c4a9325ff97782c8d95ab4 Mon Sep 17 00:00:00 2001 From: zawz Date: Sat, 15 Jun 2019 23:21:56 +0200 Subject: [PATCH] Fix symbolic links --- include/Filedat.hpp | 142 +++++++- include/options.hpp | 56 +++- include/stringTools.hpp | 132 +++++++- src/Filedat.cpp | 309 +++++++++++++++++- src/options.cpp | 191 ++++++++++- src/stringTools.cpp | 702 +++++++++++++++++++++++++++++++++++++++- 6 files changed, 1526 insertions(+), 6 deletions(-) mode change 120000 => 100644 include/Filedat.hpp mode change 120000 => 100644 include/options.hpp mode change 120000 => 100644 include/stringTools.hpp mode change 120000 => 100644 src/Filedat.cpp mode change 120000 => 100644 src/options.cpp mode change 120000 => 100644 src/stringTools.cpp diff --git a/include/Filedat.hpp b/include/Filedat.hpp deleted file mode 120000 index fe943f9..0000000 --- a/include/Filedat.hpp +++ /dev/null @@ -1 +0,0 @@ -/home/zawz/code/c/tool/zFiledat/Filedat.hpp \ No newline at end of file diff --git a/include/Filedat.hpp b/include/Filedat.hpp new file mode 100644 index 0000000..46d1e0a --- /dev/null +++ b/include/Filedat.hpp @@ -0,0 +1,141 @@ +#ifndef FILEDAT_H +#define FILEDAT_H + +#include "stringTools.hpp" + +#include +#include +#include +#include +#include + +//TESTS NEEDED + +class AbstractChunk +{ +public: + enum typeEnum { none, val, chunk, list}; + + typeEnum type() { return m_type; } + + AbstractChunk() { m_type=AbstractChunk::none; } + virtual ~AbstractChunk() {} + +protected: + typeEnum m_type; +}; + +class Chunk +{ +public: + Chunk() { m_achunk=nullptr; } + Chunk(char* const in) { m_achunk=nullptr; set(std::string(in)); } + Chunk(std::string const& in) { m_achunk=nullptr; set(in); } + Chunk(Chunk const& in) { m_achunk=nullptr; set(in); } + void clear() { if(m_achunk!=nullptr) delete m_achunk; m_achunk=nullptr; } + ~Chunk() { clear(); } + + void set(std::string const& in); + void set(Chunk const& in); //TO OPTIMIZE + std::string strval(unsigned int alignment=0, std::string const& aligner="\t") const; + + // bool concatenate(Chunk const& chk); //concatenates chunks + bool addToChunk(std::string const& name, Chunk const& val); //adds if datachunk + inline bool addToChunk(std::pair const& pair) { return add(pair.first, pair.second); } //adds if datachunk + bool addToChunk(std::vector> const& vec); //adds if datachunk + bool addToList(Chunk const& val); //adds if list + bool addToList(std::vector const& vec); //adds if list + inline bool add(std::string const& name, Chunk const& val) { return addToChunk(name, val); } //adds if datachunk + inline bool add(std::pair const& pair) { return add(pair.first, pair.second); } //adds if datachunk + inline bool add(std::vector> const& vec) { return addToChunk(vec); } //adds if datachunk + inline bool add(Chunk const& val) { return addToList(val); } //adds if list + inline bool add(std::vector const& vec) { return addToList(vec); } //adds if list + + Chunk copy() const { return Chunk(*this); } + Chunk* pcopy() const { return new Chunk(*this); } + + AbstractChunk* getp() const { return m_achunk; } + AbstractChunk::typeEnum type() const { if(m_achunk!=nullptr) return m_achunk->type(); else return AbstractChunk::none; } + int listSize() const; + + Chunk* subChunkPtr(std::string const& a) const; //datachunk + Chunk* subChunkPtr(unsigned int a) const; //chunklist + Chunk& subChunkRef(std::string const& a) const; //datachunk + Chunk& subChunkRef(unsigned int a) const; //chunklist + + Chunk& operator[](std::string const& a) const { return subChunkRef(a); } + Chunk& operator[](unsigned int a) const { return subChunkRef(a); } + Chunk& operator=(Chunk const& a) { set(a); return *this; } + inline bool operator+=(std::pair const& a) { return addToChunk(a); } + inline bool operator+=(std::vector> const& a) { return addToChunk(a); } + inline bool operator+=(Chunk const& a) { return addToList(a); } + inline bool operator+=(std::vector const& a) { return addToList(a); } + // inline bool operator*=(Chunk const& a) { concatenate(a); } + + //add operator+ and operator* + +protected: + AbstractChunk* m_achunk; +}; + +std::ostream& operator<<(std::ostream& stream, Chunk const& a); + +class DataVal : public AbstractChunk +{ +public: + DataVal() { m_type=AbstractChunk::val; } + virtual ~DataVal() {} + + std::string val; +}; + +class DataChunk : public AbstractChunk +{ +public: + DataChunk() { m_type=AbstractChunk::chunk; } + virtual ~DataChunk(); + + std::map values; + +}; + +class ChunkList : public AbstractChunk +{ +public: + ChunkList() { m_type=AbstractChunk::list; } + virtual ~ChunkList(); + + std::vector list; +}; + +class Filedat +{ +public: + Filedat(); + Filedat(std::string const& in); + virtual ~Filedat(); + + bool readTest() const; + + bool importFile(); + bool exportFile(std::string const& path="", std::string const& aligner="\t") const; + + void clear(); + + std::string filePath() const { return m_filePath; } + void setFilePath(std::string const& in) { m_filePath=in; } + + std::string strval() const; + + inline Chunk* pchunk() const { return m_dataChunk; } + inline Chunk& chunk() const { return *m_dataChunk; } + + inline Chunk* pdata() const { return m_dataChunk; } + inline Chunk& data() const { return *m_dataChunk; } + +private: + std::string m_filePath; + Chunk* m_dataChunk; +}; + +#endif //FILEDAT_H diff --git a/include/options.hpp b/include/options.hpp deleted file mode 120000 index 705cd32..0000000 --- a/include/options.hpp +++ /dev/null @@ -1 +0,0 @@ -/home/zawz/code/c/tool/zOptions/options.hpp \ No newline at end of file diff --git a/include/options.hpp b/include/options.hpp new file mode 100644 index 0000000..4b73407 --- /dev/null +++ b/include/options.hpp @@ -0,0 +1,55 @@ +#ifndef OPTIONS_H +#define OPTIONS_H + +//DUPLICATES NOT HANDLED: takes last one +//NO ORDER: no way to know options order +//RETURNS TRANSITIONAL STATE IF ERROR + +#include +#include +#include + +std::vector argVector(int argc, char** argv); + +class Option +{ +public: + Option(); + Option(char c, bool arg); + Option(std::string const& str, bool arg); + Option(char c, std::string const& str, bool arg); + virtual ~Option(); + + bool shortDef; + char charName; + + bool longDef; + std::string strName; + + bool activated; + + bool takesArgument; + std::string argument; +}; + +class OptionSet +{ +public: + OptionSet(); + virtual ~OptionSet(); + + void addOption(Option opt) { m_options.push_back(opt); } + + Option* findOption(char c); + Option* findOption(std::string const& str); + + std::ostream* errStream; + + std::pair,bool> getOptions(std::vector input); + +private: + std::vector