Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 55 additions & 66 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,84 +1,73 @@
name: Build with CMake

on:
- pull_request
- workflow_dispatch
pull_request:
workflow_dispatch:

env:
BUILD_TYPE: Release
CMAKE_VERSION: 3.21
NINJA_VERSION: 1.11.1
CMAKE_VERSION: 3.30.0
NINJA_VERSION: 1.13.2

jobs:
build:
name: "${{ matrix.config.name }} Qt ${{ matrix.qt-version }}"
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
qt-version: [6.3]
config:
- {
name: "Ubuntu Latest GCC",
os: ubuntu-latest,
arch: gcc_64,
cc: "gcc", cxx: "g++"
}
- {
name: "Windows Latest MSVC",
os: windows-latest,
arch: win64_msvc2019_64,
is_msvc: true,
cc: "cl", cxx: "cl"
}
- {
name: "Windows Latest MinGW",
os: windows-latest,
arch: win64_mingw,
is_msvc: false,
cc: "gcc", cxx: "g++",
}
- {
name: "macOS Latest Clang",
os: macos-latest,
arch: clang_64,
cc: "clang", cxx: "clang++"
}
include:
# Qt 5.15.2
- name: "Ubuntu GCC Qt 5.15.2"
os: ubuntu-latest
qt-version: "5.15.2"
qt-arch: gcc_64

steps:
- uses: actions/checkout@v3
- name: "Windows MSVC Qt 5.15.2"
os: windows-latest
qt-version: "5.15.2"
qt-arch: win64_msvc2019_64

# Qt 6.9.3
- name: "Ubuntu GCC Qt 6.9.3"
os: ubuntu-latest
qt-version: "6.9.3"
qt-arch: linux_gcc_64

- name: "macOS Clang Qt 6.9.3"
os: macos-latest
qt-version: "6.9.3"
qt-arch: clang_64

- name: Set up Qt environment
uses: jurplel/install-qt-action@v3
with:
cache: true
version: ${{ matrix.qt-version }}
arch: ${{ matrix.config.arch }}
- name: "Windows MSVC Qt 6.9.3"
os: windows-latest
qt-version: "6.9.3"
qt-arch: win64_msvc2022_64

steps:
- uses: actions/checkout@v4

- name: Setup MSBuild
uses: ilammy/msvc-dev-cmd@v1
if: runner.os == 'Windows' && matrix.config.is_msvc == true
- uses: lukka/get-cmake@latest
with:
cmakeVersion: ${{ env.CMAKE_VERSION }}
ninjaVersion: ${{ env.NINJA_VERSION }}

- name: Setup cmake
uses: jwlawson/actions-setup-cmake@v1.9
with:
cmake-version: ${{env.CMAKE_VERSION}}
- name: Install Qt
uses: jurplel/install-qt-action@v4
with:
cache: true
version: ${{ matrix.qt-version }}
arch: ${{ matrix.qt-arch }}

- name: Setup Ninja
uses: ashutoshvarma/setup-ninja@v1.1
with:
version: ${{env.NINJA_VERSION}}
- name: Setup MSVC
uses: ilammy/msvc-dev-cmd@v1
if: contains(matrix.name, 'MSVC')

- name: Build with CMake
uses: ashutoshvarma/action-cmake-build@master
with:
build-dir: ${{ runner.workspace }}/build
cc: ${{ matrix.config.cc }}
cxx: ${{ matrix.config.cxx }}
configure-options: -G Ninja
build-type: Release
- uses: ashutoshvarma/action-cmake-build@master
with:
build-dir: ${{ github.workspace }}/build
build-type: Release
configure-options: >-
-G Ninja
-DQUNITCONV_QT_TESTS=ON

- name: Run tests
run: |
cd ../build/tests
./QUnitConversionTests
- run: ctest --test-dir ${{ github.workspace }}/build --output-on-failure --verbose
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*.user*
cmake-build*
build/
/doc/
.idea
.idea/
.vscode/
64 changes: 58 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,64 @@
cmake_minimum_required(VERSION 3.19)
project(QUnitConversion)
project(QUnitConversion LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED On)

add_subdirectory(QUnitConversion)
set(SOURCES
src/qlinearfunction.cpp
)

option(QUNITCONV_BUILD_TESTS "Build QUnitConversion unttests" On)
set(HEADERS
src/qaliasdictionary.h
src/qlinearfunction.h
src/qunitconversionfamily.h
src/qunitconversionrule.h
src/qunitconvertor.h
)

if (QUNITCONV_BUILD_TESTS)
add_subdirectory(tests)
add_library(QUnitConversion STATIC
${SOURCES}
${HEADERS}
)

target_include_directories(QUnitConversion PUBLIC
src
)

option(QUNITCONV_BUILD_TESTS "Build QUnitConversion unittests" ON)

if(QUNITCONV_BUILD_TESTS)
include(FetchContent)

FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.17.0
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

option(QUNITCONV_QT_TESTS "Include Qt string types in typed tests" OFF)

add_executable(QUnitConversionTests
src/qaliasdictionary_tests.cpp
src/qlinearfunction_tests.cpp
src/qunitconvertor_tests.cpp
)

target_link_libraries(QUnitConversionTests
GTest::gtest_main
QUnitConversion
)

if(QUNITCONV_QT_TESTS)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
target_link_libraries(QUnitConversionTests Qt::Core)
target_compile_definitions(QUnitConversionTests PRIVATE QUNITCONV_QT_TESTS)
endif()

enable_testing()
include(GoogleTest)
gtest_discover_tests(QUnitConversionTests)
endif()
34 changes: 0 additions & 34 deletions QUnitConversion/CMakeLists.txt

This file was deleted.

9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,4 @@ will be converted to m/s properly.

`QUnitConversion` is distributed under MIT license

## Repo contents

| Directory | Contents |
|---------------------|--------------------------------|
| `./QUnitConversion` | Library source code. |
| `./tests` | Unittests code. |

Copyright Dmitriy Linev 2020-2024
Copyright Dmitriy Linev 2020-2026
33 changes: 23 additions & 10 deletions QUnitConversion/qaliasdictionary.h → src/qaliasdictionary.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#ifndef QALIASDICTIONARY_H
#define QALIASDICTIONARY_H

#include <QMap>
#include <QDebug>
#include <algorithm>
#include <map>
#include <set>
#include <vector>

/**
* @brief The QAliasDictionary class provides
Expand All @@ -23,35 +25,45 @@ class QAliasDictionary
{
if (m_names.contains(alias))
return alias;
return m_aliases.value(alias);
auto it = m_aliases.find(alias);
if (it != m_aliases.end())
return it->second;
return {};
}
/**
* @brief Gets a list of aliases for a given name
* @param name name to get aliases
* @return QList<QString> containing aliases for a given name
* @return Vector of strings containing aliases for a given name
*/
QList<String> aliases(const String &name) const
std::vector<String> aliases(const String &name) const
{
return m_aliases.keys(name);
std::vector<String> result;
for (const auto &pair : m_aliases)
if (pair.second == name)
result.push_back(pair.first);
return result;
}

/**
* @brief Checks if this dictionary is empty
* @return true if empty, false otherwise
*/
bool isEmpty() const
{
return m_aliases.isEmpty();
return m_aliases.empty();
}

/**
* @brief Adds an alias to the dictionary
* @param name name which will be returned if an alias requested
* @param alias alias for the given name
*/
void addAlias(String name, String alias)
{
m_aliases.insert(std::move(alias), name);
m_aliases.insert_or_assign(std::move(alias), name);
m_names.insert(std::move(name));
}

/**
* @brief Checks if a dictionary contains name for the given alias
* @param alias alias to check existence
Expand All @@ -72,9 +84,10 @@ class QAliasDictionary
m_aliases.clear();
m_names.clear();
}

protected:
QMap<String, String> m_aliases;
QSet<String> m_names;
std::map<String, String> m_aliases;
std::set<String> m_names;
};

#endif // QALIASDICTIONARY_H
Loading
Loading