MCPcopy Create free account
hub / github.com/catboost/catboost / GenerateEnum

Function GenerateEnum

tools/enum_parser/enum_parser/main.cpp:136–409  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

134}
135
136void GenerateEnum(
137 const TEnumParser::TEnum& en,
138 IOutputStream& out,
139 IOutputStream* jsonEnumOut = nullptr,
140 IOutputStream* headerOutPtr = nullptr
141) {
142 TStringStream jEnum;
143 OpenMap(jEnum);
144
145 size_t count = en.Items.size();
146 OutKey(jEnum, "count", count);
147 const TString name = TEnumParser::ScopeStr(en.Scope) + en.CppName;
148 OutKey(jEnum, "full_name", name);
149 OutKey(jEnum, "cpp_name", en.CppName);
150 TStringStream scopeJson;
151 OpenArray(scopeJson);
152 for (const auto& scopeItem : en.Scope) {
153 OutItem(scopeJson, scopeItem);
154 }
155 FinishItems(scopeJson);
156 CloseArray(scopeJson);
157
158 OutKey(jEnum, "scope", scopeJson.Str(), false);
159 OutKey(jEnum, "enum_class", en.EnumClass);
160
161 TEnumParser::TScope outerScope = en.Scope;
162 if (en.EnumClass) {
163 outerScope.push_back(en.CppName);
164 }
165
166 TString outerScopeStr = TEnumParser::ScopeStr(outerScope);
167
168 TString cName = name;
169 SubstGlobal(cName, "::", "");
170
171 out << "// I/O for " << name << "\n";
172
173 TString nsName = "N" + cName + "Private";
174
175 out << "namespace { namespace " << nsName << " {\n";
176
177 TVector<TString> nameInitializerPairs;
178 TVector<std::pair<TString, TString>> valueInitializerPairsUnsorted; // data, sort_key
179 TVector<TString> cppNamesInitializer;
180
181 TStringStream jItems;
182 OpenArray(jItems);
183
184 for (const auto& it : en.Items) {
185 TStringStream jEnumItem;
186 OpenMap(jEnumItem);
187
188 OutKey(jEnumItem, "cpp_name", it.CppName);
189 OutKey(jEnumItem, "value", it.Value);
190 OutKey(jEnumItem, "comment_text", it.CommentText);
191
192 TStringStream jAliases;
193 OpenArray(jAliases);

Callers 1

mainFunction · 0.70

Calls 15

OpenMapFunction · 0.85
OutKeyFunction · 0.85
OpenArrayFunction · 0.85
OutItemFunction · 0.85
FinishItemsFunction · 0.85
CloseArrayFunction · 0.85
WrapStringBufFunction · 0.85
CloseMapFunction · 0.85
StableSortByFunction · 0.85
ReserveFunction · 0.85
SubstGlobalFunction · 0.50
UnescapeCFunction · 0.50

Tested by

no test coverage detected