18#ifndef FLATBUFFERS_CODE_GENERATORS_H_
19#define FLATBUFFERS_CODE_GENERATORS_H_
45 CodeWriter(std::string pad = std::string()) : pad_(pad), cur_ident_lvl_(0), ignore_ident_(false)
59 void SetValue(
const std::string &key,
const std::string &value) { value_map_[key] = value; }
61 std::string
GetValue(
const std::string &key)
const
63 const auto it = value_map_.find(key);
64 return it == value_map_.end() ?
"" : it->second;
74 std::string
ToString()
const {
return stream_.str(); }
85 void SetPadding(
const std::string &padding) { pad_ = padding; }
88 std::map<std::string, std::string> value_map_;
89 std::stringstream stream_;
95 void AppendIdent(std::stringstream &stream);
104 const Namespace &ns,
const bool dasherize =
false);
113 std::string qualifying_start, std::string qualifying_separator,
114 std::string default_extension)
163extern void GenComment(
const std::vector<std::string> &dc, std::string *code_ptr,
173 virtual std::string
Value(
double v,
const std::string &src)
const = 0;
174 virtual std::string Inf(
double v)
const = 0;
175 virtual std::string NaN(
double v)
const = 0;
177 virtual std::string
Value(
float v,
const std::string &src)
const = 0;
178 virtual std::string Inf(
float v)
const = 0;
179 virtual std::string NaN(
float v)
const = 0;
181 template <
typename T> std::string GenFloatConstantImpl(
const FieldDef &field)
const;
188 const char *neg_inf_number);
191 std::string
Value(
double v,
const std::string &src)
const FLATBUFFERS_OVERRIDE;
192 std::string Inf(
double v)
const FLATBUFFERS_OVERRIDE;
193 std::string NaN(
double v)
const FLATBUFFERS_OVERRIDE;
195 std::string
Value(
float v,
const std::string &src)
const FLATBUFFERS_OVERRIDE;
196 std::string Inf(
float v)
const FLATBUFFERS_OVERRIDE;
197 std::string NaN(
float v)
const FLATBUFFERS_OVERRIDE;
199 const std::string nan_number_;
200 const std::string pos_inf_number_;
201 const std::string neg_inf_number_;
209 const char *nan_number,
const char *pos_inf_number,
210 const char *neg_inf_number =
"");
213 std::string
Value(
double v,
const std::string &src)
const FLATBUFFERS_OVERRIDE;
214 std::string Inf(
double v)
const FLATBUFFERS_OVERRIDE;
216 std::string NaN(
double v)
const FLATBUFFERS_OVERRIDE;
218 std::string
Value(
float v,
const std::string &src)
const FLATBUFFERS_OVERRIDE;
219 std::string Inf(
float v)
const FLATBUFFERS_OVERRIDE;
220 std::string NaN(
float v)
const FLATBUFFERS_OVERRIDE;
222 std::string MakeNaN(
const std::string &prefix)
const;
223 std::string MakeInf(
bool neg,
const std::string &prefix)
const;
225 const std::string double_prefix_;
226 const std::string single_prefix_;
227 const std::string nan_number_;
228 const std::string pos_inf_number_;
229 const std::string neg_inf_number_;
BaseGenerator & operator=(const BaseGenerator &)
virtual bool generate()=0
const std::string default_extension_
std::string WrapInNameSpace(const Namespace *ns, const std::string &name) const
static std::string LastNamespacePart(const Namespace &ns)
BaseGenerator(const BaseGenerator &)
std::string GetNameSpace(const Definition &def) const
static const char * FlatBuffersGeneratedWarning()
static std::string ToDasherizedCase(const std::string pascal_case)
static std::string FullNamespace(const char *separator, const Namespace &ns)
std::string GeneratedFileName(const std::string &path, const std::string &file_name, const IDLOptions &options) const
const std::string qualifying_separator_
std::string NamespaceDir(const Namespace &ns, const bool dasherize=false) const
BaseGenerator(const Parser &parser, const std::string &path, const std::string &file_name, std::string qualifying_start, std::string qualifying_separator, std::string default_extension)
const std::string qualifying_start_
std::string WrapInNameSpace(const Definition &def) const
const std::string & path_
virtual const Namespace * CurrentNameSpace() const
const std::string & file_name_
static std::string NamespaceDir(const Parser &parser, const std::string &path, const Namespace &ns, const bool dasherize=false)
void SetPadding(const std::string &padding)
CodeWriter(std::string pad=std::string())
void DecrementIdentLevel()
std::string ToString() const
void IncrementIdentLevel()
std::string GetValue(const std::string &key) const
void operator+=(std::string text)
void SetValue(const std::string &key, const std::string &value)
virtual ~FloatConstantGenerator()
std::string GenFloatConstant(const FieldDef &field) const
SimpleFloatConstantGenerator(const char *nan_number, const char *pos_inf_number, const char *neg_inf_number)
TypedFloatConstantGenerator(const char *double_prefix, const char *single_prefix, const char *nan_number, const char *pos_inf_number, const char *neg_inf_number="")
void GenComment(const std::vector< std::string > &dc, std::string *code_ptr, const CommentConfig *config, const char *prefix="")