-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cceb32e
commit 733eae0
Showing
12 changed files
with
859 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2024 Man Group Operations Limited | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include "sparrow/layout/array_trivial_copyable.hpp" | ||
#include "sparrow/layout/temporal/time_types.hpp" | ||
|
||
// tts : std::chrono::seconds | ||
|
||
namespace sparrow | ||
{ | ||
using time_types_t = mpl:: | ||
typelist<chrono::time_seconds, chrono::time_milliseconds, chrono::time_microseconds, chrono::time_nanoseconds>; | ||
|
||
static constexpr time_types_t time_types; | ||
template <typename T> | ||
concept time_type = mpl::contains<T>(time_types); | ||
|
||
/** | ||
* Array of time values. | ||
* | ||
* As the other arrays in sparrow, \c time_array<T> provides an API as if it was holding | ||
* \c nullable<T> values instead of \c T values. | ||
* | ||
* Internally, the array contains a validity bitmap and a contiguous memory buffer | ||
* holding the values. | ||
* | ||
* @tparam T the type of the values in the array. | ||
* @see https://arrow.apache.org/docs/dev/format/Columnar.html#fixed-size-primitive-layout | ||
*/ | ||
template <time_type T> | ||
using time_array = array_trivial_copyable<T>; | ||
|
||
using time_seconds_array = time_array<chrono::time_seconds>; | ||
using time_milliseconds_array = time_array<chrono::time_milliseconds>; | ||
using time_microseconds_array = time_array<chrono::time_microseconds>; | ||
using time_nanoseconds_array = time_array<chrono::time_nanoseconds>; | ||
|
||
template <class T> | ||
struct is_time_array : std::false_type | ||
{ | ||
}; | ||
|
||
template <class T> | ||
struct is_time_array<time_array<T>> : std::true_type | ||
{ | ||
}; | ||
|
||
/** | ||
* Checks whether T is a time_array type. | ||
*/ | ||
template <class T> | ||
constexpr bool is_time_array_v = is_time_array<T>::value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright 2024 Man Group Operations Limited | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include <chrono> | ||
#include <cstdint> | ||
|
||
#if defined(__cpp_lib_format) | ||
# include <format> | ||
#endif | ||
|
||
namespace sparrow::chrono | ||
{ | ||
/** | ||
* A duration representing time elapsed since midnight. | ||
*/ | ||
struct time_seconds : public std::chrono::duration<int32_t> | ||
{ | ||
time_seconds() = default; | ||
|
||
explicit time_seconds(int32_t seconds) | ||
: std::chrono::duration<int32_t>(seconds) | ||
{ | ||
} | ||
}; | ||
|
||
/** | ||
* A duration representing time elapsed since midnight, in milliseconds. | ||
*/ | ||
struct time_milliseconds : public std::chrono::duration<int32_t, std::milli> | ||
{ | ||
time_milliseconds() = default; | ||
|
||
explicit time_milliseconds(int32_t milliseconds) | ||
: std::chrono::duration<int32_t, std::milli>(milliseconds) | ||
{ | ||
} | ||
}; | ||
|
||
/** | ||
* A duration representing time elapsed since midnight, in microseconds. | ||
*/ | ||
struct time_microseconds : public std::chrono::duration<int64_t, std::micro> | ||
{ | ||
time_microseconds() = default; | ||
|
||
explicit time_microseconds(int64_t microseconds) | ||
: std::chrono::duration<int64_t, std::micro>(microseconds) | ||
{ | ||
} | ||
}; | ||
|
||
/** | ||
* A duration representing time elapsed since midnight, in nanoseconds. | ||
*/ | ||
struct time_nanoseconds : public std::chrono::duration<int64_t, std::nano> | ||
{ | ||
time_nanoseconds() = default; | ||
|
||
explicit time_nanoseconds(int64_t nanoseconds) | ||
: std::chrono::duration<int64_t, std::nano>(nanoseconds) | ||
{ | ||
} | ||
}; | ||
} | ||
|
||
#if defined(__cpp_lib_format) | ||
|
||
template <typename T> | ||
requires std::same_as<T, sparrow::chrono::time_seconds> | ||
|| std::same_as<T, sparrow::chrono::time_milliseconds> | ||
|| std::same_as<T, sparrow::chrono::time_microseconds> | ||
|| std::same_as<T, sparrow::chrono::time_nanoseconds> | ||
struct std::formatter<T> | ||
{ | ||
constexpr auto parse(std::format_parse_context& ctx) | ||
{ | ||
return ctx.begin(); // Simple implementation | ||
} | ||
|
||
auto format(const T& time, std::format_context& ctx) const | ||
{ | ||
return std::format_to(ctx.out(), "{}", time.count()); | ||
} | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.