Skip to content

Commit ff31d33

Browse files
committed
Incorporate 'push_format' directly into the "EditableString" mix-in.
- Moved 'fmt' dependency from 'utils' to 'collections' #ICE-200, #ICE-214 State Done
1 parent ca27968 commit ff31d33

File tree

17 files changed

+145
-170
lines changed

17 files changed

+145
-170
lines changed

source/code/core/collections/collections.bff

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
.Public =
1313
[
14+
.Modules = {
15+
'fmt'
16+
}
1417
.Uses = {
1518
'core'
1619
'memsys'

source/code/core/collections/public/ice/heap_string.hxx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,13 @@ namespace ice
253253
}
254254

255255
} // namespace ice
256+
257+
template<typename CharType>
258+
struct fmt::formatter<ice::HeapString<CharType>> : public fmt::formatter<ice::BasicString<CharType>>
259+
{
260+
template<typename FormatContext>
261+
constexpr auto format(ice::HeapString<CharType> const& value, FormatContext& ctx) const noexcept
262+
{
263+
return fmt::formatter<ice::BasicString<CharType>>::format({ value._data, value._size }, ctx);
264+
}
265+
};

source/code/core/collections/public/ice/shard_container.hxx

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,16 @@ namespace ice
3333
) const noexcept -> ice::ncount;
3434

3535
template<typename T>
36-
inline constexpr bool inspect_first(ice::ShardID shardid, T& payload) const noexcept;
36+
inline constexpr bool inspect_first(
37+
ice::ShardID shardid,
38+
T& payload
39+
) const noexcept;
3740

3841
template<typename T>
39-
inline constexpr bool inspect_last(ice::ShardID shard, T& payload) const noexcept;
42+
inline constexpr bool inspect_last(
43+
ice::ShardID shard,
44+
T& payload
45+
) const noexcept;
4046

4147
template<typename T, ice::ContainerLogic Logic>
4248
inline constexpr auto inspect_all(
@@ -50,7 +56,10 @@ namespace ice
5056
Fn&& callback
5157
) noexcept -> ice::ncount;
5258

53-
inline constexpr void remove_all_of(this ShardContainer& self, ice::ShardID shardid) noexcept;
59+
inline constexpr void remove_all_of(
60+
this ShardContainer& self,
61+
ice::ShardID shardid
62+
) noexcept;
5463
};
5564

5665
inline constexpr bool ShardContainer::contains(ice::ShardID expected_shard) const noexcept
@@ -138,21 +147,30 @@ namespace ice
138147
}
139148

140149
template<typename T>
141-
inline constexpr bool ShardContainer::inspect_first(ice::ShardID shardid, T& payload) const noexcept
150+
inline constexpr bool ShardContainer::inspect_first(
151+
ice::ShardID shardid,
152+
T& payload
153+
) const noexcept
142154
{
143155
ice::Shard const shard = this->find_first_of(shardid);
144156
return ice::shard_inspect(shard, payload);
145157
}
146158

147159
template<typename T>
148-
inline constexpr bool ShardContainer::inspect_last(ice::ShardID shardid, T& payload) const noexcept
160+
inline constexpr bool ShardContainer::inspect_last(
161+
ice::ShardID shardid,
162+
T& payload
163+
) const noexcept
149164
{
150165
ice::Shard const shard = this->find_last_of(shardid);
151166
return ice::shard_inspect(shard, payload);
152167
}
153168

154169
template<typename T, typename Fn>
155-
inline constexpr auto ShardContainer::inspect_each(ice::ShardID shardid, Fn&& callback) noexcept -> ice::ncount
170+
inline constexpr auto ShardContainer::inspect_each(
171+
ice::ShardID shardid,
172+
Fn&& callback
173+
) noexcept -> ice::ncount
156174
{
157175
T payload;
158176
ice::u32 count = 0;

source/code/core/collections/public/ice/string.hxx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <ice/stringid.hxx>
66
#include <ice/string/string_concepts.hxx>
77
#include <ice/string/readonly_operations.hxx>
8+
#include <fmt/format.h>
89

910
namespace ice
1011
{
@@ -112,3 +113,13 @@ namespace ice
112113
}
113114

114115
} // namespace ice
116+
117+
template<typename CharType>
118+
struct fmt::formatter<ice::BasicString<CharType>> : public fmt::formatter<std::basic_string_view<CharType>>
119+
{
120+
template<typename FormatContext>
121+
constexpr auto format(ice::BasicString<CharType> value, FormatContext& ctx) const noexcept
122+
{
123+
return fmt::formatter<std::basic_string_view<CharType>>::format(value, ctx);
124+
}
125+
};

source/code/core/collections/public/ice/string/editable_operations.hxx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#pragma once
55
#include <ice/string/readonly_operations.hxx>
6+
#include <fmt/format.h>
67

78
namespace ice::string
89
{
@@ -80,6 +81,41 @@ namespace ice::string
8081
}
8182
}
8283

84+
template<MutableStringType Self, typename... Args>
85+
inline constexpr void push_format(
86+
this Self& self,
87+
fmt::format_string<Args...> format,
88+
Args&&... args
89+
) noexcept
90+
{
91+
ice::ncount const pushed_size = ::fmt::formatted_size(format, std::forward<Args>(args)...);
92+
ice::ncount const final_size = self.size() + pushed_size;
93+
ice::ncount const capacity = self.capacity() - 1;
94+
95+
// Handle resizing if supported
96+
if constexpr (ice::concepts::ResizableStringType<Self>)
97+
{
98+
if (final_size >= capacity)
99+
{
100+
self.grow(final_size + 1);
101+
}
102+
103+
::fmt::format_to_n(self.end(), pushed_size, format, std::forward<Args>(args)...);
104+
}
105+
else
106+
{
107+
//ICE_ASSERT_CORE(final_size < capacity);
108+
final_size = ice::min(final_size, capacity);
109+
110+
ice::ncount const allowed_growth = capacity - self.size();
111+
if (allowed_growth > 0)
112+
{
113+
::fmt::format_to_n(self.end(), allowed_growth, format, std::forward<Args>(args)...);
114+
}
115+
}
116+
self.resize(final_size);
117+
}
118+
83119
template<MutableStringType Self>
84120
inline void pop_back(this Self& self, ice::ncount count = 1) noexcept
85121
{

source/code/core/utils/private/params.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ namespace ice
8383
) noexcept -> ice::Params
8484
{
8585
ice::HeapString<> description_with_version{ alloc, description };
86-
ice::string::push_format(description_with_version, " (v{})", version);
86+
description_with_version.push_format(" (v{})", version);
8787
return ice::make_unique<ice::ParamsInternal>(
8888
delete_params,
8989
alloc.create<ParamsInternal>(alloc, name, description_with_version)

source/code/core/utils/public/ice/config/config_builder.hxx

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -66,34 +66,4 @@ namespace ice
6666

6767
} // namespace config
6868

69-
// inline auto configbuilder_root(ConfigBuilder& b, ice::Allocator& alloc) noexcept -> ice::Memory
70-
// {
71-
// ConfigBuilderValue val = b["asd"];
72-
// b["asd"][0][1];
73-
// b["a"]["b"] = 31u;
74-
// val = b["a"];
75-
// val["c"][2] = ice::u8{42};
76-
// b["b"] = 32;
77-
// b["c"] = 33;
78-
// val = b["asd"][0];//[0][1]["ad"];
79-
// // b.reset();
80-
// val = b["e"][3];
81-
// b["e"][4];
82-
// ice::HeapVarString<>& str = b["f"] = "Test string";
83-
// str = "Maybe not?";
84-
// b["my"]["holy"]["cow"] = 69.420;
85-
86-
// ice::Memory mem = b.finalize(alloc);
87-
88-
// ice::Config c = ice::config::from_data(ice::data_view(mem));
89-
// [[maybe_unused]]
90-
// ice::u32 f;
91-
// ice::config::get<ice::u32>(c, "a.b", f);
92-
// ice::String s = ice::config::get<ice::String>(c, "f").value();
93-
// f = 23;
94-
95-
// alloc.deallocate(mem);
96-
// return {};
97-
// }
98-
9969
} // namespace ice

source/code/core/utils/public/ice/log_formatters.hxx

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,6 @@
99
#include <ice/clock_types.hxx>
1010
#include <ice/expected.hxx>
1111

12-
template<typename CharType>
13-
struct fmt::formatter<ice::BasicString<CharType>> : public fmt::formatter<std::basic_string_view<CharType>>
14-
{
15-
template<typename FormatContext>
16-
constexpr auto format(ice::BasicString<CharType> value, FormatContext& ctx) const noexcept
17-
{
18-
return fmt::formatter<std::basic_string_view<CharType>>::format(value, ctx);
19-
}
20-
};
21-
22-
template<typename CharType>
23-
struct fmt::formatter<ice::HeapString<CharType>> : public fmt::formatter<ice::BasicString<CharType>>
24-
{
25-
template<typename FormatContext>
26-
constexpr auto format(ice::HeapString<CharType> const& value, FormatContext& ctx) const noexcept
27-
{
28-
return fmt::formatter<ice::BasicString<CharType>>::format({ value._data, value._size }, ctx);
29-
}
30-
};
3112

3213
template<>
3314
struct fmt::formatter<ice::StringID_Hash>

source/code/core/utils/public/ice/path_utils.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace ice::path
5555
//! \returns The given path as a String value.
5656
auto replace_extension(ice::HeapString<>& path, ice::String extension) noexcept -> ice::String;
5757

58-
// Wider character implementations
58+
// Wide character implementations
5959

6060
bool is_absolute(ice::WString path) noexcept;
6161
bool is_absolute_root(ice::WString path) noexcept;

source/code/core/utils/public/ice/string_utils.hxx

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,6 @@ namespace ice
1717
namespace string
1818
{
1919

20-
template<typename... Args>
21-
constexpr void push_format(
22-
ice::string::ResizableStringType auto& str,
23-
fmt::format_string<Args...> format,
24-
Args&&... args
25-
) noexcept;
26-
27-
template<ice::u32 Capacity, typename... Args>
28-
constexpr void push_format(
29-
ice::StaticString<Capacity, char>& str,
30-
fmt::format_string<Args...> format,
31-
Args&&... args
32-
) noexcept;
33-
3420
template<typename Fn>
3521
constexpr auto for_each_split(
3622
ice::String contents,
@@ -184,40 +170,6 @@ namespace ice
184170
namespace string
185171
{
186172

187-
template<typename... Args>
188-
constexpr void push_format(
189-
ice::string::ResizableStringType auto& str,
190-
fmt::format_string<Args...> format,
191-
Args&&... args
192-
) noexcept
193-
{
194-
ice::ncount const pushed_size = fmt::formatted_size(format, ice::forward<Args>(args)...);
195-
ice::ncount const final_size = str.size() + pushed_size;
196-
if (final_size + 1 >= str.capacity())
197-
{
198-
str.grow(final_size + 1);
199-
}
200-
fmt::format_to_n(str.end(), pushed_size, format, ice::forward<Args>(args)...);
201-
str.resize(final_size);
202-
}
203-
204-
template<ice::u32 Capacity, typename... Args>
205-
constexpr void push_format(
206-
ice::StaticString<Capacity, char>& str,
207-
fmt::format_string<Args...> format,
208-
Args&&... args
209-
) noexcept
210-
{
211-
ice::ncount const pushed_size = fmt::formatted_size(format, ice::forward<Args>(args)...);
212-
ice::ncount const final_size = str.size() + pushed_size;
213-
if (final_size + 1 >= Capacity)
214-
{
215-
final_size = Capacity - 1;
216-
}
217-
fmt::format_to_n(str.end(), final_size, format, ice::forward<Args>(args)...);
218-
str.resize(final_size);
219-
}
220-
221173
template<typename Fn>
222174
constexpr auto for_each_split(ice::String contents, ice::String separator, Fn&& fn) noexcept -> ice::u32
223175
{

0 commit comments

Comments
 (0)