Skip to content

Commit e4b892c

Browse files
Updating ToString() for data structures
1 parent f1a0c21 commit e4b892c

15 files changed

+317
-148
lines changed

Include/runcpp2/Data/StageInfo.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ namespace runcpp2
5858
std::string& outCommand) const;
5959

6060
bool ParseYAML_Node(ryml::ConstNodeRef& node, std::string outputTypeKeyName);
61-
std::string ToString(std::string indentation) const;
61+
std::string ToString( std::string indentation,
62+
std::string outputTypeKeyName) const;
6263
bool Equals(const StageInfo& other) const;
6364
};
6465
}

Src/runcpp2/Data/DependencyCommands.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,20 @@ bool runcpp2::Data::DependencyCommands::ParseYAML_Node(ryml::ConstNodeRef& node)
3434
std::string runcpp2::Data::DependencyCommands::ToString(std::string indentation) const
3535
{
3636
std::string out;
37+
38+
if(CommandSteps.empty())
39+
return out;
40+
3741
for(auto it = CommandSteps.begin(); it != CommandSteps.end(); it++)
3842
{
39-
out += indentation + it->first + ":\n";
40-
for(int i = 0; i < it->second.size(); i++)
41-
out += indentation + "- " + it->second[i] + "\n";
43+
if(it->second.empty())
44+
out += indentation + it->first + ": []\n";
45+
else
46+
{
47+
out += indentation + it->first + ":\n";
48+
for(int i = 0; i < it->second.size(); i++)
49+
out += indentation + "- " + GetEscapedYAMLString(it->second[i]) + "\n";
50+
}
4251
}
4352

4453
return out;

Src/runcpp2/Data/DependencyInfo.cpp

Lines changed: 56 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -167,62 +167,81 @@ bool runcpp2::Data::DependencyInfo::ParseYAML_Node(ryml::ConstNodeRef& node)
167167
std::string runcpp2::Data::DependencyInfo::ToString(std::string indentation) const
168168
{
169169
std::string out;
170-
out += indentation + "- Name: " + Name + "\n";
170+
out += indentation + "Name: " + GetEscapedYAMLString(Name) + "\n";
171171

172-
out += indentation + " Platforms:\n";
172+
out += indentation + "Platforms:\n";
173173
for(auto it = Platforms.begin(); it != Platforms.end(); ++it)
174-
out += indentation + " - " + *it + "\n";
174+
out += indentation + "- " + GetEscapedYAMLString(*it) + "\n";
175175

176+
out += indentation + "Source:\n";
176177
out += Source.ToString(indentation + " ");
177178

178179
static_assert((int)DependencyLibraryType::COUNT == 4, "");
179180

180181
if(LibraryType == DependencyLibraryType::STATIC)
181-
out += indentation + " LibraryType: Static\n";
182+
out += indentation + "LibraryType: Static\n";
182183
else if(LibraryType == DependencyLibraryType::SHARED)
183-
out += indentation + " LibraryType: Shared\n";
184+
out += indentation + "LibraryType: Shared\n";
184185
else if(LibraryType == DependencyLibraryType::OBJECT)
185-
out += indentation + " LibraryType: Object\n";
186+
out += indentation + "LibraryType: Object\n";
186187
else if(LibraryType == DependencyLibraryType::HEADER)
187-
out += indentation + " LibraryType: Header\n";
188+
out += indentation + "LibraryType: Header\n";
188189

189-
out += indentation + " IncludePaths:\n";
190-
for(auto it = IncludePaths.begin(); it != IncludePaths.end(); ++it)
191-
out += indentation + " - " + *it + "\n";
190+
if(!IncludePaths.empty())
191+
{
192+
out += indentation + "IncludePaths:\n";
193+
for(auto it = IncludePaths.begin(); it != IncludePaths.end(); ++it)
194+
out += indentation + "- " + GetEscapedYAMLString(*it) + "\n";
195+
}
192196

193-
out += indentation + " LinkProperties:\n";
194-
for(auto it = LinkProperties.begin(); it != LinkProperties.end(); ++it)
197+
if(!LinkProperties.empty())
195198
{
196-
out += indentation + " " + it->first + ":\n";
197-
out += it->second.ToString(indentation + " ");
199+
out += indentation + "LinkProperties:\n";
200+
for(auto it = LinkProperties.begin(); it != LinkProperties.end(); ++it)
201+
{
202+
out += indentation + " " + it->first + ":\n";
203+
out += it->second.ToString(indentation + " ");
204+
}
198205
}
199206

200-
out += indentation + " Setup:\n";
201-
for(auto it = Setup.begin(); it != Setup.end(); ++it)
207+
if(!Setup.empty())
202208
{
203-
out += indentation + " " + it->first + ":\n";
204-
out += it->second.ToString(indentation + " ");
209+
out += indentation + "Setup:\n";
210+
for(auto it = Setup.begin(); it != Setup.end(); ++it)
211+
{
212+
out += indentation + " " + it->first + ":\n";
213+
out += it->second.ToString(indentation + " ");
214+
}
205215
}
206216

207-
out += indentation + " Cleanup:\n";
208-
for(auto it = Cleanup.begin(); it != Cleanup.end(); ++it)
217+
if(!Cleanup.empty())
209218
{
210-
out += indentation + " " + it->first + ":\n";
211-
out += it->second.ToString(indentation + " ");
219+
out += indentation + "Cleanup:\n";
220+
for(auto it = Cleanup.begin(); it != Cleanup.end(); ++it)
221+
{
222+
out += indentation + " " + it->first + ":\n";
223+
out += it->second.ToString(indentation + " ");
224+
}
212225
}
213226

214-
out += indentation + " Build:\n";
215-
for(auto it = Build.begin(); it != Build.end(); ++it)
227+
if(!Build.empty())
216228
{
217-
out += indentation + " " + it->first + ":\n";
218-
out += it->second.ToString(indentation + " ");
229+
out += indentation + "Build:\n";
230+
for(auto it = Build.begin(); it != Build.end(); ++it)
231+
{
232+
out += indentation + " " + it->first + ":\n";
233+
out += it->second.ToString(indentation + " ");
234+
}
219235
}
220236

221-
out += indentation + " FilesToCopy:\n";
222-
for(auto it = FilesToCopy.begin(); it != FilesToCopy.end(); ++it)
237+
if(!FilesToCopy.empty())
223238
{
224-
out += indentation + " " + it->first + ":\n";
225-
out += it->second.ToString(indentation + " ");
239+
out += indentation + "FilesToCopy:\n";
240+
for(auto it = FilesToCopy.begin(); it != FilesToCopy.end(); ++it)
241+
{
242+
out += indentation + " " + it->first + ":\n";
243+
out += it->second.ToString(indentation + " ");
244+
}
226245
}
227246

228247
return out;
@@ -231,7 +250,7 @@ std::string runcpp2::Data::DependencyInfo::ToString(std::string indentation) con
231250
bool runcpp2::Data::DependencyInfo::Equals(const DependencyInfo& other) const
232251
{
233252
if( Name != other.Name ||
234-
Platforms != other.Platforms ||
253+
Platforms.size() != other.Platforms.size() ||
235254
!Source.Equals(other.Source) ||
236255
LibraryType != other.LibraryType ||
237256
IncludePaths != other.IncludePaths ||
@@ -245,6 +264,12 @@ bool runcpp2::Data::DependencyInfo::Equals(const DependencyInfo& other) const
245264
return false;
246265
}
247266

267+
for(const std::string& it : Platforms)
268+
{
269+
if(other.Platforms.count(it) == 0)
270+
return false;
271+
}
272+
248273
for(const auto& it : LinkProperties)
249274
{
250275
if( other.LinkProperties.count(it.first) == 0 ||

Src/runcpp2/Data/DependencyLinkProperty.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,26 +74,36 @@ std::string runcpp2::Data::DependencyLinkProperty::ToString(std::string indentat
7474
out += indentation + profilePair.first + ":\n";
7575
const ProfileLinkProperty& property = profilePair.second;
7676

77-
out += indentation + " SearchLibraryNames:\n";
78-
for(const std::string& name : property.SearchLibraryNames)
79-
out += indentation + " - " + name + "\n";
77+
if(property.SearchLibraryNames.empty())
78+
out += indentation + " SearchLibraryNames: []\n";
79+
else
80+
{
81+
out += indentation + " SearchLibraryNames:\n";
82+
for(const std::string& name : property.SearchLibraryNames)
83+
out += indentation + " - " + GetEscapedYAMLString(name) + "\n";
84+
}
8085

81-
out += indentation + " SearchDirectories:\n";
82-
for(const std::string& dir : property.SearchDirectories)
83-
out += indentation + " - " + dir + "\n";
86+
if(property.SearchDirectories.empty())
87+
out += indentation + " SearchDirectories: []\n";
88+
else
89+
{
90+
out += indentation + " SearchDirectories:\n";
91+
for(const std::string& dir : property.SearchDirectories)
92+
out += indentation + " - " + GetEscapedYAMLString(dir) + "\n";
93+
}
8494

8595
if(!property.ExcludeLibraryNames.empty())
8696
{
8797
out += indentation + " ExcludeLibraryNames:\n";
8898
for(const std::string& name : property.ExcludeLibraryNames)
89-
out += indentation + " - " + name + "\n";
99+
out += indentation + " - " + GetEscapedYAMLString(name) + "\n";
90100
}
91101

92102
if(!property.AdditionalLinkOptions.empty())
93103
{
94104
out += indentation + " AdditionalLinkOptions:\n";
95105
for(const std::string& option : property.AdditionalLinkOptions)
96-
out += indentation + " - " + option + "\n";
106+
out += indentation + " - " + GetEscapedYAMLString(option) + "\n";
97107
}
98108
}
99109

Src/runcpp2/Data/DependencySource.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ bool runcpp2::Data::DependencySource::ParseYAML_Node(ryml::ConstNodeRef& node)
3939

4040
std::string runcpp2::Data::DependencySource::ToString(std::string indentation) const
4141
{
42-
std::string out = indentation + "Source:\n";
42+
std::string out;
4343

4444
static_assert((int)DependencySourceType::COUNT == 2, "");
4545

4646
if(Type == DependencySourceType::GIT)
47-
out += indentation + " Type: Git\n";
47+
out += indentation + "Type: Git\n";
4848
else if(Type == DependencySourceType::LOCAL)
49-
out += indentation + " Type: Local\n";
49+
out += indentation + "Type: Local\n";
5050

51-
out += indentation + " Value: " + Value + "\n";
51+
out += indentation + "Value: " + GetEscapedYAMLString(Value) + "\n";
5252

5353
return out;
5454
}

Src/runcpp2/Data/FileProperties.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,18 @@ std::string runcpp2::Data::FileProperties::ToString(std::string indentation) con
4949
std::string out;
5050

5151
if(!Prefix.empty())
52-
out += indentation + "Prefix: \n";
53-
54-
for(auto it = Prefix.begin(); it != Prefix.end(); ++it)
55-
out += indentation + " " + it->first + ": " + it->second + "\n";
52+
{
53+
out += indentation + "Prefix:\n";
54+
for(const auto& it : Prefix)
55+
out += indentation + " " + it.first + ": " + GetEscapedYAMLString(it.second) + "\n";
56+
}
5657

5758
if(!Extension.empty())
58-
out += indentation + "Extension: \n";
59-
60-
for(auto it = Extension.begin(); it != Extension.end(); ++it)
61-
out += indentation + " " + it->first + ": " + it->second + "\n";
59+
{
60+
out += indentation + "Extension:\n";
61+
for(const auto& it : Extension)
62+
out += indentation + " " + it.first + ": " + GetEscapedYAMLString(it.second) + "\n";
63+
}
6264

6365
out += "\n";
6466
return out;

Src/runcpp2/Data/FilesToCopyInfo.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,20 @@ bool runcpp2::Data::FilesToCopyInfo::ParseYAML_Node(const ryml::ConstNodeRef& no
3333
std::string runcpp2::Data::FilesToCopyInfo::ToString(std::string indentation) const
3434
{
3535
std::string out;
36+
37+
if(ProfileFiles.empty())
38+
return out;
39+
3640
for(auto it = ProfileFiles.begin(); it != ProfileFiles.end(); it++)
3741
{
38-
out += indentation + it->first + ":\n";
39-
for(int i = 0; i < it->second.size(); i++)
40-
out += indentation + "- " + it->second[i] + "\n";
42+
if(it->second.empty())
43+
out += indentation + it->first + ": []\n";
44+
else
45+
{
46+
out += indentation + it->first + ":\n";
47+
for(int i = 0; i < it->second.size(); i++)
48+
out += indentation + "- " + GetEscapedYAMLString(it->second[i]) + "\n";
49+
}
4150
}
4251

4352
return out;

Src/runcpp2/Data/FilesTypesInfo.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,11 @@ std::string runcpp2::Data::FilesTypesInfo::ToString(std::string indentation) con
8484
out += indentation + "StaticLinkFile:\n";
8585
out += StaticLinkFile.ToString(indentation + " ");
8686

87-
out += indentation + "DebugSymbolFile:\n";
88-
out += DebugSymbolFile.ToString(indentation + " ");
87+
if(!DebugSymbolFile.Prefix.empty() || !DebugSymbolFile.Extension.empty())
88+
{
89+
out += indentation + "DebugSymbolFile:\n";
90+
out += DebugSymbolFile.ToString(indentation + " ");
91+
}
8992

9093
return out;
9194
}

Src/runcpp2/Data/FlagsOverrideInfo.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ bool runcpp2::Data::FlagsOverrideInfo::ParseYAML_Node(ryml::ConstNodeRef& node)
3333
std::string runcpp2::Data::FlagsOverrideInfo::ToString(std::string indentation) const
3434
{
3535
std::string out;
36-
out += indentation + "Remove: " + Remove + "\n";
37-
out += indentation + "Append: " + Append + "\n";
36+
37+
if(!Remove.empty())
38+
out += indentation + "Remove: " + GetEscapedYAMLString(Remove) + "\n";
39+
40+
if(!Append.empty())
41+
out += indentation + "Append: " + GetEscapedYAMLString(Append) + "\n";
3842

3943
return out;
4044
}

0 commit comments

Comments
 (0)