All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cpp-pistache-server.helpers-header.mustache Maven / Gradle / Ivy

There is a newer version: 7.9.0
Show newest version
{{>licenseInfo}}
/*
 * {{prefix}}Helpers.h
 *
 * This is the helper class for models and primitives
 */

#ifndef {{prefix}}Helpers_H_
#define {{prefix}}Helpers_H_

#include 
#include 
#include 
#include 
#include 

{{#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
    bool fromStringValue(const std::vector &inStr, std::vector &value){
        try{
            for(auto & item : inStr){
                T itemValue;
                if(fromStringValue(item, itemValue)){
                    value.push_back(itemValue);
                }
            }
        }
        catch(...){
            return false;
        }
        return value.size() > 0;
    }
    template
    bool fromStringValue(const std::string &inStr, std::vector &value, char separator = ','){
        std::vector 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_




© 2015 - 2024 Weber Informatics LLC | Privacy Policy