Skip to content

Commit 19b50d4

Browse files
committed
Fix hash_combine header.
1 parent 74b448c commit 19b50d4

4 files changed

Lines changed: 115 additions & 123 deletions

File tree

src/common/package.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "project_path.h"
2323
#include "version.h"
2424

25-
#include <primitives/hash.h>
25+
#include <primitives/hash_combine.h>
2626

2727
#include <map>
2828

src/common/project.cpp

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,7 @@ void saveOptionsMap(yaml &node, const OptionsMap &m)
14621462

14631463
String Project::print_cpp()
14641464
{
1465-
Context ctx;
1465+
CppContext ctx;
14661466

14671467
String name = pkg.ppath.back();
14681468

@@ -1762,7 +1762,7 @@ String Project::print_cpp()
17621762

17631763
String Project::print_cpp2()
17641764
{
1765-
Context ctx;
1765+
CppContext ctx;
17661766

17671767
String name = pkg.ppath.back();
17681768

@@ -1908,64 +1908,56 @@ String Project::print_cpp2()
19081908
return s;
19091909
};
19101910

1911-
auto print_def = [&ctx, &name, &escape_str](auto &k, auto &v, const String &type = {})
1911+
auto print_def = [&ctx, &name, &escape_str](auto &k, auto &v, const String &ending, const String &type = {})
19121912
{
19131913
if (k == "private")
1914-
ctx.addLine(name + ".Private += " + (type.empty() ? "" : (type + ", ")) + "\"" + escape_str(v) + "\"_d;");
1914+
ctx.addLine(name + ".Private += " + (type.empty() ? "" : (type + ", ")) + "\"" + escape_str(v) + "\"_" + ending + ";");
19151915
else if (k == "public")
1916-
ctx.addLine(name + ".Public += \"" + escape_str(v) + "\"_d;");
1916+
ctx.addLine(name + ".Public += " + (type.empty() ? "" : (type + ", ")) + "\"" + escape_str(v) + "\"_" + ending + ";");
19171917
else if (k == "interface")
1918-
ctx.addLine(name + ".Interface += \"" + escape_str(v) + "\"_d;");
1918+
ctx.addLine(name + ".Interface += " + (type.empty() ? "" : (type + ", ")) + "\"" + escape_str(v) + "\"_" + ending + ";");
19191919
};
19201920

1921-
auto print_co = [&ctx, &name, &escape_str](auto &k, auto &v, const String &type = {})
1922-
{
1923-
/*if (k == "private")
1924-
ctx.addLine(name + ".Private += " + (type.empty() ? "" : (type + ", ")) + "\"" + escape_str(v) + "\"_d;");
1925-
else if (k == "public")
1926-
ctx.addLine(name + ".Public += \"" + escape_str(v) + "\"_d;");
1927-
else if (k == "interface")
1928-
ctx.addLine(name + ".Interface += \"" + escape_str(v) + "\"_d;");*/
1929-
};
1930-
1931-
auto print_group = [this, &print_def, &print_co, &ctx](const String &gn, const String &type = {})
1921+
auto print_group = [this, &print_def, &ctx](const String &gn, const String &type = {})
19321922
{
19331923
auto g = options.find(gn);
19341924
if (g == options.end())
19351925
return;
19361926

1937-
auto print_obj = [&ctx, &type](auto &obj, auto &sysobj, auto f)
1927+
auto print_obj = [&ctx, &type](auto &obj, auto &sysobj, auto f, const String &ending)
19381928
{
19391929
for (auto &[k, v] : obj)
1940-
f(k, v, type);
1930+
f(k, v, ending, type);
19411931
for (auto &[k2, v2] : sysobj)
19421932
{
19431933
if (k2 == "win32")
19441934
{
19451935
ctx.beginBlock("if (s.Settings.TargetOS.Type == OSType::Windows)");
19461936
for (auto &[k, v] : v2)
1947-
f(k, v);
1937+
f(k, v, ending);
19481938
ctx.endBlock();
19491939
}
19501940
else if (k2 == "unix")
19511941
{
19521942
ctx.beginBlock("if (s.Settings.TargetOS.Type != OSType::Windows)");
19531943
for (auto &[k, v] : v2)
1954-
f(k, v);
1944+
f(k, v, ending);
19551945
ctx.endBlock();
19561946
}
19571947
else if (k2 == "msvc")
19581948
{
19591949
ctx.beginBlock("if (s.Settings.Native.CompilerType == CompilerType::MSVC)");
19601950
for (auto &[k, v] : v2)
1961-
f(k, v);
1951+
f(k, v, ending);
19621952
ctx.endBlock();
19631953
}
19641954
}
19651955
};
19661956

1967-
print_obj(g->second.definitions, g->second.system_definitions, print_def);
1968-
print_obj(g->second.compile_options, g->second.system_compile_options, print_co);
1957+
print_obj(g->second.definitions, g->second.system_definitions, print_def, "d");
1958+
print_obj(g->second.compile_options, g->second.system_compile_options, print_def, "xxx");
1959+
print_obj(g->second.link_options, g->second.system_link_options, print_def, "xxx");
1960+
print_obj(g->second.link_libraries, g->second.system_link_libraries, print_def, "lib");
19691961
};
19701962

19711963
print_group("any");

src/common/project_path.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "filesystem.h"
2121
#include "yaml.h"
2222

23-
#include <primitives/hash.h>
23+
#include <primitives/hash_combine.h>
2424

2525
#define ROOT_PROJECT_PATH(name) \
2626
static ProjectPath name() \

src/common/version.h

Lines changed: 97 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,97 @@
1-
/*
2-
* Copyright (C) 2016-2017, Egor Pugin
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
17-
#pragma once
18-
19-
#include "cppan_string.h"
20-
#include "filesystem.h"
21-
22-
#include <primitives/hash.h>
23-
24-
#define LOCAL_VERSION_NAME "local"
25-
26-
using ProjectId = uint64_t;
27-
using ProjectVersionId = uint64_t;
28-
using ProjectVersionNumber = int32_t;
29-
30-
enum class VersionType
31-
{
32-
Any,
33-
Equal,
34-
Version,
35-
Branch,
36-
};
37-
38-
struct Version
39-
{
40-
// undef gcc symbols
41-
#ifdef major
42-
#undef major
43-
#endif
44-
#ifdef minor
45-
#undef minor
46-
#endif
47-
#ifdef patch
48-
#undef patch
49-
#endif
50-
51-
ProjectVersionNumber major = -1;
52-
ProjectVersionNumber minor = -1;
53-
ProjectVersionNumber patch = -1;
54-
String branch;
55-
VersionType type{ VersionType::Any };
56-
57-
Version(ProjectVersionNumber ma = -1, ProjectVersionNumber mi = -1, ProjectVersionNumber pa = -1);
58-
Version(const String &s);
59-
60-
String toAnyVersion() const;
61-
String toString() const;
62-
path toPath() const;
63-
64-
bool isValid() const;
65-
bool isBranch() const;
66-
bool isVersion() const;
67-
68-
// checks if this version can be rhs using upgrade rules
69-
// does not check branches!
70-
// rhs should be exact version
71-
bool canBe(const Version &rhs) const;
72-
73-
bool operator<(const Version &rhs) const;
74-
bool operator==(const Version &rhs) const;
75-
bool operator!=(const Version &rhs) const;
76-
77-
static bool check_branch_name(const String &n, String *error = nullptr);
78-
};
79-
80-
namespace std
81-
{
82-
83-
template<> struct hash<Version>
84-
{
85-
size_t operator()(const Version& v) const
86-
{
87-
if (!v.branch.empty())
88-
return std::hash<String>()(v.branch);
89-
size_t h = 0;
90-
hash_combine(h, v.major);
91-
hash_combine(h, v.minor);
92-
hash_combine(h, v.patch);
93-
return h;
94-
}
95-
};
96-
97-
}
1+
/*
2+
* Copyright (C) 2016-2017, Egor Pugin
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#pragma once
18+
19+
#include "cppan_string.h"
20+
#include "filesystem.h"
21+
22+
#include <primitives/hash_combine.h>
23+
24+
#define LOCAL_VERSION_NAME "local"
25+
26+
using ProjectId = uint64_t;
27+
using ProjectVersionId = uint64_t;
28+
using ProjectVersionNumber = int32_t;
29+
30+
enum class VersionType
31+
{
32+
Any,
33+
Equal,
34+
Version,
35+
Branch,
36+
};
37+
38+
struct Version
39+
{
40+
// undef gcc symbols
41+
#ifdef major
42+
#undef major
43+
#endif
44+
#ifdef minor
45+
#undef minor
46+
#endif
47+
#ifdef patch
48+
#undef patch
49+
#endif
50+
51+
ProjectVersionNumber major = -1;
52+
ProjectVersionNumber minor = -1;
53+
ProjectVersionNumber patch = -1;
54+
String branch;
55+
VersionType type{ VersionType::Any };
56+
57+
Version(ProjectVersionNumber ma = -1, ProjectVersionNumber mi = -1, ProjectVersionNumber pa = -1);
58+
Version(const String &s);
59+
60+
String toAnyVersion() const;
61+
String toString() const;
62+
path toPath() const;
63+
64+
bool isValid() const;
65+
bool isBranch() const;
66+
bool isVersion() const;
67+
68+
// checks if this version can be rhs using upgrade rules
69+
// does not check branches!
70+
// rhs should be exact version
71+
bool canBe(const Version &rhs) const;
72+
73+
bool operator<(const Version &rhs) const;
74+
bool operator==(const Version &rhs) const;
75+
bool operator!=(const Version &rhs) const;
76+
77+
static bool check_branch_name(const String &n, String *error = nullptr);
78+
};
79+
80+
namespace std
81+
{
82+
83+
template<> struct hash<Version>
84+
{
85+
size_t operator()(const Version& v) const
86+
{
87+
if (!v.branch.empty())
88+
return std::hash<String>()(v.branch);
89+
size_t h = 0;
90+
hash_combine(h, v.major);
91+
hash_combine(h, v.minor);
92+
hash_combine(h, v.patch);
93+
return h;
94+
}
95+
};
96+
97+
}

0 commit comments

Comments
 (0)