-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[c++ pistache server] Support basic query handling (#943)
Support basic query handling Add helpers for primitive de-serialization Remove warnings due to unneeded commas Deserialize basic types in queries Add dependencies chain for external libraries Fixes wrong parameter passed to API
- Loading branch information
1 parent
3cfcf77
commit 3d4c3c5
Showing
21 changed files
with
413 additions
and
26 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
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
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
64 changes: 64 additions & 0 deletions
64
modules/openapi-generator/src/main/resources/cpp-pistache-server/helpers-header.mustache
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,64 @@ | ||
{{>licenseInfo}} | ||
/* | ||
* {{prefix}}Helpers.h | ||
* | ||
* This is the helper class for models and primitives | ||
*/ | ||
|
||
#ifndef {{prefix}}Helpers_H_ | ||
#define {{prefix}}Helpers_H_ | ||
|
||
#include <ctime> | ||
#include <string> | ||
#include <sstream> | ||
#include <vector> | ||
#include <map> | ||
|
||
{{#helpersNamespaceDeclarations}} | ||
namespace {{this}} { | ||
{{/helpersNamespaceDeclarations}} | ||
|
||
std::string toStringValue(const std::string &value); | ||
std::string toStringValue(const int32_t &value); | ||
std::string toStringValue(const int64_t &value); | ||
std::string toStringValue(const bool &value); | ||
std::string toStringValue(const float &value); | ||
std::string toStringValue(const double &value); | ||
|
||
bool fromStringValue(const std::string &inStr, std::string &value); | ||
bool fromStringValue(const std::string &inStr, int32_t &value); | ||
bool fromStringValue(const std::string &inStr, int64_t &value); | ||
bool fromStringValue(const std::string &inStr, bool &value); | ||
bool fromStringValue(const std::string &inStr, float &value); | ||
bool fromStringValue(const std::string &inStr, double &value); | ||
template<typename T> | ||
bool fromStringValue(const std::vector<std::string> &inStr, std::vector<T> &value){ | ||
try{ | ||
for(auto & item : inStr){ | ||
T itemValue; | ||
if(fromStringValue(item, itemValue)){ | ||
value.push_back(itemValue); | ||
} | ||
} | ||
} | ||
catch(...){ | ||
return false; | ||
} | ||
return value.size() > 0; | ||
} | ||
template<typename T> | ||
bool fromStringValue(const std::string &inStr, std::vector<T> &value, char separator = ','){ | ||
std::vector<std::string> inStrings; | ||
std::istringstream f(inStr); | ||
std::string s; | ||
while (std::getline(f, s, separator)) { | ||
inStrings.push_back(s); | ||
} | ||
return fromStringValue(inStrings, value); | ||
} | ||
|
||
{{#helpersNamespaceDeclarations}} | ||
} | ||
{{/helpersNamespaceDeclarations}} | ||
|
||
#endif // {{prefix}}Helpers_H_ |
86 changes: 86 additions & 0 deletions
86
modules/openapi-generator/src/main/resources/cpp-pistache-server/helpers-source.mustache
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,86 @@ | ||
{{>licenseInfo}} | ||
#include "{{prefix}}Helpers.h" | ||
|
||
{{#helpersNamespaceDeclarations}} | ||
namespace {{this}} { | ||
{{/helpersNamespaceDeclarations}} | ||
|
||
|
||
std::string toStringValue(const std::string &value){ | ||
return std::string(value); | ||
} | ||
|
||
std::string toStringValue(const int32_t &value){ | ||
return std::to_string(value); | ||
} | ||
|
||
std::string toStringValue(const int64_t &value){ | ||
return std::to_string(value); | ||
} | ||
|
||
std::string toStringValue(const bool &value){ | ||
return value?std::string("true"):std::string("false"); | ||
} | ||
|
||
std::string toStringValue(const float &value){ | ||
return std::to_string(value); | ||
} | ||
|
||
std::string toStringValue(const double &value){ | ||
return std::to_string(value); | ||
} | ||
|
||
bool fromStringValue(const std::string &inStr, std::string &value){ | ||
value = std::string(inStr); | ||
return true; | ||
} | ||
|
||
bool fromStringValue(const std::string &inStr, int32_t &value){ | ||
try { | ||
value = std::stoi( inStr ); | ||
} | ||
catch (const std::invalid_argument) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool fromStringValue(const std::string &inStr, int64_t &value){ | ||
try { | ||
value = std::stol( inStr ); | ||
} | ||
catch (const std::invalid_argument) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool fromStringValue(const std::string &inStr, bool &value){ | ||
bool result = true; | ||
inStr == "true"?value = true: inStr == "false"?value = false: result = false; | ||
return result; | ||
} | ||
|
||
bool fromStringValue(const std::string &inStr, float &value){ | ||
try { | ||
value = std::stof( inStr ); | ||
} | ||
catch (const std::invalid_argument) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool fromStringValue(const std::string &inStr, double &value){ | ||
try { | ||
value = std::stod( inStr ); | ||
} | ||
catch (const std::invalid_argument) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
{{#helpersNamespaceDeclarations}} | ||
} | ||
{{/helpersNamespaceDeclarations}} |
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
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
Oops, something went wrong.