Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EN-7410] Implement DXFeedFileParser sample #24

Merged
merged 5 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ set(dxFeedNativeAPIInternalSources

set(dxFeedNativeAPIInternalUtilsSources
src/internal/utils/StringUtils.cpp
src/internal/utils/CmdArgsUtils.cpp
)

set(dxFeedNativeAPIInternalUtilsDebugSources
Expand Down Expand Up @@ -242,13 +243,15 @@ add_library(dxfcxx::static ALIAS ${PROJECT_NAME}_static)
add_library(dxfcxx::graal ALIAS DxFeedGraalNativeSdk)

set_target_properties(${PROJECT_NAME} PROPERTIES CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
target_include_directories(${PROJECT_NAME} PUBLIC include)
target_include_directories(${PROJECT_NAME} PRIVATE third_party/range-v3-0.12/include)
target_compile_definitions(${PROJECT_NAME} PRIVATE
DXFCPP_USE_DLLS LIBDXFCPP_EXPORTS FMT_HEADER_ONLY=1)

target_include_directories(${PROJECT_NAME}_static PUBLIC include)
target_include_directories(${PROJECT_NAME}_static PRIVATE third_party/range-v3-0.12/include)
target_compile_definitions(${PROJECT_NAME}_static PRIVATE
FMT_HEADER_ONLY=1)
target_include_directories(${PROJECT_NAME} PUBLIC include)
target_compile_definitions(${PROJECT_NAME} PRIVATE
DXFCPP_USE_DLLS LIBDXFCPP_EXPORTS FMT_HEADER_ONLY=1)

target_compile_options(${PROJECT_NAME}
PUBLIC
Expand Down Expand Up @@ -325,6 +328,7 @@ if (DXFCXX_BUILD_SAMPLES)
add_subdirectory(samples/cpp/DxFeedSample)
add_subdirectory(samples/cpp/WriteTapeFile)
add_subdirectory(samples/cpp/ConvertTapeFile)
add_subdirectory(samples/cpp/DXFeedFileParser)
endif ()

if (DXFCXX_BUILD_TOOLS)
Expand Down
3 changes: 2 additions & 1 deletion DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

## Compile-time

- [dxFeed Graal Native SDK](https://github.com/dxFeed/dxfeed-graal-native-sdk) v1.0.0
- [dxFeed Graal Native SDK](https://github.com/dxFeed/dxfeed-graal-native-sdk) v1.0.2
- [utfcpp](https://github.com/nemtrif/utfcpp) v3.2.3
- [fmt](https://github.com/fmtlib/fmt) v10.0.0
- [doctest](https://github.com/doctest/doctest) v2.4.11 (Tests)
- [range-v3](https://github.com/ericniebler/range-v3) v0.12 (Code & Samples)

## Run-time

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ be downloaded from [Release](https://github.com/dxFeed/dxfeed-graal-cxx-api/rele
<!--
* [DxFeedConnect](https://github.com/dxFeed/dxfeed-graal-cxx-api/blob/main/samples/cpp/DxFeedConnect/src/main.cpp)
demonstrates how to subscribe various market events for the specified symbols
* [DxFeedFileParser](https://github.com/dxFeed/dxfeed-graal-cxx-api/blob/main/samples/cpp/DxFeedFileParser/src/main.cpp)
is a simple demonstration of how events are read form a tape file
-->
* [DxFeedFileParser](https://github.com/dxFeed/dxfeed-graal-cxx-api/blob/main/samples/cpp/DXFeedFileParser/src/main.cpp)
is a simple demonstration of how events are read form a tape file
* [DxFeedSample](https://github.com/dxFeed/dxfeed-graal-cxx-api/blob/main/samples/cpp/DxFeedSample/src/main.cpp)
is a simple demonstration of how to create multiple event listeners and subscribe to `Quote` and `Trade` events
* [PrintQuoteEvents](https://github.com/dxFeed/dxfeed-graal-cxx-api/blob/main/samples/cpp/PrintQuoteEvents/src/main.cpp)
Expand Down
4 changes: 3 additions & 1 deletion THIRD_PARTY_LICENSES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
2. fmt - https://github.com/fmtlib/fmt/blob/master/LICENSE.rst
SPDX-License-Identifier: MIT
3. doctest - https://github.com/doctest/doctest/blob/master/LICENSE.txt
SPDX-License-Identifier: MIT
SPDX-License-Identifier: MIT
4. range-v3 - https://github.com/ericniebler/range-v3/blob/master/LICENSE.txt
SPDX-License-Identifier: BSL-1.0
1 change: 1 addition & 0 deletions include/dxfeed_graal_cpp_api/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "internal/managers/EntityManager.hpp"
#include "internal/managers/ErrorHandlingManager.hpp"
#include "internal/utils/StringUtils.hpp"
#include "internal/utils/CmdArgsUtils.hpp"
#include "internal/utils/debug/Debug.hpp"

#include "api/ApiModule.hpp"
Expand Down
39 changes: 38 additions & 1 deletion include/dxfeed_graal_cpp_api/event/EventTypeEnum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <cstdint>
#include <string>
#include <type_traits>

namespace dxfcpp {

Expand Down Expand Up @@ -66,6 +67,8 @@ class DXFCPP_EXPORT EventTypeEnum {

static const std::vector<std::reference_wrapper<const EventTypeEnum>> ALL;

static const std::unordered_map<std::string, std::reference_wrapper<const EventTypeEnum>> ALL_BY_NAME;

explicit EventTypeEnum() noexcept : EventTypeEnum{static_cast<std::uint32_t>(-1), "INVALID", false} {
}

Expand All @@ -87,10 +90,38 @@ class DXFCPP_EXPORT EventTypeEnum {
return id_ == eventTypeEnum.id_;
}

bool operator==(const std::reference_wrapper<const dxfcpp::EventTypeEnum> &eventTypeEnum) const noexcept {
return id_ == eventTypeEnum.get().id_;
}

friend bool operator==(const std::reference_wrapper<const dxfcpp::EventTypeEnum> &eventTypeEnum1,
const std::reference_wrapper<const dxfcpp::EventTypeEnum> &eventTypeEnum2) noexcept {
return eventTypeEnum1.get().id_ == eventTypeEnum2.get().id_;
}

friend bool operator==(const std::reference_wrapper<const dxfcpp::EventTypeEnum> &eventTypeEnum1,
const EventTypeEnum &eventTypeEnum2) noexcept {
return eventTypeEnum1.get().id_ == eventTypeEnum2.id_;
}

bool operator<(const EventTypeEnum &eventTypeEnum) const noexcept {
return id_ < eventTypeEnum.id_;
}

bool operator<(const std::reference_wrapper<const dxfcpp::EventTypeEnum> &eventTypeEnum) const noexcept {
return id_ < eventTypeEnum.get().id_;
}

friend bool operator<(const std::reference_wrapper<const dxfcpp::EventTypeEnum> &eventTypeEnum1,
const std::reference_wrapper<const dxfcpp::EventTypeEnum> &eventTypeEnum2) noexcept {
return eventTypeEnum1.get().id_ < eventTypeEnum2.get().id_;
}

friend bool operator<(const std::reference_wrapper<const dxfcpp::EventTypeEnum> &eventTypeEnum1,
const EventTypeEnum &eventTypeEnum2) noexcept {
return eventTypeEnum1.get().id_ == eventTypeEnum2.id_;
}

/**
* @return `true` if the current enum element is characterizing the Lasting (TICKER) event
*/
Expand Down Expand Up @@ -124,6 +155,12 @@ class DXFCPP_EXPORT EventTypeEnum {

template <> struct DXFCPP_EXPORT std::hash<dxfcpp::EventTypeEnum> {
std::size_t operator()(const dxfcpp::EventTypeEnum &eventType) const noexcept {
return eventType.getId();
return static_cast<std::size_t>(eventType.getId());
}
};

template <> struct DXFCPP_EXPORT std::hash<std::reference_wrapper<const dxfcpp::EventTypeEnum>> {
std::size_t operator()(const std::reference_wrapper<const dxfcpp::EventTypeEnum> &eventType) const noexcept {
return static_cast<std::size_t>(eventType.get().getId());
}
};
2 changes: 2 additions & 0 deletions include/dxfeed_graal_cpp_api/internal/PrecompiledHeaders.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

#include <utf8.h>

#include <range/v3/all.hpp>

#include "Common.hpp"
#include "Handler.hpp"
#include "Id.hpp"
35 changes: 35 additions & 0 deletions include/dxfeed_graal_cpp_api/internal/utils/CmdArgsUtils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2023 Devexperts LLC.
// SPDX-License-Identifier: MPL-2.0

#pragma once

#include "../Conf.hpp"

#include <cstddef>
#include <cstdint>
#include <string>
#include <unordered_set>
#include <type_traits>

namespace dxfcpp {

class EventTypeEnum;

struct DXFCPP_EXPORT CmdArgsUtils final {
/**
* Parses an input string and returns a set of symbols.
*
* @param symbols The coma-separated list of symbols.
* @return The created set of parsed symbols.
*/
static std::unordered_set<std::string> parseSymbols(const std::string &symbols);

/**
* Parses an input string and returns a set of event types.
*
* @param types The comma-separated list of event types.
* @return The created set of parsed types.
*/
static std::unordered_set<std::reference_wrapper<const EventTypeEnum>> parseTypes(const std::string &types);
};
} // namespace dxfcpp
2 changes: 2 additions & 0 deletions include/dxfeed_graal_cpp_api/internal/utils/StringUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,6 @@ inline bool iEquals(const Range1 &first, const Range2 &second, const std::locale
return equals(first, second, detail::IsIEqual(locale));
}

DXFCPP_EXPORT std::string trimStr(const std::string &s) noexcept;

} // namespace dxfcpp
2 changes: 1 addition & 1 deletion include/dxfeed_graal_cpp_api/symbols/SymbolWrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct DXFCPP_EXPORT SymbolWrapper final {
using DataType = typename std::variant<WildcardSymbol, StringSymbol, IndexedEventSubscriptionSymbol,
TimeSeriesSubscriptionSymbol, CandleSymbol>;

class SymbolListUtils final {
class DXFCPP_EXPORT SymbolListUtils final {
static std::ptrdiff_t calculateGraalListSize(std::ptrdiff_t initSize) noexcept;
static void *newGraalList(std::ptrdiff_t size) noexcept;
static bool setGraalListElement(void *graalList, std::ptrdiff_t elementIdx, void *element) noexcept;
Expand Down
9 changes: 2 additions & 7 deletions samples/cpp/ConvertTapeFile/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,18 @@ if (DXFCXX_ENABLE_VS_ASAN)
)
endif ()

target_include_directories(${PROJECT_NAME} PRIVATE ../../../include)

if (DXFCXX_ENABLE_ASAN_UBSAN)
target_compile_options(${PROJECT_NAME} PRIVATE "-fsanitize=address" "-fsanitize=undefined")
target_link_options(${PROJECT_NAME} PRIVATE "-fsanitize=address" "-fsanitize=undefined")

target_link_libraries(${PROJECT_NAME} PRIVATE dxfcxx)
target_compile_definitions(${PROJECT_NAME} PRIVATE DXFCPP_USE_DLLS)

add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:dxfcxx::graal>
${CMAKE_CURRENT_SOURCE_DIR}/ConvertTapeFile.in
$<TARGET_FILE:dxfcxx>
$<TARGET_FILE_DIR:${PROJECT_NAME}>)
target_compile_options(${PROJECT_NAME} PRIVATE "-fsanitize=address" "-fsanitize=undefined")
target_link_options(${PROJECT_NAME} PRIVATE "-fsanitize=address" "-fsanitize=undefined")
else ()
target_link_libraries(${PROJECT_NAME} PRIVATE dxfcxx::static)

add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:dxfcxx::graal>
${CMAKE_CURRENT_SOURCE_DIR}/ConvertTapeFile.in
Expand Down
83 changes: 83 additions & 0 deletions samples/cpp/DXFeedFileParser/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Copyright (c) 2023 Devexperts LLC.
# SPDX-License-Identifier: MPL-2.0

cmake_minimum_required(VERSION 3.21)

if (POLICY CMP0092)
cmake_policy(SET CMP0092 NEW)
endif ()

if (POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif ()

project(DXFeedFileParser LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_C_STANDARD 11)
set(CXX_EXTENSIONS OFF)
set(C_EXTENSIONS OFF)

if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_MACOSX_RPATH ON)
set(CMAKE_SKIP_BUILD_RPATH ON)
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH OFF)
set(CMAKE_BUILD_RPATH_USE_ORIGIN ON)
set(CMAKE_INSTALL_RPATH "@loader_path/../${CMAKE_INSTALL_LIBDIR};@loader_path;@executable_path;@executable_path/../Frameworks")
elseif (UNIX)
set(CMAKE_SKIP_BUILD_RPATH ON)
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH OFF)
set(CMAKE_BUILD_RPATH_USE_ORIGIN ON)
set(CMAKE_INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}:$ORIGIN/../lib64:$ORIGIN/../lib:$ORIGIN")
endif ()

add_executable(${PROJECT_NAME} src/main.cpp)

target_include_directories(${PROJECT_NAME} PRIVATE ../../../third_party/range-v3-0.12/include)

if (DXFCXX_ENABLE_VS_ASAN)
target_compile_options(${PROJECT_NAME} PRIVATE "/fsanitize=address")
target_link_options(${PROJECT_NAME} PRIVATE "/fsanitize=address")

target_compile_definitions(${PROJECT_NAME}
PUBLIC
$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:
_DISABLE_VECTOR_ANNOTATION
_DISABLE_STRING_ANNOTATION
>
)
endif ()

if (DXFCXX_ENABLE_ASAN_UBSAN)
target_link_libraries(${PROJECT_NAME} PRIVATE dxfcxx)
target_compile_definitions(${PROJECT_NAME} PRIVATE DXFCPP_USE_DLLS)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:dxfcxx::graal>
$<TARGET_FILE:dxfcxx>
$<TARGET_FILE_DIR:${PROJECT_NAME}>)

target_compile_options(${PROJECT_NAME} PRIVATE "-fsanitize=address" "-fsanitize=undefined")
target_link_options(${PROJECT_NAME} PRIVATE "-fsanitize=address" "-fsanitize=undefined")
else ()
target_link_libraries(${PROJECT_NAME} PRIVATE dxfcxx)
target_compile_definitions(${PROJECT_NAME} PRIVATE DXFCPP_USE_DLLS)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:dxfcxx::graal>
$<TARGET_FILE:dxfcxx>
$<TARGET_FILE_DIR:${PROJECT_NAME}>)
# target_link_libraries(${PROJECT_NAME} PRIVATE dxfcxx::static)
#
# add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different
# $<TARGET_FILE:dxfcxx::graal>
# $<TARGET_FILE_DIR:${PROJECT_NAME}>)
endif ()

if (DXFCXX_INSTALL AND DXFCXX_INSTALL_SAMPLES)
install(TARGETS ${PROJECT_NAME})

if (WIN32)
install(FILES $<TARGET_FILE:dxfcxx::graal> DESTINATION ${CMAKE_INSTALL_BINDIR})
endif ()
endif ()
Loading