Program Listing for File codegen_base.h#
↰ Return to documentation for file (sdv_dbc_util\codegen_base.h)
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Erik Verhoeven - initial API and implementation
********************************************************************************/
#ifndef CODEGEN_BASE_H
#define CODEGEN_BASE_H
#include <map>
#include <string>
#include <sstream>
#include <cmath>
class CCodeGeneratorBase
{
protected:
typedef std::map<std::string, std::string> CKeywordMap;
static std::string ReplaceKeywords(const std::string& rssStr, const CKeywordMap& rmapKeywords, char cMarker = '%');
template <typename T>
static std::string to_string(const T& rtVar)
{
std::ostringstream sstream;
sstream << rtVar;
return sstream.str();
}
static std::string to_string(const double& rdVar)
{
std::ostringstream sstream;
sstream << rdVar;
if (std::round(rdVar) == rdVar) sstream << ".0";
return sstream.str();
}
static std::string to_string(const float& rfVar)
{
std::ostringstream sstream;
sstream << rfVar;
if (std::round(rfVar) == rfVar) sstream << ".0";
sstream << "f";
return sstream.str();
}
};
#endif // !defined CODEGEN_BASE_H