Skip to content

Commit

Permalink
Introduce fmt::format dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonMarechal25 committed Jan 17, 2025
1 parent db3c016 commit e4db64e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/cpp/benders/benders_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ target_include_directories(benders_core
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

find_package(fmt REQUIRED)
target_link_libraries(benders_core
PUBLIC
antaresXpansion::helpers
antaresXpansion::output_core
antaresXpansion::solvers
${JSONCPP_LIB}
antaresXpansion::outer_loop_lib
fmt::fmt
)

target_link_libraries(benders_core PRIVATE TBB::tbb)
Expand Down
18 changes: 18 additions & 0 deletions src/cpp/benders/benders_core/ProblemFormatStream.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "antares-xpansion/benders/benders_core/ProblemFormatStream.h"

auto fmt::formatter<ProblemsFormat>::format(ProblemsFormat problems_format,
format_context &ctx) const -> format_context::iterator
{
string_view result = "Unknown";
switch (problems_format) {
case ProblemsFormat::MPS_FILE:
result = "MPS_FILE";
break;
case ProblemsFormat::SAVED_FILE:
result = "SAVED_FILE";
break;
default:
result = "Unknown";
}
return formatter<string_view>::format(result, ctx);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <stdexcept>
#include <string>

enum class ProblemsFormat { MPS_FILE, SAVED_FILE };

inline ProblemsFormat problemsFormatFromString(const std::string &str) {
Expand All @@ -12,18 +13,4 @@ inline ProblemsFormat problemsFormatFromString(const std::string &str) {
} else {
throw std::runtime_error("Unknown ProblemsFormat: " + str);
}
}

inline std::ostream &operator<<(std::ostream &stream, ProblemsFormat const &rhs) {
switch (rhs) {
case ProblemsFormat::MPS_FILE:
stream << "MPS_FILE";
break;
case ProblemsFormat::SAVED_FILE:
stream << "SAVED_FILE";
break;
default:
stream << "Unknown";
}
return stream;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include <fmt/format.h>

#include <ostream>

#include "ProblemFormat.h"

inline std::ostream &operator<<(std::ostream &stream,
ProblemsFormat const &rhs) {
switch (rhs) {
case ProblemsFormat::MPS_FILE:
stream << "MPS_FILE";
break;
case ProblemsFormat::SAVED_FILE:
stream << "SAVED_FILE";
break;
default:
stream << "Unknown";
}
return stream;
}

template <>
struct fmt::formatter<ProblemsFormat> : formatter<string_view> {
// parse is inherited from formatter<string_view>.

auto format(ProblemsFormat problems_format,
format_context &ctx) const -> format_context::iterator;
};
3 changes: 2 additions & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"zlib"
]
},
"tbb"
"tbb",
"fmt"
],
"overrides": [
{
Expand Down

0 comments on commit e4db64e

Please sign in to comment.