diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-08-02 11:30:06 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-08-02 11:30:06 +0100 |
| commit | d05275f76cf96d577d51ee937ba3aac3be8b2d03 (patch) | |
| tree | 0e2fb84d707353fa0a86abfc6e57831bfe5d89fe | |
| parent | 678f457a9797ae064634f8ba2a83b156f2892871 (diff) | |
feat! refactor the FIX module again to meet the standard C++ design conventions.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
| -rw-r--r-- | Doxyfile | 2 | ||||
| -rw-r--r-- | dev/examples/fix/fix.cc | 2 | ||||
| -rw-r--r-- | dev/lib/fix/parser.hpp | 44 | ||||
| -rw-r--r-- | dev/tests/fix_basic/fix_test.cc | 2 |
4 files changed, 25 insertions, 25 deletions
@@ -493,7 +493,7 @@ TYPEDEF_HIDES_STRUCT = NO # an expensive process and often the same symbol appears multiple times in the # code, Doxygen keeps a cache of pre-resolved symbols. If the cache is too small # Doxygen will become slower. If the cache is too large, memory is wasted. The -# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range +# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid basic_range # is 0..9, the default is 0, corresponding to a cache size of 2^16=65536 # symbols. At the end of a run Doxygen will report the cache usage and suggest # the optimal cache size from a speed point of view. diff --git a/dev/examples/fix/fix.cc b/dev/examples/fix/fix.cc index dfe4be9..3656c0c 100644 --- a/dev/examples/fix/fix.cc +++ b/dev/examples/fix/fix.cc @@ -16,7 +16,7 @@ int main(int argc, char** argv) constexpr auto default_fix = "8=FIX.4.2|9=65|35=A|49=SERVER|56=CLIENT|34=177|52=20090107-18:15:16|98=0|108=30|10=062|"; snu::fix::basic_visitor<char> basic_visitor; - snu::fix::range_data<char> fix = basic_visitor.visit(default_fix); + snu::fix::basic_range_data<char> fix = basic_visitor.visit(default_fix); std::cout << "magic=" << fix.magic_ << std::endl; std::cout << "magic_len=" << fix.magic_len_ << std::endl; diff --git a/dev/lib/fix/parser.hpp b/dev/lib/fix/parser.hpp index 5e3bc3b..f2509c7 100644 --- a/dev/lib/fix/parser.hpp +++ b/dev/lib/fix/parser.hpp @@ -24,14 +24,14 @@ namespace snu::fix struct basic_visitor; template <typename char_type> - struct range; + struct basic_range; template <typename char_type> - struct range_data; + struct basic_range_data; /// @brief Buffer+Length structure template <typename char_type> - using range_ptr_t = range<char_type>; + using range_ptr_t = basic_range<char_type>; namespace detail { @@ -58,7 +58,7 @@ namespace snu::fix } // namespace detail template <typename char_type> - struct range final + struct basic_range final { char_type* bytes_; size_t length_; @@ -74,20 +74,20 @@ namespace snu::fix } }; - /// @brief Convert range to usable string. - /// @note This function assumes that the range is valid and contains ASCII bytes. + /// @brief Convert basic_range to usable string. + /// @note This function assumes that the basic_range is valid and contains ASCII bytes. template <typename char_type> - inline std::basic_string<char_type> to_string(range<char_type>& range) noexcept + inline std::basic_string<char_type> to_string(basic_range<char_type>& basic_range) noexcept { - if (range.length_ < 0) + if (basic_range.length_ < 0) return std::basic_string<char_type>{}; - return std::basic_string<char_type>(range.ascii_bytes_, range.length_); + return std::basic_string<char_type>(basic_range.ascii_bytes_, basic_range.length_); } - /// @brief a range object containing the FIX packet values. + /// @brief a basic_range object containing the FIX packet values. template <typename char_type> - class range_data final + class basic_range_data final { public: std::size_t magic_len_; @@ -97,11 +97,11 @@ namespace snu::fix static inline const char_type* begin = detail::begin_fix<char_type>(); - explicit range_data() = default; - ~range_data() = default; + explicit basic_range_data() = default; + ~basic_range_data() = default; - range_data& operator=(const range_data&) = default; - range_data(const range_data&) = default; + basic_range_data& operator=(const basic_range_data&) = default; + basic_range_data(const basic_range_data&) = default; std::basic_string<char_type> operator[](const std::basic_string<char_type>& key) { @@ -123,7 +123,7 @@ namespace snu::fix bool is_valid() { - return magic_.starts_with(range_data<char_type>::begin); + return magic_.starts_with(basic_range_data<char_type>::begin); } operator bool() @@ -132,7 +132,7 @@ namespace snu::fix } }; - /// @brief basic_visitor object which returns a fix::range_data instance. + /// @brief basic_visitor object which returns a fix::basic_range_data instance. template <typename char_type> class basic_visitor final { @@ -147,14 +147,14 @@ namespace snu::fix basic_visitor& operator=(const basic_visitor&) = default; basic_visitor(const basic_visitor&) = default; - range<char_type> operator()(const std::basic_string<char_type>& in) + basic_range<char_type> operator()(const std::basic_string<char_type>& in) { return this->visit(in); } - range_data<char_type> visit(const std::basic_string<char_type>& in) + basic_range_data<char_type> visit(const std::basic_string<char_type>& in) { - thread_local range_data<char_type> ret{}; + thread_local basic_range_data<char_type> ret{}; if (in.empty()) return ret; @@ -202,9 +202,9 @@ namespace snu::fix }; template <typename char_type = char> - inline void must_pass(range_data<char_type>& range) + inline void must_pass(basic_range_data<char_type>& basic_range) { - if (!range.is_valid()) + if (!basic_range.is_valid()) { ::kill(::getpid(), SIGTRAP); } diff --git a/dev/tests/fix_basic/fix_test.cc b/dev/tests/fix_basic/fix_test.cc index 960c4a1..08f435c 100644 --- a/dev/tests/fix_basic/fix_test.cc +++ b/dev/tests/fix_basic/fix_test.cc @@ -11,7 +11,7 @@ TEST(FIXTest, BasicFIXUsage) { snu::fix::basic_visitor<char> basic_visitor; - snu::fix::range_data<char> fix = basic_visitor.visit("8=FIX.4.2|9=65|35=A|49=SERVER|56=CLIENT|34=177|52=20090107-18:15:16|98=0|108=30|10=062|"); + snu::fix::basic_range_data<char> fix = basic_visitor.visit("8=FIX.4.2|9=65|35=A|49=SERVER|56=CLIENT|34=177|52=20090107-18:15:16|98=0|108=30|10=062|"); EXPECT_EQ(fix.magic_, "FIX.4.2"); EXPECT_TRUE(fix.is_valid()); |
