changed class names
generall reorganization
This commit is contained in:
parent
5f6abf300e
commit
03338fa8a6
31 changed files with 1002 additions and 636 deletions
|
@ -1,6 +1,6 @@
|
||||||
###########################################################################################
|
###########################################################################################
|
||||||
#
|
#
|
||||||
# (c) Technical Software Engineering Plazotta 2021
|
# (c) Luis Stanglmeier
|
||||||
#
|
#
|
||||||
# CMAKE project main file / LSFramework
|
# CMAKE project main file / LSFramework
|
||||||
#
|
#
|
||||||
|
@ -45,6 +45,7 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||||
# Define projects for building
|
# Define projects for building
|
||||||
#
|
#
|
||||||
add_subdirectory("Framework")
|
add_subdirectory("Framework")
|
||||||
|
add_subdirectory("Framework.UnitTest")
|
||||||
#
|
#
|
||||||
#-----------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------
|
||||||
# Define projects for managing and distributing
|
# Define projects for managing and distributing
|
||||||
|
|
79
Software/Framework.UnitTest/CMakeLists.txt
Normal file
79
Software/Framework.UnitTest/CMakeLists.txt
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
###########################################################################################
|
||||||
|
#
|
||||||
|
# (c) Luis Stanglmeier
|
||||||
|
#
|
||||||
|
# CMAKE project file / @Add your project name@
|
||||||
|
|
||||||
|
#
|
||||||
|
#-----------------------------------------------------------------------------------------
|
||||||
|
# Define project specific requirements
|
||||||
|
#
|
||||||
|
# Project name, output file name, project description
|
||||||
|
#
|
||||||
|
set(PROJECT_NAME Framework.Unittest)
|
||||||
|
set(PROJECT_OUTPUT_NAME Framework.Unittest)
|
||||||
|
set(UNITTEST_PROJECT Framework)
|
||||||
|
set(PROJECT_DESCRIPTION "Unit tests for project Framework")
|
||||||
|
#
|
||||||
|
#-----------------------------------------------------------------------------------------
|
||||||
|
# Define group file names
|
||||||
|
#
|
||||||
|
# NOTE: When using GLOB or GLOB_RECURSE for gathering files, CMake will not notice when the amount of files has changed (a file has been added/removed).
|
||||||
|
# The CMakeList has to be compiled manually after adding/removing a source/header file.
|
||||||
|
#
|
||||||
|
# SOURCE FILES
|
||||||
|
#
|
||||||
|
FILE(GLOB_RECURSE SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/*/*.cpp)
|
||||||
|
#
|
||||||
|
# HEADER FILES
|
||||||
|
#
|
||||||
|
FILE(GLOB_RECURSE HEADER_FILES ${CMAKE_CURRENT_LIST_DIR}/*/*.h)
|
||||||
|
#
|
||||||
|
#-----------------------------------------------------------------------------------------
|
||||||
|
# Define solution folders for group files
|
||||||
|
#
|
||||||
|
source_group("Source Files" FILES ${SOURCE_FILES} main.cpp)
|
||||||
|
source_group("Header Files" FILES ${HEADER_FILES})
|
||||||
|
#
|
||||||
|
#-----------------------------------------------------------------------------------------
|
||||||
|
# Console application definitions
|
||||||
|
#
|
||||||
|
# Setup application version
|
||||||
|
#
|
||||||
|
TSEP_SETUP_APP_VERSION(${PROJECT_DESCRIPTION})
|
||||||
|
#
|
||||||
|
# Create console application
|
||||||
|
#
|
||||||
|
add_executable(${PROJECT_NAME} ${SOURCE_FILES} ${HEADER_FILES} ${TSEP_APP_VERSION_RC} main.cpp)
|
||||||
|
#
|
||||||
|
# Setup output
|
||||||
|
#
|
||||||
|
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_OUTPUT_NAME})
|
||||||
|
set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER "UnitTest")
|
||||||
|
#
|
||||||
|
# Add used libs
|
||||||
|
#
|
||||||
|
target_link_libraries(${PROJECT_NAME}
|
||||||
|
PUBLIC
|
||||||
|
${UNITTEST_PROJECT}
|
||||||
|
GTest::GTest
|
||||||
|
)
|
||||||
|
#
|
||||||
|
#-----------------------------------------------------------------------------------------
|
||||||
|
# Include files, add your own includes
|
||||||
|
TSEP_GET_HEADER_DIRECTORIES(SOURCE_INCLUDE_LIST ${TSEP_SOURCE_DIR}/${UNITTEST_PROJECT})
|
||||||
|
TSEP_GET_HEADER_DIRECTORIES(UNIT_TEST_INCLUDE_LIST ${CMAKE_CURRENT_LIST_DIR})
|
||||||
|
#
|
||||||
|
target_include_directories(${PROJECT_NAME}
|
||||||
|
PUBLIC
|
||||||
|
${UNIT_TEST_INCLUDE_LIST}
|
||||||
|
${SOURCE_INCLUDE_LIST}
|
||||||
|
#PRIVATE
|
||||||
|
# include paths, which will not be exported
|
||||||
|
)
|
||||||
|
#
|
||||||
|
# Create links to necessary dependency libraries
|
||||||
|
#
|
||||||
|
TSEP_GENERATE_DEPENDENCY_LINKS()
|
||||||
|
#
|
||||||
|
|
166
Software/Framework.UnitTest/main.cpp
Normal file
166
Software/Framework.UnitTest/main.cpp
Normal file
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,6 @@
|
||||||
###########################################################################################
|
###########################################################################################
|
||||||
#
|
#
|
||||||
# (c) Technical Software Engineering Plazotta 2021
|
# (c) Luis Stanglmeier
|
||||||
#
|
#
|
||||||
# CMAKE project file / @Add your project name@
|
# CMAKE project file / @Add your project name@
|
||||||
#
|
#
|
||||||
|
@ -20,8 +20,14 @@ set(PROJECT_DESCRIPTION "LSFramework")
|
||||||
# SOURCE FILES
|
# SOURCE FILES
|
||||||
#
|
#
|
||||||
set(SOURCE_FILES
|
set(SOURCE_FILES
|
||||||
src/Timer.cpp
|
src/CString.cpp
|
||||||
src/LSString.cpp
|
src/CTimer.cpp
|
||||||
|
src/CVariant.cpp
|
||||||
|
src/CJsonDocument.cpp
|
||||||
|
src/CJsonNode.cpp
|
||||||
|
src/CJsonArray.cpp
|
||||||
|
src/CJsonObject.cpp
|
||||||
|
src/main.cpp
|
||||||
)
|
)
|
||||||
#
|
#
|
||||||
# HEADER FILES
|
# HEADER FILES
|
||||||
|
@ -29,15 +35,17 @@ set(SOURCE_FILES
|
||||||
set(HEADER_FILES
|
set(HEADER_FILES
|
||||||
src/LSFramework.Exports.h
|
src/LSFramework.Exports.h
|
||||||
src/LSMacros.h
|
src/LSMacros.h
|
||||||
src/Timer.h
|
src/CString.h
|
||||||
|
src/CTimer.h
|
||||||
|
src/CList.h
|
||||||
|
src/CListItem.h
|
||||||
|
src/CVector.h
|
||||||
src/CJsonDocument.h
|
src/CJsonDocument.h
|
||||||
src/CJsonNode.h
|
src/CJsonNode.h
|
||||||
src/CJsonArray.h
|
src/CJsonArray.h
|
||||||
src/CJsonObject.h
|
src/CJsonObject.h
|
||||||
src/LSString.h
|
src/CVariant.h
|
||||||
src/LSList.h
|
|
||||||
src/LSListItem.h
|
|
||||||
src/LSVector.h
|
|
||||||
)
|
)
|
||||||
#
|
#
|
||||||
#-----------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------
|
||||||
|
|
0
Software/Framework/src/CJsonArray.cpp
Normal file
0
Software/Framework/src/CJsonArray.cpp
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
namespace LSFramework
|
||||||
|
{
|
||||||
|
class CJsonArray
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
24
Software/Framework/src/CJsonDocument.cpp
Normal file
24
Software/Framework/src/CJsonDocument.cpp
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#include "CJsonDocument.h"
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
namespace LSFramework
|
||||||
|
{
|
||||||
|
bool LSFramework::CJsonDocument::ReadFile(const CString& sFileName)
|
||||||
|
{
|
||||||
|
CString sContent;
|
||||||
|
string myText;
|
||||||
|
ifstream oFile(sFileName.ToChar());
|
||||||
|
while (getline(oFile, myText)) {
|
||||||
|
// Output the text from the file
|
||||||
|
sContent.Append(myText);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool CJsonDocument::SaveFile(const CString& sFileName)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,28 @@
|
||||||
private:
|
#pragma once
|
||||||
CcJsonNode m_oJsonData;
|
#include "CJsonNode.h"
|
||||||
bool m_bParseError = false;
|
#include "CString"
|
||||||
CcString m_sParseErrorMsg;
|
|
||||||
bool m_bIntend = false;
|
|
||||||
uint16 m_uiIntendLevel = 0;
|
|
||||||
|
|
||||||
static const CcString c_sIndent;
|
namespace LSFramework
|
||||||
|
{
|
||||||
|
|
||||||
|
class CJsonDocument
|
||||||
|
{
|
||||||
|
CJsonDocument();
|
||||||
|
|
||||||
|
~CJsonDocument();
|
||||||
|
|
||||||
|
bool ReadFile(const CString& sFileName);
|
||||||
|
|
||||||
|
bool SaveFile(const CString& sFileName);
|
||||||
|
|
||||||
|
private:
|
||||||
|
CJsonNode m_oJsonData;
|
||||||
|
bool m_bParseError = false;
|
||||||
|
CString m_sParseErrorMsg;
|
||||||
|
bool m_bIntend = false;
|
||||||
|
size_t m_zIntendLevel = 0;
|
||||||
|
|
||||||
|
static const CString c_sIndent;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
0
Software/Framework/src/CJsonNode.cpp
Normal file
0
Software/Framework/src/CJsonNode.cpp
Normal file
|
@ -1,12 +1,33 @@
|
||||||
|
#pragma once
|
||||||
|
#include "CJsonObject.h"
|
||||||
|
#include "CJsonArray.h"
|
||||||
|
#include "CVariant.h"
|
||||||
|
#include "CString.h"
|
||||||
|
|
||||||
|
namespace LSFramework
|
||||||
|
{
|
||||||
|
enum class EJsonDataType
|
||||||
|
{
|
||||||
|
Unknown = 0,
|
||||||
|
Value,
|
||||||
|
Object,
|
||||||
|
Array
|
||||||
|
};
|
||||||
|
|
||||||
|
class CJsonNode
|
||||||
|
{
|
||||||
|
|
||||||
private:
|
private:
|
||||||
union CcDocumentsSHARED UJsonDataType
|
union UJsonDataType
|
||||||
{
|
{
|
||||||
void* m_pVoid;
|
void* m_pVoid;
|
||||||
CcVariant* m_ovValue;
|
CVariant* m_ovValue;
|
||||||
CcJsonObject* m_poJsonObject;
|
CJsonObject* m_poJsonObject;
|
||||||
CcJsonArray* m_poJsonArray;
|
CJsonArray* m_poJsonArray;
|
||||||
};
|
};
|
||||||
UJsonDataType m_uData;
|
UJsonDataType m_uData;
|
||||||
EJsonDataType m_eType = EJsonDataType::Unknown; //!< Enum of current stored Object type.
|
EJsonDataType m_eType = EJsonDataType::Unknown; //!< Enum of current stored Object type.
|
||||||
CcString m_sName; //!< Name of this Object
|
CString m_sName; //!< Name of this Object
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
0
Software/Framework/src/CJsonObject.cpp
Normal file
0
Software/Framework/src/CJsonObject.cpp
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
|
||||||
|
namespace LSFramework
|
||||||
|
{
|
||||||
|
class CJsonObject
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
114
Software/Framework/src/CList.h
Normal file
114
Software/Framework/src/CList.h
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
#pragma once
|
||||||
|
#include "LSFramework.Exports.h"
|
||||||
|
#include "LSMacros.h"
|
||||||
|
#include "CListItem.h"
|
||||||
|
|
||||||
|
namespace Framework
|
||||||
|
{
|
||||||
|
template <class T>
|
||||||
|
|
||||||
|
class LSFRAMEWORK_API CList
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
CList()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
~CList()
|
||||||
|
{
|
||||||
|
DELETE_ARRAY(m_pFirst)
|
||||||
|
DELETE_ARRAY(m_pLast)
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
CListItem<T>* Append(T tObj)
|
||||||
|
{
|
||||||
|
CListItem<T>* pNewLast;
|
||||||
|
if (!m_pFirst)
|
||||||
|
{
|
||||||
|
m_pFirst = new CListItem<T>(tObj);
|
||||||
|
m_pLast = new CListItem<T>(tObj);
|
||||||
|
m_pFirst->pNext = m_pLast;
|
||||||
|
pNewLast = m_pFirst;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pNewLast = new CListItem<T>(tObj);
|
||||||
|
if (m_pLast->pBefore)
|
||||||
|
{
|
||||||
|
CListItem<T>* pCurrentLast = m_pLast;
|
||||||
|
pCurrentLast->pNext = pNewLast;
|
||||||
|
pNewLast->pBefore = pCurrentLast;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_pFirst->pNext = pNewLast;
|
||||||
|
pNewLast->pBefore = m_pFirst;
|
||||||
|
}
|
||||||
|
m_pLast = pNewLast;
|
||||||
|
}
|
||||||
|
m_zSize++;
|
||||||
|
return pNewLast;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
CListItem<T>* Remove(T tObj)
|
||||||
|
{
|
||||||
|
if (m_zSize == 0) return nullptr;
|
||||||
|
|
||||||
|
CListItem<T>* pItemToRemove = m_pFirst;
|
||||||
|
|
||||||
|
while (pItemToRemove->tValue != tObj)
|
||||||
|
{
|
||||||
|
pItemToRemove = pItemToRemove->pNext;
|
||||||
|
}
|
||||||
|
|
||||||
|
CListItem<T>* pRet = nullptr;
|
||||||
|
|
||||||
|
if (m_zSize <= 1)
|
||||||
|
{
|
||||||
|
m_pFirst = nullptr;
|
||||||
|
m_pLast = nullptr;
|
||||||
|
}
|
||||||
|
else if (pItemToRemove == m_pFirst)
|
||||||
|
{
|
||||||
|
CListItem<T>* pNewFirst = pItemToRemove->pNext;
|
||||||
|
pNewFirst->pBefore = nullptr;
|
||||||
|
m_pFirst = pNewFirst;
|
||||||
|
pRet = pNewFirst;
|
||||||
|
}
|
||||||
|
else if (pItemToRemove == m_pLast)
|
||||||
|
{
|
||||||
|
CListItem<T>* pNewLast = pItemToRemove->pBefore;
|
||||||
|
pNewLast->pNext = nullptr;
|
||||||
|
m_pLast = pNewLast;
|
||||||
|
pRet = pNewLast;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CListItem<T>* pBefore = pItemToRemove->pBefore;
|
||||||
|
CListItem<T>* pNext = pItemToRemove->pNext;
|
||||||
|
pBefore->pNext = pNext;
|
||||||
|
pNext->pBefore = pBefore;
|
||||||
|
pRet = pNext;
|
||||||
|
}
|
||||||
|
|
||||||
|
DELETE_POINTER(pItemToRemove);
|
||||||
|
m_zSize--;
|
||||||
|
return pRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
T* RemoveAt(size_t zPos)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
CListItem<T>* m_pFirst = nullptr;
|
||||||
|
CListItem<T>* m_pLast = nullptr;
|
||||||
|
size_t m_zSize = 0;
|
||||||
|
};
|
||||||
|
}
|
25
Software/Framework/src/CListItem.h
Normal file
25
Software/Framework/src/CListItem.h
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace Framework
|
||||||
|
{
|
||||||
|
template <class T>
|
||||||
|
|
||||||
|
class CListItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
CListItem(T oObj)
|
||||||
|
: oValue(oObj)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
~CListItem()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
CListItem* pBefore = nullptr;
|
||||||
|
CListItem* pNext = nullptr;
|
||||||
|
T oValue;
|
||||||
|
};
|
||||||
|
}
|
123
Software/Framework/src/CString.cpp
Normal file
123
Software/Framework/src/CString.cpp
Normal file
|
@ -0,0 +1,123 @@
|
||||||
|
#include "CString.h"
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace LSFramework
|
||||||
|
{
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
CString::CString(const char* pData)
|
||||||
|
: m_zSize(StringLength(pData))
|
||||||
|
, m_uiCapacity(StringLength(pData))
|
||||||
|
{
|
||||||
|
Assign(pData);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
CString::CString(const std::string& sRhs)
|
||||||
|
: m_zSize(sRhs.length())
|
||||||
|
, m_uiCapacity(sRhs.length())
|
||||||
|
{
|
||||||
|
Assign(sRhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
CString& CString::operator=(const CString& sRhs)
|
||||||
|
{
|
||||||
|
m_zSize = sRhs.Size();
|
||||||
|
m_uiCapacity = sRhs.Capacity();
|
||||||
|
Assign(sRhs);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
CString::CString(const CString& sRhs)
|
||||||
|
: m_zSize(sRhs.m_zSize)
|
||||||
|
, m_uiCapacity(sRhs.m_uiCapacity)
|
||||||
|
{
|
||||||
|
Assign(sRhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
CString::~CString()
|
||||||
|
{
|
||||||
|
DELETE_ARRAY(m_pData);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
void CString::Assign(const char* pData)
|
||||||
|
{
|
||||||
|
m_pData = new char[m_zSize + 1];
|
||||||
|
memset(m_pData, 0, m_zSize + 1);
|
||||||
|
if (pData) memcpy(m_pData, pData, m_zSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
void CString::Insert(const char* pData, size_t zLength, size_t zPos)
|
||||||
|
{
|
||||||
|
if (!pData) return;
|
||||||
|
|
||||||
|
size_t zNewLength = m_zSize + zLength;
|
||||||
|
|
||||||
|
while (zNewLength > m_uiCapacity)
|
||||||
|
{
|
||||||
|
IncreaseCapacity(zNewLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
char* pLeft = m_pData + zPos;
|
||||||
|
char* pRight = m_pData + zPos + zLength;
|
||||||
|
|
||||||
|
memcpy(pRight, m_pData + zPos, m_zSize - zPos);
|
||||||
|
memcpy(pLeft, pData, zLength);
|
||||||
|
|
||||||
|
m_zSize = zNewLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool CString::RemoveAt(size_t uiPos, size_t uiSize)
|
||||||
|
{
|
||||||
|
if (uiPos > m_zSize) return false;
|
||||||
|
|
||||||
|
m_zSize = m_zSize - uiSize;
|
||||||
|
char* pLast = m_pData + uiPos + uiSize;
|
||||||
|
memcpy(m_pData + uiPos, pLast, uiSize);
|
||||||
|
memset(pLast, 0, uiSize);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
size_t CString::StringLength(const char* pChar) const
|
||||||
|
{
|
||||||
|
if (!pChar) return 0;
|
||||||
|
const char* pStart = pChar;
|
||||||
|
while (*pChar != 0x0)
|
||||||
|
{
|
||||||
|
pChar++;
|
||||||
|
}
|
||||||
|
return pChar - pStart;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
int CString::Find(const char* pData, size_t uiOffset, size_t uiLength) const
|
||||||
|
{
|
||||||
|
int iRet = -1;
|
||||||
|
while (uiOffset + uiLength <= m_zSize)
|
||||||
|
{
|
||||||
|
iRet = memcmp(m_pData + uiOffset, pData, uiLength);
|
||||||
|
if (iRet == 0) break;
|
||||||
|
uiOffset++;
|
||||||
|
}
|
||||||
|
return iRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
void CString::IncreaseCapacity(size_t uiNewLength)
|
||||||
|
{
|
||||||
|
m_uiCapacity = uiNewLength * c_uiCapacityIncreaseFactor;
|
||||||
|
char* pNew = new char[m_uiCapacity + 1];
|
||||||
|
memset(pNew, 0, m_uiCapacity + 1);
|
||||||
|
memmove(pNew, m_pData, m_zSize);
|
||||||
|
DELETE_ARRAY(m_pData);
|
||||||
|
m_pData = pNew;
|
||||||
|
}
|
||||||
|
}
|
180
Software/Framework/src/CString.h
Normal file
180
Software/Framework/src/CString.h
Normal file
|
@ -0,0 +1,180 @@
|
||||||
|
#pragma once
|
||||||
|
#include "LSFramework.Exports.h"
|
||||||
|
#include "LSMacros.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace LSFramework
|
||||||
|
{
|
||||||
|
class LSFRAMEWORK_API CString
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// - Constructor
|
||||||
|
CString() = default;
|
||||||
|
|
||||||
|
CString(const char* pData);
|
||||||
|
|
||||||
|
CString(const CString& sString);
|
||||||
|
|
||||||
|
CString(const std::string& sString);
|
||||||
|
|
||||||
|
// - Operator
|
||||||
|
CString& operator=(const CString& sRhs);
|
||||||
|
|
||||||
|
// - Destructor
|
||||||
|
~CString();
|
||||||
|
|
||||||
|
// - Alloc
|
||||||
|
#pragma region Conversion
|
||||||
|
inline void Assign(const CString& sString)
|
||||||
|
{
|
||||||
|
Assign(sString.ToChar());
|
||||||
|
}
|
||||||
|
inline void Assign(const std::string& sString)
|
||||||
|
{
|
||||||
|
Assign(sString.c_str());
|
||||||
|
}
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void Append(const CString& sRhs)
|
||||||
|
{
|
||||||
|
Insert(sRhs, sRhs.Size());
|
||||||
|
}
|
||||||
|
inline void Append(const std::string& sRhs)
|
||||||
|
{
|
||||||
|
Insert(sRhs, sRhs.length());
|
||||||
|
}
|
||||||
|
inline void Append(const char* pData)
|
||||||
|
{
|
||||||
|
Insert(pData, StringLength(pData), m_zSize);
|
||||||
|
}
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void Insert(const CString& sRhs, size_t zPos)
|
||||||
|
{
|
||||||
|
Insert(sRhs.m_pData, sRhs.Size(), zPos);
|
||||||
|
}
|
||||||
|
inline void Insert(const std::string& sRhs, size_t zPos)
|
||||||
|
{
|
||||||
|
Insert(sRhs.c_str(), sRhs.size(), zPos);
|
||||||
|
}
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline bool Remove(const CString& sRhs)
|
||||||
|
{
|
||||||
|
return RemoveAt(Find(sRhs), sRhs.m_zSize);
|
||||||
|
}
|
||||||
|
inline bool Remove(const std::string& sRhs)
|
||||||
|
{
|
||||||
|
return RemoveAt(Find(sRhs), sRhs.length());
|
||||||
|
}
|
||||||
|
inline bool Remove(const char* pData)
|
||||||
|
{
|
||||||
|
return RemoveAt(Find(pData), StringLength(pData));
|
||||||
|
}
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
|
#pragma region Logic
|
||||||
|
void Assign(const char* pData);
|
||||||
|
void Insert(const char* pData, size_t zLength, size_t zPos);
|
||||||
|
bool RemoveAt(size_t uiPos, size_t uiSize);
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
|
// - Utility
|
||||||
|
#pragma region Conversion
|
||||||
|
inline bool Contains(const CString& sRhs) const
|
||||||
|
{
|
||||||
|
return Find(sRhs) == 0;
|
||||||
|
}
|
||||||
|
inline bool Contains(const std::string& sRhs) const
|
||||||
|
{
|
||||||
|
return Find(sRhs) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool Contains(const char* pData) const
|
||||||
|
{
|
||||||
|
return Find(pData) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline int Find(const CString& sRhs, size_t uiOffset = 0) const
|
||||||
|
{
|
||||||
|
return Find(sRhs.m_pData, uiOffset);
|
||||||
|
}
|
||||||
|
inline int Find(const std::string& sRhs, size_t uiOffset = 0) const
|
||||||
|
{
|
||||||
|
return Find(sRhs.c_str(), uiOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int Find(const char* pData, size_t uiOffset = 0) const
|
||||||
|
{
|
||||||
|
return Find(pData, uiOffset, StringLength(pData));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int Find(const CString& sRhs, size_t uiOffset, size_t uiLength) const
|
||||||
|
{
|
||||||
|
return Find(sRhs.m_pData, uiOffset, uiLength);
|
||||||
|
}
|
||||||
|
inline int Find(const std::string& sRhs, size_t uiOffset, size_t uiLength) const
|
||||||
|
{
|
||||||
|
return Find(sRhs.c_str(), uiOffset, uiLength);
|
||||||
|
}
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
|
#pragma region Logic
|
||||||
|
size_t StringLength(const char* pData) const;
|
||||||
|
|
||||||
|
int Find(const char* pData, size_t uiOffset, size_t uiLength) const;
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline char At(size_t uiPos) const
|
||||||
|
{
|
||||||
|
return *(m_pData + uiPos);
|
||||||
|
}
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline size_t Size() const
|
||||||
|
{
|
||||||
|
return m_zSize;
|
||||||
|
}
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline size_t Capacity() const
|
||||||
|
{
|
||||||
|
return m_uiCapacity;
|
||||||
|
}
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline std::string ToStdString() const
|
||||||
|
{
|
||||||
|
return std::string(m_pData);
|
||||||
|
}
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline const char* ToChar() const
|
||||||
|
{
|
||||||
|
return m_pData;
|
||||||
|
}
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
|
private:
|
||||||
|
void IncreaseCapacity(size_t uiNewLength = 0);
|
||||||
|
|
||||||
|
char* m_pData = nullptr;
|
||||||
|
size_t m_zSize = 0;
|
||||||
|
size_t m_uiCapacity = 0;
|
||||||
|
const float c_uiCapacityIncreaseFactor = 1.5;
|
||||||
|
};
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline CString operator+(const CString& sLhs, const CString& sRhs)
|
||||||
|
{
|
||||||
|
CString sNew(sLhs);
|
||||||
|
sNew.Append(sRhs);
|
||||||
|
return sNew;
|
||||||
|
}
|
||||||
|
inline CString operator+(const CString& sLhs, const char* sRhs)
|
||||||
|
{
|
||||||
|
CString sNew(sLhs);
|
||||||
|
sNew.Append(sRhs);
|
||||||
|
return sNew;
|
||||||
|
}
|
||||||
|
inline CString operator+(const char* sLhs, const CString& sRhs)
|
||||||
|
{
|
||||||
|
CString sNew(sLhs);
|
||||||
|
sNew.Append(sRhs);
|
||||||
|
return sNew;
|
||||||
|
}
|
||||||
|
}
|
25
Software/Framework/src/CTimer.cpp
Normal file
25
Software/Framework/src/CTimer.cpp
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#include "CTimer.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace LSFramework
|
||||||
|
{
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
CTimer::CTimer(CString sEndString)
|
||||||
|
: m_StartTimePoint(std::chrono::high_resolution_clock::now())
|
||||||
|
, m_sEndString(sEndString)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
CTimer::~CTimer()
|
||||||
|
{
|
||||||
|
auto endTimePoint = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
|
auto start = std::chrono::time_point_cast<std::chrono::microseconds>(m_StartTimePoint).time_since_epoch().count();
|
||||||
|
auto end = std::chrono::time_point_cast<std::chrono::microseconds>(endTimePoint).time_since_epoch().count();
|
||||||
|
|
||||||
|
auto duration = end - start;
|
||||||
|
printf("%sMicroseconds: %2d (%.3f ms)\n", m_sEndString.ToChar(), static_cast<int>(duration), (duration * 0.001));
|
||||||
|
//std::cout << "Duration in Microseconds: " << duration << " (" << duration * 0.001 << " ms)" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
18
Software/Framework/src/CTimer.h
Normal file
18
Software/Framework/src/CTimer.h
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#pragma once
|
||||||
|
#include "LSFramework.Exports.h"
|
||||||
|
#include "CString.h"
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
namespace LSFramework
|
||||||
|
{
|
||||||
|
class LSFRAMEWORK_API CTimer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CTimer(CString sEndString = "");
|
||||||
|
|
||||||
|
~CTimer(void);
|
||||||
|
private:
|
||||||
|
CString m_sEndString;
|
||||||
|
std::chrono::time_point<std::chrono::high_resolution_clock> m_StartTimePoint;
|
||||||
|
};
|
||||||
|
}
|
0
Software/Framework/src/CVariant.cpp
Normal file
0
Software/Framework/src/CVariant.cpp
Normal file
7
Software/Framework/src/CVariant.h
Normal file
7
Software/Framework/src/CVariant.h
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
namespace LSFramework
|
||||||
|
{
|
||||||
|
class CVariant
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
136
Software/Framework/src/CVector.h
Normal file
136
Software/Framework/src/CVector.h
Normal file
|
@ -0,0 +1,136 @@
|
||||||
|
#pragma once
|
||||||
|
#include "LSFramework.Exports.h"
|
||||||
|
#include "LSMacros.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace Framework
|
||||||
|
{
|
||||||
|
template <class T>
|
||||||
|
|
||||||
|
class LSFRAMEWORK_API CVector
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
CVector()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CVector(size_t zSize)
|
||||||
|
{
|
||||||
|
m_pData = new T[zSize];
|
||||||
|
m_zCapacity = zSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
CVector(const CVector& oRhs)
|
||||||
|
: m_pData(oRhs.m_pData)
|
||||||
|
, m_zSize(oRhs.m_zSize)
|
||||||
|
, m_zCapacity(oRhs.m_zCapacity)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~CVector()
|
||||||
|
{
|
||||||
|
DELETE_ARRAY(m_pData)
|
||||||
|
}
|
||||||
|
|
||||||
|
T& PushBack(T oNewobj)
|
||||||
|
{
|
||||||
|
return Assign(oNewobj);
|
||||||
|
}
|
||||||
|
|
||||||
|
T& Assign(T oNewobj)
|
||||||
|
{
|
||||||
|
if (m_zSize == m_zCapacity)
|
||||||
|
{
|
||||||
|
m_zCapacity *= c_dCapacityIncreaseFactor;
|
||||||
|
T* pNew = new T[m_zCapacity];
|
||||||
|
memmove(pNew, m_pData, m_zSize);
|
||||||
|
DELETE_ARRAY(m_pData);
|
||||||
|
m_pData = pNew;
|
||||||
|
}
|
||||||
|
m_zSize += 1;
|
||||||
|
m_pData[m_zSize] = oNewobj;
|
||||||
|
return m_pData[m_zSize];
|
||||||
|
}
|
||||||
|
|
||||||
|
T& Insert(T oNewobj, const size_t zPos)
|
||||||
|
{
|
||||||
|
if (zPos == m_zCapacity)
|
||||||
|
{
|
||||||
|
return Assign(oNewobj);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_pData[zPos] = oNewobj;
|
||||||
|
return m_pData[zPos];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PopBack()
|
||||||
|
{
|
||||||
|
Remove(m_zSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Remove(const size_t zPos)
|
||||||
|
{
|
||||||
|
memset(m_pData[zPos], 0, sizeof(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
T& At(const size_t zPos) const
|
||||||
|
{
|
||||||
|
return m_pData[zPos];
|
||||||
|
}
|
||||||
|
|
||||||
|
void Reserve(const size_t zNewCapacity)
|
||||||
|
{
|
||||||
|
if (zNewCapacity < m_zCapacity) return;
|
||||||
|
T* pOld = m_pData;
|
||||||
|
m_pData = new T[zNewCapacity];
|
||||||
|
memmove_s(m_pData, zNewCapacity, pOld, m_zSize);
|
||||||
|
m_zCapacity = zNewCapacity;
|
||||||
|
DELETE_ARRAY(pOld)
|
||||||
|
}
|
||||||
|
|
||||||
|
void Clear()
|
||||||
|
{
|
||||||
|
DELETE_ARRAY(m_pData)
|
||||||
|
m_zSize = 0;
|
||||||
|
m_zCapacity = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Size() const
|
||||||
|
{
|
||||||
|
return m_zSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Capacity() const
|
||||||
|
{
|
||||||
|
return m_zCapacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
T* Data() const
|
||||||
|
{
|
||||||
|
return m_pData;
|
||||||
|
}
|
||||||
|
|
||||||
|
CVector operator=(const CVector oRhs)
|
||||||
|
{
|
||||||
|
CVector vTemp();
|
||||||
|
vTemp.m_pData = oRhs.m_pData;
|
||||||
|
}
|
||||||
|
|
||||||
|
T& operator[](const size_t zPos)
|
||||||
|
{
|
||||||
|
return m_pData[zPos];
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
std::vector<int> s;
|
||||||
|
T* m_pData = nullptr;
|
||||||
|
size_t m_zSize = 0;
|
||||||
|
size_t m_zCapacity = 0;
|
||||||
|
const float c_dCapacityIncreaseFactor = 1.5;
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,106 +0,0 @@
|
||||||
#pragma once
|
|
||||||
#include "LSFramework.Exports.h"
|
|
||||||
#include "LSMacros.h"
|
|
||||||
#include "LSListItem.h"
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
|
|
||||||
class LSFRAMEWORK_API LSList
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
LSList()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
~LSList()
|
|
||||||
{
|
|
||||||
DELETE_ARRAY(m_pFirst)
|
|
||||||
DELETE_ARRAY(m_pLast)
|
|
||||||
}
|
|
||||||
|
|
||||||
LSListItem<T>* Append(T tObj)
|
|
||||||
{
|
|
||||||
LSListItem<T>* pNewLast;
|
|
||||||
if (!m_pFirst)
|
|
||||||
{
|
|
||||||
m_pFirst = new LSListItem<T>(tObj);
|
|
||||||
m_pLast = new LSListItem<T>(tObj);
|
|
||||||
m_pFirst->pNext = m_pLast;
|
|
||||||
pNewLast = m_pFirst;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pNewLast = new LSListItem<T>(tObj);
|
|
||||||
if (m_pLast->pBefore)
|
|
||||||
{
|
|
||||||
LSListItem<T>* pCurrentLast = m_pLast;
|
|
||||||
pCurrentLast->pNext = pNewLast;
|
|
||||||
pNewLast->pBefore = pCurrentLast;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_pFirst->pNext = pNewLast;
|
|
||||||
pNewLast->pBefore = m_pFirst;
|
|
||||||
}
|
|
||||||
m_pLast = pNewLast;
|
|
||||||
}
|
|
||||||
m_zSize++;
|
|
||||||
return pNewLast;
|
|
||||||
}
|
|
||||||
|
|
||||||
LSListItem<T>* Remove(T tObj)
|
|
||||||
{
|
|
||||||
if (m_zSize == 0) return nullptr;
|
|
||||||
|
|
||||||
LSListItem<T>* pItemToRemove = m_pFirst;
|
|
||||||
|
|
||||||
while (pItemToRemove->tValue != tObj)
|
|
||||||
{
|
|
||||||
pItemToRemove = pItemToRemove->pNext;
|
|
||||||
}
|
|
||||||
|
|
||||||
LSListItem<T>* pRet = nullptr;
|
|
||||||
|
|
||||||
if (m_zSize <= 1)
|
|
||||||
{
|
|
||||||
m_pFirst = nullptr;
|
|
||||||
m_pLast = nullptr;
|
|
||||||
}
|
|
||||||
else if (pItemToRemove == m_pFirst)
|
|
||||||
{
|
|
||||||
LSListItem<T>* pNewFirst = pItemToRemove->pNext;
|
|
||||||
pNewFirst->pBefore = nullptr;
|
|
||||||
m_pFirst = pNewFirst;
|
|
||||||
pRet = pNewFirst;
|
|
||||||
}
|
|
||||||
else if (pItemToRemove == m_pLast)
|
|
||||||
{
|
|
||||||
LSListItem<T>* pNewLast = pItemToRemove->pBefore;
|
|
||||||
pNewLast->pNext = nullptr;
|
|
||||||
m_pLast = pNewLast;
|
|
||||||
pRet = pNewLast;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LSListItem<T>* pBefore = pItemToRemove->pBefore;
|
|
||||||
LSListItem<T>* pNext = pItemToRemove->pNext;
|
|
||||||
pBefore->pNext = pNext;
|
|
||||||
pNext->pBefore = pBefore;
|
|
||||||
pRet = pNext;
|
|
||||||
}
|
|
||||||
|
|
||||||
DELETE_POINTER(pItemToRemove);
|
|
||||||
m_zSize--;
|
|
||||||
return pRet;
|
|
||||||
}
|
|
||||||
|
|
||||||
T* RemoveAt(size_t zPos)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
LSListItem<T>* m_pFirst = nullptr;
|
|
||||||
LSListItem<T>* m_pLast = nullptr;
|
|
||||||
size_t m_zSize = 0;
|
|
||||||
};
|
|
|
@ -1,22 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
|
|
||||||
class LSListItem
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
LSListItem(T tObj)
|
|
||||||
: tValue(tObj)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
~LSListItem()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
LSListItem* pBefore = nullptr;
|
|
||||||
LSListItem* pNext = nullptr;
|
|
||||||
T tValue;
|
|
||||||
};
|
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
// no ; after the macro needed
|
||||||
#define DELETE_POINTER(pPointer) \
|
#define DELETE_POINTER(pPointer) \
|
||||||
if (pPointer != nullptr)\
|
if (pPointer != nullptr)\
|
||||||
{\
|
{\
|
||||||
|
@ -7,6 +8,7 @@ if (pPointer != nullptr)\
|
||||||
pPointer = nullptr;\
|
pPointer = nullptr;\
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// no ; after the macro needed
|
||||||
#define DELETE_ARRAY(vArray) \
|
#define DELETE_ARRAY(vArray) \
|
||||||
if (vArray != nullptr)\
|
if (vArray != nullptr)\
|
||||||
{\
|
{\
|
||||||
|
|
|
@ -1,119 +0,0 @@
|
||||||
#include "LSString.h"
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------------------------------------------------
|
|
||||||
LSString::LSString(const char* pData)
|
|
||||||
: m_zSize(StringLength(pData))
|
|
||||||
, m_uiCapacity(StringLength(pData))
|
|
||||||
{
|
|
||||||
Assign(pData);
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------------------------------------------------
|
|
||||||
LSString::LSString(const std::string& sRhs)
|
|
||||||
: m_zSize(sRhs.length())
|
|
||||||
, m_uiCapacity(sRhs.length())
|
|
||||||
{
|
|
||||||
Assign(sRhs);
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------------------------------------------------
|
|
||||||
LSString& LSString::operator=(const LSString& sRhs)
|
|
||||||
{
|
|
||||||
m_zSize = sRhs.Size();
|
|
||||||
m_uiCapacity = sRhs.Capacity();
|
|
||||||
Assign(sRhs);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------------------------------------------------
|
|
||||||
LSString::LSString(const LSString& sRhs)
|
|
||||||
: m_zSize(sRhs.m_zSize)
|
|
||||||
, m_uiCapacity(sRhs.m_uiCapacity)
|
|
||||||
{
|
|
||||||
Assign(sRhs);
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------------------------------------------------
|
|
||||||
LSString::~LSString()
|
|
||||||
{
|
|
||||||
DELETE_ARRAY(m_pData);
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------------------------------------------------
|
|
||||||
void LSString::Assign(const char* pData)
|
|
||||||
{
|
|
||||||
m_pData = new char[m_zSize + 1];
|
|
||||||
memset(m_pData, 0, m_zSize + 1);
|
|
||||||
if (pData) memcpy(m_pData, pData, m_zSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------------------------------------------------
|
|
||||||
void LSString::Insert(const char* pData, size_t zLength, size_t zPos)
|
|
||||||
{
|
|
||||||
if (!pData) return;
|
|
||||||
|
|
||||||
size_t zNewLength = m_zSize + zLength;
|
|
||||||
|
|
||||||
while (zNewLength > m_uiCapacity)
|
|
||||||
{
|
|
||||||
IncreaseCapacity(zNewLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
char* pLeft = m_pData + zPos;
|
|
||||||
char* pRight = m_pData + zPos + zLength;
|
|
||||||
|
|
||||||
memcpy(pRight, m_pData + zPos, m_zSize - zPos);
|
|
||||||
memcpy(pLeft, pData, zLength);
|
|
||||||
|
|
||||||
m_zSize = zNewLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------------------------------------------------
|
|
||||||
bool LSString::RemoveAt(size_t uiPos, size_t uiSize)
|
|
||||||
{
|
|
||||||
if (uiPos > m_zSize) return false;
|
|
||||||
|
|
||||||
m_zSize = m_zSize - uiSize;
|
|
||||||
char* pLast = m_pData + uiPos + uiSize;
|
|
||||||
memcpy(m_pData + uiPos, pLast, uiSize);
|
|
||||||
memset(pLast, 0, uiSize);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------------------------------------------------
|
|
||||||
size_t LSString::StringLength(const char* pChar) const
|
|
||||||
{
|
|
||||||
if (!pChar) return 0;
|
|
||||||
const char* pStart = pChar;
|
|
||||||
while (*pChar != 0x0)
|
|
||||||
{
|
|
||||||
pChar++;
|
|
||||||
}
|
|
||||||
return pChar - pStart;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------------------------------------------------
|
|
||||||
int LSString::Find(const char * pData, size_t uiOffset, size_t uiLength) const
|
|
||||||
{
|
|
||||||
int iRet = -1;
|
|
||||||
while (uiOffset + uiLength <= m_zSize)
|
|
||||||
{
|
|
||||||
iRet = memcmp(m_pData + uiOffset, pData, uiLength);
|
|
||||||
if (iRet == 0) break;
|
|
||||||
uiOffset++;
|
|
||||||
}
|
|
||||||
return iRet;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------------------------------------------------
|
|
||||||
void LSString::IncreaseCapacity(size_t uiNewLength)
|
|
||||||
{
|
|
||||||
m_uiCapacity = uiNewLength * c_uiCapacityIncreaseFactor;
|
|
||||||
char* pNew = new char[m_uiCapacity + 1];
|
|
||||||
memset(pNew, 0, m_uiCapacity + 1);
|
|
||||||
memmove(pNew, m_pData, m_zSize);
|
|
||||||
DELETE_ARRAY(m_pData);
|
|
||||||
m_pData = pNew;
|
|
||||||
}
|
|
|
@ -1,178 +0,0 @@
|
||||||
#pragma once
|
|
||||||
#include "LSFramework.Exports.h"
|
|
||||||
#include "LSMacros.h"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
class LSFRAMEWORK_API LSString
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// - Constructor
|
|
||||||
LSString() = default;
|
|
||||||
|
|
||||||
LSString(const char* pData);
|
|
||||||
|
|
||||||
LSString(const LSString& sString);
|
|
||||||
|
|
||||||
LSString(const std::string& sString);
|
|
||||||
|
|
||||||
// - Operator
|
|
||||||
LSString& operator=(const LSString& sRhs);
|
|
||||||
|
|
||||||
// - Destructor
|
|
||||||
~LSString();
|
|
||||||
|
|
||||||
// - Alloc
|
|
||||||
#pragma region Conversion
|
|
||||||
inline void Assign(const LSString& sString)
|
|
||||||
{
|
|
||||||
Assign(sString.ToCChar());
|
|
||||||
}
|
|
||||||
inline void Assign(const std::string& sString)
|
|
||||||
{
|
|
||||||
Assign(sString.c_str());
|
|
||||||
}
|
|
||||||
//-----------------------------------------------------------------------------------------------------------------------------
|
|
||||||
inline void Append(const LSString& sRhs)
|
|
||||||
{
|
|
||||||
Insert(sRhs, sRhs.Size());
|
|
||||||
}
|
|
||||||
inline void Append(const std::string& sRhs)
|
|
||||||
{
|
|
||||||
Insert(sRhs, sRhs.length());
|
|
||||||
}
|
|
||||||
inline void Append(const char* pData)
|
|
||||||
{
|
|
||||||
Insert(pData, StringLength(pData), m_zSize);
|
|
||||||
}
|
|
||||||
//-----------------------------------------------------------------------------------------------------------------------------
|
|
||||||
inline void Insert(const LSString& sRhs, size_t zPos)
|
|
||||||
{
|
|
||||||
Insert(sRhs.m_pData, sRhs.Size(), zPos);
|
|
||||||
}
|
|
||||||
inline void Insert(const std::string& sRhs, size_t zPos)
|
|
||||||
{
|
|
||||||
Insert(sRhs.c_str(), sRhs.size(), zPos);
|
|
||||||
}
|
|
||||||
//-----------------------------------------------------------------------------------------------------------------------------
|
|
||||||
inline bool Remove(const LSString& sRhs)
|
|
||||||
{
|
|
||||||
return RemoveAt(Find(sRhs), sRhs.m_zSize);
|
|
||||||
}
|
|
||||||
inline bool Remove(const std::string& sRhs)
|
|
||||||
{
|
|
||||||
return RemoveAt(Find(sRhs), sRhs.length());
|
|
||||||
}
|
|
||||||
inline bool Remove(const char* pData)
|
|
||||||
{
|
|
||||||
return RemoveAt(Find(pData), StringLength(pData));
|
|
||||||
}
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
#pragma region Logic
|
|
||||||
void Assign(const char* pData);
|
|
||||||
void Insert(const char* pData, size_t zLength, size_t zPos);
|
|
||||||
bool RemoveAt(size_t uiPos, size_t uiSize);
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
// - Utility
|
|
||||||
#pragma region Conversion
|
|
||||||
inline bool Contains(const LSString& sRhs) const
|
|
||||||
{
|
|
||||||
return Find(sRhs) == 0;
|
|
||||||
}
|
|
||||||
inline bool Contains(const std::string& sRhs) const
|
|
||||||
{
|
|
||||||
return Find(sRhs) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Contains(const char* pData) const
|
|
||||||
{
|
|
||||||
return Find(pData) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------------------------------------------------
|
|
||||||
inline int Find(const LSString& sRhs, size_t uiOffset = 0) const
|
|
||||||
{
|
|
||||||
return Find(sRhs.m_pData, uiOffset);
|
|
||||||
}
|
|
||||||
inline int Find(const std::string& sRhs, size_t uiOffset = 0) const
|
|
||||||
{
|
|
||||||
return Find(sRhs.c_str(), uiOffset);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int Find(const char* pData, size_t uiOffset = 0) const
|
|
||||||
{
|
|
||||||
return Find(pData, uiOffset, StringLength(pData));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int Find(const LSString& sRhs, size_t uiOffset, size_t uiLength) const
|
|
||||||
{
|
|
||||||
return Find(sRhs.m_pData, uiOffset, uiLength);
|
|
||||||
}
|
|
||||||
inline int Find(const std::string& sRhs, size_t uiOffset, size_t uiLength) const
|
|
||||||
{
|
|
||||||
return Find(sRhs.c_str(), uiOffset, uiLength);
|
|
||||||
}
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
#pragma region Logic
|
|
||||||
size_t StringLength(const char* pData) const;
|
|
||||||
|
|
||||||
int Find(const char* pData, size_t uiOffset, size_t uiLength) const;
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------------------------------------------------
|
|
||||||
inline char At(size_t uiPos) const
|
|
||||||
{
|
|
||||||
return *(m_pData + uiPos);
|
|
||||||
}
|
|
||||||
//-----------------------------------------------------------------------------------------------------------------------------
|
|
||||||
inline size_t Size() const
|
|
||||||
{
|
|
||||||
return m_zSize;
|
|
||||||
}
|
|
||||||
//-----------------------------------------------------------------------------------------------------------------------------
|
|
||||||
inline size_t Capacity() const
|
|
||||||
{
|
|
||||||
return m_uiCapacity;
|
|
||||||
}
|
|
||||||
//-----------------------------------------------------------------------------------------------------------------------------
|
|
||||||
inline std::string ToStdString() const
|
|
||||||
{
|
|
||||||
return std::string(m_pData);
|
|
||||||
}
|
|
||||||
//-----------------------------------------------------------------------------------------------------------------------------
|
|
||||||
inline const char* ToCChar() const
|
|
||||||
{
|
|
||||||
return m_pData;
|
|
||||||
}
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
private:
|
|
||||||
void IncreaseCapacity(size_t uiNewLength = 0);
|
|
||||||
|
|
||||||
char* m_pData = nullptr;
|
|
||||||
size_t m_zSize = 0;
|
|
||||||
size_t m_uiCapacity = 0;
|
|
||||||
const float c_uiCapacityIncreaseFactor = 1.5;
|
|
||||||
};
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------------------------------------------------
|
|
||||||
inline LSString operator+(const LSString& sLhs, const LSString& sRhs)
|
|
||||||
{
|
|
||||||
LSString sNew(sLhs);
|
|
||||||
sNew.Append(sRhs);
|
|
||||||
return sNew;
|
|
||||||
}
|
|
||||||
inline LSString operator+(const LSString& sLhs, const char* sRhs)
|
|
||||||
{
|
|
||||||
LSString sNew(sLhs);
|
|
||||||
sNew.Append(sRhs);
|
|
||||||
return sNew;
|
|
||||||
}
|
|
||||||
inline LSString operator+(const char* sLhs, const LSString& sRhs)
|
|
||||||
{
|
|
||||||
LSString sNew(sLhs);
|
|
||||||
sNew.Append(sRhs);
|
|
||||||
return sNew;
|
|
||||||
}
|
|
|
@ -1,131 +0,0 @@
|
||||||
#pragma once
|
|
||||||
#include "LSFramework.Exports.h"
|
|
||||||
#include "LSMacros.h"
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
|
|
||||||
class LSFRAMEWORK_API LSVector
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
LSVector()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
LSVector(size_t zSize)
|
|
||||||
{
|
|
||||||
m_pData = new T[zSize];
|
|
||||||
m_zCapacity = zSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
LSVector(const LSVector& oRhs)
|
|
||||||
: m_pData(oRhs.m_pData)
|
|
||||||
, m_zSize(oRhs.m_zSize)
|
|
||||||
, m_zCapacity(oRhs.m_zCapacity)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
~LSVector()
|
|
||||||
{
|
|
||||||
DELETE_ARRAY(m_pData)
|
|
||||||
}
|
|
||||||
|
|
||||||
T& PushBack(T oNewobj)
|
|
||||||
{
|
|
||||||
return Assign(oNewobj);
|
|
||||||
}
|
|
||||||
|
|
||||||
T& Assign(T oNewobj)
|
|
||||||
{
|
|
||||||
if (m_zSize == m_zCapacity)
|
|
||||||
{
|
|
||||||
m_zCapacity *= c_dCapacityIncreaseFactor;
|
|
||||||
T* pNew = new T[m_zCapacity];
|
|
||||||
memmove(pNew, m_pData, m_zSize);
|
|
||||||
DELETE_ARRAY(m_pData);
|
|
||||||
m_pData = pNew;
|
|
||||||
}
|
|
||||||
m_zSize += 1;
|
|
||||||
m_pData[m_zSize] = oNewobj;
|
|
||||||
return m_pData[m_zSize];
|
|
||||||
}
|
|
||||||
|
|
||||||
T& Insert(T oNewobj, const size_t zPos)
|
|
||||||
{
|
|
||||||
if (zPos == m_zCapacity)
|
|
||||||
{
|
|
||||||
return Assign(oNewobj);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_pData[zPos] = oNewobj;
|
|
||||||
return m_pData[zPos];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PopBack()
|
|
||||||
{
|
|
||||||
Remove(m_zSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Remove(const size_t zPos)
|
|
||||||
{
|
|
||||||
memset(m_pData[zPos], 0, sizeof(T));
|
|
||||||
}
|
|
||||||
|
|
||||||
T& At(const size_t zPos)
|
|
||||||
{
|
|
||||||
return m_pData[zPos];
|
|
||||||
}
|
|
||||||
|
|
||||||
void Reserve(const size_t zNewCapacity)
|
|
||||||
{
|
|
||||||
if (zNewCapacity < m_zCapacity) return;
|
|
||||||
T* pOld = m_pData;
|
|
||||||
m_pData = new T[zNewCapacity];
|
|
||||||
memmove_s(m_pData, zNewCapacity, pOld, m_zSize);
|
|
||||||
m_zCapacity = zNewCapacity;
|
|
||||||
DELETE_ARRAY(pOld);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Clear()
|
|
||||||
{
|
|
||||||
DELETE_ARRAY(m_pData)
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t Size() const
|
|
||||||
{
|
|
||||||
return m_zSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t Capacity() const
|
|
||||||
{
|
|
||||||
return m_zCapacity;
|
|
||||||
}
|
|
||||||
|
|
||||||
T* Data() const
|
|
||||||
{
|
|
||||||
return m_pData;
|
|
||||||
}
|
|
||||||
|
|
||||||
LSVector operator=(const LSVector oRhs)
|
|
||||||
{
|
|
||||||
LSVector vTemp();
|
|
||||||
vTemp.m_pData = oRhs.m_pData;
|
|
||||||
}
|
|
||||||
|
|
||||||
T& operator[](const size_t _Pos)
|
|
||||||
{
|
|
||||||
m_pData + _Pos * sizeof(T);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
std::vector<int> s;
|
|
||||||
T* m_pData = nullptr;
|
|
||||||
size_t m_zSize = 0;
|
|
||||||
size_t m_zCapacity = 0;
|
|
||||||
const float c_dCapacityIncreaseFactor = 1.5;
|
|
||||||
};
|
|
|
@ -1,22 +0,0 @@
|
||||||
#include "Timer.h"
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------------------------------------------------
|
|
||||||
Timer::Timer(LSString sEndString)
|
|
||||||
: m_StartTimePoint(std::chrono::high_resolution_clock::now())
|
|
||||||
{
|
|
||||||
m_sEndString = sEndString;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------------------------------------------------
|
|
||||||
Timer::~Timer()
|
|
||||||
{
|
|
||||||
auto endTimePoint = std::chrono::high_resolution_clock::now();
|
|
||||||
|
|
||||||
auto start = std::chrono::time_point_cast<std::chrono::microseconds>(m_StartTimePoint).time_since_epoch().count();
|
|
||||||
auto end = std::chrono::time_point_cast<std::chrono::microseconds>(endTimePoint).time_since_epoch().count();
|
|
||||||
|
|
||||||
auto duration = end - start;
|
|
||||||
printf("%sMicroseconds: %2d (%.3f ms)\n", m_sEndString.ToCChar(), static_cast<int>(duration), (duration * 0.001));
|
|
||||||
//std::cout << "Duration in Microseconds: " << duration << " (" << duration * 0.001 << " ms)" << std::endl;
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
#pragma once
|
|
||||||
#include "LSFramework.Exports.h"
|
|
||||||
#include "LSString.h"
|
|
||||||
|
|
||||||
#include <chrono>
|
|
||||||
|
|
||||||
class LSFRAMEWORK_API Timer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Timer(LSString sEndString = "");
|
|
||||||
|
|
||||||
~Timer(void);
|
|
||||||
private:
|
|
||||||
LSString m_sEndString;
|
|
||||||
std::chrono::time_point<std::chrono::high_resolution_clock> m_StartTimePoint;
|
|
||||||
};
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include <iostream>
|
/*#include <iostream>
|
||||||
#include "LSString.h"
|
#include "CString.h"
|
||||||
#include "LSList.h"
|
#include "LSList.h"
|
||||||
#include "Timer.h"
|
#include "Timer.h"
|
||||||
|
|
||||||
|
@ -56,9 +56,9 @@ int main()
|
||||||
return i;
|
return i;
|
||||||
|
|
||||||
printf("---LSString---\n");
|
printf("---LSString---\n");
|
||||||
LSString s3;
|
CString s3;
|
||||||
const LSString s1 = "187";
|
const CString s1 = "187";
|
||||||
const LSString s2 = "361";
|
const CString s2 = "361";
|
||||||
|
|
||||||
{
|
{
|
||||||
s3 = s1 + s2;
|
s3 = s1 + s2;
|
||||||
|
@ -75,7 +75,7 @@ int main()
|
||||||
printf("Run: %2d: ", static_cast<int>(zRun));
|
printf("Run: %2d: ", static_cast<int>(zRun));
|
||||||
|
|
||||||
Timer tSingle("Duration in ");
|
Timer tSingle("Duration in ");
|
||||||
LSString s = "12345";
|
CString s = "12345";
|
||||||
|
|
||||||
for (size_t z = 0; z < 187; z++)
|
for (size_t z = 0; z < 187; z++)
|
||||||
{
|
{
|
||||||
|
@ -111,3 +111,4 @@ int main()
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
*/
|
|
@ -16,7 +16,7 @@ set (TSEP_STORAGE_PATH /opt/tsep-storage)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
set (TSEP_PRODUCT_GROUP "Development")
|
set (TSEP_PRODUCT_GROUP "Development")
|
||||||
set (TSEP_PRODUCT_NAME "LSFramework")
|
set (TSEP_PRODUCT_NAME "LSFramework")
|
||||||
set (TSEP_PRODUCT_DESCRIPTION "TSEP Core Framework")
|
set (TSEP_PRODUCT_DESCRIPTION "LSFramework")
|
||||||
set (TSEP_PRODUCT_VERSION "1,5,100")
|
set (TSEP_PRODUCT_VERSION "1,5,100")
|
||||||
set (TSEP_VERSION "1.5.100")
|
set (TSEP_VERSION "1.5.100")
|
||||||
set (TSEP_VERSION_MAJOR 1)
|
set (TSEP_VERSION_MAJOR 1)
|
||||||
|
@ -24,18 +24,13 @@ set (TSEP_VERSION_MINOR 5)
|
||||||
set (TSEP_VERSION_PATCH 100)
|
set (TSEP_VERSION_PATCH 100)
|
||||||
set (TSEP_NEXUS_VERSION "01.05.100")
|
set (TSEP_NEXUS_VERSION "01.05.100")
|
||||||
set (TSEP_UPDATE_IN_NEXUS "true")
|
set (TSEP_UPDATE_IN_NEXUS "true")
|
||||||
set (TSEP_COPYRIGHT_STRING "Copyright Technical Software Engineering Plazotta 2022")
|
set (TSEP_COPYRIGHT_STRING "Copyright Luis Stanglmeier")
|
||||||
set (TSEP_COMPANY_LONGNAME "Technical Software Engineering Plazotta")
|
|
||||||
set (TSEP_NEXUS_URL "https://srv-nexus-3.tsep.local/repository")
|
|
||||||
set (TSEP_NEXUS_GUID "53ec8373-e298-31ed-bd2f-c21204d48a32")
|
|
||||||
#
|
#
|
||||||
#-----------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------
|
||||||
# Define component specific private elements
|
# Define component specific private elements
|
||||||
#
|
#
|
||||||
set (TSEP_PROJECT_CMAKE "${TSEP_STORAGE_PATH}/CMake/CMake.1.5.1")
|
set (TSEP_PROJECT_CMAKE "${TSEP_STORAGE_PATH}/CMake/CMake.1.6.0")
|
||||||
set (TSEP_PROJECT_GOOGLE.TEST "${TSEP_STORAGE_PATH}/Google.Test/Google.Test.1.10.1")
|
set (TSEP_PROJECT_GOOGLE.TEST "${TSEP_STORAGE_PATH}/Google.Test/Google.Test.1.10.1")
|
||||||
set (TSEP_PROJECT_INTIME "${TSEP_STORAGE_PATH}/INtime/INtime.6.4.5")
|
|
||||||
|
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------
|
||||||
# Include the cmake definition for basic compiler and os defines
|
# Include the cmake definition for basic compiler and os defines
|
||||||
|
@ -46,5 +41,5 @@ include(${TSEP_PROJECT_CMAKE}/CMakeCore.cmake)
|
||||||
#-----------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------
|
||||||
# Define component specific public elements
|
# Define component specific public elements
|
||||||
#
|
#
|
||||||
set (TSEP_PROJECT_FRAMEWORK.CORE "${TSEP_STORAGE_PATH}/Framework.Core/Framework.Core.1.5.100/bin/${TSEP_CMAKE_GENERATOR}/cmake")
|
#set (TSEP_PROJECT_FRAMEWORK.CORE "${TSEP_STORAGE_PATH}/Framework.Core/Framework.Core.1.5.100/bin/${TSEP_CMAKE_GENERATOR}/cmake")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue