Skip to content

Commit

Permalink
Tmp
Browse files Browse the repository at this point in the history
Signed-off-by: Osyotr <[email protected]>
  • Loading branch information
Osyotr committed Dec 3, 2024
1 parent 2d95381 commit 824e0ec
Show file tree
Hide file tree
Showing 40 changed files with 262 additions and 160 deletions.
3 changes: 0 additions & 3 deletions 3party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ if (NOT WITH_SYSTEM_PROVIDED_3PARTY)
add_subdirectory(expat/expat)
add_library(expat::expat ALIAS expat)

# Add GTest library.
add_subdirectory(googletest)

# Configure Jansson library.
set(JANSSON_BUILD_DOCS OFF)
set(JANSSON_BUILD_MAN OFF)
Expand Down
7 changes: 6 additions & 1 deletion 3party/vulkan_wrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ target_include_directories(${PROJECT_NAME} PUBLIC .)


# dlopen
target_link_libraries(${PROJECT_NAME} $<$<BOOL:CMAKE_DL_LIBS>:${CMAKE_DL_LIBS}>)
if(WIN32)
find_package(dlfcn-win32 CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} dlfcn-win32::dl)
else()
target_link_libraries(${PROJECT_NAME} $<$<BOOL:CMAKE_DL_LIBS>:${CMAKE_DL_LIBS}>)
endif()
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ if (WITH_SYSTEM_PROVIDED_3PARTY)
find_package(gflags REQUIRED)

find_package(expat CONFIG REQUIRED)
find_package(GTest REQUIRED)
find_package(jansson CONFIG REQUIRED)
find_package(Protobuf REQUIRED)
find_package(pugixml REQUIRED)
Expand All @@ -349,7 +348,7 @@ endif()

find_package(ZLIB REQUIRED)

find_package(Boost REQUIRED)
find_package(Boost CONFIG REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})

# Include 3party dependencies.
Expand Down
2 changes: 1 addition & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"VCPKG_INSTALL_OPTIONS": {
"type": "STRING",
"value": "--disable-metrics;--no-print-usage;--x-abi-tools-use-exact-versions;--clean-buildtrees-after-build;--clean-packages-after-build;--x-buildtrees-root=${sourceDir}/out/btrees"
"value": "--disable-metrics;--no-print-usage;--x-abi-tools-use-exact-versions;--clean-buildtrees-after-build;--clean-packages-after-build"
}
},
"condition": {
Expand Down
6 changes: 3 additions & 3 deletions base/atomic_shared_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ class AtomicSharedPtr final

AtomicSharedPtr() = default;

void Set(ValueType value) noexcept { atomic_store(&m_wrapped, value); }
ValueType Get() const noexcept { return atomic_load(&m_wrapped); }
void Set(ValueType value) noexcept { m_wrapped.store(value); }
ValueType Get() const noexcept { return m_wrapped.load(); }

private:
ValueType m_wrapped = std::make_shared<ContentType>();
std::atomic<ValueType> m_wrapped = std::make_shared<ContentType>();

DISALLOW_COPY_AND_MOVE(AtomicSharedPtr);
};
Expand Down
2 changes: 1 addition & 1 deletion base/base_tests/beam_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void Smoke()

vector<double> expected;
for (size_t i = 0; i < kCapacity; ++i)
expected.emplace_back(kTotal - 1 - i);
expected.emplace_back(static_cast<double>(kTotal - 1 - i));

vector<double> actual;
actual.reserve(kCapacity);
Expand Down
6 changes: 1 addition & 5 deletions base/file_name_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ string GetDirectory(string const & name)

string::value_type GetNativeSeparator()
{
#ifdef OMIM_OS_WINDOWS
return '\\';
#else
return '/';
#endif
return '/';
}

string AddSlashIfNeeded(string const & path)
Expand Down
3 changes: 3 additions & 0 deletions base/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <mutex>
#include <sstream>

#include <windows.h>

namespace base
{
namespace
Expand Down Expand Up @@ -79,6 +81,7 @@ void LogMessageDefault(LogLevel level, SrcPoint const & srcPoint, std::string co
logger.WriteLog(out, srcPoint, msg);

std::cerr << out.str();
OutputDebugStringA(out.str().c_str());

CHECK_LESS(level, g_LogAbortLevel, ("Abort. Log level is too serious", level));
}
Expand Down
4 changes: 3 additions & 1 deletion base/random.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ template <class T> class UniformRandom

std::random_device m_rd;
std::mt19937 m_gen;
std::uniform_int_distribution<T> m_distr;

using distribution_int_type = std::conditional_t<sizeof(T) != 1, T, std::conditional_t<std::is_signed_v<T>, short, unsigned short>>;
std::uniform_int_distribution<distribution_int_type> m_distr;

public:
UniformRandom(T min, T max) : m_gen(m_rd()), m_distr(min, max) {}
Expand Down
47 changes: 26 additions & 21 deletions base/string_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,31 @@ bool IsASCIILatin(UniChar c);

inline std::string DebugPrint(UniString const & s) { return ToUtf8(s); }

template <typename DelimFn, typename Iter> class TokenizeIteratorBase
class TokenizeIteratorBase
{
template<typename...>
static constexpr bool is_utf8cpp_iterator = false;

template<typename... Args>
static constexpr bool is_utf8cpp_iterator<utf8::unchecked::iterator<Args...>> = true;

public:
using difference_type = std::ptrdiff_t;
using iterator_category = std::input_iterator_tag;

// Hack to get buffer pointer from any iterator.
// Deliberately made non-static to simplify the call like this->ToCharPtr.
char const * ToCharPtr(char const * p) const { return p; }
template <class T> auto ToCharPtr(T const & i) const { return ToCharPtr(i.base()); }
// Deliberately made non-static to simplify the call like this->ToStringView.
template<class T>
std::string_view ToStringView(T first, T last) const
{
if constexpr (is_utf8cpp_iterator<T>)
return TokenizeIteratorBase::ToStringView(first.base(), last.base());
else
return std::string_view(first, last);
}
};

template <typename DelimFn, typename Iter, bool KeepEmptyTokens = false>
class TokenizeIterator : public TokenizeIteratorBase<DelimFn, Iter>
class TokenizeIterator : public TokenizeIteratorBase
{
public:
template <class InIterT> TokenizeIterator(InIterT beg, InIterT end, DelimFn const & delimFn)
Expand All @@ -166,9 +177,7 @@ class TokenizeIterator : public TokenizeIteratorBase<DelimFn, Iter>
std::string_view operator*() const
{
ASSERT(m_start != m_finish, ("Dereferencing of empty iterator."));

auto const baseI = this->ToCharPtr(m_start);
return std::string_view(baseI, std::distance(baseI, this->ToCharPtr(m_end)));
return this->ToStringView(m_start, m_end);
}

UniString GetUniString() const
Expand Down Expand Up @@ -228,7 +237,7 @@ class TokenizeIterator : public TokenizeIteratorBase<DelimFn, Iter>

/// Used in ParseCSVRow for the generator routine.
template <typename DelimFn, typename Iter>
class TokenizeIterator<DelimFn, Iter, true /* KeepEmptyTokens */> : public TokenizeIteratorBase<DelimFn, Iter>
class TokenizeIterator<DelimFn, Iter, true /* KeepEmptyTokens */> : public TokenizeIteratorBase
{
public:
template <class InIterT> TokenizeIterator(InIterT beg, InIterT end, DelimFn const & delimFn)
Expand All @@ -241,9 +250,7 @@ class TokenizeIterator<DelimFn, Iter, true /* KeepEmptyTokens */> : public Token
std::string_view operator*() const
{
ASSERT(!m_finished, ("Dereferencing of empty iterator."));

auto const baseI = this->ToCharPtr(m_start);
return std::string_view(baseI, std::distance(baseI, this->ToCharPtr(m_end)));
return this->ToStringView(m_start, m_end);
}

explicit operator bool() const { return !m_finished; }
Expand Down Expand Up @@ -362,37 +369,35 @@ UniChar LastUniChar(std::string const & s);
//@{
namespace internal
{
template <typename T, typename = std::enable_if_t<std::is_signed<T>::value &&
sizeof(T) < sizeof(long long)>>
template <typename T, std::enable_if_t<std::is_signed_v<T> && (sizeof(T) < sizeof(long)), int> = 0>
long IntConverter(char const * start, char ** stop, int base)
{
return std::strtol(start, stop, base);
}

template <typename T, typename = std::enable_if_t<std::is_unsigned<T>::value &&
sizeof(T) < sizeof(unsigned long long)>>
template <typename T, std::enable_if_t<std::is_unsigned_v<T> && (sizeof(T) < sizeof(unsigned long)), int> = 0>
unsigned long IntConverter(char const * start, char ** stop, int base)
{
return std::strtoul(start, stop, base);
}

template <typename T, typename = std::enable_if_t<std::is_signed<T>::value &&
sizeof(T) == sizeof(long long)>>
sizeof(T) >= sizeof(long)>>
long long IntConverter(char const * start, char ** stop, int base)
{
#ifdef OMIM_OS_WINDOWS_NATIVE
return _strtoi64(start, &stop, base);
return _strtoi64(start, stop, base);
#else
return std::strtoll(start, stop, base);
#endif
}

template <typename T, typename = std::enable_if_t<std::is_unsigned<T>::value &&
sizeof(T) == sizeof(unsigned long long)>>
sizeof(T) >= sizeof(unsigned long)>>
unsigned long long IntConverter(char const * start, char ** stop, int base)
{
#ifdef OMIM_OS_WINDOWS_NATIVE
return _strtoui64(start, &stop, base);
return _strtoui64(start, stop, base);
#else
return std::strtoull(start, stop, base);
#endif
Expand Down
1 change: 0 additions & 1 deletion cmake/OmimConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ set(OMIM_WARNING_FLAGS
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-unused-parameter> # We have a lot of functions with unused parameters
)
set(3PARTY_INCLUDE_DIRS "${OMIM_ROOT}/3party/boost")
set(OMIM_DATA_DIR "${OMIM_ROOT}/data")
set(OMIM_USER_RESOURCES_DIR "${OMIM_ROOT}/data")
2 changes: 0 additions & 2 deletions cmake/OmimHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ function(omim_add_executable executable)

# Enable warnings for all our binaries.
target_compile_options(${executable} PRIVATE ${OMIM_WARNING_FLAGS})
target_include_directories(${executable} SYSTEM PRIVATE ${3PARTY_INCLUDE_DIRS})
target_compile_definitions(${executable} PRIVATE $<$<BOOL:${PLATFORM_WIN}>:BOOST_ALL_NO_LIB>)
if (USE_ASAN)
target_link_libraries(${executable}
Expand Down Expand Up @@ -53,7 +52,6 @@ function(omim_add_library library)

# Enable warnings for all our libraries.
target_compile_options(${library} PRIVATE ${OMIM_WARNING_FLAGS})
target_include_directories(${library} SYSTEM PRIVATE ${3PARTY_INCLUDE_DIRS})
target_compile_definitions(${library} PRIVATE $<$<BOOL:${PLATFORM_WIN}>:BOOST_ALL_NO_LIB>)
if (USE_PPROF AND PLATFORM_MAC)
find_path(PPROF_INCLUDE_DIR NAMES gperftools/profiler.h)
Expand Down
4 changes: 2 additions & 2 deletions cmake/OmimTesting.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ endif()
# TestServer fixture configuration
add_test(
NAME OmimStartTestServer
COMMAND start_server.py
COMMAND Python3::Interpreter start_server.py
WORKING_DIRECTORY ${OMIM_ROOT}/tools/python/test_server
)
add_test(
NAME OmimStopTestServer
COMMAND stop_server.py
COMMAND Python3::Interpreter stop_server.py
WORKING_DIRECTORY ${OMIM_ROOT}/tools/python/test_server
)
set_tests_properties(OmimStartTestServer PROPERTIES FIXTURES_SETUP TestServer)
Expand Down
18 changes: 10 additions & 8 deletions coding/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,16 @@ set(SRC
omim_add_library(${PROJECT_NAME} ${SRC})

target_link_libraries(${PROJECT_NAME}
base
expat::expat
cppjansson
succinct
ICU::uc
ICU::i18n # For transliteration.
minizip
ZLIB::ZLIB
PUBLIC
base
PRIVATE
expat::expat
cppjansson
succinct
ICU::uc
ICU::i18n # For transliteration.
minizip
ZLIB::ZLIB
)

omim_add_test_subdirectory(coding_tests)
17 changes: 10 additions & 7 deletions coding/internal/file_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
#include <cerrno>
#include <cstring>
#include <exception>
#include <filesystem>
#include <fstream>
#include <vector>

#ifdef OMIM_OS_WINDOWS
#include <io.h>
#include <windows.h>
#else
#include <unistd.h> // ftruncate
#endif
Expand Down Expand Up @@ -212,8 +214,9 @@ bool DeleteFileX(string const & fName)

bool RenameFileX(string const & fOld, string const & fNew)
{
int res = rename(fOld.c_str(), fNew.c_str());
return CheckFileOperationResult(res, fOld);
std::error_code ec;
std::filesystem::rename(fOld, fNew, ec);
return CheckFileOperationResult(ec.value(), fOld);
}

bool MoveFileX(string const & fOld, string const & fNew)
Expand Down Expand Up @@ -270,13 +273,13 @@ void AppendFileToFile(string const & fromFilename, string const & toFilename)

bool CopyFileX(string const & fOld, string const & fNew)
{
ifstream ifs;
ofstream ofs;
ifs.exceptions(ifstream::failbit | ifstream::badbit);
ofs.exceptions(ifstream::failbit | ifstream::badbit);

try
{
ifstream ifs;
ofstream ofs;
ifs.exceptions(ifstream::failbit | ifstream::badbit);
ofs.exceptions(ifstream::failbit | ifstream::badbit);

ifs.open(fOld.c_str());
ofs.open(fNew.c_str());

Expand Down
8 changes: 2 additions & 6 deletions coding/sha1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,11 @@ namespace
{
SHA1::Hash ExtractHash(boost::uuids::detail::sha1 & sha1)
{
uint32_t digest[5];
unsigned char digest[20];
sha1.get_digest(digest);
for (auto & b : digest)
b = boost::core::byteswap(b);

SHA1::Hash result;
static_assert(result.size() == sizeof(digest));
std::copy_n(reinterpret_cast<uint8_t const *>(digest), sizeof(digest), std::begin(result));
return result;
return std::to_array(digest);
}
}

Expand Down
6 changes: 3 additions & 3 deletions drape/drape_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ target_compile_definitions(${PROJECT_NAME}

if (WITH_SYSTEM_PROVIDED_3PARTY)
find_package(GTest REQUIRED)
target_link_libraries(${PROJECT_NAME} GTest::gtest)
else()
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/../../3party/googletest" "${CMAKE_CURRENT_BINARY_DIR}/googletest")
target_include_directories(${PROJECT_NAME} PUBLIC ${OMIM_ROOT}/3party/glm)
endif()

target_include_directories(${PROJECT_NAME} PUBLIC ${OMIM_ROOT}/3party/glm)

target_link_libraries(${PROJECT_NAME}
qt_tstfrm
GTest::gmock
${DRAPE_LINK_LIBRARIES}
GTest::gmock
)
Loading

0 comments on commit 824e0ec

Please sign in to comment.