-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iss-25: Add initial IntervalDTO, MultiDimInterDTO, and their associat…
…ed converters (#37) * Fix missing <vector> include in util/defs.hpp header * Initial IntervalDTO implementation * Change namespace from DTO to API * Initial IntervalDTOConverter implementation * Re-add isEmpty method for future MultiDimInter implementation * Initial implementation of MultiDimInterDTO and it's converter. Separate makefiles * Remove include --------- Co-authored-by: Lucio Trincheri <[email protected]>
- Loading branch information
1 parent
f17b50a
commit 4b547a4
Showing
11 changed files
with
456 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# DTO Sources | ||
DTO_SRC := \ | ||
$(DTO_ROOT)/interval_dto.cpp \ | ||
$(DTO_ROOT)/multidim_inter_dto.cpp \ | ||
$(CONVERTERS_ROOT)/interval_dto_converter.cpp \ | ||
$(CONVERTERS_ROOT)/multidim_inter_dto_converter.cpp | ||
|
||
# DTO Objects | ||
DTO_OBJ=$(addprefix $(BUILD_DIR)/, $(DTO_SRC:.cpp=.o)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/******************************************************************************* | ||
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 <http://www.gnu.org/licenses/>. | ||
******************************************************************************/ | ||
|
||
#include "sbg/dto/converters/interval_dto_converter.hpp" | ||
|
||
namespace SBG { | ||
|
||
namespace API { | ||
|
||
SBG::LIB::Interval IntervalDTOConverter::convertToInterval(const IntervalDTO& dto) { | ||
return SBG::LIB::Interval(dto.begin_, dto.step_, dto.end_); | ||
} | ||
|
||
} // namespace API | ||
|
||
} // namespace SBG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** @file interval_dto_converter.hpp | ||
@brief <b>IntervalDTOConverter implementation</b> | ||
The IntervalDTOConverter provides the methods to convert an IntervalDTO to | ||
the corresponding interval representation. Currently, it can convert to | ||
LIB::Interval, but more conversions can/will be added in the future. | ||
<hr> | ||
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 <http://www.gnu.org/licenses/>. | ||
******************************************************************************/ | ||
|
||
#ifndef SBG_DTO_INTERVAL_CONVERTER_HPP | ||
#define SBG_DTO_INTERVAL_CONVERTER_HPP | ||
|
||
#include "sbg/dto/interval_dto.hpp" | ||
#include "sbg/interval.hpp" | ||
|
||
namespace SBG { | ||
|
||
namespace API { | ||
|
||
class IntervalDTOConverter { | ||
public: | ||
/** | ||
* @brief Converts an IntervalDTO object to an actual interval implementation (e.g., LIB::Interval). | ||
* | ||
* @param dto The IntervalDTO object to convert. | ||
* @return SBG::LIB::Interval The converted interval object. | ||
*/ | ||
static SBG::LIB::Interval convertToInterval(const IntervalDTO& dto); | ||
}; | ||
|
||
} // namespace API | ||
|
||
} // namespace SBG | ||
|
||
#endif // SBG_DTO_INTERVAL_CONVERTER_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/******************************************************************************* | ||
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 <http://www.gnu.org/licenses/>. | ||
******************************************************************************/ | ||
|
||
#include "sbg/dto/converters/interval_dto_converter.hpp" | ||
#include "sbg/dto/converters/multidim_inter_dto_converter.hpp" | ||
#include "sbg/dto/interval_dto.hpp" | ||
#include "sbg/dto/multidim_inter_dto.hpp" | ||
#include "sbg/multidim_inter.hpp" | ||
#include "sbg/interval.hpp" | ||
|
||
namespace SBG { | ||
|
||
namespace API { | ||
|
||
SBG::LIB::MultiDimInter MultiDimInterDTOConverter::convertToMultiDimInter(const MultiDimInterDTO& dto) { | ||
SBG::LIB::InterVector intervals; | ||
intervals.reserve(dto.intervals_.size()); | ||
|
||
std::transform(dto.intervals_.begin(), dto.intervals_.end(), intervals.begin(), | ||
[](const IntervalDTO& intervalDTO) { | ||
return IntervalDTOConverter::convertToInterval(intervalDTO); | ||
}); | ||
|
||
return SBG::LIB::MultiDimInter(intervals); | ||
} | ||
|
||
} // namespace API | ||
|
||
} // namespace SBG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** @file interval_dto_converter.hpp | ||
@brief <b>MultiDimInterDTOConverter implementation</b> | ||
The MultiDimInterDTOConverter provides the methods to convert an MultiDimInterDTO | ||
to the corresponding multidimensional interval representation. Currently, it can | ||
convert to LIB::MultiDimInter, but more conversions can/will be added in the future. | ||
<hr> | ||
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 <http://www.gnu.org/licenses/>. | ||
******************************************************************************/ | ||
|
||
#ifndef SBG_DTO_MULTIDIM_INTERVAL_CONVERTER_HPP | ||
#define SBG_DTO_MULTIDIM_INTERVAL_CONVERTER_HPP | ||
|
||
#include "sbg/dto/multidim_inter_dto.hpp" | ||
#include "sbg/multidim_inter.hpp" | ||
|
||
namespace SBG { | ||
|
||
namespace API { | ||
|
||
class MultiDimInterDTOConverter { | ||
public: | ||
/** | ||
* @brief Converts a MultiDimInterDTO object to an actual multidimensional | ||
* interval implementation (e.g., SBG::LIB::MultiDimInter). | ||
* | ||
* @param dto The MultiDimInterDTO object to convert. | ||
* @return SBG::LIB::MultiDimInter The converted interval object. | ||
*/ | ||
static SBG::LIB::MultiDimInter convertToMultiDimInter(const MultiDimInterDTO& dto); | ||
}; | ||
|
||
} // namespace API | ||
|
||
} // namespace SBG | ||
|
||
#endif // SBG_DTO_MULTIDIM_INTERVAL_CONVERTER_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/******************************************************************************* | ||
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 <http://www.gnu.org/licenses/>. | ||
******************************************************************************/ | ||
|
||
#include "sbg/dto/interval_dto.hpp" | ||
|
||
namespace SBG { | ||
|
||
namespace API { | ||
|
||
IntervalDTO::IntervalDTO() : begin_(1), step_(1), end_(0) {} | ||
IntervalDTO::IntervalDTO(const NAT &x) : begin_(x), step_(1), end_(x) {} | ||
IntervalDTO::IntervalDTO(const NAT &begin, const NAT &step, const NAT &end) | ||
: begin_(begin), step_(step), end_(end) | ||
{ | ||
} | ||
|
||
// Set functions --------------------------------------------------------------- | ||
bool IntervalDTO::isEmpty() const { return end_ < begin_; } | ||
|
||
// Operators ------------------------------------------------------------------- | ||
std::ostream &operator<<(std::ostream &out, const IntervalDTO &i) | ||
{ | ||
out << "[" << Util::toStr(i.begin_); | ||
if (i.step_ != 1) | ||
out << ":" << Util::toStr(i.step_); | ||
out << ":" << Util::toStr(i.end_) << "]"; | ||
|
||
return out; | ||
} | ||
|
||
} // namespace API | ||
|
||
} // namespace SBG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** @file interval_dto.hpp | ||
@brief <b>IntervalDTO implementation</b> | ||
The IntervalDTO class is a Data Transfer Object (DTO) for parsing raw | ||
interval data, such as from JSON. It is designed for conversion into | ||
concrete implementations like Interval via a dedicated converter. | ||
<hr> | ||
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 <http://www.gnu.org/licenses/>. | ||
******************************************************************************/ | ||
|
||
#ifndef SBG_DTO_INTERVAL_HPP | ||
#define SBG_DTO_INTERVAL_HPP | ||
|
||
#include "util/defs.hpp" | ||
|
||
namespace SBG { | ||
|
||
namespace API { | ||
|
||
class IntervalDTOConverter; | ||
|
||
using NAT = Util::NAT; | ||
|
||
struct IntervalDTO { | ||
|
||
IntervalDTO(); | ||
IntervalDTO(const NAT &x); | ||
IntervalDTO(const NAT &begin, const NAT &step, const NAT &end); | ||
|
||
/** | ||
* @brief Traditional set operations. | ||
*/ | ||
bool isEmpty() const; | ||
|
||
private: | ||
NAT begin_; | ||
NAT step_; | ||
NAT end_; | ||
|
||
friend std::ostream &operator<<(std::ostream &out, const IntervalDTO &i); | ||
friend class IntervalDTOConverter; | ||
}; | ||
|
||
} // namespace API | ||
|
||
} // namespace SBG | ||
|
||
#endif |
Oops, something went wrong.