-
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.
Add initial implementation of PWMapDTO and its converter.
- Loading branch information
Lucio Trincheri
committed
Dec 20, 2024
1 parent
be506e3
commit 5ff2ec8
Showing
5 changed files
with
263 additions
and
0 deletions.
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,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 <http://www.gnu.org/licenses/>. | ||
******************************************************************************/ | ||
|
||
#include "sbg/dto/converters/pw_map_dto_converter.hpp" | ||
#include "sbg/dto/converters/map_dto_converter.hpp" | ||
|
||
namespace SBG { | ||
|
||
namespace API { | ||
SBG::LIB::BasePWMap PWMapDTOConverter::convertToBasePWMap(const PWMapDTO& dto) { | ||
SBG::LIB::BasePWMap base_pw_map; | ||
for (const MapDTO& map_dto : dto.maps_) { | ||
base_pw_map.emplaceBack(MapDTOConverter::convertToBaseMap(map_dto)); | ||
} | ||
|
||
return base_pw_map; | ||
} | ||
|
||
SBG::LIB::CanonPWMap PWMapDTOConverter::convertToCanonPWMap(const PWMapDTO& dto) { | ||
SBG::LIB::CanonPWMap canon_pw_map; | ||
for (const MapDTO& map_dto : dto.maps_) { | ||
canon_pw_map.emplaceBack(MapDTOConverter::convertToCanonMap(map_dto)); | ||
} | ||
|
||
return canon_pw_map; | ||
} | ||
|
||
} // 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,56 @@ | ||
/** @file map_dto_converter.hpp | ||
@brief <b> PWMapDTOConverter implementation</b> | ||
The PWMapDTOConverter is used to convert a PWMapDTO | ||
to the corresponding piecewise SBG map representation. | ||
Currently, it can convert to SBG::LIB::PWMap<UnordSet> (BasePWMap) and | ||
SBG::LIB::PWMap<OrdSet> (CanonPWMap), but more conversions can be added. | ||
<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_PWMAP_CONVERTER_HPP | ||
#define SBG_DTO_PWMAP_CONVERTER_HPP | ||
|
||
#include "sbg/dto/pw_map_dto.hpp" | ||
#include "sbg/pw_map.hpp" | ||
|
||
namespace SBG { | ||
|
||
namespace API { | ||
|
||
class PWMapDTOConverter { | ||
public: | ||
/** | ||
* @brief Converts a PWMapDTO object to an actual SBG piecewise map | ||
* implementation (e.g., SBG::LIB::BasePWMap / SBG::LIB::CanonPWMap). | ||
* | ||
* @param dto: The PWMapDTO object to convert. | ||
* @return SBG::LIB::BasePWMap/CanonPWMap: The converted SBG piecewise map object. | ||
*/ | ||
static SBG::LIB::BasePWMap convertToBasePWMap(const PWMapDTO& dto); | ||
static SBG::LIB::CanonPWMap convertToCanonPWMap(const PWMapDTO& dto); | ||
}; | ||
|
||
} // namespace API | ||
|
||
} // namespace SBG | ||
|
||
#endif // SBG_DTO_PWMAP_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,92 @@ | ||
/******************************************************************************* | ||
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/pw_map_dto.hpp" | ||
|
||
namespace SBG { | ||
|
||
namespace API { | ||
|
||
// Type definitions ------------------------------------------------------------ | ||
|
||
std::ostream &operator<<(std::ostream &out, const MapDTOVector &ms) | ||
{ | ||
MapDTOVector aux = ms; | ||
int sz = aux.size(); | ||
|
||
out << "<<"; | ||
if (sz > 0) { | ||
auto it = aux.begin(); | ||
for (int i = 0; i < sz - 1; ++i) { | ||
if (!it->dom().isEmpty()) | ||
out << *it << ", "; | ||
++it; | ||
} | ||
if (!it->dom().isEmpty()) | ||
out << *it; | ||
} | ||
out << ">>"; | ||
|
||
return out; | ||
} | ||
|
||
// PWMapDTO ----------------------------------------------------------------------- | ||
|
||
PWMapDTO::PWMapDTO() : maps_() {} | ||
PWMapDTO::PWMapDTO(SetDTO s) : maps_() { | ||
if (!s.isEmpty()) { | ||
MapDTO map(s, ExpDTO(s.begin()->arity(), LExpDTO())); | ||
maps_.emplace_back(map); | ||
} | ||
} | ||
PWMapDTO::PWMapDTO(MapDTO map) : maps_() { | ||
if (!map.dom().isEmpty()) | ||
maps_.emplace_back(map); | ||
} | ||
PWMapDTO::PWMapDTO(MapDTOVector maps) : maps_(maps) {} | ||
|
||
member_imp(PWMapDTO, MapDTOVector, maps); | ||
|
||
void PWMapDTO::emplace(MapDTO map) { | ||
if (!map.dom().isEmpty()) | ||
maps_.emplace_back(map); | ||
} | ||
|
||
void PWMapDTO::emplaceBack(MapDTO map) | ||
{ | ||
if (!map.dom().isEmpty()) | ||
maps_.emplace_back(map); | ||
} | ||
|
||
// PWMapDTO functions ------------------------------------------------------------- | ||
|
||
bool PWMapDTO::isEmpty() const { return maps_.empty(); } | ||
|
||
// std::ostream operators ------------------------------------------------------ | ||
|
||
std::ostream &operator<<(std::ostream &out, const PWMapDTO &pw) | ||
{ | ||
out << pw.maps(); | ||
|
||
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,67 @@ | ||
/** @file pw_map.hpp | ||
@brief <b>Piecewise map DTO implementation</b> | ||
<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_PWMAP_HPP | ||
#define SBG_DTO_PWMAP_HPP | ||
|
||
#include "sbg/dto/map_dto.hpp" | ||
|
||
namespace SBG { | ||
|
||
namespace API { | ||
|
||
class PWMapDTOConverter; | ||
|
||
/** | ||
* @brief Unordered collection of map DTOs. | ||
*/ | ||
|
||
using MapDTOVector = std::vector<MapDTO>; // ex MapSet. | ||
std::ostream &operator<<(std::ostream &out, const MapDTOVector &ms); | ||
|
||
struct PWMapDTO { | ||
member_class(MapDTOVector, maps); | ||
|
||
PWMapDTO(); | ||
PWMapDTO(SetDTO s); // Create id with s as domain | ||
PWMapDTO(MapDTO m); | ||
PWMapDTO(MapDTOVector maps); | ||
|
||
std::size_t size() const; | ||
void emplace(MapDTO m); | ||
void emplaceBack(MapDTO m); | ||
|
||
/** | ||
* @brief Traditional map operations. | ||
*/ | ||
bool isEmpty() const; | ||
|
||
friend std::ostream &operator<<(std::ostream &out, const PWMapDTO &pw); | ||
friend class PWMapDTOConverter; | ||
}; | ||
|
||
} // namespace API | ||
|
||
} // namespace SBG | ||
|
||
#endif |