|
17 | 17 |
|
18 | 18 | #include <range/v3/algorithm/max_element.hpp> |
19 | 19 |
|
| 20 | +#include "openvic-simulation/types/StackString.hpp" |
20 | 21 | #include "openvic-simulation/utility/ErrorMacros.hpp" |
21 | 22 | #include "openvic-simulation/utility/Getters.hpp" |
22 | | -#include "openvic-simulation/utility/Utility.hpp" |
23 | 23 | #include "openvic-simulation/utility/StringUtils.hpp" |
24 | | -#include "openvic-simulation/utility/Containers.hpp" |
| 24 | +#include "openvic-simulation/utility/Utility.hpp" |
25 | 25 |
|
26 | 26 | namespace OpenVic { |
27 | 27 | // A relative period between points in time, measured in days |
@@ -322,56 +322,13 @@ namespace OpenVic { |
322 | 322 | struct stack_string; |
323 | 323 | inline constexpr stack_string to_array(bool pad_year = false, bool pad_month = true, bool pad_day = true) const; |
324 | 324 |
|
325 | | - struct stack_string { |
326 | | - static constexpr size_t array_length = // |
327 | | - fmt::detail::count_digits(uint64_t(std::numeric_limits<year_t>::max())) + |
328 | | - fmt::detail::count_digits(uint64_t(MONTHS_IN_YEAR)) + fmt::detail::count_digits(uint64_t(MAX_DAYS_IN_MONTH)) + |
329 | | - 4; |
330 | | - |
331 | | - private: |
332 | | - std::array<char, array_length> array {}; |
333 | | - uint8_t string_size = 0; |
334 | | - |
335 | | - constexpr stack_string() {}; |
336 | | - |
| 325 | + struct stack_string final : StackString< |
| 326 | + fmt::detail::count_digits(uint64_t(std::numeric_limits<year_t>::max())) + |
| 327 | + fmt::detail::count_digits(uint64_t(MONTHS_IN_YEAR)) + |
| 328 | + fmt::detail::count_digits(uint64_t(MAX_DAYS_IN_MONTH)) + 4> { |
| 329 | + protected: |
| 330 | + using StackString::StackString; |
337 | 331 | friend inline constexpr stack_string Date::to_array(bool pad_year, bool pad_month, bool pad_day) const; |
338 | | - |
339 | | - public: |
340 | | - constexpr const char* data() const { |
341 | | - return array.data(); |
342 | | - } |
343 | | - |
344 | | - constexpr size_t size() const { |
345 | | - return string_size; |
346 | | - } |
347 | | - |
348 | | - constexpr size_t length() const { |
349 | | - return string_size; |
350 | | - } |
351 | | - |
352 | | - constexpr decltype(array)::const_iterator begin() const { |
353 | | - return array.begin(); |
354 | | - } |
355 | | - |
356 | | - constexpr decltype(array)::const_iterator end() const { |
357 | | - return begin() + size(); |
358 | | - } |
359 | | - |
360 | | - constexpr decltype(array)::const_reference operator[](size_t index) const { |
361 | | - return array[index]; |
362 | | - } |
363 | | - |
364 | | - constexpr bool empty() const { |
365 | | - return size() == 0; |
366 | | - } |
367 | | - |
368 | | - constexpr operator std::string_view() const { |
369 | | - return std::string_view { data(), data() + size() }; |
370 | | - } |
371 | | - |
372 | | - operator memory::string() const { |
373 | | - return memory::string { data(), size() }; |
374 | | - } |
375 | 332 | }; |
376 | 333 |
|
377 | 334 | memory::string to_string(bool pad_year = false, bool pad_month = true, bool pad_day = true) const; |
@@ -620,8 +577,8 @@ namespace OpenVic { |
620 | 577 | inline constexpr Date::stack_string Date::to_array(bool pad_year, bool pad_month, bool pad_day) const { |
621 | 578 | stack_string str {}; |
622 | 579 | std::to_chars_result result = |
623 | | - to_chars(str.array.data(), str.array.data() + str.array.size(), pad_year, pad_month, pad_day); |
624 | | - str.string_size = result.ptr - str.data(); |
| 580 | + to_chars(str._array.data(), str._array.data() + str._array.size(), pad_year, pad_month, pad_day); |
| 581 | + str._string_size = result.ptr - str.data(); |
625 | 582 | return str; |
626 | 583 | } |
627 | 584 | } |
|
0 commit comments