diff --git a/sbg/dto/Makefile.include b/sbg/dto/Makefile.include index f4630be..70a76db 100644 --- a/sbg/dto/Makefile.include +++ b/sbg/dto/Makefile.include @@ -2,8 +2,10 @@ DTO_SRC := \ $(DTO_ROOT)/interval_dto.cpp \ $(DTO_ROOT)/multidim_inter_dto.cpp \ + $(DTO_ROOT)/pw_mdinter_dto.cpp \ $(CONVERTERS_ROOT)/interval_dto_converter.cpp \ - $(CONVERTERS_ROOT)/multidim_inter_dto_converter.cpp + $(CONVERTERS_ROOT)/multidim_inter_dto_converter.cpp \ + $(CONVERTERS_ROOT)/pw_mdinter_dto_converter.cpp # DTO Objects DTO_OBJ=$(addprefix $(BUILD_DIR)/, $(DTO_SRC:.cpp=.o)) \ No newline at end of file diff --git a/sbg/dto/converters/pw_mdinter_dto_converter.cpp b/sbg/dto/converters/pw_mdinter_dto_converter.cpp new file mode 100644 index 0000000..16f6c18 --- /dev/null +++ b/sbg/dto/converters/pw_mdinter_dto_converter.cpp @@ -0,0 +1,46 @@ +/******************************************************************************* + + This file is part of Set--Based Graph Library. + + SBG Library is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + SBG 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with SBG Library. If not, see . + + ******************************************************************************/ + +#include "sbg/dto/converters/multidim_inter_dto_converter.hpp" +#include "sbg/dto/converters/pw_mdinter_dto_converter.hpp" + +namespace SBG { + +namespace API { +SBG::LIB::OrdSet PWMDInterDTOConverter::convertToOrdSet(const SetDTO& dto) { + SBG::LIB::OrdSet ord_set; + for (const SetPieceDTO& set_piece_dto : dto.pieces_) { + ord_set.emplace(SetPieceDTOConverter::convertToSetPiece(set_piece_dto)); + } + + return ord_set; +} + +SBG::LIB::UnordSet PWMDInterDTOConverter::convertToUnordSet(const PWMDInterDTO& dto) { + SBG::LIB::UnordSet unord_set; + for (const SetPieceDTO& set_piece_dto : dto.pieces_) { + unord_set.emplace(SetPieceDTOConverter::convertToSetPiece(set_piece_dto)); + } + + return unord_set; +} + +} // namespace API + +} // namespace SBG \ No newline at end of file diff --git a/sbg/dto/converters/pw_mdinter_dto_converter.hpp b/sbg/dto/converters/pw_mdinter_dto_converter.hpp new file mode 100644 index 0000000..efcead3 --- /dev/null +++ b/sbg/dto/converters/pw_mdinter_dto_converter.hpp @@ -0,0 +1,59 @@ +/** @file pw_mdinter_dto_converter.hpp + + @brief PWMDInterDTOConverter implementation + + The PWMDInterDTOConverter is used to convert a PWMDInterDTO (SetDTO) + to the corresponding piecewise multi-dimensional interval representation. + Currently, it can convert to SBG::LIB::OrdSet and SBG::LIB::UnordSet, + but more conversions can be added in the future. + +
+ + This file is part of Set--Based Graph Library. + + SBG Library is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + SBG 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with SBG Library. If not, see . + + ******************************************************************************/ + +#ifndef SBG_DTO_PW_MDINTERVAL_CONVERTER_HPP +#define SBG_DTO_PW_MDINTERVAL_CONVERTER_HPP + +#include "sbg/dto/pw_mdinter_dto.hpp" +#include "sbg/ord_pw_mdinter.hpp" +#include "sbg/unord_pw_mdinter.hpp" + +namespace SBG { + +namespace API { + +class PWMDInterDTOConverter { +public: + /** + * @brief Converts a SetDTO object to an actual piecewise multi-dimensional + * interval implementation (e.g., SBG::LIB::OrdSet / SBG::LIB::UnordSet). + * + * @param dto: The SetDTO object to convert. + * @return SBG::LIB::OrdSet/UnordSet: The converted interval object. + */ + static SBG::LIB::OrdSet convertToOrdSet(const SetDTO& dto); + static SBG::LIB::UnordSet convertToUnordSet(const SetDTO& dto); +}; + +typedef PWMDInterDTOConverter SetDTOConverter; + +} // namespace API + +} // namespace SBG + +#endif // SBG_DTO_PW_MDINTERVAL_CONVERTER_HPP diff --git a/sbg/dto/pw_mdinter_dto.cpp b/sbg/dto/pw_mdinter_dto.cpp new file mode 100644 index 0000000..a7a47b3 --- /dev/null +++ b/sbg/dto/pw_mdinter_dto.cpp @@ -0,0 +1,96 @@ +/******************************************************************************* + + This file is part of Set--Based Graph Library. + + SBG Library is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + SBG 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with SBG Library. If not, see . + + ******************************************************************************/ + +#include "sbg/dto/pw_mdinter_dto.hpp" + +namespace SBG { + +namespace API { + +// Type definitions ------------------------------------------------------------ + +std::ostream &operator<<(std::ostream &out, const SetPieceDTOVector &ii) +{ + std::size_t sz = ii.size(); + + out << "{"; + if (sz > 0) { + unsigned int j = 0; + for (const SetPieceDTO &mdi : ii) { + if (j < sz - 1) + out << mdi << ", "; + else + out << mdi; + + ++j; + } + } + out << "}"; + + return out; +} + +// PWMDInterDTO ------------------------------------------------------------------ + +PWMDInterDTO::PWMDInterDTO() : pieces_() {} +PWMDInterDTO::PWMDInterDTO(MD_NAT x) : pieces_() { + pieces_.push_back(SetPieceDTO(x)); +} +PWMDInterDTO::PWMDInterDTO(IntervalDTO i) : pieces_() { + if (!i.isEmpty()) + pieces_.push_back(SetPieceDTO(i)); +} +PWMDInterDTO::PWMDInterDTO(SetPieceDTO mdi) : pieces_() { + if (!mdi.isEmpty()) + pieces_.push_back(mdi); +} +PWMDInterDTO::PWMDInterDTO(SetPieceDTOVector container) : pieces_() { + for (const SetPieceDTO &mdi : container) { + if (!mdi.isEmpty()) + pieces_.push_back(mdi); + } +} + +member_imp(PWMDInterDTO, SetPieceDTOVector, pieces); + +std::size_t PWMDInterDTO::size() const { return pieces_.size(); } + +void PWMDInterDTO::emplace(SetPieceDTO mdi) +{ + if (!mdi.isEmpty()) + pieces_.push_back(mdi); +} +void PWMDInterDTO::emplaceBack(SetPieceDTO mdi) +{ + if (!mdi.isEmpty()) + pieces_.push_back(mdi); +} + +bool PWMDInterDTO::isEmpty() const { return pieces_.empty(); } + +std::ostream &operator<<(std::ostream &out, const PWMDInterDTO &pwi) +{ + out << pwi.pieces_; //TODO: check if this translates ok (it should use the operator<< for SetPieceDTOVector at the top of this file). + + return out; +} + +} // namespace API + +} // namespace SBG diff --git a/sbg/dto/pw_mdinter_dto.hpp b/sbg/dto/pw_mdinter_dto.hpp new file mode 100644 index 0000000..61e5c9b --- /dev/null +++ b/sbg/dto/pw_mdinter_dto.hpp @@ -0,0 +1,74 @@ +/** @file pw_mdinter_dto.hpp + + @brief Piecewise multi-dimensional interval dto implementation + + The PWMDInterDTO class is a Data Transfer Object (DTO) for handling + raw data, such as from JSON. It is designed for conversion into + concrete implementations like OrdSet/UnordSet via a dedicated converter. + +
+ + This file is part of Set--Based Graph Library. + + SBG Library is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + SBG 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with SBG Library. If not, see . + + ******************************************************************************/ + +#ifndef SBG_DTO_PW_MDINTERVAL_HPP +#define SBG_DTO_PW_MDINTERVAL_HPP + +#include + +#include "sbg/dto/multidim_inter_dto.hpp" + +namespace SBG { + +namespace API { + +// Container ------------------------------------------------------------------- + +typedef std::vector SetPieceDTOVector; +std::ostream &operator<<(std::ostream &out, const SetPieceDTOVector &ii); + +struct PWMDInterDTO { + member_class(SetPieceDTOVector, pieces); + + /** + * @brief Constructors don't check if intervals are disjoint (performance). + */ + PWMDInterDTO(); + PWMDInterDTO(Util::MD_NAT x); + PWMDInterDTO(IntervalDTO i); + PWMDInterDTO(SetPieceDTO mdi); + PWMDInterDTO(SetPieceDTOVector container); + + std::size_t size() const; + void emplace(SetPieceDTO mdi); + void emplaceBack(SetPieceDTO mdi); + + /** + * @brief Traditional set operations. + */ + bool isEmpty() const; + + friend std::ostream &operator<<(std::ostream &out, const PWMDInterDTO &i); +}; + +typedef PWMDInterDTO SetDTO; + +} // namespace API + +} // namespace SBG + +#endif