Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Tropby/EBCpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Tropby committed Apr 19, 2024
2 parents 70a3695 + 6303d73 commit 4226706
Show file tree
Hide file tree
Showing 39 changed files with 1,227 additions and 2,508 deletions.
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
name: CMake
# This starter workflow is for a CMake project running on a single platform. There is a different starter workflow if you need cross-platform coverage.
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-multi-platform.yml
name: CMake on a single platform

on:
push:
branches: [ master ]
branches: [ "master" ]
pull_request:
branches: [ master ]
branches: [ "master" ]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest
runs-on: windows-latest

steps:
- uses: actions/checkout@v2
steps:
- uses: actions/checkout@v3

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
run: cmake -G "MinGW Makefiles" -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

# - name: Test
# working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
# run: ctest -C ${{env.BUILD_TYPE}}
run: ctest -C ${{env.BUILD_TYPE}}

23 changes: 22 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"doxygen_runner.configuration_file_override": "${workspaceFolder}/Doxyfile",
"C_Cpp.default.configurationProvider": "go2sh.cmake-integration",
"files.associations": {
"*.embeddedhtml": "html",
"array": "cpp",
"atomic": "cpp",
"*.tcc": "cpp",
Expand Down Expand Up @@ -67,7 +68,27 @@
"numbers": "cpp",
"semaphore": "cpp",
"stop_token": "cpp",
"complex": "cpp"
"complex": "cpp",
"charconv": "cpp",
"format": "cpp",
"forward_list": "cpp",
"ios": "cpp",
"locale": "cpp",
"xfacet": "cpp",
"xhash": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocbuf": "cpp",
"xlocinfo": "cpp",
"xlocmes": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp",
"xmemory": "cpp",
"xstring": "cpp",
"xtr1common": "cpp",
"xtree": "cpp",
"xutility": "cpp"
},
"C_Cpp.clang_format_style": "file",
"formatFiles.excludePattern": "[ default: '**/build, **/.vscode, **/bin' ]",
Expand Down
25 changes: 0 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ project(EBCppExamples VERSION 0.1 LANGUAGES CXX)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../bin)

# Configure and Include EBCpp
set(EBCPP_USE_GUI On) # On/Off - Using the windows gui functions (only for testing)
set(EBCPP_USE_SSL Off) # On/Off - Using openssl for ssl sockets and https
set(EBCPP_USE_SSL_STATIC Off) # On/Off - Activate static linking of openssl into your application (see openssl license)
set(EBCPP_USE_SQLITE Off) # On/Off - Using sqlite in your application (static linked)
Expand Down Expand Up @@ -94,30 +93,6 @@ if(WIN32)
else()
target_link_libraries(EBCppExampleSerialPort pthread)
endif()

# Compile EBCppExampleGui
add_executable(EBCppExampleGui examples/ExampleGui.cpp)
if(WIN32)
target_link_libraries(EBCppExampleGui gdiplus -Wl,-subsystem,windows)
else()
target_link_libraries(EBCppExampleGui pthread)
endif()

# Compile EBCppExampleImage
add_executable(EBCppExampleGuiImage examples/ExampleGuiImage.cpp)
if(WIN32)
target_link_libraries(EBCppExampleGuiImage gdiplus -Wl,-subsystem,windows)
else()
target_link_libraries(EBCppExampleGui pthread)
endif()

# Compile EBCppExampleGuiLayout
add_executable(EBCppExampleGuiLayout examples/ExampleGuiLayout.cpp)
if(WIN32)
target_link_libraries(EBCppExampleGuiLayout gdiplus -Wl,-subsystem,windows)
else()
target_link_libraries(EBCppExampleGuiLayout pthread)
endif()
endif()

find_package(OpenSSL)
Expand Down
23 changes: 0 additions & 23 deletions EBString.todo

This file was deleted.

4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MIT License
# MIT License

Copyright (c) 2024 Carsten (Tropby)

Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
27 changes: 10 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
# EBCpp

[![CMake](https://github.com/Tropby/EBCpp/actions/workflows/cmake.yml/badge.svg)](https://github.com/Tropby/EBCpp/actions/workflows/cmake.yml)
[![CMake on Windows (!SSL, !SQLITE)](https://github.com/Tropby/EBCpp/actions/workflows/cmake-single-platform.yml/badge.svg)](https://github.com/Tropby/EBCpp/actions/workflows/cmake-single-platform.yml)

Event Based C++ (EBCpp) will be a framework that uses Events (Signal-Slot) to provide features to the user. This framework is designed to work with C++17 and without a special pre compiler. The framework is a header only framework and designed that it could be used very easily. Just include the header files and use the functionalities provided.

The events are synchronised to one thread. Therefore the events are thread-safe. You can use multible threads by setting up additional `EBEventLoop`s. This should only be used by experienced users.

## Table of Content

* [Installation](#installation)
* [Example](#example)

## Usage with CMake

Add EBCpp as submodule to your git project

```bash
mkdir dep
git submodule https://github.com/Tropby/EBCpp.git dep/ebcpp
```

Include EBCpp in your `CMakeLists.txt` file:

```cmake
# Configure and Include EBCpp
set(EBCPP_USE_GUI Off) # On/Off - Using the windows gui functions (only for testing)
Expand All @@ -29,15 +26,16 @@ set(EBCPP_USE_SQLITE On) # On/Off - Using sqlite in your application (sta
set(EBCPP_STATIC On) # On/Off - Static linking of libc, libc++ and winpthread
include(dep/ebcpp/ebcpp.cmake)
```
```

Now you can use EBCpp within your project.
Now you can use EBCpp within your project.

### Using EBCpp the easy way

Create a `main.cpp` that includes `EBApplication.hpp`. The EBApplication provides a makro that creates the EBCpp init and shutdown functions and handels your main class. The follwoing code blocks are showing the usage of this makro.

`CMakeLists.txt`

```cmake
cmake_minimum_required(VERSION 3.10)
Expand All @@ -64,6 +62,7 @@ target_link_libraries(Example ${EBCPP_LIBS})
```

`main.cpp`

```c++
// Include EBApplication and the main class header file
#include <EBApplication.hpp>
Expand All @@ -87,6 +86,7 @@ public:
```

`Example.cpp`

```c++
#include "Example.hpp"

Expand All @@ -108,11 +108,12 @@ TestBoe::TestBoe()
```

## Examples

See examples direcory for more examples!

### Example Pointer

With EBCpp you should not use raw C pointer. You should use `EBCpp::EBObjectBase::createObject<T>()`. The following example shows how to use the pointers. There is an `EBPtr` makro.
With EBCpp you should not use raw C pointer. You should use `EBCpp::EBObjectBase::createObject<T>()`. The following example shows how to use the pointers. There is an `EBPtr` makro.

```C++
#include "../src/EBObject.hpp"
Expand Down Expand Up @@ -194,11 +195,3 @@ int main()
return 0;
}
```

## GUI (Example)

Currently working on a GUI implementation. That can render a GUI for Windows (GDI+). Other renderes can be added.

GUI rendering is done in another thread than the event handler.

See ExampleGui.cpp for an example.
5 changes: 5 additions & 0 deletions src/EBApplication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ class EBApplication : public EBObject<EBApplication>
}
}

static bool containsArgument( const EBString& argument )
{
return arguments.contains(argument);
}

static EBString getArgument( int index )
{
return arguments.get(index);
Expand Down
2 changes: 2 additions & 0 deletions src/EBException.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ namespace EBCpp
//! Macro for exception with file and line
#define EB_EXCEPTION(message) throw EBCpp::EBException(std::string(message) + "\n\t in " EB_AT)

#define EB_EXCEPTION_EX(type, message) throw EBCpp::type(message + "\n\t in " EB_AT)

/**
* @brief Exceptions from EBCpp
*
Expand Down
5 changes: 5 additions & 0 deletions src/EBList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ class EBListIterator : public EBObject<EBListIterator<T>>
{
}

operator const T()
{
return current->get();
}

const T get() const
{
return current->get();
Expand Down
8 changes: 8 additions & 0 deletions src/EBObject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ class EBObjectPointer : public EBObjectPointerBase
this->pointer->use(this);
}



T& operator*()
{
return (T&)(*this->pointer);
Expand Down Expand Up @@ -403,6 +405,12 @@ class EBObjectPointer : public EBObjectPointerBase
return static_cast<T*>(pointer);
}

template<class NT>
operator EBPtr<NT>()
{
return EBPtr<NT>(pointer);
}

template<class NT>
EBPtr<NT> cast()
{
Expand Down
34 changes: 31 additions & 3 deletions src/EBString.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class EBString : public EBObject<EBString>
return strstr(this->data, other.data) != NULL;
}

EBList<EBString> split(const EBString& delimiter) const
EBList<EBString> split(const EBString delimiter) const
{
EBList<EBString> result;
EBString data = *this;
Expand Down Expand Up @@ -220,9 +220,12 @@ class EBString : public EBObject<EBString>
return std::string(data, size);
}

int32_t indexOf(const EBString& other) const
int32_t indexOf(const EBString& subString, int startIndex = 0) const
{
char* pos = strstr(this->data, other.data);
if( startIndex >= this->size )
return -1;

char* pos = strstr(this->data + startIndex, subString.data);
if (pos == NULL)
{
return -1;
Expand All @@ -231,6 +234,25 @@ class EBString : public EBObject<EBString>
return pos - this->data;
}

int32_t lastIndexOf(const EBString& subString, int startIndex = 0) const
{
if( startIndex >= this->size )
return -1;

char* lastPos = nullptr;
while( char* pos = strstr(this->data + startIndex, subString.data) )
{
lastPos = pos;
startIndex = lastPos - this->data + 1;
}
if (lastPos == nullptr)
{
return -1;
}

return lastPos - this->data;
}

const EBString trim() const
{
int start = 0;
Expand Down Expand Up @@ -352,3 +374,9 @@ inline std::ostream& operator<<(std::ostream& os, const EBCpp::EBString& str)
{
return os << str.dataPtr();
}

inline EBCpp::EBString operator+(const char* other, const EBCpp::EBString& str)
{
EBCpp::EBString res = EBCpp::EBString(other) + str;
return res;
}
14 changes: 13 additions & 1 deletion src/EBTest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,20 @@
std::cout << "Start Test: " << STR(x) << std::endl; \
x();

#define CHECK_EXCEPTION(x) \
std::cout << "Check Exception: " << STR(x) << "\t\t"; \
try \
{ \
x; \
std::cout << "ERROR" << std::endl; \
} \
catch (...) \
{ \
std::cout << "OKAY" << std::endl; \
}

#define CHECK(x) \
std::cout << "Result: " << STR(x) << "\t\t"; \
std::cout << "Check: " << STR(x) << "\t\t"; \
if (x) \
{ \
std::cout << "OKAY" << std::endl; \
Expand Down
Loading

0 comments on commit 4226706

Please sign in to comment.