From 53dc6213fa801c738d2714e09bc5470a1da1d9a5 Mon Sep 17 00:00:00 2001 From: Sameer Agarwal Date: Thu, 18 Apr 2019 07:54:37 -0700 Subject: [PATCH] Add some missing string-to-enum-to-string convertors. LoggingTypeToString StringtoLoggingType DumpFormatTypeToString StringtoDumpFormatType Fixes https://github.com/ceres-solver/ceres-solver/issues/470 Change-Id: Ic7eb98dada008c869a686fbdf2c7ff9ab81dad54 --- include/ceres/types.h | 6 ++++++ internal/ceres/types.cc | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/ceres/types.h b/include/ceres/types.h index d01e921bb..4473ad50b 100644 --- a/include/ceres/types.h +++ b/include/ceres/types.h @@ -498,6 +498,12 @@ CERES_EXPORT bool StringToNumericDiffMethodType( std::string value, NumericDiffMethodType* type); +CERES_EXPORT const char* LoggingTypeToString(LoggingType type); +CERES_EXPORT bool StringtoLoggingType(std::string value, LoggingType* type); + +CERES_EXPORT const char* DumpFormatTypeToString(DumpFormatType type); +CERES_EXPORT bool StringtoDumpFormatType(std::string value, LoggingType* type); + CERES_EXPORT const char* TerminationTypeToString(TerminationType type); CERES_EXPORT bool IsSchurType(LinearSolverType type); diff --git a/internal/ceres/types.cc b/internal/ceres/types.cc index 932ec7d70..469141452 100644 --- a/internal/ceres/types.cc +++ b/internal/ceres/types.cc @@ -336,6 +336,39 @@ const char* TerminationTypeToString(TerminationType type) { } } +const char* LoggingTypeToString(LoggingType type) { + switch (type) { + CASESTR(SILENT); + CASESTR(PER_MINIMIZER_ITERATION); + default: + return "UNKNOWN"; + } +} + +bool StringtoLoggingType(std::string value, LoggingType* type) { + UpperCase(&value); + STRENUM(SILENT); + STRENUM(PER_MINIMIZER_ITERATION); + return false; +} + + +const char* DumpFormatTypeToString(DumpFormatType type) { + switch (type) { + CASESTR(CONSOLE); + CASESTR(TEXTFILE); + default: + return "UNKNOWN"; + } +} + +bool StringtoDumpFormatType(std::string value, DumpFormatType* type) { + UpperCase(&value); + STRENUM(CONSOLE); + STRENUM(TEXTFILE); + return false; +} + #undef CASESTR #undef STRENUM