Format code based on clang format
This commit is contained in:
+334
@@ -0,0 +1,334 @@
|
||||
---
|
||||
Language: Cpp
|
||||
AccessModifierOffset: -2
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignArrayOfStructures: None
|
||||
AlignConsecutiveAssignments:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionDeclarations: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: true
|
||||
AlignConsecutiveBitFields:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionDeclarations: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveDeclarations:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionDeclarations: true
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveMacros:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionDeclarations: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveShortCaseStatements:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCaseArrows: false
|
||||
AlignCaseColons: false
|
||||
AlignConsecutiveTableGenBreakingDAGArgColons:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionDeclarations: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveTableGenCondOperatorColons:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionDeclarations: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveTableGenDefinitionColons:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionDeclarations: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: false
|
||||
AlignEscapedNewlines: Left
|
||||
AlignOperands: Align
|
||||
AlignTrailingComments:
|
||||
Kind: Always
|
||||
OverEmptyLines: 0
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowBreakBeforeNoexceptSpecifier: Never
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortCaseExpressionOnASingleLine: true
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortCompoundRequirementOnASingleLine: true
|
||||
AllowShortEnumsOnASingleLine: true
|
||||
AllowShortFunctionsOnASingleLine: false
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
AllowShortNamespacesOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: true
|
||||
AttributeMacros:
|
||||
- __capability
|
||||
- absl_nonnull
|
||||
- absl_nullable
|
||||
- absl_nullability_unknown
|
||||
BinPackArguments: false
|
||||
BinPackLongBracedList: true
|
||||
BinPackParameters: false
|
||||
BitFieldColonSpacing: Both
|
||||
BracedInitializerIndentWidth: -1
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: false
|
||||
AfterControlStatement: Never
|
||||
AfterEnum: false
|
||||
AfterExternBlock: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
BeforeLambdaBody: false
|
||||
BeforeWhile: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakAdjacentStringLiterals: true
|
||||
BreakAfterAttributes: Leave
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakAfterReturnType: None
|
||||
BreakArrays: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeConceptDeclarations: Always
|
||||
BreakBeforeBraces: Allman
|
||||
BreakBeforeInlineASMColon: OnlyMultiline
|
||||
BreakBeforeTemplateCloser: false
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakBinaryOperations: Never
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakFunctionDefinitionParameters: false
|
||||
BreakInheritanceList: BeforeColon
|
||||
BreakStringLiterals: true
|
||||
BreakTemplateDeclarations: Yes
|
||||
ColumnLimit: 120
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerIndentWidth: 2
|
||||
ContinuationIndentWidth: 2
|
||||
Cpp11BracedListStyle: true
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
EmptyLineAfterAccessModifier: Never
|
||||
EmptyLineBeforeAccessModifier: LogicalBlock
|
||||
EnumTrailingComma: Leave
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: false
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
IfMacros:
|
||||
- KJ_IF_MAYBE
|
||||
IncludeBlocks: Regroup
|
||||
IncludeCategories:
|
||||
- Regex: '^<ext/.*\.h>'
|
||||
Priority: 2
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
- Regex: '^<.*\.h>'
|
||||
Priority: 1
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
- Regex: '^<.*'
|
||||
Priority: 2
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
- Regex: '.*'
|
||||
Priority: 3
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
IncludeIsMainRegex: '([-_](test|unittest))?$'
|
||||
IncludeIsMainSourceRegex: ''
|
||||
IndentAccessModifiers: false
|
||||
IndentCaseBlocks: false
|
||||
IndentCaseLabels: true
|
||||
IndentExportBlock: true
|
||||
IndentExternBlock: AfterExternBlock
|
||||
IndentGotoLabels: true
|
||||
IndentPPDirectives: None
|
||||
IndentRequiresClause: true
|
||||
IndentWidth: 2
|
||||
IndentWrappedFunctionNames: false
|
||||
InsertBraces: false
|
||||
InsertNewlineAtEOF: false
|
||||
InsertTrailingCommas: None
|
||||
IntegerLiteralSeparator:
|
||||
Binary: 0
|
||||
BinaryMinDigits: 0
|
||||
Decimal: 0
|
||||
DecimalMinDigits: 0
|
||||
Hex: 0
|
||||
HexMinDigits: 0
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLines:
|
||||
AtEndOfFile: false
|
||||
AtStartOfBlock: false
|
||||
AtStartOfFile: true
|
||||
KeepFormFeed: false
|
||||
LambdaBodyIndentation: Signature
|
||||
LineEnding: DeriveLF
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MainIncludeChar: Quote
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: All
|
||||
ObjCBinPackProtocolList: Never
|
||||
ObjCBlockIndentWidth: 2
|
||||
ObjCBreakBeforeNestedBlockParam: true
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
OneLineFormatOffRegex: ''
|
||||
PackConstructorInitializers: Never
|
||||
PenaltyBreakAssignment: 2
|
||||
PenaltyBreakBeforeFirstCallParameter: 1
|
||||
PenaltyBreakBeforeMemberAccess: 150
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakOpenParenthesis: 0
|
||||
PenaltyBreakScopeResolution: 500
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyIndentedWhitespace: 0
|
||||
PenaltyReturnTypeOnItsOwnLine: 200
|
||||
PointerAlignment: Left
|
||||
PPIndentWidth: -1
|
||||
QualifierAlignment: Leave
|
||||
RawStringFormats:
|
||||
- Language: Cpp
|
||||
Delimiters:
|
||||
- cc
|
||||
- CC
|
||||
- cpp
|
||||
- Cpp
|
||||
- CPP
|
||||
- 'c++'
|
||||
- 'C++'
|
||||
CanonicalDelimiter: ''
|
||||
BasedOnStyle: google
|
||||
- Language: TextProto
|
||||
Delimiters:
|
||||
- pb
|
||||
- PB
|
||||
- proto
|
||||
- PROTO
|
||||
EnclosingFunctions:
|
||||
- EqualsProto
|
||||
- EquivToProto
|
||||
- PARSE_PARTIAL_TEXT_PROTO
|
||||
- PARSE_TEST_PROTO
|
||||
- PARSE_TEXT_PROTO
|
||||
- ParseTextOrDie
|
||||
- ParseTextProtoOrDie
|
||||
- ParseTestProto
|
||||
- ParsePartialTestProto
|
||||
CanonicalDelimiter: pb
|
||||
BasedOnStyle: google
|
||||
ReferenceAlignment: Pointer
|
||||
ReflowComments: Always
|
||||
RemoveBracesLLVM: false
|
||||
RemoveEmptyLinesInUnwrappedLines: false
|
||||
RemoveParentheses: Leave
|
||||
RemoveSemicolon: false
|
||||
RequiresClausePosition: OwnLine
|
||||
RequiresExpressionIndentation: OuterScope
|
||||
SeparateDefinitionBlocks: Always
|
||||
ShortNamespaceLines: 1
|
||||
SkipMacroDefinitionBody: false
|
||||
SortIncludes:
|
||||
Enabled: true
|
||||
IgnoreCase: false
|
||||
SortJavaStaticImport: Before
|
||||
SortUsingDeclarations: LexicographicNumeric
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterOperatorKeyword: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceAroundPointerQualifiers: Default
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCaseColon: false
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeJsonColon: false
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeParensOptions:
|
||||
AfterControlStatements: true
|
||||
AfterForeachMacros: true
|
||||
AfterFunctionDefinitionName: false
|
||||
AfterFunctionDeclarationName: false
|
||||
AfterIfMacros: true
|
||||
AfterNot: false
|
||||
AfterOverloadedOperator: false
|
||||
AfterPlacementOperator: true
|
||||
AfterRequiresInClause: false
|
||||
AfterRequiresInExpression: false
|
||||
BeforeNonEmptyParentheses: false
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceBeforeSquareBrackets: false
|
||||
SpaceInEmptyBlock: false
|
||||
SpacesBeforeTrailingComments: 2
|
||||
SpacesInAngles: Never
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInLineCommentPrefix:
|
||||
Minimum: 1
|
||||
Maximum: -1
|
||||
SpacesInParens: Never
|
||||
SpacesInParensOptions:
|
||||
ExceptDoubleParentheses: false
|
||||
InCStyleCasts: false
|
||||
InConditionalStatements: false
|
||||
InEmptyParentheses: false
|
||||
Other: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Auto
|
||||
StatementAttributeLikeMacros:
|
||||
- Q_EMIT
|
||||
StatementMacros:
|
||||
- Q_UNUSED
|
||||
- QT_REQUIRE_VERSION
|
||||
TableGenBreakInsideDAGArg: DontBreak
|
||||
TabWidth: 2
|
||||
UseTab: Never
|
||||
VerilogBreakBetweenInstancePorts: true
|
||||
WhitespaceSensitiveMacros:
|
||||
- BOOST_PP_STRINGIZE
|
||||
- CF_SWIFT_NAME
|
||||
- NS_SWIFT_NAME
|
||||
- PP_STRINGIZE
|
||||
- STRINGIZE
|
||||
WrapNamespaceBodyWithEmptyLines: Leave
|
||||
...
|
||||
|
||||
Executable → Regular
+1
-2
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
#define BIT(x) (1 << x)
|
||||
|
||||
@@ -31,7 +31,6 @@ const static unsigned int FLAG_SIMPLE = BIT(9);
|
||||
const static unsigned int FLAG_CONFIG = BIT(10);
|
||||
const static unsigned int FLAG_TARGET = BIT(11);
|
||||
|
||||
|
||||
#define LOG_INFO(...) LogHelper(__VA_ARGS__)
|
||||
#define LOG_WARNING(...) LogHelper(__VA_ARGS__)
|
||||
#define LOG_ERROR(...) LogHelper(__VA_ARGS__)
|
||||
|
||||
@@ -128,7 +128,6 @@ Valid settings are:
|
||||
genhfile Specifies if MakeGen should generate a project h-file)");
|
||||
}
|
||||
|
||||
|
||||
ConfigSetting ConfigCLI::CLIStringToSetting(const std::string& s)
|
||||
{
|
||||
static std::map<std::string, ConfigSetting> map{
|
||||
|
||||
+1
-1
@@ -6,6 +6,7 @@ struct ConfigCLI
|
||||
{
|
||||
public:
|
||||
static int Main(int argc, char** argv);
|
||||
|
||||
private:
|
||||
static void DisplayCLIHelp();
|
||||
static void DisplayGenHelp();
|
||||
@@ -21,5 +22,4 @@ struct ConfigCLI
|
||||
static int Remove(int argc, char** argv, ConfigFile& config);
|
||||
static int Set(int argc, char** argv, ConfigFile& config);
|
||||
static int Get(int argc, char** argv, ConfigFile& config);
|
||||
|
||||
};
|
||||
|
||||
Executable → Regular
+19
-19
@@ -1,11 +1,11 @@
|
||||
#include "ConfigFile.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "FileUtils.h"
|
||||
#include "compatibility/ConfigFileConf.h"
|
||||
#include "xml/XML.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
ConfigFile::ConfigFile(const std::string& path, const FlagData& flagData, int)
|
||||
: configPath{path}
|
||||
{
|
||||
@@ -36,13 +36,15 @@ ConfigFile::ConfigFile(const std::string& path, const FlagData& flagData, int)
|
||||
}
|
||||
|
||||
ConfigFile::ConfigFile(const std::string& path, const FlagData& flagData)
|
||||
: config{XML::FromFile(path + CONFIG_FILENAME)}, configPath{path}
|
||||
: config{XML::FromFile(path + CONFIG_FILENAME)},
|
||||
configPath{path}
|
||||
{
|
||||
Init(flagData);
|
||||
}
|
||||
|
||||
ConfigFile::ConfigFile(XMLObject& config, const std::string& path, const FlagData& flagData)
|
||||
: config{config}, configPath{path}
|
||||
: config{config},
|
||||
configPath{path}
|
||||
{
|
||||
Init(flagData);
|
||||
}
|
||||
@@ -67,7 +69,6 @@ void ConfigFile::Init(const FlagData& flagData)
|
||||
if (targetXml->size() > 0)
|
||||
target = (*targetXml)[0].GetText();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::string& ConfigFile::GetSettingString(ConfigSetting setting)
|
||||
@@ -319,7 +320,8 @@ XMLObject& ConfigFile::GetConfiguration()
|
||||
}
|
||||
}
|
||||
|
||||
LOG_ERROR("Couldn\'t find given target in config file. Using target=", (*configurations)[0].HasAttribute("name") ? (*configurations)[0].GetAttribute("name") : "");
|
||||
LOG_ERROR("Couldn\'t find given target in config file. Using target=",
|
||||
(*configurations)[0].HasAttribute("name") ? (*configurations)[0].GetAttribute("name") : "");
|
||||
return (*configurations)[0];
|
||||
}
|
||||
|
||||
@@ -339,7 +341,9 @@ std::optional<ConfigFile> ConfigFile::GetConfigFile(const std::string& filepath,
|
||||
return GetConfigFile(filepath, loadedConfigs, flagData);
|
||||
}
|
||||
|
||||
std::optional<ConfigFile> ConfigFile::GetConfigFile(const std::string& filepath, std::map<std::string, ConfigFile>& loadedConfigs, const FlagData& flagData)
|
||||
std::optional<ConfigFile> ConfigFile::GetConfigFile(const std::string& filepath,
|
||||
std::map<std::string, ConfigFile>& loadedConfigs,
|
||||
const FlagData& flagData)
|
||||
{
|
||||
std::string realPath = FileUtils::GetRealPath(filepath);
|
||||
if (realPath == "")
|
||||
@@ -438,7 +442,8 @@ void ConfigFile::InputMultiple(const std::string& inputText, std::vector<std::st
|
||||
ConfigFile ConfigFile::Gen(const FlagData& flagData)
|
||||
{
|
||||
bool executable, shared, generateHFile;
|
||||
std::vector<std::string> libs, libdirs, includedirs, defines, compileFlags, linkingFlags, dependencies, excludeSources, excludeHeaders;
|
||||
std::vector<std::string> libs, libdirs, includedirs, defines, compileFlags, linkingFlags, dependencies,
|
||||
excludeSources, excludeHeaders;
|
||||
std::string srcdir, outputdir, projectname, outputname, hFile;
|
||||
|
||||
InputBoolean("Should it be compiled as an executable? (y/n)", executable);
|
||||
@@ -471,7 +476,6 @@ ConfigFile ConfigFile::Gen(const FlagData& flagData)
|
||||
InputString("Enter a name for the project:", projectname, false, false);
|
||||
InputString("Enter a name for the output file:", outputname, false, false);
|
||||
|
||||
|
||||
// Create xml
|
||||
XMLObject makegen("makegen", {}, std::map<std::string, std::vector<XMLObject>>{});
|
||||
|
||||
@@ -488,20 +492,16 @@ ConfigFile ConfigFile::Gen(const FlagData& flagData)
|
||||
configuration.AddXMLObject(XMLObject("srcdir", {}, srcdir));
|
||||
configuration.AddXMLObject(XMLObject("outputdir", {}, outputdir));
|
||||
configuration.AddXMLObject(XMLObject("hfilename", {}, hFile));
|
||||
configuration.AddXMLObject(XMLObject("outputtype", {},
|
||||
executable ? "executable" : (shared ? "sharedlibrary" : "staticlibrary")));
|
||||
configuration.AddXMLObject(
|
||||
XMLObject("outputtype", {}, executable ? "executable" : (shared ? "sharedlibrary" : "staticlibrary")));
|
||||
configuration.AddXMLObject(XMLObject("generatehfile", {}, generateHFile ? "true" : "false"));
|
||||
|
||||
for(auto it = libs.begin();it != libs.end(); ++it)
|
||||
configuration.AddXMLObject({"library",{},*it});
|
||||
for(auto it = libdirs.begin();it != libdirs.end(); ++it)
|
||||
configuration.AddXMLObject({"librarydir",{},*it});
|
||||
for (auto it = libs.begin(); it != libs.end(); ++it) configuration.AddXMLObject({"library", {}, *it});
|
||||
for (auto it = libdirs.begin(); it != libdirs.end(); ++it) configuration.AddXMLObject({"librarydir", {}, *it});
|
||||
for (auto it = includedirs.begin(); it != includedirs.end(); ++it)
|
||||
configuration.AddXMLObject({"includedir", {}, *it});
|
||||
for(auto it = defines.begin();it != defines.end(); ++it)
|
||||
configuration.AddXMLObject({"define",{},*it});
|
||||
for(auto it = compileFlags.begin();it != compileFlags.end(); ++it)
|
||||
configuration.AddXMLObject({"cflag",{},*it});
|
||||
for (auto it = defines.begin(); it != defines.end(); ++it) configuration.AddXMLObject({"define", {}, *it});
|
||||
for (auto it = compileFlags.begin(); it != compileFlags.end(); ++it) configuration.AddXMLObject({"cflag", {}, *it});
|
||||
for (auto it = dependencies.begin(); it != dependencies.end(); ++it)
|
||||
configuration.AddXMLObject({"dependency", {}, *it});
|
||||
|
||||
|
||||
Executable → Regular
+9
-5
@@ -1,14 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "ConfigUtils.h"
|
||||
#include "FlagData.h"
|
||||
#include "xml/XMLObject.h"
|
||||
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "ConfigUtils.h"
|
||||
#include "FlagData.h"
|
||||
#include "xml/XMLObject.h"
|
||||
|
||||
static const std::string CONFIG_FILENAME = "makegen.xml";
|
||||
|
||||
class ConfigFile
|
||||
@@ -45,14 +45,18 @@ class ConfigFile
|
||||
XMLObject& GetConfiguration();
|
||||
const std::string& GetConfigPath() const;
|
||||
ConfigFile& GetDependencyConfig(size_t i);
|
||||
|
||||
private:
|
||||
void Init(const FlagData& flagData);
|
||||
|
||||
public:
|
||||
static ConfigFile Gen(const FlagData& flagData);
|
||||
static std::optional<ConfigFile> GetConfigFile(const std::string& filepath, const FlagData& flagData);
|
||||
|
||||
private:
|
||||
static std::optional<ConfigFile> GetConfigFile(const std::string& filepath, std::map<std::string, ConfigFile>& loadedConfigs, const FlagData& flagData);
|
||||
static std::optional<ConfigFile> GetConfigFile(const std::string& filepath,
|
||||
std::map<std::string, ConfigFile>& loadedConfigs,
|
||||
const FlagData& flagData);
|
||||
static std::optional<ConfigFile> Load(const std::string& filename);
|
||||
static void InputBoolean(const std::string& inputText, bool& b);
|
||||
static void InputMultiple(const std::string& inputText, std::vector<std::string>& vec, bool needEnding);
|
||||
|
||||
+30
-21
@@ -1,13 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Common.h"
|
||||
#include "FileUtils.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
struct ConfigCache
|
||||
{
|
||||
std::map<std::string, std::string> strings;
|
||||
@@ -18,9 +19,26 @@ struct ConfigCache
|
||||
enum class ConfigSetting
|
||||
{
|
||||
// vectors
|
||||
Library = 0, LibraryDir = 1, IncludeDir = 2, Define = 3, Dependency = 4, CFlag = 5, LFlag = 6, ExcludeSource = 7, ExcludeHeader = 8, ExecPreArgument = 9, ExecArgument = 10, SourceFile = 11, IncludeDirExclDep = 12,
|
||||
Library = 0,
|
||||
LibraryDir = 1,
|
||||
IncludeDir = 2,
|
||||
Define = 3,
|
||||
Dependency = 4,
|
||||
CFlag = 5,
|
||||
LFlag = 6,
|
||||
ExcludeSource = 7,
|
||||
ExcludeHeader = 8,
|
||||
ExecPreArgument = 9,
|
||||
ExecArgument = 10,
|
||||
SourceFile = 11,
|
||||
IncludeDirExclDep = 12,
|
||||
// Strings
|
||||
SourceDir = 32, OutputDir = 33, OutputName = 34, OutputType = 35, ProjectName = 36, HFileName = 37,
|
||||
SourceDir = 32,
|
||||
OutputDir = 33,
|
||||
OutputName = 34,
|
||||
OutputType = 35,
|
||||
ProjectName = 36,
|
||||
HFileName = 37,
|
||||
// Bools
|
||||
GenerateHFile = 64,
|
||||
// Other
|
||||
@@ -171,6 +189,7 @@ struct ConfigUtils
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool IsBoolSetting(ConfigSetting setting)
|
||||
{
|
||||
switch (setting)
|
||||
@@ -248,8 +267,7 @@ struct ConfigUtils
|
||||
{
|
||||
std::string projectname = GetDefaultProjectName(path);
|
||||
std::string outputname;
|
||||
std::transform(
|
||||
projectname.begin(),
|
||||
std::transform(projectname.begin(),
|
||||
projectname.end(),
|
||||
std::back_inserter(outputname),
|
||||
[](unsigned char c)
|
||||
@@ -258,13 +276,9 @@ struct ConfigUtils
|
||||
return '_';
|
||||
return (char)std::tolower(c);
|
||||
});
|
||||
auto it = std::remove_if(
|
||||
outputname.begin(),
|
||||
auto it = std::remove_if(outputname.begin(),
|
||||
outputname.end(),
|
||||
[](unsigned char c)
|
||||
{
|
||||
return (c < '0' || c > '9') && (c < 'a' || c > 'z') && c != '_';
|
||||
});
|
||||
[](unsigned char c) { return (c < '0' || c > '9') && (c < 'a' || c > 'z') && c != '_'; });
|
||||
outputname.erase(it, outputname.end());
|
||||
outputname += ".out";
|
||||
return outputname;
|
||||
@@ -274,12 +288,7 @@ struct ConfigUtils
|
||||
{
|
||||
std::string hfile = GetDefaultProjectName(path);
|
||||
auto it = std::remove_if(
|
||||
hfile.begin(),
|
||||
hfile.end(),
|
||||
[](unsigned char c)
|
||||
{
|
||||
return (c < 'a' || c > 'z') && (c < 'A' || c > 'Z');
|
||||
});
|
||||
hfile.begin(), hfile.end(), [](unsigned char c) { return (c < 'a' || c > 'z') && (c < 'A' || c > 'Z'); });
|
||||
hfile.erase(it, hfile.end());
|
||||
hfile += ".h";
|
||||
return hfile;
|
||||
|
||||
+16
-14
@@ -1,18 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <assert.h>
|
||||
#include <dirent.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Common.h"
|
||||
#include "Utils.h"
|
||||
#include <algorithm>
|
||||
#include <assert.h>
|
||||
#include <cstring>
|
||||
#include <dirent.h>
|
||||
#include <fstream>
|
||||
#include <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unistd.h>
|
||||
#include <filesystem>
|
||||
|
||||
struct FileUtils
|
||||
{
|
||||
@@ -115,8 +117,7 @@ struct FileUtils
|
||||
std::string commonPath = Utils::CommonPrefix(from, to);
|
||||
if (commonPath.empty())
|
||||
return "";
|
||||
while(commonPath.back() != '/')
|
||||
commonPath.pop_back();
|
||||
while (commonPath.back() != '/') commonPath.pop_back();
|
||||
commonPath.pop_back();
|
||||
|
||||
// Go back to the common directory
|
||||
@@ -138,7 +139,8 @@ struct FileUtils
|
||||
{
|
||||
DIR* dp;
|
||||
struct dirent* dirp;
|
||||
if((dp = opendir(folder.c_str())) == NULL){
|
||||
if ((dp = opendir(folder.c_str())) == NULL)
|
||||
{
|
||||
LOG_ERROR("Failed to open directory: ", folder);
|
||||
return;
|
||||
}
|
||||
|
||||
+4
-2
@@ -1,8 +1,9 @@
|
||||
#include "HFileGen.h"
|
||||
|
||||
#include "FileUtils.h"
|
||||
#include <set>
|
||||
|
||||
#include "FileUtils.h"
|
||||
|
||||
void HFileGen::Create(ConfigFile& conf)
|
||||
{
|
||||
std::set<std::string> hFiles;
|
||||
@@ -17,7 +18,8 @@ void HFileGen::Create(ConfigFile& conf)
|
||||
if (extensionPos != std::string::npos)
|
||||
{
|
||||
std::string filename = it->substr(path.length());
|
||||
if(Utils::IsHeaderFile(filename) && filename != conf.GetConfigPath() + conf.GetSettingString(ConfigSetting::HFileName))
|
||||
if (Utils::IsHeaderFile(filename) &&
|
||||
filename != conf.GetConfigPath() + conf.GetSettingString(ConfigSetting::HFileName))
|
||||
{
|
||||
// Make files sorted in alphabetical order
|
||||
hFiles.emplace(filename);
|
||||
|
||||
Executable → Regular
+19
-7
@@ -1,17 +1,25 @@
|
||||
#include "IncludeDeps.h"
|
||||
|
||||
#include "Common.h"
|
||||
#include <sstream>
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
std::set<std::string> IncludeDeps::printSet;
|
||||
int IncludeDeps::printCounter = 0;
|
||||
|
||||
IncludeDeps::IncludeDeps(const std::string& filename, const std::set<HFile>& files, std::map<std::string, IncludeDeps*>& allDeps)
|
||||
IncludeDeps::IncludeDeps(const std::string& filename,
|
||||
const std::set<HFile>& files,
|
||||
std::map<std::string, IncludeDeps*>& allDeps)
|
||||
: IncludeDeps{filename, false, files, allDeps}
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
IncludeDeps::IncludeDeps(const std::string& filename, bool projectHFile, const std::set<HFile>& files, std::map<std::string, IncludeDeps*>& allDeps)
|
||||
: filepath(filename), projectHFile{projectHFile}
|
||||
IncludeDeps::IncludeDeps(const std::string& filename,
|
||||
bool projectHFile,
|
||||
const std::set<HFile>& files,
|
||||
std::map<std::string, IncludeDeps*>& allDeps)
|
||||
: filepath(filename),
|
||||
projectHFile{projectHFile}
|
||||
{
|
||||
std::filesystem::path path{filepath};
|
||||
if (Utils::IsHeaderFile(filename))
|
||||
@@ -43,7 +51,9 @@ IncludeDeps::IncludeDeps(const std::string& filename, bool projectHFile, const s
|
||||
{
|
||||
IncludeDeps* inc = new IncludeDeps(includeFileRelativeToSource.string(), false, files, allDeps);
|
||||
dependencies.emplace(includeFileRelativeToSource, inc);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
dependencies.emplace(itD->first, itD->second);
|
||||
}
|
||||
}
|
||||
@@ -57,7 +67,9 @@ IncludeDeps::IncludeDeps(const std::string& filename, bool projectHFile, const s
|
||||
{
|
||||
IncludeDeps* inc = new IncludeDeps(it->filepath, it->isProjectHFile, files, allDeps);
|
||||
dependencies.emplace(it->filepath, inc);
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
dependencies.emplace(itD->first, itD->second);
|
||||
}
|
||||
}
|
||||
|
||||
Executable → Regular
+11
-5
@@ -1,14 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "ConfigFile.h"
|
||||
#include "FileUtils.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "ConfigFile.h"
|
||||
#include "FileUtils.h"
|
||||
|
||||
struct CompareIncludeDeps;
|
||||
|
||||
class IncludeDeps
|
||||
@@ -22,7 +22,10 @@ class IncludeDeps
|
||||
|
||||
IncludeDeps(const std::string& filename, const std::set<HFile>& files, std::map<std::string, IncludeDeps*>& allDeps);
|
||||
|
||||
IncludeDeps(const std::string& filename, bool projectHFile, const std::set<HFile>& files, std::map<std::string, IncludeDeps*>& allDeps);
|
||||
IncludeDeps(const std::string& filename,
|
||||
bool projectHFile,
|
||||
const std::set<HFile>& files,
|
||||
std::map<std::string, IncludeDeps*>& allDeps);
|
||||
|
||||
std::string GetIncludeFile(const std::string& line);
|
||||
|
||||
@@ -55,14 +58,17 @@ class IncludeDeps
|
||||
struct CompareIncludeDeps
|
||||
{
|
||||
using is_transparent = void;
|
||||
|
||||
bool operator()(const IncludeDeps* d1, const IncludeDeps* d2) const
|
||||
{
|
||||
return d1->filepath < d2->filepath;
|
||||
}
|
||||
|
||||
bool operator()(const IncludeDeps* d, const std::string& filepath) const
|
||||
{
|
||||
return d->filepath < filepath;
|
||||
}
|
||||
|
||||
bool operator()(const std::string& filepath, const IncludeDeps* d) const
|
||||
{
|
||||
return filepath < d->filepath;
|
||||
|
||||
+10
-10
@@ -1,12 +1,12 @@
|
||||
#include "Makefile.h"
|
||||
|
||||
#include "IncludeDeps.h"
|
||||
#include "Utils.h"
|
||||
#include "Common.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
|
||||
#include "Common.h"
|
||||
#include "IncludeDeps.h"
|
||||
#include "Utils.h"
|
||||
|
||||
void Makefile::Save(ConfigFile& conf, unsigned int flags)
|
||||
{
|
||||
std::set<HFile> hFiles; // hFile, directory
|
||||
@@ -17,7 +17,8 @@ void Makefile::Save(ConfigFile& conf, unsigned int flags)
|
||||
Utils::GetCppAndHFiles(conf, hFiles, cppFiles);
|
||||
|
||||
std::ofstream outputFile(conf.GetConfigPath() + "Makefile");
|
||||
outputFile << "# This Makefile was generated using MakeGen "<< MAKEGEN_VERSION << " made by Tim Håkansson" << std::endl;
|
||||
outputFile << "# This Makefile was generated using MakeGen " << MAKEGEN_VERSION << " made by Tim Håkansson"
|
||||
<< std::endl;
|
||||
outputFile << "# and is licensed under MIT. Full source of the project can be found at" << std::endl;
|
||||
outputFile << "# https://github.com/Thraix/MakeGen" << std::endl;
|
||||
outputFile << "CC=@g++" << std::endl;
|
||||
@@ -138,11 +139,9 @@ void Makefile::Save(ConfigFile& conf, unsigned int flags)
|
||||
std::vector<std::string>& arguments = conf.GetSettingVectorString(ConfigSetting::ExecArgument);
|
||||
|
||||
outputFile << "\t@";
|
||||
for(auto&& preargument : prearguments)
|
||||
outputFile << preargument << " ";
|
||||
for (auto&& preargument : prearguments) outputFile << preargument << " ";
|
||||
outputFile << "./$(OUTPUT)";
|
||||
for(auto&& argument : arguments)
|
||||
outputFile << " " << argument;
|
||||
for (auto&& argument : arguments) outputFile << " " << argument;
|
||||
outputFile << std::endl;
|
||||
}
|
||||
|
||||
@@ -164,7 +163,8 @@ void Makefile::Save(ConfigFile& conf, unsigned int flags)
|
||||
|
||||
// Install
|
||||
outputFile << "install: all" << std::endl;
|
||||
outputFile << "\t$(info Installing " << conf.GetSettingString(ConfigSetting::ProjectName) <<" to /usr/bin/)" << std::endl;
|
||||
outputFile << "\t$(info Installing " << conf.GetSettingString(ConfigSetting::ProjectName) << " to /usr/bin/)"
|
||||
<< std::endl;
|
||||
outputFile << "\t@cp $(OUTPUT) /usr/bin/" << conf.GetSettingString(ConfigSetting::OutputName) << std::endl;
|
||||
|
||||
std::map<std::string, IncludeDeps*> dependencies;
|
||||
|
||||
Executable → Regular
Executable → Regular
+7
-2
@@ -6,8 +6,10 @@ class Timer
|
||||
{
|
||||
private:
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> m_start;
|
||||
|
||||
public:
|
||||
Timer(){
|
||||
Timer()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
@@ -18,6 +20,9 @@ class Timer
|
||||
|
||||
float Elapsed()
|
||||
{
|
||||
return std::chrono::duration_cast<std::chrono::duration<float,std::milli>>(std::chrono::high_resolution_clock::now() - m_start).count() / 1000.0f;
|
||||
return std::chrono::duration_cast<std::chrono::duration<float, std::milli>>(
|
||||
std::chrono::high_resolution_clock::now() - m_start)
|
||||
.count() /
|
||||
1000.0f;
|
||||
}
|
||||
};
|
||||
|
||||
+7
-4
@@ -1,10 +1,10 @@
|
||||
#include "Utils.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
#include "ConfigFile.h"
|
||||
#include "FileUtils.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
bool Utils::IsSourceFile(const std::string& filepath)
|
||||
{
|
||||
std::string_view extension(filepath);
|
||||
@@ -40,7 +40,6 @@ bool Utils::StartsWith(const std::string& str, const std::string& prefix)
|
||||
return str.compare(0, prefix.size(), prefix) == 0;
|
||||
}
|
||||
|
||||
|
||||
std::string Utils::CommonPrefix(const std::string& s1, const std::string& s2)
|
||||
{
|
||||
size_t n = 0;
|
||||
@@ -176,11 +175,15 @@ void Utils::GetHFiles(const std::string& dependencyDir, ConfigFile& conf, std::s
|
||||
}
|
||||
else
|
||||
{
|
||||
hFiles.emplace(HFile{filename, depSrcDir, conf.GetSettingBool(ConfigSetting::GenerateHFile) && filename == conf.GetSettingString(ConfigSetting::HFileName)});
|
||||
hFiles.emplace(HFile{filename,
|
||||
depSrcDir,
|
||||
conf.GetSettingBool(ConfigSetting::GenerateHFile) &&
|
||||
filename == conf.GetSettingString(ConfigSetting::HFileName)});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Utils::IsWhiteSpace(char c)
|
||||
{
|
||||
return c == '\n' || c == '\t' || c == '\r' || c == ' ' || c == '\t';
|
||||
|
||||
+5
-3
@@ -5,7 +5,6 @@
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
|
||||
struct HFile
|
||||
{
|
||||
std::string filename;
|
||||
@@ -14,8 +13,11 @@ struct HFile
|
||||
std::filesystem::path filepath;
|
||||
|
||||
HFile(const std::string& filename, const std::string& directory, bool isProjectHFile)
|
||||
: filename{filename}, isProjectHFile{isProjectHFile}, filepath{directory+filename}
|
||||
{}
|
||||
: filename{filename},
|
||||
isProjectHFile{isProjectHFile},
|
||||
filepath{directory + filename}
|
||||
{
|
||||
}
|
||||
|
||||
friend bool operator<(const HFile& h1, const HFile& h2)
|
||||
{
|
||||
|
||||
@@ -2,24 +2,30 @@
|
||||
|
||||
const std::string CONFIG_FILENAME_CONF = "makegen.conf";
|
||||
|
||||
#include "../ConfigFile.h"
|
||||
#include "../FileUtils.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
|
||||
#include "../ConfigFile.h"
|
||||
#include "../FileUtils.h"
|
||||
|
||||
#define FLAG_NONE 0
|
||||
#define FLAG_VECTOR 1
|
||||
#define FLAG_STRING 2
|
||||
#define FLAG_BOOL 3
|
||||
|
||||
ConfigFileConf::ConfigFileConf()
|
||||
: outputdir("bin/"), srcdir("src/"), outputname(""), projectname(FileUtils::GetCurrentDirectory()), hFile(""), executable(true), shared(true), generateHFile(false)
|
||||
: outputdir("bin/"),
|
||||
srcdir("src/"),
|
||||
outputname(""),
|
||||
projectname(FileUtils::GetCurrentDirectory()),
|
||||
hFile(""),
|
||||
executable(true),
|
||||
shared(true),
|
||||
generateHFile(false)
|
||||
{
|
||||
// Converts project name (current directory) to lowercase
|
||||
// and replace whitespace with underscore
|
||||
std::transform(
|
||||
projectname.begin(),
|
||||
std::transform(projectname.begin(),
|
||||
projectname.end(),
|
||||
std::back_inserter(outputname),
|
||||
[](unsigned char c)
|
||||
@@ -31,12 +37,7 @@ ConfigFileConf::ConfigFileConf()
|
||||
|
||||
// Removes all other characters
|
||||
outputdir.erase(std::remove_if(
|
||||
outputdir.begin(),
|
||||
outputdir.end(),
|
||||
[](unsigned char c)
|
||||
{
|
||||
return (c < 'a' || c > 'z') && c != '_';
|
||||
}));
|
||||
outputdir.begin(), outputdir.end(), [](unsigned char c) { return (c < 'a' || c > 'z') && c != '_'; }));
|
||||
|
||||
// Add suffix
|
||||
outputname += ".out";
|
||||
@@ -60,8 +61,7 @@ void ConfigFileConf::CreateXMLFile(const std::string& filepath)
|
||||
if (file.is_open())
|
||||
{
|
||||
// config name, { pointer to memory, isDirectory}
|
||||
std::map<std::string, std::pair<std::string*, bool>> strings =
|
||||
{
|
||||
std::map<std::string, std::pair<std::string*, bool>> strings = {
|
||||
{"#srcdir", {&conf.srcdir, true}},
|
||||
{"#outputdir", {&conf.outputdir, true}},
|
||||
{"#outputname", {&conf.outputname, false}},
|
||||
@@ -70,8 +70,7 @@ void ConfigFileConf::CreateXMLFile(const std::string& filepath)
|
||||
};
|
||||
|
||||
// config name, { pointer to memory, isDirectory}
|
||||
std::map<std::string, std::pair<std::vector<std::string>*, bool>> vectors =
|
||||
{
|
||||
std::map<std::string, std::pair<std::vector<std::string>*, bool>> vectors = {
|
||||
{"#libs", {&conf.libs, false}},
|
||||
{"#libdirs", {&conf.libdirs, true}},
|
||||
{"#includedirs", {&conf.includedirs, true}},
|
||||
@@ -81,8 +80,7 @@ void ConfigFileConf::CreateXMLFile(const std::string& filepath)
|
||||
{"#sourcefiles", {&conf.sourceFiles, false}},
|
||||
};
|
||||
|
||||
std::map<std::string, bool*> booleans =
|
||||
{
|
||||
std::map<std::string, bool*> booleans = {
|
||||
{"#executable", &conf.executable},
|
||||
{"#shared", &conf.shared},
|
||||
{"#generatehfile", &conf.generateHFile},
|
||||
@@ -139,7 +137,8 @@ void ConfigFileConf::CreateXMLFile(const std::string& filepath)
|
||||
else if (loadFlag == FLAG_VECTOR)
|
||||
{
|
||||
if (isDirectory && line[line.size() - 1] != '/')
|
||||
{;
|
||||
{
|
||||
;
|
||||
line += '/';
|
||||
}
|
||||
vec->push_back(line);
|
||||
@@ -171,20 +170,18 @@ void ConfigFileConf::CreateXMLFile(const std::string& filepath)
|
||||
configuration.AddXMLObject(XMLObject("srcdir", {}, conf.srcdir));
|
||||
configuration.AddXMLObject(XMLObject("outputdir", {}, conf.outputdir));
|
||||
configuration.AddXMLObject(XMLObject("hfilename", {}, conf.hFile));
|
||||
configuration.AddXMLObject(XMLObject("outputtype", {},
|
||||
conf.executable ? "executable" : (conf.shared ? "sharedlibrary" : "staticlibrary")));
|
||||
configuration.AddXMLObject(
|
||||
XMLObject("outputtype", {}, conf.executable ? "executable" : (conf.shared ? "sharedlibrary" : "staticlibrary")));
|
||||
configuration.AddXMLObject(XMLObject("generatehfile", {}, conf.generateHFile ? "true" : "false"));
|
||||
|
||||
for(auto it = conf.libs.begin();it != conf.libs.end(); ++it)
|
||||
configuration.AddXMLObject({"library",{},*it});
|
||||
for (auto it = conf.libs.begin(); it != conf.libs.end(); ++it) configuration.AddXMLObject({"library", {}, *it});
|
||||
for (auto it = conf.libdirs.begin(); it != conf.libdirs.end(); ++it)
|
||||
configuration.AddXMLObject({"librarydir", {}, *it});
|
||||
for (auto it = conf.includedirs.begin(); it != conf.includedirs.end(); ++it)
|
||||
configuration.AddXMLObject({"includedir", {}, *it});
|
||||
for (auto it = conf.defines.begin(); it != conf.defines.end(); ++it)
|
||||
configuration.AddXMLObject({"define", {}, *it});
|
||||
for(auto it = conf.flags.begin();it != conf.flags.end(); ++it)
|
||||
configuration.AddXMLObject({"cflag",{},*it});
|
||||
for (auto it = conf.flags.begin(); it != conf.flags.end(); ++it) configuration.AddXMLObject({"cflag", {}, *it});
|
||||
for (auto it = conf.dependencies.begin(); it != conf.dependencies.end(); ++it)
|
||||
configuration.AddXMLObject({"dependency", {}, *it});
|
||||
for (auto it = conf.sourceFiles.begin(); it != conf.sourceFiles.end(); ++it)
|
||||
|
||||
@@ -27,9 +27,11 @@ class ConfigFileConf
|
||||
bool executable;
|
||||
bool shared;
|
||||
bool generateHFile;
|
||||
|
||||
public:
|
||||
ConfigFileConf();
|
||||
|
||||
static void CreateXMLFile(const std::string& filename);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
Executable → Regular
+4
-4
@@ -1,3 +1,7 @@
|
||||
#include <cmath>
|
||||
#include <filesystem>
|
||||
#include <thread>
|
||||
|
||||
#include "Common.h"
|
||||
#include "ConfigCLI.h"
|
||||
#include "ConfigFile.h"
|
||||
@@ -7,10 +11,6 @@
|
||||
#include "Makefile.h"
|
||||
#include "Timer.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <thread>
|
||||
#include <filesystem>
|
||||
|
||||
#define RETURN_IF(x, b) \
|
||||
if (x) \
|
||||
return b;
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
#include "XML.h"
|
||||
|
||||
#include "XMLException.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
|
||||
#include "XMLException.h"
|
||||
|
||||
XMLObject XML::FromString(const std::string& string, const std::string& filename = "")
|
||||
{
|
||||
|
||||
+10
-4
@@ -1,19 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "XMLObject.h"
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
#include "XMLObject.h"
|
||||
|
||||
class XMLException : public std::exception
|
||||
{
|
||||
private:
|
||||
std::string m_message;
|
||||
|
||||
public:
|
||||
explicit XMLException(const std::string& message) : m_message("XMLException: " + message) {}
|
||||
explicit XMLException(const std::string& message)
|
||||
: m_message("XMLException: " + message)
|
||||
{
|
||||
}
|
||||
|
||||
explicit XMLException(const std::string& message, const XMLObject::XMLLoadData& data)
|
||||
: m_message("XMLException(" + data.file + ":" + std::to_string(data.line) + "): " + message)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
virtual const char* what() const throw()
|
||||
{
|
||||
|
||||
+40
-36
@@ -1,9 +1,9 @@
|
||||
#include "XMLObject.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "../Common.h"
|
||||
#include "../Utils.h"
|
||||
|
||||
#include <cstring>
|
||||
#include "XMLException.h"
|
||||
|
||||
XMLObject::XMLObject(const std::string& string)
|
||||
@@ -28,16 +28,22 @@ XMLObject::XMLObject(const std::string& string, XMLLoadData& data)
|
||||
ReadBodyTail(string, data);
|
||||
}
|
||||
|
||||
XMLObject::XMLObject(const std::string& name, const std::map<std::string, std::string>& attributes, const std::string& text)
|
||||
:name(name), attributes(attributes), text(text)
|
||||
XMLObject::XMLObject(const std::string& name,
|
||||
const std::map<std::string, std::string>& attributes,
|
||||
const std::string& text)
|
||||
: name(name),
|
||||
attributes(attributes),
|
||||
text(text)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
XMLObject::XMLObject(const std::string& name, const std::map<std::string, std::string>& attributes, const std::map<std::string,std::vector<XMLObject>>& objects)
|
||||
: name(name), attributes(attributes), objects(objects)
|
||||
XMLObject::XMLObject(const std::string& name,
|
||||
const std::map<std::string, std::string>& attributes,
|
||||
const std::map<std::string, std::vector<XMLObject>>& objects)
|
||||
: name(name),
|
||||
attributes(attributes),
|
||||
objects(objects)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool XMLObject::HasAttribute(const std::string& property) const
|
||||
@@ -154,7 +160,6 @@ XMLObject XMLObject::GetStrippedXMLObject() const
|
||||
// //
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
bool XMLObject::ReadHead(const std::string& string, XMLLoadData& data)
|
||||
{
|
||||
// Check if the first character is the start of and xml tag.
|
||||
@@ -179,7 +184,8 @@ bool XMLObject::ReadHead(const std::string& string, XMLLoadData& data)
|
||||
data.pos++;
|
||||
ReadWhiteSpace(string, data);
|
||||
if (string[data.pos] != '>')
|
||||
throw XMLException((std::string("Invalid character proceeding / in opening XML Tag \"") + string[data.pos] + "\".").c_str(), data);
|
||||
throw XMLException(
|
||||
(std::string("Invalid character proceeding / in opening XML Tag \"") + string[data.pos] + "\".").c_str(), data);
|
||||
data.pos++;
|
||||
// nothing more to read.
|
||||
return true;
|
||||
@@ -187,7 +193,9 @@ bool XMLObject::ReadHead(const std::string& string, XMLLoadData& data)
|
||||
|
||||
ReadWhiteSpace(string, data);
|
||||
if (string[data.pos] != '>')
|
||||
throw XMLException((std::string("Invalid character proceeding attributes in opening XML Tag \"") + string[data.pos] + "\".").c_str(), data);
|
||||
throw XMLException(
|
||||
(std::string("Invalid character proceeding attributes in opening XML Tag \"") + string[data.pos] + "\".").c_str(),
|
||||
data);
|
||||
(data.pos)++;
|
||||
return false;
|
||||
}
|
||||
@@ -203,7 +211,8 @@ void XMLObject::ReadName(const std::string& string, XMLLoadData& data)
|
||||
ReadWhiteSpace(string, data);
|
||||
if (string[data.pos] != '/' && string[data.pos] != '>' && Utils::IsWhiteSpace(string[data.pos]))
|
||||
{
|
||||
throw XMLException((std::string("Invalid character proceeding name in XML Tag \"") + string[data.pos] + "\".").c_str(), data);
|
||||
throw XMLException(
|
||||
(std::string("Invalid character proceeding name in XML Tag \"") + string[data.pos] + "\".").c_str(), data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,7 +239,9 @@ void XMLObject::ReadAttribute(const std::string& string, XMLLoadData& data)
|
||||
|
||||
// Read =
|
||||
if (string[data.pos] != '=')
|
||||
throw XMLException((std::string("Invalid character proceeding property name in XML Tag \"") + string[data.pos] + "\".").c_str(), data);
|
||||
throw XMLException(
|
||||
(std::string("Invalid character proceeding property name in XML Tag \"") + string[data.pos] + "\".").c_str(),
|
||||
data);
|
||||
(data.pos)++;
|
||||
ReadWhiteSpace(string, data);
|
||||
|
||||
@@ -256,7 +267,10 @@ void XMLObject::ReadBodyTail(const std::string& string, XMLLoadData& data)
|
||||
ReadWhiteSpace(string, data);
|
||||
std::string closeTag = GetClosingTag(string, data);
|
||||
if (closeTag.length() == 0)
|
||||
throw XMLException("Tag after XML Test was not a closing tag. XMLObject doesn't support text and other XMLObjects at the same time.", data);
|
||||
throw XMLException(
|
||||
"Tag after XML Test was not a closing tag. XMLObject doesn't support text and other XMLObjects at the same "
|
||||
"time.",
|
||||
data);
|
||||
return;
|
||||
}
|
||||
// Check if we can read the closing tag.
|
||||
@@ -279,14 +293,14 @@ void XMLObject::ReadText(const std::string& string, XMLLoadData& data)
|
||||
|
||||
void XMLObject::ReadWhiteSpace(const std::string& string, XMLLoadData& data)
|
||||
{
|
||||
while (Utils::IsWhiteSpace(string[data.pos])) {
|
||||
while (Utils::IsWhiteSpace(string[data.pos]))
|
||||
{
|
||||
if (string[data.pos] == '\n')
|
||||
(data.line)++;
|
||||
(data.pos)++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string XMLObject::GetClosingTag(const std::string& string, XMLLoadData& data)
|
||||
{
|
||||
int startPos = data.pos;
|
||||
@@ -307,7 +321,8 @@ std::string XMLObject::GetClosingTag(const std::string& string, XMLLoadData& dat
|
||||
ReadWhiteSpace(string, data);
|
||||
std::string tag = Utils::GetWord(string, data.pos);
|
||||
if (tag != name)
|
||||
throw XMLException((std::string("Closing tag doesn't match opening tag. (\"") + name + "\" != \"" + tag+ "\")").c_str(), data);
|
||||
throw XMLException(
|
||||
(std::string("Closing tag doesn't match opening tag. (\"") + name + "\" != \"" + tag + "\")").c_str(), data);
|
||||
data.pos += tag.length();
|
||||
ReadWhiteSpace(string, data);
|
||||
if (string[data.pos] != '>')
|
||||
@@ -318,14 +333,8 @@ std::string XMLObject::GetClosingTag(const std::string& string, XMLLoadData& dat
|
||||
|
||||
void XMLObject::ReplacePredefinedEntities(std::string& string, XMLLoadData& data)
|
||||
{
|
||||
std::vector<std::pair<std::string, std::string>> entities
|
||||
{
|
||||
{""","\""},
|
||||
{"'", "\'"},
|
||||
{"<", "<"},
|
||||
{">",">"},
|
||||
{"&", "&"}
|
||||
};
|
||||
std::vector<std::pair<std::string, std::string>> entities{
|
||||
{""", "\""}, {"'", "\'"}, {"<", "<"}, {">", ">"}, {"&", "&"}};
|
||||
size_t pos = string.find('&');
|
||||
while (pos != std::string::npos)
|
||||
{
|
||||
@@ -339,25 +348,21 @@ void XMLObject::ReplacePredefinedEntities(std::string& string, XMLLoadData& data
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
LOG_ERROR("(" + data.file + ":" + std::to_string(data.line) + "): ""Ampersand found in xml but isn't a predefined entity.");
|
||||
LOG_ERROR("(" + data.file + ":" + std::to_string(data.line) +
|
||||
"): "
|
||||
"Ampersand found in xml but isn't a predefined entity.");
|
||||
pos = string.find('&', pos + 1);
|
||||
}
|
||||
}
|
||||
|
||||
std::string XMLObject::ReadXMLName(const std::string& string, XMLLoadData& data)
|
||||
{
|
||||
if(!(Utils::IsLetter(string[data.pos]) ||
|
||||
string[data.pos] == '_' ||
|
||||
string[data.pos] == ':'))
|
||||
if (!(Utils::IsLetter(string[data.pos]) || string[data.pos] == '_' || string[data.pos] == ':'))
|
||||
throw XMLException(std::string("Name doesn't start with a letter."), data);
|
||||
|
||||
int endPos = data.pos + 1;
|
||||
while (endPos < string.length() && (
|
||||
Utils::IsLetter(string[endPos]) ||
|
||||
string[endPos] == '_' ||
|
||||
string[endPos] == '-' ||
|
||||
string[endPos] == ':' ||
|
||||
string[endPos] == '.'))
|
||||
while (endPos < string.length() && (Utils::IsLetter(string[endPos]) || string[endPos] == '_' ||
|
||||
string[endPos] == '-' || string[endPos] == ':' || string[endPos] == '.'))
|
||||
endPos++;
|
||||
return string.substr(data.pos, endPos - data.pos);
|
||||
}
|
||||
@@ -403,4 +408,3 @@ std::ostream& XMLObject::WriteToStream(std::ostream& stream, int indent) const
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
+11
-3
@@ -1,20 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class XMLObject
|
||||
{
|
||||
public:
|
||||
friend class XMLexception;
|
||||
|
||||
struct XMLLoadData
|
||||
{
|
||||
int pos;
|
||||
int line;
|
||||
const std::string& file;
|
||||
};
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
std::string text;
|
||||
@@ -23,12 +25,17 @@ class XMLObject
|
||||
std::map<std::string, std::vector<XMLObject>> objects;
|
||||
|
||||
public:
|
||||
XMLObject() {}
|
||||
XMLObject()
|
||||
{
|
||||
}
|
||||
|
||||
XMLObject(const std::string& string);
|
||||
XMLObject(const std::string& string, int pos, int line, const std::string& file);
|
||||
XMLObject(const std::string& string, XMLLoadData& data);
|
||||
XMLObject(const std::string& name, const std::map<std::string, std::string>& properties, const std::string& text);
|
||||
XMLObject(const std::string& name, const std::map<std::string, std::string>& properties, const std::map<std::string, std::vector<XMLObject>>& objects);
|
||||
XMLObject(const std::string& name,
|
||||
const std::map<std::string, std::string>& properties,
|
||||
const std::map<std::string, std::vector<XMLObject>>& objects);
|
||||
|
||||
bool HasAttribute(const std::string& property) const;
|
||||
const std::string& GetAttribute(const std::string& property) const;
|
||||
@@ -53,6 +60,7 @@ class XMLObject
|
||||
}
|
||||
|
||||
std::ostream& WriteToStream(std::ostream& stream, int indent = 0) const;
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& stream, const XMLObject& object)
|
||||
{
|
||||
return object.WriteToStream(stream);
|
||||
|
||||
Reference in New Issue
Block a user