summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--README.md11
-rw-r--r--examples/fix_tag_example/example.cc2
-rw-r--r--examples/hash_crc32_example/example.cc2
-rw-r--r--include/ocl/core/config.hpp5
-rw-r--r--include/ocl/core/is_same.hpp8
-rw-r--r--include/ocl/core/option.hpp23
-rw-r--r--include/ocl/fix/parser.hpp2
-rw-r--r--include/ocl/hashing/crc_hash.hpp5
-rw-r--r--include/ocl/io/print.hpp31
-rw-r--r--include/ocl/net/unique_socket.hpp6
-rw-r--r--tests/network_basic/network_basic_test.cc7
11 files changed, 72 insertions, 30 deletions
diff --git a/README.md b/README.md
index 7288ae4..203390e 100644
--- a/README.md
+++ b/README.md
@@ -2,20 +2,21 @@
[![License: BSL](https://img.shields.io/badge/license-BSL-blue.svg)](LICENSE)
-## Brief:
-
-A set of containers in C++ for developers.
+A set of containers in C++ for developers.<br/>
+You use them to speed up your development cycle for C++ applications.
## Requirements:
+The OCL requires the following:
+
- [Boost](https://www.boost.org/)
- [Clang](https://clang.llvm.org/)
- [CMake](https://cmake.org/)
- [Git](https://git-scm.com/)
-## Examples:
+### Example: The Option container
-### Logic Module (Option container)
+Evaluates whether an expression is passing the options.
```cpp
#include <logic/option.hpp>
diff --git a/examples/fix_tag_example/example.cc b/examples/fix_tag_example/example.cc
index 640dfbe..ad9725b 100644
--- a/examples/fix_tag_example/example.cc
+++ b/examples/fix_tag_example/example.cc
@@ -19,6 +19,8 @@ int main(int argc, char** argv)
ocl::fix::visitor basic_visitor;
ocl::fix::range_data fix = basic_visitor.visit(default_fix);
+ ocl::io::enable_stdio_sync(false);
+
ocl::io::print(":key=35\n");
ocl::io::print(":value=", fix["35"], "\n");
diff --git a/examples/hash_crc32_example/example.cc b/examples/hash_crc32_example/example.cc
index dc4b3e3..cddebda 100644
--- a/examples/hash_crc32_example/example.cc
+++ b/examples/hash_crc32_example/example.cc
@@ -6,6 +6,8 @@ int main(int argc, char** argv)
if (argc != 2) return 1;
std::hash<ocl::crc_hash_trait> hash{};
+
+ ocl::io::enable_stdio_sync(false);
ocl::io::print(hash(argv[1]));
return 0;
diff --git a/include/ocl/core/config.hpp b/include/ocl/core/config.hpp
index a0ddd66..13abae0 100644
--- a/include/ocl/core/config.hpp
+++ b/include/ocl/core/config.hpp
@@ -31,3 +31,8 @@
#define OCL_DECL
#define OCL_EXPORT_DECL
#endif
+
+#ifdef _WIN32
+#define OCL_USE_CRLF_ENDINGS 1
+#define OCL_WINDOWS 1
+#endif \ No newline at end of file
diff --git a/include/ocl/core/is_same.hpp b/include/ocl/core/is_same.hpp
index fdf80d7..27a85d0 100644
--- a/include/ocl/core/is_same.hpp
+++ b/include/ocl/core/is_same.hpp
@@ -15,11 +15,13 @@ namespace ocl
template <typename T>
struct basic_hash
{
+ using result_type = typename T::result_type;
+ using type = T;
+
/// @brief hash from T's result_type.
- static typename T::result_type hash()
+ static result_type hash()
{
- static T val;
- return val.hash();
+ return T{}.hash();
}
};
diff --git a/include/ocl/core/option.hpp b/include/ocl/core/option.hpp
index e333dd5..b5a2778 100644
--- a/include/ocl/core/option.hpp
+++ b/include/ocl/core/option.hpp
@@ -23,15 +23,17 @@ namespace ocl
template <typename char_type = char>
struct option final
{
- explicit option(const return_type& return_type)
+ option() = delete;
+
+ option(const return_type& return_type)
: ret_(return_type)
{
}
~option() = default;
- option& operator=(const option&) = default;
- option(const option&) = default;
+ option& operator=(const option&) = delete;
+ option(const option&) = delete;
option& expect(const char_type* input)
{
@@ -65,7 +67,7 @@ namespace ocl
return tell(std::forward<Lst>(arg)...) ? return_type::okay : return_type::err;
}
- namespace traits
+ namespace detail
{
struct int_eq_teller
{
@@ -90,26 +92,26 @@ namespace ocl
return (a < b);
}
};
- } // namespace traits
+ } // namespace detail
template <typename... Lst>
inline return_type eval_less_than(Lst&&... arg)
{
- static traits::int_less_than_teller eq;
+ static detail::int_less_than_teller eq;
return eq(std::forward<Lst>(arg)...) ? return_type::okay : return_type::err;
}
template <typename... Lst>
inline return_type eval_eq(Lst&&... arg)
{
- static traits::int_eq_teller less_than;
+ static detail::int_eq_teller less_than;
return less_than(std::forward<Lst>(arg)...) ? return_type::okay : return_type::err;
}
template <typename... Lst>
inline return_type eval_greater_than(Lst&&... arg)
{
- static traits::int_greater_than_teller greater_than;
+ static detail::int_greater_than_teller greater_than;
return greater_than(std::forward<Lst>(arg)...) ? return_type::okay : return_type::err;
}
@@ -122,6 +124,11 @@ namespace ocl
{
return return_type::err;
}
+
+ inline return_type eval_invalid() noexcept
+ {
+ return return_type::invalid;
+ }
} // namespace ocl
#endif /* ifndef _OCL_OPT_HPP */ \ No newline at end of file
diff --git a/include/ocl/fix/parser.hpp b/include/ocl/fix/parser.hpp
index 9809bd5..17fb63c 100644
--- a/include/ocl/fix/parser.hpp
+++ b/include/ocl/fix/parser.hpp
@@ -11,9 +11,7 @@
#include <core/config.hpp>
#include <hashing/crc_hash.hpp>
#include <io/print.hpp>
-#include <algorithm>
#include <string>
-#include <vector>
namespace ocl::fix
{
diff --git a/include/ocl/hashing/crc_hash.hpp b/include/ocl/hashing/crc_hash.hpp
index 0322e65..89f3eff 100644
--- a/include/ocl/hashing/crc_hash.hpp
+++ b/include/ocl/hashing/crc_hash.hpp
@@ -67,9 +67,10 @@ namespace ocl
return 0;
std::uint32_t crc = 0xffffffff;
- std::size_t cnt = 0;
+ std::size_t cnt = 0;
- while ((len--) > 0) {
+ while ((len--) > 0)
+ {
crc = (crc >> 8) ^ crc_array_[(crc ^ in[cnt]) & 0xFF];
++cnt;
}
diff --git a/include/ocl/io/print.hpp b/include/ocl/io/print.hpp
index 669dfef..5c8a17c 100644
--- a/include/ocl/io/print.hpp
+++ b/include/ocl/io/print.hpp
@@ -13,6 +13,7 @@
#include <iostream>
#define console_io_out std::cout
+#define console_io_in std::cin
namespace ocl::io
{
@@ -40,19 +41,37 @@ namespace ocl::io
print(other...);
}
- template <typename... T>
- inline void println(T... fmt) noexcept
+ namespace detail
{
- print(fmt...);
+ inline bool is_stdio_sync = true;
+ }
+
+ inline void enable_stdio_sync(const bool& enable) noexcept
+ {
+ console_io_out.sync_with_stdio(enable);
+ detail::is_stdio_sync = false;
+ }
+
+ inline const bool& is_stdio_sync()
+ {
+ return detail::is_stdio_sync;
+ }
-#ifdef _WIN32
+ inline void lf() noexcept
+ {
+#ifdef OCL_USE_CRLF_ENDINGS
print("\r\n");
#else
print("\n");
#endif
}
-} // namespace ocl::io
-#undef console_io_out
+ template <typename... T>
+ inline void println(T... fmt) noexcept
+ {
+ print(fmt...);
+ lf();
+ }
+} // namespace ocl::io
#endif // ifndef _OCL_PRINT_HPP
diff --git a/include/ocl/net/unique_socket.hpp b/include/ocl/net/unique_socket.hpp
index ed1d549..5e74af0 100644
--- a/include/ocl/net/unique_socket.hpp
+++ b/include/ocl/net/unique_socket.hpp
@@ -17,8 +17,8 @@
#include <cstddef>
#include <cstring>
-#ifdef _WIN32
-#error !!! "Windows is not supported yet for <socket>" !!!
+#ifdef OCL_WINDOWS
+#error !!! "Windows is not supported yet for <unique_socket>" !!!
#endif // _WIN32
namespace ocl::net
@@ -128,7 +128,7 @@ namespace ocl::net
if (is_server_)
return;
- auto ret = ::recv(this->socket_, static_cast<void*>(out), len, 0);
+ auto ret = ::recv(this->socket_, static_cast<void*>(out), len, 0);
this->bad_ = ret < 0L;
}
diff --git a/tests/network_basic/network_basic_test.cc b/tests/network_basic/network_basic_test.cc
index 302478e..43d2461 100644
--- a/tests/network_basic/network_basic_test.cc
+++ b/tests/network_basic/network_basic_test.cc
@@ -14,7 +14,12 @@ TEST(NetworkTest, BasicNetworkReceive1)
{
ocl::net::unique_socket sock = ocl::net::unique_socket::make_socket<8000>(ocl::net::unique_socket::local_address_ip4, false);
std::vector<char> buf_dst(512);
- sock.read_client_buffer(buf_dst.data(), buf_dst.size());
+
+ auto buf = buf_dst.data();
+ auto sz = buf_dst.size();
+
+ sock.read_client_buffer(buf, sz);
+
EXPECT_TRUE(sock.bad());
}