Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iss-25: Add initial LExpDTO, MDLExpDTO, MapDTO, PWMapDTO and their associated converters #40

Merged
merged 6 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions sbg/dto/Makefile.include
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
# DTO Sources
DTO_SRC := \
$(DTO_ROOT)/interval_dto.cpp \
$(DTO_ROOT)/lexp_dto.cpp \
$(DTO_ROOT)/map_dto.cpp \
$(DTO_ROOT)/multidim_inter_dto.cpp \
$(DTO_ROOT)/multidim_lexp_dto.cpp \
$(DTO_ROOT)/pw_map_dto.cpp \
$(DTO_ROOT)/pw_mdinter_dto.cpp \
$(CONVERTERS_ROOT)/interval_dto_converter.cpp \
$(CONVERTERS_ROOT)/lexp_dto_converter.cpp \
$(CONVERTERS_ROOT)/map_dto_converter.cpp \
$(CONVERTERS_ROOT)/multidim_inter_dto_converter.cpp \
$(CONVERTERS_ROOT)/multidim_lexp_dto_converter.cpp \
$(CONVERTERS_ROOT)/pw_map_dto_converter.cpp \
$(CONVERTERS_ROOT)/pw_mdinter_dto_converter.cpp

# DTO Objects
Expand Down
31 changes: 31 additions & 0 deletions sbg/dto/converters/lexp_dto_converter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************

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/lexp_dto_converter.hpp"

namespace SBG {

namespace API {
SBG::LIB::LExp LExpDTOConverter::convertToLExp(const LExpDTO& dto) {
return SBG::LIB::LExp(dto.slope_, dto.offset_);
}

} // namespace API

} // namespace SBG
55 changes: 55 additions & 0 deletions sbg/dto/converters/lexp_dto_converter.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/** @file lexp_dto_converter.hpp

@brief <b> LExpDTOConverter implementation</b>

The LExpDTOConverter is used to convert a LExpDTO to
the corresponding linear expression representation.
Currently, it can convert to SBG::LIB::LExp,
but more conversions can 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_LEXP_CONVERTER_HPP
#define SBG_DTO_LEXP_CONVERTER_HPP

#include "sbg/dto/lexp_dto.hpp"
#include "sbg/lexp.hpp"

namespace SBG {

namespace API {

class LExpDTOConverter {
public:
/**
* @brief Converts a LExpDTO object to an actual linear
* expression implementation (e.g., SBG::LIB::LExp).
*
* @param dto: The LExpDTO object to convert.
* @return SBG::LIB::LExp: The converted linear expression object.
*/
static SBG::LIB::LExp convertToLExp(const LExpDTO& dto);
};

} // namespace API

} // namespace SBG

#endif // SBG_DTO_LEXP_CONVERTER_HPP
37 changes: 37 additions & 0 deletions sbg/dto/converters/map_dto_converter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*******************************************************************************

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/map_dto_converter.hpp"
#include "sbg/dto/converters/pw_mdinter_dto_converter.hpp"
#include "sbg/dto/converters/multidim_lexp_dto_converter.hpp"

namespace SBG {

namespace API {
SBG::LIB::BaseMap SBGMapDTOConverter::convertToBaseMap(const MapDTO& dto) {
return SBG::LIB::BaseMap(SetDTOConverter::convertToUnordSet(dto.dom_), ExpDTOConverter::convertToExp(dto.exp_));
}

SBG::LIB::CanonMap SBGMapDTOConverter::convertToCanonMap(const MapDTO& dto) {
return SBG::LIB::CanonMap(SetDTOConverter::convertToOrdSet(dto.dom_), ExpDTOConverter::convertToExp(dto.exp_));
}

} // namespace API

} // namespace SBG
58 changes: 58 additions & 0 deletions sbg/dto/converters/map_dto_converter.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/** @file map_dto_converter.hpp

@brief <b> SBGMapDTOConverter implementation</b>

The SBGMapDTOConverter is used to convert a SBGMapDTO (MapDTO)
to the corresponding SBG map representation.
Currently, it can convert to SBG::LIB::SBGMap<UnordSet> (BaseMap) and
SBG::LIB::SBGMap<OrdSet> (CanonMap), 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_MAP_CONVERTER_HPP
#define SBG_DTO_MAP_CONVERTER_HPP

#include "sbg/dto/map_dto.hpp"
#include "sbg/map.hpp"

namespace SBG {

namespace API {

class SBGMapDTOConverter {
public:
/**
* @brief Converts a MapDTO object to an actual SBG map implementation
* (e.g., SBG::LIB::BaseMap / SBG::LIB::CanonMap).
*
* @param dto: The MapDTO object to convert.
* @return SBG::LIB::BaseMap/CanonMap: The converted SBG map object.
*/
static SBG::LIB::BaseMap convertToBaseMap(const MapDTO& dto);
static SBG::LIB::CanonMap convertToCanonMap(const MapDTO& dto);
};

typedef SBGMapDTOConverter MapDTOConverter;

} // namespace API

} // namespace SBG

#endif // SBG_DTO_MAP_CONVERTER_HPP
37 changes: 37 additions & 0 deletions sbg/dto/converters/multidim_lexp_dto_converter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*******************************************************************************

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/multidim_lexp_dto_converter.hpp"
#include "sbg/dto/converters/lexp_dto_converter.hpp"

namespace SBG {

namespace API {
SBG::LIB::Exp MDLExpDTOConverter::convertToExp(const ExpDTO& dto) {
SBG::LIB::Exp exp;
for (const LExpDTO& lexp_dto : dto.exps_) {
exp.emplaceBack(LExpDTOConverter::convertToLExp(lexp_dto));
}

return exp;
}

} // namespace API

} // namespace SBG
57 changes: 57 additions & 0 deletions sbg/dto/converters/multidim_lexp_dto_converter.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/** @file multidim_lexp_dto_converter.hpp

@brief <b> MDLExpDTOConverter implementation</b>

The MDLExpDTOConverter is used to convert a MDLExpDTO (ExpDTO) to the
corresponding multi-dimensional linear expression representation.
Currently, it can convert to SBG::LIB::MDLExp (Exp),
but more conversions can 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_MDLEXP_CONVERTER_HPP
#define SBG_DTO_MDLEXP_CONVERTER_HPP

#include "sbg/dto/multidim_lexp_dto.hpp"
#include "sbg/multidim_lexp.hpp"

namespace SBG {

namespace API {

class MDLExpDTOConverter {
public:
/**
* @brief Converts a ExpDTO object to an actual multi-dimensional
* linear expression implementation (e.g., SBG::LIB::Exp).
*
* @param dto: The ExpDTO object to convert.
* @return SBG::LIB::Exp: The converted multi-dimensional linear expression object.
*/
static SBG::LIB::Exp convertToExp(const ExpDTO& dto);
};

typedef MDLExpDTOConverter ExpDTOConverter;

} // namespace API

} // namespace SBG

#endif // SBG_DTO_MDLEXP_CONVERTER_HPP
46 changes: 46 additions & 0 deletions sbg/dto/converters/pw_map_dto_converter.cpp
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
Loading