Skip to content

Commit

Permalink
224 option parser (#225)
Browse files Browse the repository at this point in the history
* Implemented option parser, documented codes. Fixed important bug in the string.
  • Loading branch information
aregtech authored Aug 17, 2023
1 parent 020516b commit db6019f
Show file tree
Hide file tree
Showing 23 changed files with 1,790 additions and 35 deletions.
3 changes: 3 additions & 0 deletions areg-sdk.sln
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,9 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest_main", "thirdparty\gtest_main.vcxproj", "{11927EA9-1F1B-497D-8251-0C1EC93A770E}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "areg-unit-tests", "tests\areg-unit-tests.vcxproj", "{E8BD18E5-EF07-42A0-BB98-461F3D9BCDE1}"
ProjectSection(ProjectDependencies) = postProject
{A3E5EE71-6F14-43FD-A80F-C7791FD64E9E} = {A3E5EE71-6F14-43FD-A80F-C7791FD64E9E}
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "res", "res", "{C485A89F-A149-4893-A023-253593403974}"
ProjectSection(SolutionItems) = preProject
Expand Down
2 changes: 1 addition & 1 deletion conf/cmake/user.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ endif()

# Set build configuration. Set "Debug" for debug build, and "Release" for release build.
if (NOT DEFINED AREG_BUILD_TYPE OR NOT ${AREG_BUILD_TYPE} STREQUAL "Debug")
set(AREG_BUILD_TYPE "Debug")
set(AREG_BUILD_TYPE "Release")
endif()

# Set the AREG binary library type to compile. Set "shared" if not "static"
Expand Down
3 changes: 0 additions & 3 deletions framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,3 @@ if("${AREG_DEVELOP_ENV}" STREQUAL "Win32")
POST_BUILD
COMMAND cmd /c "${logger_RESOURCE}/logger_post_build.bat" "${logger_RESOURCE}" "${AREG_OUTPUT_BIN}")
endif()

# add_custom_command(TARGET areg POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${AREG_BASE}/areg/resources/log.ini ${AREG_OUTPUT_BIN}/config/log.ini)
# add_custom_command(TARGET areg POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${AREG_BASE}/areg/resources/router.ini ${AREG_OUTPUT_BIN}/config/router.ini)
4 changes: 3 additions & 1 deletion framework/areg-extensions.vcxproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" Condition="'$(AregSdkRoot)'==''">
<Import Project="$(SolutionDir)\msvc_setup.props"/>
<Import Project="$(SolutionDir)\msvc_setup.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(AregSdkRoot)\conf\msvc\compile.props" Label="LocalAppCompileSettings" />
Expand Down Expand Up @@ -42,9 +42,11 @@
<ClCompile Include="extensions\console\private\Console.cpp" />
<ClCompile Include="extensions\console\private\ansi\ConsoleAnsi.cpp" />
<ClCompile Include="extensions\console\private\ncurses\ConsoleNcurses.cpp" />
<ClCompile Include="extensions\console\private\OptionParser.cpp" />
<ClCompile Include="extensions\console\private\win32\ConsoleWin32.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="extensions\console\OptionParser.hpp" />
<ClInclude Include="extensions\Extensions.hpp" />
<ClInclude Include="extensions\console\Console.hpp" />
</ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions framework/areg-extensions.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<ClCompile Include="extensions\console\private\win32\ConsoleWin32.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="extensions\console\private\OptionParser.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="extensions\Extensions.hpp">
Expand All @@ -35,6 +38,9 @@
<ClInclude Include="extensions\console\Console.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="extensions\console\OptionParser.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Text Include="extensions\CMakeLists.txt" />
Expand Down
2 changes: 1 addition & 1 deletion framework/areg/base/NECommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ namespace NECommon
* \brief NECommon::ARRAY_DEFAULT_CAPACITY
* The default capacity of the array.
**/
constexpr unsigned int ARRAY_DEFAULT_CAPACITY { static_cast<unsigned int>(2048) };
constexpr unsigned int ARRAY_DEFAULT_CAPACITY { static_cast<unsigned int>(64) };

/**
* \brief NECommon::RING_START_POSITION
Expand Down
83 changes: 80 additions & 3 deletions framework/areg/base/TEArrayList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,20 @@ class TEArrayList : private Constless<std::vector<VALUE>>
* \brief Copies entries from given source.
* \param src The source to copy data.
**/
TEArrayList( const TEArrayList< VALUE > & src ) = default;
TEArrayList( const TEArrayList< VALUE > & src );
TEArrayList( const std::vector< VALUE > & src );

/**
* \brief Moves entries from given source.
* \param src The source to move data.
**/
TEArrayList( TEArrayList< VALUE > && src ) noexcept = default;
TEArrayList( TEArrayList< VALUE > && src ) noexcept;
TEArrayList( std::vector< VALUE > && src ) noexcept;

/**
* \brief Destructor.
**/
~TEArrayList( void ) = default;
~TEArrayList( void );

//////////////////////////////////////////////////////////////////////////
// Operators
Expand Down Expand Up @@ -373,6 +375,20 @@ class TEArrayList : private Constless<std::vector<VALUE>>
**/
void shift( uint32_t startAt, int count);

/**
* \brief Return the fist entry in the array. The array must not be empty.
* Otherwise, it fails with the assertion.
**/
inline const VALUE & firstEntry( void ) const;
inline VALUE & firstEntry( void );

/**
* \brief Return the last entry in the array. The array must not be empty.
* Otherwise, it fails with the assertion.
**/
inline const VALUE & lastEntry( void ) const;
inline VALUE & lastEntry( void );

//////////////////////////////////////////////////////////////////////////
// Protected operations
//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -436,6 +452,39 @@ TEArrayList< VALUE >::TEArrayList( uint32_t resize /*= 0*/, uint32_t capacity /*
mValueList.resize( resize );
}

template<typename VALUE>
inline TEArrayList<VALUE>::TEArrayList( const TEArrayList<VALUE> & src )
: Constless<std::vector<VALUE>>( )
, mValueList( src.mValueList )
{
}

template<typename VALUE>
inline TEArrayList<VALUE>::TEArrayList( const std::vector<VALUE> & src )
: Constless<std::vector<VALUE>>( )
, mValueList( src )
{
}

template<typename VALUE>
inline TEArrayList<VALUE>::TEArrayList( TEArrayList<VALUE> && src ) noexcept
: Constless<std::vector<VALUE>>( )
, mValueList( std::move(src.mValueList) )
{
}

template<typename VALUE>
inline TEArrayList<VALUE>::TEArrayList( std::vector<VALUE> && src ) noexcept
: Constless<std::vector<VALUE>>( )
, mValueList( std::move( src ) )
{
}

template<typename VALUE>
inline TEArrayList<VALUE>::~TEArrayList( void )
{
}

template<typename VALUE >
inline bool TEArrayList< VALUE >::isEmpty( void ) const
{
Expand Down Expand Up @@ -844,6 +893,34 @@ void TEArrayList< VALUE >::shift(uint32_t startAt, int count)
}
}

template<typename VALUE>
inline const VALUE & TEArrayList<VALUE>::firstEntry( void ) const
{
ASSERT( mValueList.size( ) != 0 );
return mValueList[ 0 ];
}

template<typename VALUE>
inline VALUE & TEArrayList<VALUE>::firstEntry( void )
{
ASSERT( mValueList.size( ) != 0 );
return mValueList[ 0 ];
}

template<typename VALUE>
inline const VALUE & TEArrayList<VALUE>::lastEntry( void ) const
{
ASSERT( mValueList.size( ) != 0 );
return mValueList[ mValueList.size( ) - 1 ];
}

template<typename VALUE>
inline VALUE & TEArrayList<VALUE>::lastEntry( void )
{
ASSERT( mValueList.size( ) != 0 );
return mValueList[ mValueList.size( ) - 1 ];
}

template<typename VALUE >
inline void TEArrayList< VALUE >::setSize(uint32_t elemCount)
{
Expand Down
42 changes: 42 additions & 0 deletions framework/areg/base/TEFixedArray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,20 @@ class TEFixedArray
**/
inline void resize(uint32_t newLength );

/**
* \brief Return the fist entry in the array. The array must not be empty.
* Otherwise, it fails with the assertion.
**/
inline const VALUE & firstEntry( void ) const;
inline VALUE & firstEntry( void );

/**
* \brief Return the last entry in the array. The array must not be empty.
* Otherwise, it fails with the assertion.
**/
inline const VALUE & lastEntry( void ) const;
inline VALUE & lastEntry( void );

//////////////////////////////////////////////////////////////////////////
// Protected member variables
//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -525,6 +539,34 @@ inline void TEFixedArray<VALUE>::resize(uint32_t newLength)
mElemCount = newLength;
}

template<typename VALUE>
inline const VALUE & TEFixedArray<VALUE>::firstEntry( void ) const
{
ASSERT( mElemCount != 0 );
return mValueList[ 0 ];
}

template<typename VALUE>
inline VALUE & TEFixedArray<VALUE>::firstEntry( void )
{
ASSERT( mElemCount != 0 );
return mValueList[ 0 ];
}

template<typename VALUE>
inline const VALUE & TEFixedArray<VALUE>::lastEntry( void ) const
{
ASSERT( mElemCount != 0 );
return mValueList[ mElemCount - 1 ];
}

template<typename VALUE>
inline VALUE & TEFixedArray<VALUE>::lastEntry( void )
{
ASSERT( mElemCount != 0 );
return mValueList[ mElemCount - 1 ];
}

//////////////////////////////////////////////////////////////////////////
// Friend function implementation
//////////////////////////////////////////////////////////////////////////
Expand Down
16 changes: 8 additions & 8 deletions framework/areg/base/TELinkedList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,15 @@ class TELinkedList : private Constless<std::list<VALUE>>
* \brief Returns value of head element in Linked List container.
* On call the Linked List should not be empty, otherwise assertion is raised.
**/
inline const VALUE & getFirstEntry( void ) const;
inline VALUE & getFirstEntry(void);
inline const VALUE & firstEntry( void ) const;
inline VALUE & firstEntry(void);

/**
* \brief Returns value of tail element in Linked List container.
* On call the Linked List should not be empty, otherwise assertion is raised.
**/
inline const VALUE & getLastEntry( void ) const;
inline VALUE & getLastEntry(void);
inline const VALUE & lastEntry( void ) const;
inline VALUE & lastEntry(void);

/**
* \brief Returns the value at the given position of the linked list and on output the value
Expand Down Expand Up @@ -670,28 +670,28 @@ inline void TELinkedList<VALUE>::release(void)
}

template <typename VALUE >
inline const VALUE & TELinkedList<VALUE>::getFirstEntry( void ) const
inline const VALUE & TELinkedList<VALUE>::firstEntry( void ) const
{
ASSERT(mValueList.empty() == false);
return mValueList.front();
}

template <typename VALUE >
inline VALUE& TELinkedList<VALUE>::getFirstEntry(void)
inline VALUE& TELinkedList<VALUE>::firstEntry(void)
{
ASSERT(mValueList.empty() == false);
return mValueList.front();
}

template <typename VALUE >
inline const VALUE & TELinkedList<VALUE>::getLastEntry( void ) const
inline const VALUE & TELinkedList<VALUE>::lastEntry( void ) const
{
ASSERT(mValueList.empty() == false);
return mValueList.back();
}

template <typename VALUE >
inline VALUE& TELinkedList<VALUE>::getLastEntry(void)
inline VALUE& TELinkedList<VALUE>::lastEntry(void)
{
ASSERT(mValueList.empty() == false);
return mValueList.back();
Expand Down
16 changes: 8 additions & 8 deletions framework/areg/base/TESortedLinkedList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,15 @@ class TESortedLinkedList : private Constless<std::list<VALUE>>
* \brief Returns value of head element in Linked List container.
* On call the Linked List should not be empty, otherwise assertion is raised.
**/
inline const VALUE& getFirstEntry(void) const;
inline VALUE& getFirstEntry(void);
inline const VALUE& firstEntry(void) const;
inline VALUE& firstEntry(void);

/**
* \brief Returns value of tail element in Linked List container.
* On call the Linked List should not be empty, otherwise assertion is raised.
**/
inline const VALUE& getLastEntry(void) const;
inline VALUE& getLastEntry(void);
inline const VALUE& lastEntry(void) const;
inline VALUE& lastEntry(void);

/**
* \brief Returns given position value and on exit position of next element in Linked List container.
Expand Down Expand Up @@ -746,28 +746,28 @@ void TESortedLinkedList<VALUE>::release(void)
}

template <typename VALUE >
inline const VALUE& TESortedLinkedList<VALUE>::getFirstEntry(void) const
inline const VALUE& TESortedLinkedList<VALUE>::firstEntry(void) const
{
ASSERT(mValueList.empty() == false);
return mValueList.front();
}

template <typename VALUE >
inline VALUE& TESortedLinkedList<VALUE>::getFirstEntry(void)
inline VALUE& TESortedLinkedList<VALUE>::firstEntry(void)
{
ASSERT(mValueList.empty() == false);
return mValueList.front();
}

template <typename VALUE >
inline const VALUE& TESortedLinkedList<VALUE>::getLastEntry(void) const
inline const VALUE& TESortedLinkedList<VALUE>::lastEntry(void) const
{
ASSERT(mValueList.empty() == false);
return mValueList.back();
}

template <typename VALUE >
inline VALUE& TESortedLinkedList<VALUE>::getLastEntry(void)
inline VALUE& TESortedLinkedList<VALUE>::lastEntry(void)
{
ASSERT(mValueList.empty() == false);
return mValueList.back();
Expand Down
4 changes: 2 additions & 2 deletions framework/areg/base/TEString.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2970,13 +2970,13 @@ inline bool TEString<CharType>::endsWith(const TEString<CharType>& phrase, bool
template<typename CharType>
inline bool TEString<CharType>::endsWith(const std::basic_string<CharType>& phrase, bool isCaseSensitive /*= true*/) const
{
return (phrase.length() <= mData.length() ? startsWith(phrase.c_str(), isCaseSensitive, static_cast<NEString::CharCount>(phrase.length())) : false);
return (phrase.length() <= mData.length() ? endsWith(phrase.c_str(), isCaseSensitive, static_cast<NEString::CharCount>(phrase.length())) : false);
}

template<typename CharType>
inline bool TEString<CharType>::endsWith(const std::basic_string_view<CharType>& phrase, bool isCaseSensitive /*= true*/) const
{
return (phrase.length() <= mData.length() ? startsWith(phrase.data(), isCaseSensitive, static_cast<NEString::CharCount>(phrase.length())) : false);
return (phrase.length() <= mData.length() ? endsWith(phrase.data(), isCaseSensitive, static_cast<NEString::CharCount>(phrase.length())) : false);
}

template<typename CharType>
Expand Down
4 changes: 2 additions & 2 deletions framework/areg/component/private/StubBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ void StubBase::sendUpdateEvent( unsigned int msgId, const EventDataStream & data
StubBase::StubListenerList listeners;
if (findListeners(msgId, listeners) > 0)
{
const ProxyAddress & proxy = listeners.getFirstEntry( ).mProxy;
const ProxyAddress & proxy = listeners.firstEntry( ).mProxy;
TRACE_WARN( "Sends busy message to proxy [ %s ] for the request [ %u ]", ProxyAddress::convAddressToPath( proxy).getString(), msgId);

ResponseEvent* eventElem = createResponseEvent(proxy, msgId, result, data);
Expand All @@ -365,7 +365,7 @@ void StubBase::sendResponseEvent( unsigned int respId, const EventDataStream & d
StubBase::StubListenerList listeners;
if (findListeners(respId, listeners) > 0)
{
ResponseEvent* eventElem = createResponseEvent(listeners.getFirstEntry().mProxy, respId, NEService::eResultType::RequestOK, data);
ResponseEvent* eventElem = createResponseEvent(listeners.firstEntry().mProxy, respId, NEService::eResultType::RequestOK, data);
if (eventElem != nullptr)
{
sendResponseNotification(listeners, *eventElem);
Expand Down
Loading

0 comments on commit db6019f

Please sign in to comment.