Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
Osyotr committed Jan 15, 2025
1 parent 0263f53 commit 528c0fd
Show file tree
Hide file tree
Showing 31 changed files with 198 additions and 136 deletions.
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()
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
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
1 change: 1 addition & 0 deletions data/world_feed_integration_tests_data
Submodule world_feed_integration_tests_data added at 30ecb0
39 changes: 24 additions & 15 deletions drape/gl_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ typedef void(DP_APIENTRY * TglClearFn)(GLbitfield mask);
typedef void(DP_APIENTRY * TglViewportFn)(GLint x, GLint y, GLsizei w, GLsizei h);
typedef void(DP_APIENTRY * TglScissorFn)(GLint x, GLint y, GLsizei w, GLsizei h);
typedef void(DP_APIENTRY * TglFlushFn)();
typedef void(DP_APIENTRY * TglStencilOpSeparateFn)(GLenum face, GLenum func, GLenum ref, GLenum mask);
typedef void(DP_APIENTRY * TglStencilFuncSeparateFn)(GLenum face, GLenum sfail, GLint dpfail, GLuint dppass);

typedef void(DP_APIENTRY * TglActiveTextureFn)(GLenum texture);
typedef void(DP_APIENTRY * TglBlendEquationFn)(GLenum mode);
Expand Down Expand Up @@ -79,7 +81,7 @@ typedef void(DP_APIENTRY * TglFlushMappedBufferRangeFn)(GLenum target, GLintptr

typedef GLuint(DP_APIENTRY * TglCreateShaderFn)(GLenum type);
typedef void(DP_APIENTRY * TglShaderSourceFn)(GLuint shaderID, GLsizei count,
GLchar const ** string, GLint const * length);
GLchar const * const * string, GLint const * length);
typedef void(DP_APIENTRY * TglCompileShaderFn)(GLuint shaderID);
typedef void(DP_APIENTRY * TglDeleteShaderFn)(GLuint shaderID);
typedef void(DP_APIENTRY * TglGetShaderivFn)(GLuint shaderID, GLenum name, GLint * p);
Expand Down Expand Up @@ -138,6 +140,9 @@ TglViewportFn glViewportFn = nullptr;
TglScissorFn glScissorFn = nullptr;
TglFlushFn glFlushFn = nullptr;

TglStencilOpSeparateFn glStencilOpSeparateFn = nullptr;
TglStencilFuncSeparateFn glStencilFuncSeparateFn = nullptr;

TglActiveTextureFn glActiveTextureFn = nullptr;
TglBlendEquationFn glBlendEquationFn = nullptr;

Expand Down Expand Up @@ -228,6 +233,7 @@ TFunc LoadExtension(std::string const & ext)
return func;
}
#define LOAD_GL_FUNC(type, func) LoadExtension<type>(#func);
#define LOAD_GL_FUNC_SIMPLE(type, func) static_cast<type>(&::func)
#else
#define LOAD_GL_FUNC(type, func) static_cast<type>(&::func)
#endif
Expand Down Expand Up @@ -314,13 +320,19 @@ void GLFunctions::Init(dp::ApiVersion apiVersion)
}
glMapBufferFn = LOAD_GL_FUNC(TglMapBufferFn, glMapBuffer);
glUnmapBufferFn = LOAD_GL_FUNC(TglUnmapBufferFn, glUnmapBuffer);
glMapBufferRangeFn = LOAD_GL_FUNC(TglMapBufferRangeFn, glMapBufferRange);
glFlushMappedBufferRangeFn = LOAD_GL_FUNC(TglFlushMappedBufferRangeFn, glFlushMappedBufferRange);
glGetStringiFn = LOAD_GL_FUNC(TglGetStringiFn, glGetStringi);
#endif

glClearColorFn = LOAD_GL_FUNC(TglClearColorFn, glClearColor);
glClearFn = LOAD_GL_FUNC(TglClearFn, glClear);
glViewportFn = LOAD_GL_FUNC(TglViewportFn, glViewport);
glScissorFn = LOAD_GL_FUNC(TglScissorFn, glScissor);
glFlushFn = LOAD_GL_FUNC(TglFlushFn, glFlush);
glClearColorFn = LOAD_GL_FUNC_SIMPLE(TglClearColorFn, glClearColor);
glClearFn = LOAD_GL_FUNC_SIMPLE(TglClearFn, glClear);
glViewportFn = LOAD_GL_FUNC_SIMPLE(TglViewportFn, glViewport);
glScissorFn = LOAD_GL_FUNC_SIMPLE(TglScissorFn, glScissor);
glFlushFn = LOAD_GL_FUNC_SIMPLE(TglFlushFn, glFlush);

glStencilFuncSeparateFn = LOAD_GL_FUNC(TglStencilFuncSeparateFn, glStencilFuncSeparate);
glStencilOpSeparateFn = LOAD_GL_FUNC(TglStencilOpSeparateFn, glStencilOpSeparate);

glActiveTextureFn = LOAD_GL_FUNC(TglActiveTextureFn, glActiveTexture);
glBlendEquationFn = LOAD_GL_FUNC(TglBlendEquationFn, glBlendEquation);
Expand All @@ -340,13 +352,7 @@ void GLFunctions::Init(dp::ApiVersion apiVersion)

/// Shaders
glCreateShaderFn = LOAD_GL_FUNC(TglCreateShaderFn, glCreateShader);
#ifdef OMIM_OS_WINDOWS
glShaderSourceFn = LOAD_GL_FUNC(TglShaderSourceFn, glShaderSource);
#else
typedef void(DP_APIENTRY * glShaderSource_Type)(GLuint shaderID, GLsizei count,
GLchar const ** string, GLint const * length);
glShaderSourceFn = reinterpret_cast<glShaderSource_Type>(&::glShaderSource);
#endif
glCompileShaderFn = LOAD_GL_FUNC(TglCompileShaderFn, glCompileShader);
glDeleteShaderFn = LOAD_GL_FUNC(TglDeleteShaderFn, glDeleteShader);
glGetShaderivFn = LOAD_GL_FUNC(TglGetShaderivFn, glGetShaderiv);
Expand Down Expand Up @@ -484,13 +490,13 @@ void GLFunctions::glCullFace(glConst face)
void GLFunctions::glStencilOpSeparate(glConst face, glConst sfail, glConst dpfail, glConst dppass)
{
ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ());
GLCHECK(::glStencilOpSeparate(face, sfail, dpfail, dppass));
GLCHECK(glStencilOpSeparateFn(face, sfail, dpfail, dppass));
}

void GLFunctions::glStencilFuncSeparate(glConst face, glConst func, int ref, uint32_t mask)
{
ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ());
GLCHECK(::glStencilFuncSeparate(face, func, ref, mask));
GLCHECK(glStencilFuncSeparateFn(face, func, ref, mask));
}

void GLFunctions::glPixelStore(glConst name, uint32_t value)
Expand Down Expand Up @@ -1123,7 +1129,10 @@ uint32_t GLFunctions::glCheckFramebufferStatus()
void GLFunctions::glLineWidth(uint32_t value)
{
ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ());
GLCHECK(::glLineWidth(static_cast<float>(value)));

GLint range[2];
GLCHECK(::glGetIntegerv(GL_SMOOTH_LINE_WIDTH_RANGE, range));
GLCHECK(::glLineWidth(static_cast<float>(std::clamp(static_cast<GLint>(value), range[0], range[1]))));
}

namespace
Expand Down
Loading

0 comments on commit 528c0fd

Please sign in to comment.