2017-05-26 04:48:44 +08:00
|
|
|
|
/*
|
|
|
|
|
* cpp.cs
|
|
|
|
|
*
|
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
|
*
|
|
|
|
|
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
|
2018-02-22 02:25:11 +08:00
|
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
2018-02-22 02:25:11 +08:00
|
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-02-22 02:25:11 +08:00
|
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace vexillographer
|
|
|
|
|
{
|
|
|
|
|
class cpp : BindingWriter
|
|
|
|
|
{
|
|
|
|
|
private static void writeCppEnum(TextWriter outFile, Scope scope, IEnumerable<Option> options)
|
|
|
|
|
{
|
|
|
|
|
outFile.WriteLine("struct FDB{0}s {{", scope.ToString());
|
|
|
|
|
outFile.WriteLine("\tfriend class FDBOptionInfoMap<FDB{0}s>;",scope.ToString());
|
|
|
|
|
outFile.WriteLine();
|
2019-12-04 10:07:31 +08:00
|
|
|
|
outFile.WriteLine("\tenum Option : int {");
|
2017-05-26 04:48:44 +08:00
|
|
|
|
outFile.WriteLine(string.Join(",\n\n", options.Select(f => c.getCLine(f, "\t\t", "")).ToArray()));
|
|
|
|
|
outFile.WriteLine("\t};");
|
|
|
|
|
outFile.WriteLine();
|
|
|
|
|
outFile.WriteLine("\tstatic FDBOptionInfoMap<FDB{0}s> optionInfo;", scope.ToString());
|
|
|
|
|
outFile.WriteLine();
|
|
|
|
|
outFile.WriteLine("private:");
|
|
|
|
|
outFile.WriteLine("\tstatic void init();");
|
|
|
|
|
outFile.WriteLine("};");
|
|
|
|
|
outFile.WriteLine("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string getCInfoLine(Option o, string indent, string structName)
|
|
|
|
|
{
|
2021-09-18 06:47:51 +08:00
|
|
|
|
return String.Format("{0}ADD_OPTION_INFO({1}, {2}, \"{2}\", \"{3}\", \"{4}\", {5}, {6}, {7}, {8}, FDBOptionInfo::ParamType::{9})",
|
2021-09-17 08:21:14 +08:00
|
|
|
|
indent, structName, o.name.ToUpper(), o.comment, o.getParameterComment(), (o.paramDesc != null).ToString().ToLower(),
|
|
|
|
|
o.hidden.ToString().ToLower(), o.persistent.ToString().ToLower(), o.defaultFor, o.paramType);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void writeCppInfo(TextWriter outFile, Scope scope, IEnumerable<Option> options)
|
|
|
|
|
{
|
|
|
|
|
outFile.WriteLine("FDBOptionInfoMap<FDB{0}s> FDB{0}s::optionInfo;", scope.ToString());
|
|
|
|
|
outFile.WriteLine();
|
|
|
|
|
outFile.WriteLine("void FDB{0}s::init() {{", scope.ToString());
|
|
|
|
|
outFile.WriteLine(string.Join("\n", options.Select(f => getCInfoLine(f, "\t", "FDB{0}s")).ToArray()), scope.ToString());
|
|
|
|
|
outFile.WriteLine("}");
|
|
|
|
|
outFile.WriteLine();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void writeFiles(string fileName, IEnumerable<Option> options)
|
|
|
|
|
{
|
|
|
|
|
using (var header = System.IO.File.Open(fileName + ".h",
|
|
|
|
|
System.IO.FileMode.Create, System.IO.FileAccess.Write))
|
|
|
|
|
{
|
|
|
|
|
TextWriter outFile = new StreamWriter(header);
|
|
|
|
|
outFile.NewLine = "\n";
|
|
|
|
|
outFile.WriteLine("#ifndef FDBCLIENT_FDBOPTIONS_G_H");
|
|
|
|
|
outFile.WriteLine("#define FDBCLIENT_FDBOPTIONS_G_H");
|
|
|
|
|
outFile.WriteLine("#pragma once");
|
|
|
|
|
outFile.WriteLine();
|
2018-10-20 01:30:13 +08:00
|
|
|
|
outFile.WriteLine("#include \"fdbclient/FDBOptions.h\"");
|
2017-05-26 04:48:44 +08:00
|
|
|
|
outFile.WriteLine();
|
|
|
|
|
foreach (Scope s in Enum.GetValues(typeof(Scope)))
|
|
|
|
|
{
|
|
|
|
|
writeCppEnum(outFile, s, options.Where(o => o.scope == s));
|
|
|
|
|
}
|
|
|
|
|
outFile.WriteLine("");
|
|
|
|
|
outFile.WriteLine("#endif");
|
|
|
|
|
outFile.Flush();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using (var cFile = System.IO.File.Open(fileName + ".cpp",
|
|
|
|
|
System.IO.FileMode.Create, System.IO.FileAccess.Write))
|
|
|
|
|
{
|
|
|
|
|
TextWriter outFile = new StreamWriter(cFile);
|
|
|
|
|
outFile.NewLine = "\n";
|
2018-10-20 01:30:13 +08:00
|
|
|
|
outFile.WriteLine("#include \"fdbclient/FDBOptions.g.h\"");
|
2017-05-26 04:48:44 +08:00
|
|
|
|
outFile.WriteLine();
|
|
|
|
|
foreach (Scope s in Enum.GetValues(typeof(Scope)))
|
|
|
|
|
{
|
|
|
|
|
writeCppInfo(outFile, s, options.Where(o => o.scope == s));
|
|
|
|
|
}
|
|
|
|
|
outFile.Flush();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|