Compare commits

..

2 Commits

236 changed files with 12459 additions and 33261 deletions

View File

@ -1,25 +0,0 @@
pipeline:
build-archlinux:
image: heeroyui/droneio-runner/archlinux:latest
group: build
commands:
- ls -l
- pwd
- uname -a
- pip install --user lutin
- pip install --user island
- export PATH=$PATH:~/.local/bin/
- lutin --help
pipeline:
build-ubuntu:
image: heeroyui/droneio-runner/ubuntu:latest
group: build
commands:
- ls -l
- pwd
- uname -a
- pip install --user lutin
- pip install --user island
- export PATH=$PATH:/root/.local/bin/
- lutin -H

235
.prude
View File

@ -1,235 +0,0 @@
# This file is for prude parsing (must start with .prude_* or project file .prude)
# some possibiliries:
# - Check the compleate name with case sensitive [a-zA-Z0-9_] ==> to ignore it. format +ABC_def
# - not case-sensitive separate word camel-case and snake-case (set direct word)
# - with # simple comment
# - start with ! for global parameter
etk
obj
rgb
rgba
+TK_PRINT
+TK_ERROR
+TK_WARNING
+TK_INFO
+TK_DEBUG
+TK_VERBOSE
+TK_CRITICAL
+TK_ASSERT
+TK_HIDDEN
+TK_REG_DEBUG
+TK_REG_DEBUG_2
+TK_REG_DEBUG_3
+TK_CHECK_INOUT
+ELOG_BASE
+TK_TODO
+_obj
+anjdi
+abghjkh
+abgh
+gt
+getURegEx
# Add generic color
+Peru
+peru
+NavajoWhite
+navajowhite
+IndianRed
+indianred
+Gainsboro
+gainsboro
+Darkorange
+darkorange
+Cornsilk
+cornsilk
+AliceBlue
+aliceblue
# color in a description:
+F6780FFF
+FEDCBA98
+rrggbb
+rrggbbaa
+color:aliceBlue
+color:antiqueWhite
+color:aqua
+color:aquamarine
+color:azure
+color:beige
+color:bisque
+color:black
+color:blanchedAlmond
+color:blue
+color:blueViolet
+color:brown
+color:burlyWood
+color:cadetBlue
+color:chartreuse
+color:chocolate
+color:coral
+color:cornflowerBlue
+color:cornsilk
+color:crimson
+color:cyan
+color:darkBlue
+color:darkCyan
+color:darkGoldenRod
+color:darkGray
+color:darkGrey
+color:darkGreen
+color:darkKhaki
+color:darkMagenta
+color:darkOliveGreen
+color:darkorange
+color:darkOrchid
+color:darkRed
+color:darkSalmon
+color:darkSeaGreen
+color:darkSlateBlue
+color:darkSlateGray
+color:darkSlateGrey
+color:darkTurquoise
+color:darkViolet
+color:deepPink
+color:deepSkyBlue
+color:dimGray
+color:dimGrey
+color:dodgerBlue
+color:fireBrick
+color:floralWhite
+color:forestGreen
+color:fuchsia
+color:gainsboro
+color:ghostWhite
+color:gold
+color:goldenRod
+color:gray
+color:grey
+color:green
+color:greenYellow
+color:honeyDew
+color:hotPink
+color:indianRed
+color:indigo
+color:ivory
+color:khaki
+color:lavender
+color:lavenderBlush
+color:lawnGreen
+color:lemonChiffon
+color:lightBlue
+color:lightCoral
+color:lightCyan
+color:lightGoldenRodYellow
+color:lightGray
+color:lightGrey
+color:lightGreen
+color:lightPink
+color:lightSalmon
+color:lightSeaGreen
+color:lightSkyBlue
+color:lightSlateGray
+color:lightSlateGrey
+color:lightSteelBlue
+color:lightYellow
+color:lime
+color:limeGreen
+color:linen
+color:magenta
+color:maroon
+color:mediumAquaMarine
+color:mediumBlue
+color:mediumOrchid
+color:mediumPurple
+color:mediumSeaGreen
+color:mediumSlateBlue
+color:mediumSpringGreen
+color:mediumTurquoise
+color:mediumVioletRed
+color:midnightBlue
+color:mintCream
+color:mistyRose
+color:moccasin
+color:navajoWhite
+color:navy
+color:oldLace
+color:olive
+color:oliveDrab
+color:orange
+color:orangeRed
+color:orchid
+color:paleGoldenRod
+color:paleGreen
+color:paleTurquoise
+color:paleVioletRed
+color:papayaWhip
+color:peachPuff
+color:peru
+color:pink
+color:plum
+color:powderBlue
+color:purple
+color:red
+color:rosyBrown
+color:royalBlue
+color:saddleBrown
+color:salmon
+color:sandyBrown
+color:seaGreen
+color:seaShell
+color:sienna
+color:silver
+color:skyBlue
+color:slateBlue
+color:slateGray
+color:slateGrey
+color:snow
+color:springGreen
+color:steelBlue
+color:tan
+color:teal
+color:thistle
+color:tomato
+color:turquoise
+color:violet
+color:wheat
+color:white
+color:whiteSmoke
+color:yellow
+color:yellowGreen
+parseStringStartWithRGBGen
+parseStringStartWithRGBUnsigned32
+parseStringStartWithRGBUnsigned16
+parseStringStartWithRGBUnsigned8
+navajoWhite
+indianRed
+aliceBlue
# specific regex:
pthese
+string_to_int8_t
+string_to_int16_t
+string_to_int32_t
+string_to_int64_t
+string_to_uint8_t
+string_to_uint16_t
+string_to_uint32_t
+string_to_uint64_t
+string_to_bool
std
+u32char
+BS
+ESC
+stod
+stof
+stoi
+stol
+stold
+stoll
+stoul
+stoull
+tolower
+toupper
+srand
+irand
+frand

View File

@ -1,115 +0,0 @@
+PTHREAD_MUTEX_INITIALIZER
# Thread Management APIs
+pthread_attr_destroy
+pthread_attr_getdetachstate
+pthread_attr_getinheritsched
+pthread_attr_getschedparam
+pthread_attr_init
+pthread_attr_setdetachstate
+pthread_attr_setinheritsched
+pthread_attr_setschedparam
+pthread_clear_exit_np
+pthread_create
+pthread_delay_np
+pthread_detach
+pthread_equal
+pthread_exit
+pthread_extendedjoin_np
+pthread_getconcurrency
+pthread_getpthreadoption_np
+pthread_getschedparam
+pthread_getthreadid_np
+pthread_getunique_np
Thread
+pthread_is_multithreaded_np
+pthread_join
+pthread_join_np
+pthread_once
+pthread_self
+pthread_setconcurrency
+pthread_setpthreadoption_np
+pthread_setschedparam
+sched_yield
# Thread Specific Storage APIs
+pthread_getspecific
+pthread_key_create
+pthread_key_delete
+pthread_setspecific
# Thread Cancelation APIs
+pthread_cancel
+pthread_cleanup_peek_np
+pthread_cleanup_pop
+pthread_cleanup_push
+pthread_getcancelstate_np
+pthread_setcancelstate
+pthread_setcanceltype
+pthread_testcancel
+pthread_test_exit_np
# Mutex Synchronization APIs
+pthread_mutexattr_destroy
+pthread_mutexattr_getkind_np
+pthread_mutexattr_getname_np
+pthread_mutexattr_getpshared
+pthread_mutexattr_gettype
+pthread_mutexattr_init
+pthread_mutexattr_setkind_np
+pthread_mutexattr_setname_np
+pthread_mutexattr_setpshared
+pthread_mutexattr_settype
+pthread_set_mutexattr_default_np
+pthread_mutex_destroy
+pthread_mutex_init
+pthread_mutex_lock
+pthread_mutex_timedlock_np
+pthread_mutex_trylock
+pthread_mutex_unlock
+pthread_lock_global_np
+pthread_unlock_global_np
# Condition Variable Synchronization APIs
+pthread_condattr_destroy
+pthread_condattr_getpshared
+pthread_condattr_init
+pthread_condattr_setpshared
+pthread_cond_broadcast
+pthread_cond_destroy
+pthread_cond_init
+pthread_cond_signal
+pthread_cond_timedwait
+pthread_cond_wait
+pthread_get_expiration_np
# Read/Write Lock Synchronization APIs
+pthread_rwlockattr_destroy
+pthread_rwlockattr_getpshared
+pthread_rwlockattr_init
+pthread_rwlockattr_setpshared
+pthread_rwlock_destroy
+pthread_rwlock_init
+pthread_rwlock_rdlock
+pthread_rwlock_timedrdlock_np
+pthread_rwlock_timedwrlock_np
+pthread_rwlock_tryrdlock
+pthread_rwlock_trywrlock
+pthread_rwlock_unlock
+pthread_rwlock_wrlock
# Signals APIs
+pthread_kill
+pthread_sigmask
+pthread_signal_to_cancel_np
# Unsupported APIs
+pthread_atfork
+pthread_atfork_np
+pthread_attr_getschedpolicy
+pthread_attr_getscope
+pthread_attr_getstackaddr
+pthread_attr_getstacksize
+pthread_attr_setschedpolicy
+pthread_attr_setscope
+pthread_attr_setstackaddr
+pthread_attr_setstacksize
+pthread_mutexattr_getprioceiling
+pthread_mutexattr_getprotocol
+pthread_mutexattr_setprioceiling
+pthread_mutexattr_setprotocol
+pthread_mutex_getprioceiling
+pthread_mutex_setprioceiling

View File

@ -1,8 +1,11 @@
language: cpp
language:
- cpp
#sudo: false
sudo: required
dist: trusty
sudo: false
os:
- linux
- osx
branches:
only:
@ -15,69 +18,36 @@ addons:
- ubuntu-toolchain-r-test
packages:
- g++-4.9
- expect
- binutils-mingw-w64-x86-64 # 64bit MinGW
- gcc-mingw-w64-x86-64
- g++-mingw-w64-x86-64
matrix:
include:
- os: linux
env: CONF=release BUILDER=gcc TARGET=Linux TAG=Linux COMPILATOR_OPTION="--compilator-version=4.9" GCOV=--gcov
compiler: gcc
- os: linux
env: CONF=debug BUILDER=clang TARGET=Linux
compiler: clang
- os: linux
env: CONF=release BUILDER=gcc TARGET=Windows TAG=Mingw
compiler: x86_64-w64-mingw32-gcc
- os: linux
env: CONF=release BUILDER=gcc TARGET=Android TAG=Android DISABLE_PACKAGE=-p
compiler: gcc
- os: osx
env: CONF=release BUILDER=clang TARGET=MacOs TAG=MacOs
compiler: clang
- os: osx
env: CONF=release BUILDER=clang TARGET=IOs TAG=IOs
compiler: clang
install:
- cd ..
- pip install --user lutin
- if [ "$TAG" == "Android" ]; then
git clone --depth 1 --branch master https://github.com/HeeroYui/android-download-tool;
./android-download-tool/dl-android.sh;
fi
- git clone --depth 1 --branch master https://github.com/atria-soft/ci.git
- cd -
env:
- CONF=debug BOARD=Linux BUILDER=clang GCOV=
- CONF=release BOARD=Linux BUILDER=clang GCOV=
- CONF=debug BOARD=Linux BUILDER=gcc GCOV=
- CONF=release BOARD=Linux BUILDER=gcc GCOV=
- CONF=debug BOARD=Linux BUILDER=gcc GCOV=--gcov
before_script:
- cd ..
- git clone https://github.com/atria-soft/elog.git
- git clone https://github.com/atria-soft/ememory.git
- wget http://atria-soft.com/ci/coverage_send.py
- wget http://atria-soft.com/ci/test_send.py
- wget http://atria-soft.com/ci/warning_send.py
- git clone https://github.com/generic-library/gtest-lutin.git --recursive
- git clone https://github.com/generic-library/z-lutin.git --recursive
- pwd
- ls -l
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then
export PATH=$PATH:/Users/travis/Library/Python/2.7/bin/;
fi
- ./ci/build_send.py --tag=$TAG --status=START;
- if [ "$BUILDER" == "gcc" ]; then COMPILATOR_OPTION="--compilator-version=4.9"; else COMPILATOR_OPTION=""; fi
script:
- lutin -w -j4 -C -P -t $TARGET -c $BUILDER $COMPILATOR_OPTION $BUS -m $CONF $GCOV $DISABLE_PACKAGE etk-test; STATUS=$?
- ./ci/build_send.py --tag=$TAG --status="$STATUS";
- lutin -w -j4 -C -P -c $BUILDER $COMPILATOR_OPTION -m $CONF $GCOV -p etk-test
after_script:
- if [ "$GCOV" != "" ]; then
./ci/warning_send.py --find-path ./out/Linux_x86_64/$CONF/build/$BUILDER/etk/;
fi
- ./out/Linux_x86_64/$CONF/staging/$BUILDER/etk-test/etk-test.app/bin/etk-test --etk-log-level=3 | tee out_test.txt
- if [ "$GCOV" != "" ]; then
./ci/test_send.py --file=out_test.txt;
lutin -C -P -t $TARGET -c $BUILDER $COMPILATOR_OPTION $BUS -m $CONF -p etk?gcov;
./ci/coverage_send.py --json=out/Linux_x86_64/$CONF/build/$BUILDER/etk/etk_coverage.json;
fi
- if [ "$GCOV" != "" ]; then python ./warning_send.py --find-path ./out/Linux_x86_64/$CONF/build/$BUILDER/etk/ ; fi
- ./out/Linux_x86_64/$CONF/staging/$BUILDER/etk-test/usr/bin/etk-test -l6 | tee out_test.txt
- if [ "$GCOV" != "" ]; then python ./test_send.py --file=out_test.txt; fi
- if [ "$GCOV" != "" ]; then lutin -C -P -c $BUILDER $COMPILATOR_OPTION -m $CONF -p etk?gcov; fi
- if [ "$GCOV" != "" ]; then python ./coverage_send.py --json=out/Linux_x86_64/$CONF/build/$BUILDER/etk/etk_coverage.json; fi
notifications:
email:

95
CMakeLists.txt Normal file
View File

@ -0,0 +1,95 @@
cmake_minimum_required(VERSION 2.8)
# Declare the project
project(etk CXX)
##
## Include C++ X11 dependency ... (check correct flags)
##
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
endif()
# set output path:
set(LIBRARY_OUTPUT_PATH lib/${CMAKE_BUILD_TYPE})
include_directories(.)
#Create src file list
set(src_files
etk/debugGeneric.cpp
etk/debugGeneric.h
etk/debug.cpp
etk/debug.h
etk/stdTools.cpp
etk/stdTools.h
etk/Stream.cpp
etk/Stream.h
etk/tool.cpp
etk/tool.h
etk/Noise.cpp
etk/Noise.h
etk/Color.cpp
etk/Color.h
etk/math/Matrix4.cpp
etk/math/Matrix4.h
etk/math/Vector2D.cpp
etk/math/Vector2D.h
etk/math/Vector3D.cpp
etk/math/Vector3D.h
etk/math/Vector4D.cpp
etk/math/Vector4D.h
etk/os/FSNode.cpp
etk/os/FSNode.h
etk/os/FSNodeRight.cpp
etk/os/FSNodeRight.h
etk/archive/Archive.cpp
etk/archive/Archive.h
etk/archive/Zip.cpp
etk/archive/Zip.h
etk/os/Mutex.Generic.cpp
etk/os/Mutex.h
etk/os/Semaphore.Generic.cpp
etk/os/Semaphore.h
)
add_definitions( -DDEBUG_LEVEL=3 )
add_definitions( -DDEBUG=1 )
if (APPLE)
add_definitions( -D__TARGET_OS__MacOs )
elseif (UNIX)
add_definitions( -D__TARGET_OS__Linux )
elseif (WIN32)
add_definitions( -D__TARGET_OS__Windows )
endif ()
#Create a static Lib:
add_library(etk STATIC ${src_files} )
include_directories(${zlib_SOURCE_DIR}/contrib/)
include_directories(${linearmath_SOURCE_DIR}/bullet/src/)
target_link_libraries(etk linearmath zlib)
#myModule.add_export_flag_LD("-lpthread")
# display all variable ...
#get_cmake_property(_variableNames VARIABLES)
#foreach (_variableName ${_variableNames})
# message(STATUS "${_variableName}=${${_variableName}}")
#endforeach()

373
LICENSE
View File

@ -1,373 +0,0 @@
Mozilla Public License Version 2.0
==================================
1. Definitions
--------------
1.1. "Contributor"
means each individual or legal entity that creates, contributes to
the creation of, or owns Covered Software.
1.2. "Contributor Version"
means the combination of the Contributions of others (if any) used
by a Contributor and that particular Contributor's Contribution.
1.3. "Contribution"
means Covered Software of a particular Contributor.
1.4. "Covered Software"
means Source Code Form to which the initial Contributor has attached
the notice in Exhibit A, the Executable Form of such Source Code
Form, and Modifications of such Source Code Form, in each case
including portions thereof.
1.5. "Incompatible With Secondary Licenses"
means
(a) that the initial Contributor has attached the notice described
in Exhibit B to the Covered Software; or
(b) that the Covered Software was made available under the terms of
version 1.1 or earlier of the License, but not also under the
terms of a Secondary License.
1.6. "Executable Form"
means any form of the work other than Source Code Form.
1.7. "Larger Work"
means a work that combines Covered Software with other material, in
a separate file or files, that is not Covered Software.
1.8. "License"
means this document.
1.9. "Licensable"
means having the right to grant, to the maximum extent possible,
whether at the time of the initial grant or subsequently, any and
all of the rights conveyed by this License.
1.10. "Modifications"
means any of the following:
(a) any file in Source Code Form that results from an addition to,
deletion from, or modification of the contents of Covered
Software; or
(b) any new file in Source Code Form that contains any Covered
Software.
1.11. "Patent Claims" of a Contributor
means any patent claim(s), including without limitation, method,
process, and apparatus claims, in any patent Licensable by such
Contributor that would be infringed, but for the grant of the
License, by the making, using, selling, offering for sale, having
made, import, or transfer of either its Contributions or its
Contributor Version.
1.12. "Secondary License"
means either the GNU General Public License, Version 2.0, the GNU
Lesser General Public License, Version 2.1, the GNU Affero General
Public License, Version 3.0, or any later versions of those
licenses.
1.13. "Source Code Form"
means the form of the work preferred for making modifications.
1.14. "You" (or "Your")
means an individual or a legal entity exercising rights under this
License. For legal entities, "You" includes any entity that
controls, is controlled by, or is under common control with You. For
purposes of this definition, "control" means (a) the power, direct
or indirect, to cause the direction or management of such entity,
whether by contract or otherwise, or (b) ownership of more than
fifty percent (50%) of the outstanding shares or beneficial
ownership of such entity.
2. License Grants and Conditions
--------------------------------
2.1. Grants
Each Contributor hereby grants You a world-wide, royalty-free,
non-exclusive license:
(a) under intellectual property rights (other than patent or trademark)
Licensable by such Contributor to use, reproduce, make available,
modify, display, perform, distribute, and otherwise exploit its
Contributions, either on an unmodified basis, with Modifications, or
as part of a Larger Work; and
(b) under Patent Claims of such Contributor to make, use, sell, offer
for sale, have made, import, and otherwise transfer either its
Contributions or its Contributor Version.
2.2. Effective Date
The licenses granted in Section 2.1 with respect to any Contribution
become effective for each Contribution on the date the Contributor first
distributes such Contribution.
2.3. Limitations on Grant Scope
The licenses granted in this Section 2 are the only rights granted under
this License. No additional rights or licenses will be implied from the
distribution or licensing of Covered Software under this License.
Notwithstanding Section 2.1(b) above, no patent license is granted by a
Contributor:
(a) for any code that a Contributor has removed from Covered Software;
or
(b) for infringements caused by: (i) Your and any other third party's
modifications of Covered Software, or (ii) the combination of its
Contributions with other software (except as part of its Contributor
Version); or
(c) under Patent Claims infringed by Covered Software in the absence of
its Contributions.
This License does not grant any rights in the trademarks, service marks,
or logos of any Contributor (except as may be necessary to comply with
the notice requirements in Section 3.4).
2.4. Subsequent Licenses
No Contributor makes additional grants as a result of Your choice to
distribute the Covered Software under a subsequent version of this
License (see Section 10.2) or under the terms of a Secondary License (if
permitted under the terms of Section 3.3).
2.5. Representation
Each Contributor represents that the Contributor believes its
Contributions are its original creation(s) or it has sufficient rights
to grant the rights to its Contributions conveyed by this License.
2.6. Fair Use
This License is not intended to limit any rights You have under
applicable copyright doctrines of fair use, fair dealing, or other
equivalents.
2.7. Conditions
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
in Section 2.1.
3. Responsibilities
-------------------
3.1. Distribution of Source Form
All distribution of Covered Software in Source Code Form, including any
Modifications that You create or to which You contribute, must be under
the terms of this License. You must inform recipients that the Source
Code Form of the Covered Software is governed by the terms of this
License, and how they can obtain a copy of this License. You may not
attempt to alter or restrict the recipients' rights in the Source Code
Form.
3.2. Distribution of Executable Form
If You distribute Covered Software in Executable Form then:
(a) such Covered Software must also be made available in Source Code
Form, as described in Section 3.1, and You must inform recipients of
the Executable Form how they can obtain a copy of such Source Code
Form by reasonable means in a timely manner, at a charge no more
than the cost of distribution to the recipient; and
(b) You may distribute such Executable Form under the terms of this
License, or sublicense it under different terms, provided that the
license for the Executable Form does not attempt to limit or alter
the recipients' rights in the Source Code Form under this License.
3.3. Distribution of a Larger Work
You may create and distribute a Larger Work under terms of Your choice,
provided that You also comply with the requirements of this License for
the Covered Software. If the Larger Work is a combination of Covered
Software with a work governed by one or more Secondary Licenses, and the
Covered Software is not Incompatible With Secondary Licenses, this
License permits You to additionally distribute such Covered Software
under the terms of such Secondary License(s), so that the recipient of
the Larger Work may, at their option, further distribute the Covered
Software under the terms of either this License or such Secondary
License(s).
3.4. Notices
You may not remove or alter the substance of any license notices
(including copyright notices, patent notices, disclaimers of warranty,
or limitations of liability) contained within the Source Code Form of
the Covered Software, except that You may alter any license notices to
the extent required to remedy known factual inaccuracies.
3.5. Application of Additional Terms
You may choose to offer, and to charge a fee for, warranty, support,
indemnity or liability obligations to one or more recipients of Covered
Software. However, You may do so only on Your own behalf, and not on
behalf of any Contributor. You must make it absolutely clear that any
such warranty, support, indemnity, or liability obligation is offered by
You alone, and You hereby agree to indemnify every Contributor for any
liability incurred by such Contributor as a result of warranty, support,
indemnity or liability terms You offer. You may include additional
disclaimers of warranty and limitations of liability specific to any
jurisdiction.
4. Inability to Comply Due to Statute or Regulation
---------------------------------------------------
If it is impossible for You to comply with any of the terms of this
License with respect to some or all of the Covered Software due to
statute, judicial order, or regulation then You must: (a) comply with
the terms of this License to the maximum extent possible; and (b)
describe the limitations and the code they affect. Such description must
be placed in a text file included with all distributions of the Covered
Software under this License. Except to the extent prohibited by statute
or regulation, such description must be sufficiently detailed for a
recipient of ordinary skill to be able to understand it.
5. Termination
--------------
5.1. The rights granted under this License will terminate automatically
if You fail to comply with any of its terms. However, if You become
compliant, then the rights granted under this License from a particular
Contributor are reinstated (a) provisionally, unless and until such
Contributor explicitly and finally terminates Your grants, and (b) on an
ongoing basis, if such Contributor fails to notify You of the
non-compliance by some reasonable means prior to 60 days after You have
come back into compliance. Moreover, Your grants from a particular
Contributor are reinstated on an ongoing basis if such Contributor
notifies You of the non-compliance by some reasonable means, this is the
first time You have received notice of non-compliance with this License
from such Contributor, and You become compliant prior to 30 days after
Your receipt of the notice.
5.2. If You initiate litigation against any entity by asserting a patent
infringement claim (excluding declaratory judgment actions,
counter-claims, and cross-claims) alleging that a Contributor Version
directly or indirectly infringes any patent, then the rights granted to
You by any and all Contributors for the Covered Software under Section
2.1 of this License shall terminate.
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
end user license agreements (excluding distributors and resellers) which
have been validly granted by You or Your distributors under this License
prior to termination shall survive termination.
************************************************************************
* *
* 6. Disclaimer of Warranty *
* ------------------------- *
* *
* Covered Software is provided under this License on an "as is" *
* basis, without warranty of any kind, either expressed, implied, or *
* statutory, including, without limitation, warranties that the *
* Covered Software is free of defects, merchantable, fit for a *
* particular purpose or non-infringing. The entire risk as to the *
* quality and performance of the Covered Software is with You. *
* Should any Covered Software prove defective in any respect, You *
* (not any Contributor) assume the cost of any necessary servicing, *
* repair, or correction. This disclaimer of warranty constitutes an *
* essential part of this License. No use of any Covered Software is *
* authorized under this License except under this disclaimer. *
* *
************************************************************************
************************************************************************
* *
* 7. Limitation of Liability *
* -------------------------- *
* *
* Under no circumstances and under no legal theory, whether tort *
* (including negligence), contract, or otherwise, shall any *
* Contributor, or anyone who distributes Covered Software as *
* permitted above, be liable to You for any direct, indirect, *
* special, incidental, or consequential damages of any character *
* including, without limitation, damages for lost profits, loss of *
* goodwill, work stoppage, computer failure or malfunction, or any *
* and all other commercial damages or losses, even if such party *
* shall have been informed of the possibility of such damages. This *
* limitation of liability shall not apply to liability for death or *
* personal injury resulting from such party's negligence to the *
* extent applicable law prohibits such limitation. Some *
* jurisdictions do not allow the exclusion or limitation of *
* incidental or consequential damages, so this exclusion and *
* limitation may not apply to You. *
* *
************************************************************************
8. Litigation
-------------
Any litigation relating to this License may be brought only in the
courts of a jurisdiction where the defendant maintains its principal
place of business and such litigation shall be governed by laws of that
jurisdiction, without reference to its conflict-of-law provisions.
Nothing in this Section shall prevent a party's ability to bring
cross-claims or counter-claims.
9. Miscellaneous
----------------
This License represents the complete agreement concerning the subject
matter hereof. If any provision of this License is held to be
unenforceable, such provision shall be reformed only to the extent
necessary to make it enforceable. Any law or regulation which provides
that the language of a contract shall be construed against the drafter
shall not be used to construe this License against a Contributor.
10. Versions of the License
---------------------------
10.1. New Versions
Mozilla Foundation is the license steward. Except as provided in Section
10.3, no one other than the license steward has the right to modify or
publish new versions of this License. Each version will be given a
distinguishing version number.
10.2. Effect of New Versions
You may distribute the Covered Software under the terms of the version
of the License under which You originally received the Covered Software,
or under the terms of any subsequent version published by the license
steward.
10.3. Modified Versions
If you create software not governed by this License, and you want to
create a new license for such software, you may create and use a
modified version of this License if you rename the license and remove
any references to the name of the license steward (except to note that
such modified license differs from this License).
10.4. Distributing Source Code Form that is Incompatible With Secondary
Licenses
If You choose to distribute Source Code Form that is Incompatible With
Secondary Licenses under the terms of this version of the License, the
notice described in Exhibit B of this License must be attached.
Exhibit A - Source Code Form License Notice
-------------------------------------------
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
If it is not possible or desirable to put the notice in a particular
file, then You may include the notice in a location (such as a LICENSE
file in a relevant directory) where a recipient would be likely to look
for such a notice.
You may add additional accurate notices of copyright ownership.
Exhibit B - "Incompatible With Secondary Licenses" Notice
---------------------------------------------------------
This Source Code Form is "Incompatible With Secondary Licenses", as
defined by the Mozilla Public License, v. 2.0.

View File

@ -1,73 +1,30 @@
etk
===
`etk` is a simple basic toolkit to wrap some things (I maybe need not doing it ...)
Release (master)
----------------
`etk` is a simple basic toolkit to wrap some things (I maybe need to not se it ...
[![Build Status](https://travis-ci.org/atria-soft/etk.svg?branch=master)](https://travis-ci.org/atria-soft/etk)
[![Coverage Status](http://atria-soft.com/ci/coverage/atria-soft/etk.svg?branch=master)](http://atria-soft.com/ci/atria-soft/etk)
[![Test Status](http://atria-soft.com/ci/test/atria-soft/etk.svg?branch=master)](http://atria-soft.com/ci/atria-soft/etk)
[![Warning Status](http://atria-soft.com/ci/warning/atria-soft/etk.svg?branch=master)](http://atria-soft.com/ci/atria-soft/etk)
[![Build Status](http://atria-soft.com/ci/build/atria-soft/etk.svg?branch=master&tag=Linux)](http://atria-soft.com/ci/atria-soft/etk)
[![Build Status](http://atria-soft.com/ci/build/atria-soft/etk.svg?branch=master&tag=MacOs)](http://atria-soft.com/ci/atria-soft/etk)
[![Build Status](http://atria-soft.com/ci/build/atria-soft/etk.svg?branch=master&tag=Mingw)](http://atria-soft.com/ci/atria-soft/etk)
[![Build Status](http://atria-soft.com/ci/build/atria-soft/etk.svg?branch=master&tag=Android)](http://atria-soft.com/ci/atria-soft/etk)
[![Build Status](http://atria-soft.com/ci/build/atria-soft/etk.svg?branch=master&tag=IOs)](http://atria-soft.com/ci/atria-soft/etk)
Developement (dev)
------------------
[![Build Status](https://travis-ci.org/atria-soft/etk.svg?branch=dev)](https://travis-ci.org/atria-soft/etk)
[![Coverage Status](http://atria-soft.com/ci/coverage/atria-soft/etk.svg?branch=dev)](http://atria-soft.com/ci/atria-soft/etk)
[![Test Status](http://atria-soft.com/ci/test/atria-soft/etk.svg?branch=dev)](http://atria-soft.com/ci/atria-soft/etk)
[![Warning Status](http://atria-soft.com/ci/warning/atria-soft/etk.svg?branch=dev)](http://atria-soft.com/ci/atria-soft/etk)
[![Build Status](http://atria-soft.com/ci/build/atria-soft/etk.svg?branch=dev&tag=Linux)](http://atria-soft.com/ci/atria-soft/etk)
[![Build Status](http://atria-soft.com/ci/build/atria-soft/etk.svg?branch=dev&tag=MacOs)](http://atria-soft.com/ci/atria-soft/etk)
[![Build Status](http://atria-soft.com/ci/build/atria-soft/etk.svg?branch=dev&tag=Mingw)](http://atria-soft.com/ci/atria-soft/etk)
[![Build Status](http://atria-soft.com/ci/build/atria-soft/etk.svg?branch=dev&tag=Android)](http://atria-soft.com/ci/atria-soft/etk)
[![Build Status](http://atria-soft.com/ci/build/atria-soft/etk.svg?branch=dev&tag=IOs)](http://atria-soft.com/ci/atria-soft/etk)
Instructions
============
download Build system:
----------------------
To compile and use see 'ewol' or 'edn' project
sudo pip install lutin
sudo pip install pillow
download the software:
----------------------
mkdir WORKING_DIRECTORY
cd WORKING_DIRECTORY
git clone https://github.com/atria-soft/etk.git
git clone https://github.com/generic-library/gtest-lutin.git --recursive
git clone https://github.com/generic-library/z-lutin.git --recursive
Compile software:
-----------------
cd WORKING_DIRECTORY
lutin -C -P etk-test
License (MPL v2.0)
License (APACHE v2.0)
=====================
Copyright etk Edouard DUPIN
Licensed under the Mozilla Public License, Version 2.0 (the "License");
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.mozilla.org/MPL/2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,

View File

@ -0,0 +1,144 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#ifdef ETK_BUILD_MINIZIP
#include <etk/archive/Archive.h>
#include <etk/archive/Zip.h>
#include <etk/debug.h>
static const etk::ArchiveContent g_error;
const std::string& etk::Archive::getName(size_t _id) const {
std::unique_lock<std::mutex> lock(m_mutex);
size_t id = 0;
for (auto &it : m_content) {
if (id == _id) {
return it.first;
}
++id;
}
static const std::string error("");
return error;
}
const etk::ArchiveContent& etk::Archive::getContent(size_t _id) const {
std::unique_lock<std::mutex> lock(m_mutex);
size_t id = 0;
for (auto &it : m_content) {
if (id == _id) {
return it.second;
}
++id;
}
return g_error;
}
const etk::ArchiveContent& etk::Archive::getContent(const std::string& _key) const {
std::unique_lock<std::mutex> lock(m_mutex);
auto it = m_content.find(_key);
if (it == m_content.end()) {
return g_error;
}
return it->second;
}
bool etk::Archive::exist(const std::string& _key) const {
std::unique_lock<std::mutex> lock(m_mutex);
return m_content.find(_key) != m_content.end();
}
void etk::Archive::display() {
std::unique_lock<std::mutex> lock(m_mutex);
for (auto &it : m_content) {
int32_t size = it.second.getTheoricSize();
int32_t sizeR = it.second.size();
TK_INFO(" element : " << it.first << " size=" << size << " allocated=" << sizeR);
}
}
etk::Archive* etk::Archive::load(const std::string& _fileName) {
etk::Archive* output=nullptr;
std::string tmpName = etk::tolower(_fileName);
// select the corect Loader :
if( true == end_with(tmpName, ".zip")
|| true == end_with(tmpName, ".apk") ) {
output = new etk::archive::Zip(_fileName);
if (nullptr==output) {
TK_ERROR("An error occured when load archive : " << _fileName);
}
} else {
TK_ERROR("Extention not managed " << _fileName << " Sopported extention : .zip");
}
return output;
}
etk::Archive* etk::Archive::loadPackage(const std::string& _fileName) {
etk::Archive* output=nullptr;
FILE* file = fopen(_fileName.c_str(), "rb");
if (file == nullptr) {
TK_ERROR("Can not open file : '" << _fileName);
return nullptr;
}
// move to end - 16 bytes:
fseek(file, -8, SEEK_END);
// get the basic binary size
uint64_t position = 0;
fread(&position, 1, sizeof(uint64_t), file);
TK_ERROR("position = " << position);
// move to the position
fseek(file, position, SEEK_SET);
char plop[1024];
fread(plop, 1, 16, file);
plop[16] = '\0';
// check if we have the mark: "***START DATA***" ==> if not ==> error
if (std::string(plop) != "***START DATA***") {
TK_ERROR("Error in the tag file : '" << plop << "'");
fclose(file);
return nullptr;
}
fclose(file);
file = nullptr;
output = new etk::archive::Zip(_fileName, position);
if (nullptr==output) {
TK_ERROR("An error occured when load archive : " << _fileName);
}
return output;
}
void etk::Archive::open(const std::string& _key) {
std::unique_lock<std::mutex> lock(m_mutex);
auto it = m_content.find(_key);
if (it == m_content.end()) {
TK_ERROR("Try open an unexistant file : '" << _key << "'");
return;
}
if (it->second.getNumberOfRef()==-1) {
loadFile(it);
it->second.increaseRef();
}
it->second.increaseRef();
}
void etk::Archive::close(const std::string& _key) {
std::unique_lock<std::mutex> lock(m_mutex);
auto it = m_content.find(_key);
if (it == m_content.end()) {
TK_ERROR("Try close an unexistant file : '" << _key << "'");
return;
}
if (it->second.getNumberOfRef()==0){
TK_ERROR("Try close one more time the file : '" << _key << "'");
} else {
it->second.decreaseRef();
}
}
#endif

View File

@ -0,0 +1,152 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#ifdef ETK_BUILD_MINIZIP
#include <etk/types.h>
#ifndef __ETK_ARCHIVE_H__
#define __ETK_ARCHIVE_H__
#include <map>
#include <mutex>
#include <memory>
namespace etk {
class ArchiveContent {
private:
int32_t m_link; //!< number of element open on this file
public:
void increaseRef() {
m_link++;
};
void decreaseRef() {
m_link--;
};
int32_t getNumberOfRef() const {
return m_link;
};
private:
int32_t m_theoricSize; //!< number of element open on this file
public:
int32_t getTheoricSize() const {
return m_theoricSize;
};
private:
std::vector<char> m_data;
public:
ArchiveContent(int32_t _basicSize=0) :
m_link(-1),
m_theoricSize(_basicSize) { };
int32_t size() const {
return m_data.size();
};
void* data() const {
return (void*)&m_data[0];
};
std::vector<char>& getDataVector() {
return m_data;
};
};
class Archive {
private:
mutable std::mutex m_mutex;
public:
Archive(const std::string& _fileName) :
m_fileName(_fileName) {
};
virtual ~Archive() { };
protected:
std::string m_fileName; //!< File name when it came from an file
public:
/**
* @brief Get the current file name.
* @return the requested file name.
*/
const std::string& getFileName() {
return m_fileName;
};
protected:
std::map<std::string, ArchiveContent> m_content;
public:
/**
* @brief Get the number of elements
* @return nb files in the archive
*/
int32_t size() const {
return m_content.size();
};
/**
* @brief Get the File name of the ID
* @param[in] _id id of the element (must be < Size())
* @return FileName of the requested id
*/
const std::string& getName(size_t _id) const;
/**
* @brief Get the File name of the ID
* @param[in] _id id of the element (must be < Size())
* @return the archive content
*/
const ArchiveContent& getContent(size_t _id) const;
/**
* @brief Get the File name of the ID
* @param[in] _key name of the file
* @return FileName of the requested id
*/
const ArchiveContent& getContent(const std::string& _key) const;
/**
* @brief Check if a file exist
* @param[in] _key Name of the file
* @return true if the file is present
*/
bool exist(const std::string& _key) const;
/**
* @brief Load the specific file in the memory
* @param[in] _key Name of the file
*/
void open(const std::string& _key);
/**
* @brief Un-Load the specific file from the memory
* @param[in] _key Name of the file
*/
void close(const std::string& _key);
/**
* @brief Display all Element in the archive
*/
void display();
protected:
/**
* @brief Request the load in memory of the concerned file.
* @param[in] _id Id of the file to load.
*/
virtual void loadFile(const std::map<std::string, ArchiveContent>::iterator& it) { };
public:
/**
* @brief Load an Achive with a specific name.
* @param[in] _fileName File name of the specific archive.
* @return A pointer an the specified archive, the user might delete it.
*/
static Archive* load(const std::string& _fileName);
/**
* @brief Load an Achive with a specific name in package mode ==> this mean the data is associated with the basic binary.
* @param[in] _fileName File name of the specific archive.
* @return A pointer an the specified archive, the user might delete it.
*/
static Archive* loadPackage(const std::string& _fileName);
/**
* @brief Create an Achive with a specific name.
* @param[in] _fileName File name of the specific archive.
* @return A pointer an the specified archive. it is empty due to the fact of create a new archive file.
*/
//Archive* create(const std::u32string& _fileName);
};
};
#endif
#endif

113
archive/etk-archive/Zip.cpp Normal file
View File

@ -0,0 +1,113 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#ifdef ETK_BUILD_MINIZIP
#include <etk/archive/Zip.h>
#include <etk/types.h>
etk::archive::Zip::Zip(const std::string& _fileName, uint64_t _offset) :
etk::Archive(_fileName),
m_ctx(nullptr) {
/* Open the zip file */
m_ctx = unzOpenOffset(m_fileName.c_str(), _offset);
if(!m_ctx) {
TK_ERROR("Unable to open the zip file '" << m_fileName << "'");
return;
}
/* Get info about the zip file */
if(unzGetGlobalInfo(m_ctx, &m_info) != UNZ_OK) {
TK_ERROR("Unable to read the global info related to the '" << m_fileName << "' zip file");
return;
}
// Store all the file in the standard structure
for(uint32_t iii=0; iii<m_info.number_entry; iii++) {
char tmpFileName[FILENAME_MAX];
unz_file_info tmpFileInfo;
/* Get info about current file. */
if(unzGetCurrentFileInfo(m_ctx, &tmpFileInfo, tmpFileName, FILENAME_MAX, NULL, 0, NULL, 0) != UNZ_OK) {
TK_ERROR("Could not read file info from the zip file '" << m_fileName << "'");
return;
}
if(tmpFileName[strlen(tmpFileName) - 1] == '/' ) {
// find directory ...
} else {
m_content.insert(std::pair<std::string, etk::ArchiveContent>(tmpFileName, etk::ArchiveContent(tmpFileInfo.uncompressed_size)));
}
/* Go the the next entry listed in the zip file. */
if((iii+1) < m_info.number_entry) {
if (unzGoToNextFile(m_ctx) != UNZ_OK) {
TK_ERROR("Could not read next file from the zip file '" << m_fileName << "'");
return;
}
}
}
}
etk::archive::Zip::~Zip() {
if (m_ctx!= NULL) {
unzClose(m_ctx);
m_ctx = NULL;
};
}
void etk::archive::Zip::loadFile(const std::map<std::string, ArchiveContent>::iterator& it) {
TK_VERBOSE("Real load file : '" << it->first << "'");
unzGoToFirstFile(m_ctx);
// Store all the file in the standard structure
for(uint32_t iii=0; iii<m_info.number_entry; iii++) {
char tmpFileName[FILENAME_MAX];
unz_file_info tmpFileInfo;
/* Get info about current file. */
if(unzGetCurrentFileInfo(m_ctx, &tmpFileInfo, tmpFileName, FILENAME_MAX, NULL, 0, NULL, 0) != UNZ_OK) {
TK_ERROR("Could not read file info from the zip file '" << m_fileName << "'");
return;
}
if (it->first == tmpFileName ) {
// Entry is a file, so extract it.
if(unzOpenCurrentFile(m_ctx) != UNZ_OK) {
TK_ERROR("Could not open file '" << it->first << "' into the zip file '" << m_fileName << "'");
return;
}
int error = UNZ_OK;
// request the resize of the data :
it->second.getDataVector().resize(it->second.getTheoricSize(), 0);
void* data = it->second.data();
if(NULL == data) {
TK_ERROR("Allocation error...");
return;
}
/* read the file */
do {
error = unzReadCurrentFile(m_ctx, data, it->second.getTheoricSize());
if ( error < 0 ) {
TK_ERROR("Could not read file '" << tmpFileName << "' into the zip file '" << m_fileName << "': " << error);
unzCloseCurrentFile(m_ctx);
return;
}
} while ( error > 0 );
//((char*)data)[m_content.GetValue(_id).GetTheoricSize()] = '\0';
// stop searching here
unzCloseCurrentFile(m_ctx);
return;
}
unzCloseCurrentFile(m_ctx);
/* Go the the next entry listed in the zip file. */
if((iii+1) < m_info.number_entry) {
if (unzGoToNextFile(m_ctx) != UNZ_OK) {
TK_ERROR("Could not read next file from the zip file '" << m_fileName << "'");
return;
}
}
}
}
#endif

35
archive/etk-archive/Zip.h Normal file
View File

@ -0,0 +1,35 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#ifndef __ETK_ARCHIVE_ZIP_H__
#define __ETK_ARCHIVE_ZIP_H__
#include <etk/archive/Archive.h>
#ifdef ETK_BUILD_MINIZIP
extern "C" {
#include <minizip/unzip.h>
}
namespace etk {
namespace archive {
class Zip : public etk::Archive {
private:
unzFile m_ctx; //!< mini zip context
unz_global_info m_info; //!< global information of the Zip
public:
Zip(const std::string& _fileName, uint64_t _offset = 0LL);
virtual ~Zip();
protected: // herited functions :
virtual void loadFile(const std::map<std::string, ArchiveContent>::iterator& it);
};
};
};
#endif
#endif

View File

@ -0,0 +1,27 @@
#!/usr/bin/python
import lutin.module as module
import lutin.tools as tools
def get_desc():
return "Zip file access"
def get_license():
return "APACHE v2.0"
def create(target):
# module name is 'edn' and type binary.
myModule = module.Module(__file__, 'etk-archive', 'LIBRARY')
# add extra compilation flags :
myModule.add_extra_compile_flags()
# add the file to compile:
myModule.add_src_file([
'etk-archive/Archive.cpp',
'etk-archive/Zip.cpp'
])
myModule.add_module_depend(["etk-base"])
myModule.add_optionnal_module_depend('minizip', ["c++", "-DETK_BUILD_MINIZIP"])
myModule.add_export_path(tools.get_current_path(__file__))
return myModule

View File

@ -1 +0,0 @@
MR Edouard DUPIN <yui.heero@gmail.com>

View File

@ -1,16 +1,19 @@
/** @file
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*
* @license APACHE v2.0 (see license file)
*/
#include <etk/types.hpp>
#include <etk/types.h>
#pragma once
#ifndef __ETK_MESSAGE_FIFO_H__
#define __ETK_MESSAGE_FIFO_H__
#include <ethread/Mutex.hpp>
#include <ethread/Semaphore.hpp>
#include <etk/Vector.hpp>
#include <mutex>
#include <vector>
#include <condition_variable>
namespace etk {
/**
@ -20,9 +23,9 @@ namespace etk {
*/
template<class MY_TYPE=int32_t> class Fifo {
private :
ethread::Mutex m_mutex; //!< protection of the internal data.
ethread::Semaphore m_semaphore; //!< protection of the internal data.
etk::Vector<MY_TYPE> m_data; //!< List of all message to send
std::mutex m_mutex; //!< protection of the internal data.
std::condition_variable m_condition; //!< Message system to send event on an other thread.
std::vector<MY_TYPE> m_data; //!< List of all message to send
public :
/**
* @brief Create a fifo with no message.
@ -43,15 +46,15 @@ namespace etk {
* @return false No data found or closed fifo
*/
bool wait(MY_TYPE &_data) {
std::unique_lock<std::mutex> lock(m_mutex);
// Check if data is not previously here
while(m_data.size() == 0) {
m_semaphore.wait();
while(0==m_data.size()) {
m_condition.wait(lock);
}
ethread::UniqueLock lock(m_mutex);
// End Waiting message :
if (m_data.size() > 0) {
if (0<m_data.size()) {
// copy element :
etk::swap(_data, m_data[0]);
_data = m_data[0];
// remove element :
m_data.erase(m_data.begin());
return true;
@ -66,17 +69,17 @@ namespace etk {
* @return false No message found while time-out appear.
*/
bool wait(MY_TYPE &_data, uint32_t _timeOutInUs) {
std::unique_lock<std::mutex> lock(m_mutex);
// Check if data is not previously here
while(m_data.size() == 0) {
if (m_semaphore.wait(_timeOutInUs) == false) {
while(0==m_data.size()) {
if (m_condition.wait_for(lock, std::chrono::microseconds(_timeOutInUs)) == std::cv_status::timeout) {
return false;
}
}
ethread::UniqueLock lock(m_mutex);
// End Waiting message :
if (m_data.size() > 0) {
if (0<m_data.size()) {
// copy element :
etk::swap(_data, m_data[0]);
_data = m_data[0];
// remove element :
m_data.erase(0);
return true;
@ -88,7 +91,7 @@ namespace etk {
* @return Number of message in the fifo.
*/
int32_t count() {
ethread::UniqueLock lock(m_mutex);
std::unique_lock<std::mutex> lock(m_mutex);
int32_t nbElement = m_data.size();
return nbElement;
};
@ -97,29 +100,26 @@ namespace etk {
* @param[in] _data New data to add at the fifo.
*/
void post(MY_TYPE &_data) {
ethread::UniqueLock lock(m_mutex);
m_data.pushBack(_data);
m_semaphore.post();
std::unique_lock<std::mutex> lock(m_mutex);
m_data.push_back(_data);
m_condition.notify_all();
};
/**
* @brief Send a message at the other thread by setting a new message in the fifo.
* @param[in] _data New data to add at the fifo.
*/
//! @previous
void post(const MY_TYPE &_data) {
ethread::UniqueLock lock(m_mutex);
m_data.pushBack(_data);
m_semaphore.post();
std::unique_lock<std::mutex> lock(m_mutex);
m_data.push_back(_data);
m_condition.notify_all();
};
/**
* @brief Remove all the message in the fifo.
*/
void clean() {
ethread::UniqueLock lock(m_mutex);
std::unique_lock<std::mutex> lock(m_mutex);
// remove data
m_data.clear();
//m_condition.wait_for(lock, echrono::microseconds(0));
m_semaphore.post();
m_condition.wait_for(lock, std::chrono::microseconds(0));
};
};
}
};
#endif

275
base/etk/Hash.h Normal file
View File

@ -0,0 +1,275 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#include <etk/types.h>
#ifndef __ETK_HACH_H__
#define __ETK_HACH_H__
#undef __class__
#define __class__ "etk::Hash"
namespace etk {
/**
* @brief internel data of the [class[etk::hash]] class, it contain
* the name and the value of the hash vector.
* @not-in-doc
*/
template<class MY_TYPE> class HashData {
public:
std::string m_key; //!< name of the current hash
MY_TYPE m_value; //!< data of the current Hash
/**
* @brief Constructor of the data for hash table.
* @param[in] _key name of the hash table.
* @param[in] _val Value of the hash element.
*/
HashData(const std::string& _key, const MY_TYPE& _val) :
m_key(_key),
m_value(_val) {
// nothing to do ...
}
};
/**
* @brief Hash table tamplate is a simple classical hash interface.
* A hash table is a equivalent of the dictionary in python, this is a
* simple interfaace between a name and a value:
* :** "name" : 19
* :** "name 2" : 99
*
* [note]The name is unique and the value is what you want.[/note]
*
* A simple example of use:
* [code style=c++]
* // Create a integer hash table
* Hash<int> myValue;
* // add some element (note add and set is the same function)
* myValue.add("example", 98837);
* myValue.add("plop", 88);
* // Display an element:
* printf("my value is : %d", myValue["example"]);
* // Change value of an element:
* myValue.set("example", 99);
* // Remove an element:
* myValue.remove("plop");
* //Clean all the table:
* myValue.clear();
* [/code]
*/
template<class MY_TYPE> class Hash {
private:
std::vector<HashData<MY_TYPE>* > m_data; //!< Data of the hash ==> the Hash table is composed of pointer, this permit to have high speed when resize the vestor ...
public:
/**
* @brief Contructor of the Hach table.
* @param[in] _count Number ob basic elent in the vector.
*/
Hash(int32_t _count = 0) :
m_data(_count) {
// nothing to do
}
/**
* @brief Destructor of the Hash table(clear all element in the table)
*/
~Hash() {
clear();
}
/**
* @brief Remove all entry in the Hash table.
* @note It does not delete pointer if your value is a pointer type...
*/
void clear() {
for (size_t iii = 0; iii < m_data.size(); ++iii) {
if (m_data[iii] != NULL) {
delete(m_data[iii]);
m_data[iii]=NULL;
}
}
m_data.clear();
}
/**
* @brief Get a current element ID in the Hash table
* @param[in] _key Name of the hash requested
* @return Id of the element in the table or -1 of it does not existed
*/
int64_t getId(const std::string& _key) const {
for (size_t iii=0; iii<m_data.size(); iii++) {
if (m_data[iii] != NULL) {
//TK_INFO("Compare key : '" << m_data[iii]->m_key << "' with '" << _key << "'" );
if (m_data[iii]->m_key == _key) {
return iii;
}
}
}
//TK_ERROR(" ==> not fund key '" << _key << "'" );
return -1;
}
/**
* @brief Check if an element exist or not
* @param[in] _key Name of the hash requested
* @return true if the element exist
*/
bool exist(const std::string& _name) const {
int64_t elementId = getId(_name);
//TK_INFO(" Exist ? '" << _name << "' id=" << elementId );
if (elementId<0) {
//TK_INFO(" ==> return false" );
return false;
}
//TK_INFO(" ==> return true" );
return true;
}
/**
* @brief Get a current element in the hash table, with his name.
* @param[in] _key Name of the hash requested
* @return Reference on the Element
*/
MY_TYPE& get(const std::string& _key) const {
static MY_TYPE g_error;
int64_t elementId = getId(_key);
if (elementId<0) {
TK_ERROR("try to acces at an unexistant hash element : " << _key);
return g_error;
}
return m_data[elementId]->m_value;
}
/**
* @brief Get an copy Element an a special position
* @param[in] _key Name of the hash requested
* @return An reference on the copy of selected element
*/
MY_TYPE& operator[] (const std::string& _key) {
return get(_key);
}
//! @previous
const MY_TYPE& operator[] (const std::string& _key) const {
return get(_key);
}
/**
* @brief Add an element OR set an element value
* @note add and set is the same function.
* @param[in] _key Name of the value to set in the hash table.
* @param[in] _value Value to set in the hash table.
*/
void add(const std::string& _key, const MY_TYPE& _value) {
int64_t elementId = getId(_key);
if (elementId <0) {
HashData<MY_TYPE>* tmp = new HashData<MY_TYPE>(_key, _value);
if (NULL == tmp) {
TK_ERROR("allocation error in Hash table : '" << _key << "'");
return;
}
m_data.push_back(tmp);
return;
}
m_data[elementId]->m_value = _value;
}
/**
* @previous
*/
void set(const std::string& _key, const MY_TYPE& _value) {
add(_key, _value);
}
/**
* @brief Remove an element in the hash table.
* @param[in] _key Name of the element to remove.
*/
void remove(const std::string& _key) {
int64_t elementId = getId(_key);
if (elementId <0) {
//nothing to do ==> not existed
return;
}
delete(m_data[elementId]);
m_data[elementId] = NULL;
m_data.erase(m_data.begin()+elementId);
}
/**
* @brief Get the number of element in the hash table
* @return number of elements
*/
int32_t size() const {
return m_data.size();
}
/**
* @brief get an element with his id.
* @param[in] _pos Position on the element in the hash table.
* @return requested element at this position.
* @note this is a dangerous use of the hash table. Maybe you will use a simple vector.
*/
MY_TYPE& operator[] (size_t _pos) {
return getValue(_pos);
}
/**
* @previous
*/
const MY_TYPE& operator[] (size_t _pos) const {
return getValue(_pos);
}
/**
* @brief Get the name of the element at a specific position.
* @param[in] _pos Position of the element in the hash table.
* @return name of the element (key).
*/
const std::string& getKey(size_t _pos) const {
// NOTE :Do not change log level, this generate error only in debug mode
#if DEBUG_LEVEL > 2
if(_pos>m_data.size()){
TK_CRITICAL("Access to an unexistant data in hach : " << _pos << "/ " << m_data.size());
}
#endif
return m_data[_pos]->m_key;
}
/**
* @brief Get all the element name (keys).
* @return a vector of all name (key).
*/
std::vector<std::string> getKeys() const {
std::vector<std::string> keys;
for (size_t iii = 0; iii < m_data.size(); ++iii) {
if (m_data[iii] != NULL) {
keys.push_back(m_data[iii]->m_key);
}
}
return keys;
}
/**
* @brief Get a value of the hash table at a specific position.
* @param[in] _posPosition of the element in the hash table.
* @return Value availlable at this position.
*/
const MY_TYPE& getValue(size_t _pos) const {
// NOTE :Do not change log level, this generate error only in debug mode
#if DEBUG_LEVEL > 2
if(_pos>m_data.size()){
TK_CRITICAL("Access to an unexistant data in hach : " << _pos << "/ " << m_data.size());
}
#endif
return m_data[_pos]->m_value;
}
/**
* @previous
*/
MY_TYPE& getValue(size_t _pos) {
// NOTE :Do not change log level, this generate error only in debug mode
#if DEBUG_LEVEL > 2
if(_pos>m_data.size()){
TK_CRITICAL("Access to an unexistant data in hach : " << _pos << "/ " << m_data.size());
}
#endif
return m_data[_pos]->m_value;
}
};
};
#undef __class__
#define __class__ NULL
#endif

View File

@ -1,31 +1,41 @@
/** @file
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*
* @license APACHE v2.0 (see license file)
*/
#include <etk/types.hpp>
#include <etk/debug.hpp>
#include <etk/tool.hpp>
#include <etk/Noise.hpp>
extern "C" {
#include <time.h>
#include <math.h>
#include <stdlib.h>
}
#include <etk/types.h>
#include <etk/debug.h>
#include <etk/tool.h>
#include <etk/Noise.h>
// for the rand ...
#include <time.h>
#include <math.h>
#include <unistd.h>
#include <stdlib.h>
etk::BaseNoise::BaseNoise(const ivec2& _size, float _min, float _max) :
m_data(_size.x()*_size.y()),
m_size(_size) {
etk::BaseNoise::BaseNoise(ivec2 _size, float _min, float _max) :
m_data(_size.x()*_size.y()),
m_size(_size)
{
m_data.resize(_size.x()*_size.y(), 0);
for(int32_t iii=0; iii<m_size.x()*m_size.y(); iii++) {
m_data[iii] = etk::tool::frand(_min, _max);
}
}
float etk::BaseNoise::get(int32_t _x, int32_t _y) const {
// We increment of the size to prevent the <0 result due to the "%" method ...
etk::BaseNoise::~BaseNoise()
{
}
float etk::BaseNoise::get(int32_t _x, int32_t _y) const
{
// We increment of the size to prevent the <0 result due to the "%" methode ...
_x += m_size.x();
_y += m_size.y();
_x %= m_size.x();
@ -33,10 +43,11 @@ float etk::BaseNoise::get(int32_t _x, int32_t _y) const {
return m_data[_x + _y*m_size.x()];
}
float etk::Noise::smoothNoise(float _x, float _y, const etk::BaseNoise& _noise) {
float etk::Noise::smoothNoise(float _x, float _y, const etk::BaseNoise& _noise)
{
//get fractional part of x and y
float fractionX = _x - (int32_t)_x;
float fractionY = _y - (int32_t)_y;
float fractX = _x - (int32_t)_x;
float fractY = _y - (int32_t)_y;
//wrap around
int32_t x1 = (int32_t)_x;
@ -48,16 +59,17 @@ float etk::Noise::smoothNoise(float _x, float _y, const etk::BaseNoise& _noise)
//smooth the noise with bilinear interpolation
float value = 0.0f;
value += fractionX * fractionY * _noise.get(x1,y1);
value += fractionX * (1 - fractionY) * _noise.get(x1,y2);
value += (1 - fractionX) * fractionY * _noise.get(x2,y1);
value += (1 - fractionX) * (1 - fractionY) * _noise.get(x2,y2);
value += fractX * fractY * _noise.get(x1,y1);
value += fractX * (1 - fractY) * _noise.get(x1,y2);
value += (1 - fractX) * fractY * _noise.get(x2,y1);
value += (1 - fractX) * (1 - fractY) * _noise.get(x2,y2);
return value;
}
float etk::Noise::turbulence(float _x, float _y, float _size, const etk::BaseNoise& _noise) {
float etk::Noise::turbulence(float _x, float _y, float _size, const etk::BaseNoise& _noise)
{
float value = 0.0f;
float initialSize = _size;
while(1<=_size) {
@ -68,7 +80,8 @@ float etk::Noise::turbulence(float _x, float _y, float _size, const etk::BaseNoi
// NOTE : with 128 here, we have wood ...
}
float etk::Noise::turbulenceNoSmooth(float _x, float _y, float _size, const etk::BaseNoise& _noise) {
float etk::Noise::turbulenceNoSmooth(float _x, float _y, float _size, const etk::BaseNoise& _noise)
{
float value = 0.0f;
float initialSize = _size;
while(1<=_size) {
@ -80,14 +93,15 @@ float etk::Noise::turbulenceNoSmooth(float _x, float _y, float _size, const etk:
}
etk::Noise::Noise(enum etk::noiseType _type, ivec2 _size, int32_t _depth) :
m_data(_size.x()*_size.y()),
m_size(_size),
m_type(_type) {
etk::Noise::Noise(enum noise _type, ivec2 _size, int32_t _depth) :
m_data(_size.x()*_size.y()),
m_size(_size),
m_type(_type)
{
m_data.resize(_size.x()*_size.y(), 0);
switch(m_type) {
default:
case etk::noiseType_base:
case etk::Noise::NOISE_BASE:
{
etk::BaseNoise myNoise(ivec2(m_size.x()/_depth,m_size.y()/_depth),0.0f,1.0f);
for(int32_t iii=0; iii<m_size.y(); iii++) {
@ -97,7 +111,7 @@ etk::Noise::Noise(enum etk::noiseType _type, ivec2 _size, int32_t _depth) :
}
}
break;
case etk::noiseType_smooth:
case etk::Noise::NOISE_SMOOTH:
{
etk::BaseNoise myNoise(ivec2(m_size.x()/_depth,m_size.y()/_depth),0.0f,1.0f);
for(int32_t iii=0; iii<m_size.y(); iii++) {
@ -107,7 +121,7 @@ etk::Noise::Noise(enum etk::noiseType _type, ivec2 _size, int32_t _depth) :
}
}
break;
case etk::noiseType_turbulence:
case etk::Noise::NOISE_TURBULENCE:
{
etk::BaseNoise myNoise(ivec2(m_size.x()/_depth,m_size.y()/_depth),0.0f,1.0f);
for(int32_t iii=0; iii<m_size.y(); iii++) {
@ -117,7 +131,7 @@ etk::Noise::Noise(enum etk::noiseType _type, ivec2 _size, int32_t _depth) :
}
}
break;
case etk::noiseType_turbulenceNoSmooth:
case etk::Noise::NOISE_TURBULENCE_NO_SMOOTH:
{
etk::BaseNoise myNoise(ivec2(m_size.x()/_depth,m_size.y()/_depth),0.0f,1.0f);
for(int32_t iii=0; iii<m_size.y(); iii++) {
@ -127,22 +141,27 @@ etk::Noise::Noise(enum etk::noiseType _type, ivec2 _size, int32_t _depth) :
}
}
break;
case etk::noiseType_cloud:
case etk::Noise::NOISE_CLOUD:
break;
case etk::noiseType_marble:
case etk::Noise::NOISE_MARBLE:
break;
case etk::noiseType_wood:
case etk::Noise::NOISE_WOOD:
break;
}
}
etk::Noise::~Noise()
{
}
float etk::Noise::get(int32_t _x, int32_t _y) const
{
// We increment of the size to prevent the <0 result due to the "%" method ...
// We increment of the size to prevent the <0 result due to the "%" methode ...
_x += m_size.x();
_y += m_size.y();
_x %= m_size.x();

52
base/etk/Noise.h Normal file
View File

@ -0,0 +1,52 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#include <etk/types.h>
#ifndef __ETK_NOISE_H__
#define __ETK_NOISE_H__
#include <etk/math/Vector2D.h>
namespace etk {
class BaseNoise
{
private:
std::vector<float> m_data;
ivec2 m_size;
public:
BaseNoise(ivec2 _size, float _min, float _max);
~BaseNoise();
float get(int32_t _x, int32_t _y) const;
};
class Noise {
public:
enum noise {
NOISE_BASE,
NOISE_SMOOTH,
NOISE_TURBULENCE,
NOISE_TURBULENCE_NO_SMOOTH,
NOISE_CLOUD,
NOISE_MARBLE,
NOISE_WOOD
};
private:
std::vector<float> m_data;
ivec2 m_size;
enum noise m_type;
float smoothNoise(float _x, float _y, const etk::BaseNoise& _noise);
float turbulence(float _x, float _y, float _size, const etk::BaseNoise& _noise);
float turbulenceNoSmooth(float _x, float _y, float _size, const etk::BaseNoise& _noise);
public:
Noise(enum noise _type, ivec2 _size, int32_t _depth);
~Noise();
float get(int32_t _x, int32_t _y) const;
};
};
#endif

15
base/etk/debug.cpp Normal file
View File

@ -0,0 +1,15 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#include <etk/debug.h>
int32_t etk::getLogId() {
static int32_t g_val = etk::log::registerInstance("etk");
return g_val;
}

View File

@ -1,20 +1,23 @@
/** @file
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*
* @license APACHE v2.0 (see license file)
*/
#include <etk/types.hpp>
#include <etk/types.h>
#pragma once
#ifndef __ETK_DEBUG_H__
#define __ETK_DEBUG_H__
#include <elog/log.hpp>
#include <etk/log.h>
namespace etk {
int32_t getLogId();
};
#define ETK_BASE(info,data) ELOG_BASE(etk::getLogId(),info,data)
#define ETK_BASE(info,data) TK_LOG_BASE(etk::getLogId(),info,data)
#define TK_PRINT(data) ETK_BASE(-1, data)
#define TK_CRITICAL(data) ETK_BASE(1, data)
@ -34,23 +37,13 @@ namespace etk {
#define TK_HIDDEN(data) do { } while(false)
#ifdef DEBUG
#define TK_CHECK_INOUT(condition) \
do { \
if (!(condition)) { \
TK_ERROR("Wrong condition : " #condition); \
} \
} while (0)
#else
#define TK_CHECK_INOUT(condition) do { } while(false)
#endif
#define TK_ASSERT(condition,data) \
#define TK_ASSERT(cond,data) \
do { \
if (!(condition)) { \
if (!(cond)) { \
TK_CRITICAL(data); \
assert(!#condition); \
assert(!#cond); \
} \
} while (0)
#endif

1413
base/etk/stdTools.cpp Normal file

File diff suppressed because it is too large Load Diff

573
base/etk/stdTools.h Normal file
View File

@ -0,0 +1,573 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#ifndef __ETK_STD_TOOLS_H__
#define __ETK_STD_TOOLS_H__
#include <etk/debug.h>
#include <vector>
#include <sstream>
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <etk/chrono.h>
namespace u32char {
extern const char32_t Null; //!< '\0'
extern const char32_t Return; //!< '\n'
extern const char32_t CarrierReturn; //!< '\r' CR
extern const char32_t Tabulation; //!< '\t' TAB
extern const char32_t Suppress; //!< BS (SUPPRESS)
extern const char32_t Delete; //!< DEL
extern const char32_t Space; //!< ' ' SPACE
extern const char32_t Escape; //!< ESC Escape
/**
* @brief check if the current element is white or not : '\t' '\n' '\r' ' '
* @return tue if it is white char
*/
bool isWhiteChar(char32_t _val);
bool isSpecialChar(char32_t _val);
/**
* @brief check if the curent element is number or not
* @return tue if it is a number char
*/
bool isInteger(char32_t _val);
int32_t toInt(char32_t _val);
char32_t changeOrder(char32_t _val);
int8_t convertUtf8(char32_t _val, char _output[5]);
#if __CPP_VERSION__ >= 2011
std::string convertToUtf8(const std::u32string& _input);
#endif
};
namespace utf8 {
/**
* @brief Get the size of an utf8 char with his first char.
* @param[in] _input Char to parse
* @return number of char needed
*/
int8_t theoricLen(const char _input);
/**
* @brief When parsing a string in a reverse mode, we need to know if we get the first char
* @param[in] _input Char to parse.
* @return true if it was the first char.
*/
bool theoricFirst(const char _input);
char32_t convertChar32(const char* _input);
#if __CPP_VERSION__ >= 2011
std::u32string convertUnicode(const std::string& _input);
#endif
class iterator {
private:
char32_t m_value; //!< store vlue to prevent multiple calcule of getting the data
std::string* m_data; //!< Pointer on the current Buffer
int64_t m_current; //!< curent Id in the Buffer
public:
iterator():
m_value(u32char::Null),
m_data(nullptr),
m_current(0) {
// nothing to do ...
};
iterator(std::string& _str) :
m_value(u32char::Null),
m_data(&_str),
m_current(0) {
// nothing to do ...
};
iterator(std::string& _str, const std::string::iterator& _pos) :
m_value(u32char::Null),
m_data(&_str),
m_current(0) {
if (m_data != nullptr) {
m_current = std::distance(m_data->begin(), _pos);
}
};
iterator(std::string& _str, size_t _pos) :
m_value(u32char::Null),
m_data(&_str),
m_current(0) {
if (m_data != nullptr) {
if (_pos > m_data->size()) {
m_current = m_data->size();
} else {
m_current = _pos;
}
}
};
iterator(std::string* _str, const std::string::iterator& _pos) :
m_value(u32char::Null),
m_data(_str),
m_current(0) {
if (m_data != nullptr) {
m_current = std::distance(m_data->begin(), _pos);
}
};
iterator(std::string* _str, size_t _pos) :
m_value(u32char::Null),
m_data(_str),
m_current(0) {
if (m_data != nullptr) {
if (_pos > m_data->size()) {
m_current = m_data->size();
} else {
m_current = _pos;
}
}
};
/**
* @brief Recopy constructor.
* @param[in] _obj The Iterator that might be copy
*/
iterator(const iterator& _obj):
m_value(u32char::Null),
m_data(_obj.m_data),
m_current(_obj.m_current) {
// nothing to do ...
};
/**
* @brief Asignation operator.
* @param[in] _otherIterator The Iterator that might be copy
* @return reference on the curent Iterator
*/
iterator& operator=(const iterator & _obj) {
m_current = _obj.m_current;
m_data = _obj.m_data;
m_value = u32char::Null;
return *this;
};
/**
* @brief Basic destructor
*/
virtual ~iterator() {
m_current = 0;
m_data = nullptr;
m_value = u32char::Null;
};
/**
* @brief basic boolean cast
* @return true if the element is present in buffer
*/
operator size_t () const {
if (m_data == nullptr) {
return 0;
}
if (m_current < 0) {
return 0;
}
if (m_current > (int64_t)m_data->size()) {
return m_data->size();
}
return (size_t)m_current;
};
/**
* @brief Incremental operator
* @return Reference on the current iterator incremented
*/
iterator& operator++ ();
/**
* @brief Decremental operator
* @return Reference on the current iterator decremented
*/
iterator& operator-- ();
/**
* @brief Incremental operator
* @return Reference on a new iterator and increment the other one
*/
iterator operator++ (int32_t) {
iterator it(*this);
++(*this);
return it;
};
/**
* @brief Decremental operator
* @return Reference on a new iterator and decrement the other one
*/
iterator operator-- (int32_t) {
iterator it(*this);
--(*this);
return it;
};
/**
* @brief egality iterator
* @return true if the iterator is identical pos
*/
bool operator== (const iterator& _obj) const {
if ( m_current == _obj.m_current
&& m_data == _obj.m_data) {
return true;
}
return false;
};
/**
* @brief egality iterator
* @return true if the iterator is identical pos
*/
bool operator!= (const iterator& _obj) const {
if ( m_current != _obj.m_current
|| m_data != _obj.m_data) {
return true;
}
return false;
};
/**
* @brief <= iterator
* @return true if the iterator is identical pos
*/
bool operator<= (const iterator& _obj) const {
if (m_data != _obj.m_data) {
return false;
}
if (m_current <= _obj.m_current) {
return true;
}
return false;
};
/**
* @brief >= iterator
* @return true if the iterator is identical pos
*/
bool operator>= (const iterator& _obj) const {
if (m_data != _obj.m_data) {
return false;
}
if (m_current >= _obj.m_current) {
return true;
}
return false;
};
/**
* @brief < iterator
* @return true if the iterator is identical pos
*/
bool operator< (const iterator& _obj) const {
if (m_data != _obj.m_data) {
return false;
}
if (m_current < _obj.m_current) {
return true;
}
return false;
};
/**
* @brief > iterator
* @return true if the iterator is identical pos
*/
bool operator> (const iterator& _obj) const {
if (m_data != _obj.m_data) {
return false;
}
if (m_current > _obj.m_current) {
return true;
}
return false;
};
/**
* @brief Get the value on the current element
* @return The request element value
*/
char32_t operator* ();
/**
* @brief Get the position in the buffer
* @return The requested position.
*/
size_t getPos() const {
if (m_data == nullptr) {
return 0;
}
if (m_current < 0) {
return 0;
}
if (m_current >= (int64_t)m_data->size()) {
return m_data->size()-1;
}
return (size_t)m_current;
};
/**
* @brief move the element position
* @return a new iterator.
*/
iterator operator+ (const int64_t _val) const {
iterator tmpp(*this);
for (int64_t iii=0; iii<_val; ++iii) {
++tmpp;
}
return tmpp;
};
iterator operator+ (const int32_t _val) const {
iterator tmpp(*this);
for (int64_t iii=0; iii<_val; ++iii) {
++tmpp;
}
return tmpp;
};
iterator operator+ (const size_t _val) const {
iterator tmpp(*this);
for (int64_t iii=0; iii<(int64_t)_val; ++iii) {
++tmpp;
}
return tmpp;
};
/**
* @brief move the element position
* @return a new iterator.
*/
iterator operator- (const int64_t _val) const {
iterator tmpp(*this);
for (int64_t iii=0; iii<_val; ++iii) {
--tmpp;
}
return tmpp;
};
iterator operator- (const int32_t _val) const {
iterator tmpp(*this);
for (int64_t iii=0; iii<_val; ++iii) {
--tmpp;
}
return tmpp;
};
iterator operator- (const size_t _val) const {
iterator tmpp(*this);
for (int64_t iii=0; iii<(int64_t)_val; ++iii) {
--tmpp;
}
return tmpp;
};
/*
iterator begin() const {
return iterator(m_data);
}
iterator end() const {
return --iterator(m_data, m_data.end());
}
*/
};
};
namespace std {
#if (defined(__TARGET_OS__MacOs) || defined(__TARGET_OS__Windows))
typedef std::basic_string<char32_t> u32string;
#endif
#if (defined(__TARGET_OS__Android))
//! @previous
std::string to_string(int _val);
//! @previous
std::string to_string(long _val);
//! @previous
std::string to_string(long long _val);
//! @previous
std::string to_string(unsigned _val);
//! @previous
std::string to_string(unsigned long _val);
//! @previous
std::string to_string(unsigned long long _val);
//! @previous
std::string to_string(float _val);
//! @previous
std::string to_string(double _val);
//! @previous
std::string to_string(long double _val);
double stod(const std::string& _str, size_t* _idx = 0);
float stof(const std::string& _str, size_t* _idx = 0);
int stoi(const std::string& _str, size_t* _idx = 0, int _base = 10);
long stol(const std::string& _str, size_t* _idx = 0, int _base = 10);
long double stold(const std::string& _str, size_t* _idx = 0);
long long stoll(const std::string& _str, size_t* _idx = 0, int _base = 10);
unsigned long stoul(const std::string& _str, size_t* _idx = 0, int _base = 10);
unsigned long long stoull(const std::string& _str, size_t* _idx = 0, int _base = 10);
#endif
};
namespace etk {
// these declaration is to prevent some under template declaration of unknown type
template <class TYPE> std::string to_string(const TYPE& _variable);
template <class TYPE> std::string to_string(const std::vector<TYPE>& _list) {
std::string out = "{";
for (size_t iii=0; iii<_list.size(); ++iii) {
if (iii!=0) {
out += ";";
}
out+= etk::to_string(_list[iii]);
}
out += "}";
return out;
}
#if __CPP_VERSION__ >= 2011
template <class TYPE> std::u32string to_u32string(const TYPE& _variable);
#endif
// these declaration is to prevent some under template declaration of unknown type
template <class TYPE> bool from_string(TYPE& _variableRet, const std::string& _value);
#if __CPP_VERSION__ >= 2011
template <class TYPE> bool from_string(TYPE& _variableRet, const std::u32string& _value);
#endif
// TODO : Change this in :
// TODO : template <typename TYPE> TYPE string_to<TYPE>(const std::u32string& _value); ==> check exceptions ...
long double string_to_long_double(const std::string& _str);
#if __CPP_VERSION__ >= 2011
long double string_to_long_double(const std::u32string& _str);
#endif
double string_to_double(const std::string& _str);
#if __CPP_VERSION__ >= 2011
double string_to_double(const std::u32string& _str);
#endif
float string_to_float(const std::string& _str);
#if __CPP_VERSION__ >= 2011
float string_to_float(const std::u32string& _str);
#endif
int8_t string_to_int8_t(const std::string& _str, int _base = 10);
#if __CPP_VERSION__ >= 2011
int8_t string_to_int8_t(const std::u32string& _str, int _base = 10);
#endif
int16_t string_to_int16_t(const std::string& _str, int _base = 10);
#if __CPP_VERSION__ >= 2011
int16_t string_to_int16_t(const std::u32string& _str, int _base = 10);
#endif
int32_t string_to_int32_t(const std::string& _str, int _base = 10);
#if __CPP_VERSION__ >= 2011
int32_t string_to_int32_t(const std::u32string& _str, int _base = 10);
#endif
int64_t string_to_int64_t(const std::string& _str, int _base = 10);
#if __CPP_VERSION__ >= 2011
int64_t string_to_int64_t(const std::u32string& _str, int _base = 10);
#endif
uint8_t string_to_uint8_t(const std::string& _str, int _base = 10);
#if __CPP_VERSION__ >= 2011
uint8_t string_to_uint8_t(const std::u32string& _str, int _base = 10);
#endif
uint16_t string_to_uint16_t(const std::string& _str, int _base = 10);
#if __CPP_VERSION__ >= 2011
uint16_t string_to_uint16_t(const std::u32string& _str, int _base = 10);
#endif
uint32_t string_to_uint32_t(const std::string& _str, int _base = 10);
#if __CPP_VERSION__ >= 2011
uint32_t string_to_uint32_t(const std::u32string& _str, int _base = 10);
#endif
uint64_t string_to_uint64_t(const std::string& _str, int _base = 10);
#if __CPP_VERSION__ >= 2011
uint64_t string_to_uint64_t(const std::u32string& _str, int _base = 10);
#endif
bool string_to_bool(const std::string& _str);
#if __CPP_VERSION__ >= 2011
bool string_to_bool(const std::u32string& _str);
#endif
std::string tolower(std::string _obj);
#if __CPP_VERSION__ >= 2011
//! @previous
std::u32string tolower(std::u32string _obj);
#endif
std::string toupper(std::string _obj);
#if __CPP_VERSION__ >= 2011
//! @previous
std::u32string toupper(std::u32string _obj);
#endif
bool compare_no_case(const std::string& _obj, const std::string& _val);
#if __CPP_VERSION__ >= 2011
//! @previous
bool compare_no_case(const std::u32string& _obj, const std::u32string& _val);
#endif
bool end_with(const std::string& _obj, const std::string& _val, bool _caseSensitive = true);
#if __CPP_VERSION__ >= 2011
//! @previous
bool end_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive = true);
#endif
bool start_with(const std::string& _obj, const std::string& _val, bool _caseSensitive = true);
#if __CPP_VERSION__ >= 2011
//! @previous
bool start_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive = true);
#endif
std::string replace(const std::string& _obj, char _val, char _replace);
#if __CPP_VERSION__ >= 2011
//! @previous
std::u32string replace(const std::u32string& _obj, char32_t _val, char32_t _replace);
#endif
std::string extract_line(const std::string& _obj, int32_t _pos);
#if __CPP_VERSION__ >= 2011
//! @previous
std::u32string extract_line(const std::u32string& _obj, int32_t _pos);
#endif
std::vector<std::string> split(const std::string& _input, char _val);
#if __CPP_VERSION__ >= 2011
//! @previous
std::vector<std::u32string> split(const std::u32string& _input, char32_t _val);
#endif
void sort(std::vector<std::string *>& _list);
#if __CPP_VERSION__ >= 2011
//! @previous
void sort(std::vector<std::u32string *>& _list);
#endif
template<typename T, typename T2> bool isIn(const T& _val, const std::vector<T2>& _list) {
for (size_t iii=0; iii<_list.size(); ++iii) {
if (_list[iii] == _val) {
return true;
}
}
return false;
}
};
namespace std {
template <class TYPE> const TYPE& avg(const TYPE& a, const TYPE& b, const TYPE& c) {
return std::min(std::max(a,b),c);
}
};
namespace std {
std::ostream& operator <<(std::ostream& _os, const std::string& _obj);
std::ostream& operator <<(std::ostream& _os, const std::vector<std::string>& _obj);
#if __CPP_VERSION__ >= 2011
std::ostream& operator <<(std::ostream& _os, const std::u32string& _obj);
std::ostream& operator <<(std::ostream& _os, const std::vector<std::u32string>& _obj);
#endif
std::ostream& operator <<(std::ostream& _os, const std::vector<float>& _obj);
std::ostream& operator <<(std::ostream& _os, const std::vector<double>& _obj);
std::ostream& operator <<(std::ostream& _os, const std::vector<int64_t>& _obj);
std::ostream& operator <<(std::ostream& _os, const std::vector<uint64_t>& _obj);
std::ostream& operator <<(std::ostream& _os, const std::vector<int32_t>& _obj);
std::ostream& operator <<(std::ostream& _os, const std::vector<uint32_t>& _obj);
std::ostream& operator <<(std::ostream& _os, const std::vector<int16_t>& _obj);
std::ostream& operator <<(std::ostream& _os, const std::vector<uint16_t>& _obj);
std::ostream& operator <<(std::ostream& _os, const std::vector<int8_t>& _obj);
std::ostream& operator <<(std::ostream& _os, const std::vector<uint8_t>& _obj);
std::ostream& operator <<(std::ostream& _os, const std11::chrono::system_clock::time_point& _obj);
std::ostream& operator <<(std::ostream& _os, const std11::chrono::steady_clock::time_point& _obj);
};
int32_t strlen(const char32_t * _data);
#if (defined(__TARGET_OS__Windows))
#define M_PI 3.14159265358979323846
#endif
#endif

180
base/etk/thread/tools.cpp Normal file
View File

@ -0,0 +1,180 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#include <etk/debug.h>
#include <etk/thread/tools.h>
#include <etk/mutex.h>
#include <map>
static std11::mutex g_lock;
static std::map<uint32_t, std::string>& getThreadList() {
static std::map<uint32_t, std::string> g_val;
return g_val;
}
static uint32_t getThreadHumanId(std11::thread::id _id) {
uint32_t out = 0;
uint64_t iddd = std11::hash<std11::thread::id>()(_id);
g_lock.lock();
static std::map<uint64_t, uint32_t> g_list;
std::map<uint64_t, uint32_t>::iterator it = g_list.find(iddd);
if (it == g_list.end()) {
// attribute new ID :
static uint32_t tmpId = 0;
g_list.insert(std::pair<uint64_t, uint32_t>(iddd,tmpId));
out = tmpId;
tmpId++;
} else {
out = it->second;
}
g_lock.unlock();
return out;
}
static std::string getThreadName(std11::thread::id _id) {
std::map<uint32_t,std::string>& list = getThreadList();
uint32_t threadID = getThreadHumanId(_id);
std::string out;
g_lock.lock();
std::map<uint32_t,std::string>::iterator it = list.find(threadID);
if (it != list.end()) {
out = it->second;
}
g_lock.unlock();
return out;
}
static void setThreadName(std11::thread* _thread, const std::string& _name) {
std::map<uint32_t,std::string>& list = getThreadList();
uint32_t threadID = etk::thread::getId();
g_lock.lock();
std::map<uint32_t,std::string>::iterator it = list.find(threadID);
if (it == list.end()) {
list.insert(std::pair<uint32_t, std::string>(threadID, _name));
} else {
it->second = _name;
}
g_lock.unlock();
// try now to set the thread name with Pthread
#if defined(__TARGET_OS__Linux)
pthread_t pthreadID;
if (_thread == nullptr) {
pthreadID = pthread_self();
} else {
pthreadID = (pthread_t) _thread->native_handle();
}
std::string name = _name;
if (name.size() > 15) {
name.resize(15);
}
if (pthread_setname_np(pthreadID, name.c_str()) < 0) {
TK_ERROR("Error when setting the Name in the OS thread naming");
}
#else
TK_DEBUG("Can not set the thread name in this OS (local set)");
#endif
}
uint32_t etk::thread::getId() {
return getThreadHumanId(std11::this_thread::get_id());
}
uint32_t etk::thread::getId(std11::thread& _thread) {
return getThreadHumanId(_thread.get_id());
}
void etk::thread::setName(const std::string& _name) {
setThreadName(nullptr, _name);
}
void etk::thread::setName(std11::thread& _thread, const std::string& _name) {
setThreadName(&_thread, _name);
}
std::string etk::thread::getName() {
return getThreadName(std11::this_thread::get_id());
}
std::string etk::thread::getName(std11::thread& _thread) {
return getThreadName(_thread.get_id());
}
#if defined(__TARGET_OS__Linux)
static void setThreadPriority(pthread_t _threadID, int32_t _priority) {
int retcode;
int policy;
struct sched_param param;
retcode = pthread_getschedparam(_threadID, &policy, &param);
if (retcode != 0) {
TK_ERROR("Can not get prioriry " << ((retcode == ESRCH) ? "WRONG THREAD ID (ESRCH)" :"???") );
return;
}
TK_INFO("Try to set the thread proiority at :" << _priority);
policy = SCHED_OTHER;
if (_priority < 0) {
_priority *= -1;
policy = SCHED_FIFO;
}
param.sched_priority = _priority;
retcode = pthread_setschedparam(_threadID, policy, &param);
if (retcode != 0) {
TK_ERROR("Can not set prioriry " << ((retcode == ESRCH) ? "WRONG THREAD ID (ESRCH)" :
(retcode == EINVAL) ? "WRONG POLICY (EINVAL)" :
(retcode == EPERM) ? "NO PRIVILEGE (EPERM)" :
"???") );
}
}
static int32_t getThreadPriority(pthread_t _threadID) {
int retcode;
int policy;
struct sched_param param;
retcode = pthread_getschedparam(_threadID, &policy, &param);
if (retcode != 0) {
TK_ERROR("Can not get prioriry " << ((retcode == ESRCH) ? "WRONG THREAD ID (ESRCH)" : "???") );
return 20;
}
if (policy != SCHED_OTHER) {
return -param.sched_priority;
}
return param.sched_priority;
}
#endif
void etk::thread::setPriority(int32_t _priority) {
#if defined(__TARGET_OS__Linux)
pthread_t threadID = pthread_self();
setThreadPriority(threadID, _priority);
#endif
}
void etk::thread::setPriority(std11::thread& _thread, int32_t _priority) {
#if defined(__TARGET_OS__Linux)
pthread_t threadID = (pthread_t) _thread.native_handle();
setThreadPriority(threadID, _priority);
#endif
}
int32_t etk::thread::getPriority() {
#if defined(__TARGET_OS__Linux)
pthread_t threadID = pthread_self();
return getThreadPriority(threadID);
#else
return 20;
#endif
}
int32_t etk::thread::getPriority(std11::thread& _thread) {
#if defined(__TARGET_OS__Linux)
pthread_t threadID = static_cast<pthread_t>(_thread.native_handle());
return getThreadPriority(threadID);
#else
return 20;
#endif
}

78
base/etk/thread/tools.h Normal file
View File

@ -0,0 +1,78 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#include <etk/types.h>
#ifndef __ETK_THREAD_TOOLS_H__
#define __ETK_THREAD_TOOLS_H__
#include <etk/thread.h>
namespace etk {
namespace thread {
/**
* @brief get human readable thread ID. (not the std::thread::get_id())
* @return the ID of the thread.
*/
uint32_t getId();
/**
* @brief get human readable thread ID. (not the std::thread::get_id())
* @param[in] _thread Thread handle
* @return the ID of the thread.
*/
uint32_t getId(std11::thread& _thread);
/**
* @brief Set the Current thread name
* @param[in] _name New name of the thread
*/
void setName(const std::string& _name);
/**
* @brief Set an other thread name
* @param[in] _thread Thread handle
* @param[in] _name New name of the thread
*/
void setName(std11::thread& _thread, const std::string& _name);
/**
* @brief Set the Current thread name
* @return The current name of the thread
*/
std::string getName();
/**
* @brief Get an other thread name
* @praram[in] _thread Thread handle
* @return The external thread name of the thread
*/
std::string getName(std11::thread& _thread);
/**
* @brief Set the Current thread priority [-20..0] for RT and ]0..50] for normal priority
* @param[in] _priority New priority of the thread
* @note If your process have not the right to change thread name, it does not work
*/
void setPriority(int32_t _priority);
/**
* @brief Set an other thread priority [-20..0] for RT and ]0..50] for normal priority
* @param[in] _thread Thread handle
* @param[in] _priority New priority of the thread
* @note If your process have not the right to change thread name, it does not work
*/
void setPriority(std11::thread& _thread, int32_t _priority);
/**
* @brief get the Current thread priority [-20..0] for RT and ]0..50] for normal priority
* @return current priority of the thread
*/
int32_t getPriority();
/**
* @brief Get an other thread priority [-20..0] for RT and ]0..50] for normal priority
* @param[in] _thread Thread handle
* @return current priority of the thread
*/
int32_t getPriority(std11::thread& _thread);
}
}
#endif

33
base/etk/tool.cpp Normal file
View File

@ -0,0 +1,33 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#include <etk/tool.h>
#include <etk/os/FSNode.h>
// for the rand ...
#include <time.h>
#include <math.h>
#include <unistd.h>
#include <stdlib.h>
double etk::tool::frand(double _a, double _b)
{
return (float)(( (double)rand()/(double)RAND_MAX ) * ((double)_b-(double)_a) + (double)_a);
}
int32_t etk::tool::irand(int32_t _a, int32_t _b)
{
return (int32_t)(( rand()/(double)RAND_MAX ) * ((double)_b-(double)_a) + (double)_a);
}
void etk::tool::resetRandom() {
srand(time(NULL));
}
void etk::tool::randSeek(int32_t _val) {
srand(_val);
}

37
base/etk/tool.h Normal file
View File

@ -0,0 +1,37 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#include <etk/types.h>
#ifndef __ETK_TOOL_H__
#define __ETK_TOOL_H__
namespace etk {
namespace tool {
/**
* @brief Get a random value in a specific range.
* @param[in] _a Lower value of the random.
* @param[in] _b Bigger value of the random.
* @return Random Value between [_a and _b]
*/
double frand(double _a, double _b);
//! @previous
int32_t irand(int32_t _a, int32_t _b);
/**
* @brief Reset the random system with a random value (time).
*/
void resetRandom();
/**
* @brief Reset the random system with The specify value.
* @param[in] _val Seek value for the pseudo random system.
*/
void randSeek(int32_t _val);
};
};
#endif

74
base/etk/types.h Normal file
View File

@ -0,0 +1,74 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#ifndef __ETK_TYPES_H__
#define __ETK_TYPES_H__
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <assert.h>
// defien type : uintXX_t and intXX_t
#define __STDC_LIMIT_MACROS
// note in android include the macro of min max are overwitten
#include <stdint.h>
// in case of android error ...
#ifdef __TARGET_OS__Android
#if __ANDROID_BOARD_ID__ <= 20
#ifndef __STDINT_LIMITS
#define INT8_MIN (-128)
#define INT8_MAX (127)
#define UINT8_MAX (255U)
#define INT16_MIN (-32768)
#define INT16_MAX (32767)
#define UINT16_MAX (65535U)
#define INT32_MIN (-2147483647-1)
#define INT32_MAX (2147483647)
#define UINT32_MAX (4294967295U)
#define INT64_MIN (__INT64_C(-9223372036854775807)-1)
#define INT64_MAX (__INT64_C(9223372036854775807))
#define UINT64_MAX (__UINT64_C(18446744073709551615))
#endif
#endif
#endif
#if __CPP_VERSION__ < 2011
#define nullptr NULL
typedef uint32_t char32_t;
namespace boost {
// just define
}
namespace std11 = boost;
#else
namespace std11 = std;
#endif
#include <etk/stdTools.h>
#ifndef ETK_BUILD_LINEARMATH
typedef float btScalar;
#endif
#ifndef _WIN32
#include <math.h>
#ifndef _MATH_H_MATHDEF
typedef float float_t;
#endif
#endif
#endif

56
base/lutin_etk-base.py Normal file
View File

@ -0,0 +1,56 @@
#!/usr/bin/python
import lutin.module as module
import lutin.tools as tools
def get_desc():
return "etk basis"
def get_license():
return "APACHE v2.0"
def create(target):
myModule = module.Module(__file__, 'etk-base', 'LIBRARY')
myModule.add_extra_compile_flags()
myModule.add_src_file([
'etk/debug.cpp',
'etk/stdTools.cpp',
'etk/tool.cpp',
'etk/Noise.cpp',
'etk/thread/tools.cpp'
])
myModule.add_module_depend(["etk-log"])
if target.config["mode"] == "release":
myModule.compile_flags('c', "-DMODE_RELEASE")
else:
myModule.add_export_flag('c', "-DDEBUG_LEVEL=3")
myModule.add_export_flag('c', "-DDEBUG=1")
# Bor backtrace display :
if target.name != "Windows":
myModule.add_export_flag('link', "-ldl -rdynamic")
# for ald C++ compatibility (old GCC) just link with boost ...
if target.config["compilator"] == "gcc" \
and target.xx_version < 4007000:
# note : this framework depend on C++ 11, but a simple port of Boost for old compatibility has been done ...
myModule.compile_version_XX(1999)
myModule.add_optionnal_module_depend('boost', ["c++", "-DETK_BUILD_BOOST"], export=True)
myModule.add_export_path(tools.get_current_path(__file__) + "/binding_boost")
else:
myModule.compile_version_XX(2011)
# name of the dependency
myModule.add_export_path(tools.get_current_path(__file__) + "/binding_X11")
if target.name=="Windows":
pass
elif target.name=="Android":
pass
else:
myModule.add_export_flag('link', "-lpthread")
myModule.add_export_path(tools.get_current_path(__file__))
return myModule

1
binding_X11/etk/chrono.h Normal file
View File

@ -0,0 +1 @@
#include <chrono>

View File

@ -0,0 +1 @@
#include <condition_variable>

View File

@ -0,0 +1 @@
#include <functional>

1
binding_X11/etk/memory.h Normal file
View File

@ -0,0 +1 @@
#include <memory>

2
binding_X11/etk/mutex.h Normal file
View File

@ -0,0 +1,2 @@
#include <mutex>

1
binding_X11/etk/thread.h Normal file
View File

@ -0,0 +1 @@
#include <thread>

View File

@ -0,0 +1,7 @@
#ifndef __ETK_CHRONO_FROM_BOOST_H__
#define __ETK_CHRONO_FROM_BOOST_H__
#include <boost/chrono.hpp>
#endif

View File

@ -0,0 +1,7 @@
#ifndef __ETK_CONDITION_VARIABLE_FROM_BOOST_H__
#define __ETK_CONDITION_VARIABLE_FROM_BOOST_H__
#include <boost/thread/condition_variable.hpp>
#endif

View File

@ -0,0 +1,23 @@
#ifndef __ETK_FUNCTIONNAL_FROM_BOOST_H__
#define __ETK_FUNCTIONNAL_FROM_BOOST_H__
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/bind/placeholders.hpp>
namespace boost {
namespace placeholders {
static boost::arg<1> _1;
static boost::arg<2> _2;
static boost::arg<3> _3;
static boost::arg<4> _4;
static boost::arg<5> _5;
static boost::arg<6> _6;
static boost::arg<7> _7;
static boost::arg<8> _8;
static boost::arg<9> _9;
}
}
#endif

View File

@ -0,0 +1,11 @@
#ifndef __ETK_MEMORY_FROM_BOOST_H__
#define __ETK_MEMORY_FROM_BOOST_H__
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <boost/make_shared.hpp>
#include <boost/enable_shared_from_this.hpp>
#endif

View File

@ -0,0 +1,8 @@
#ifndef __ETK_MUTEX_FROM_BOOST_H__
#define __ETK_MUTEX_FROM_BOOST_H__
#include <boost/thread/mutex.hpp>
#include <boost/thread/recursive_mutex.hpp>
#endif

View File

@ -0,0 +1,7 @@
#ifndef __ETK_THREAD_FROM_BOOST_H__
#define __ETK_THREAD_FROM_BOOST_H__
#include <boost/thread/thread.hpp>
#endif

80
catkin/CMakeLists.txt Normal file
View File

@ -0,0 +1,80 @@
cmake_minimum_required(VERSION 2.8.3)
project(etk)
set(CMAKE_VERBOSE_MAKEFILE ON)
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin)
###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if you package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
INCLUDE_DIRS ../ ../binding_X11
LIBRARIES ${PROJECT_NAME}
DEPENDS system_lib rosconsole
CFG_EXTRAS ${PROJECT_NAME}-extras.cmake
)
###########
## Build ##
###########
## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
..
../binding_X11
${catkin_INCLUDE_DIRS}
)
## Declare a cpp library
add_library(${PROJECT_NAME}
../${PROJECT_NAME}/debug.cpp
../${PROJECT_NAME}/etk.cpp
../${PROJECT_NAME}/stdTools.cpp
../${PROJECT_NAME}/log.cpp
../${PROJECT_NAME}/tool.cpp
../${PROJECT_NAME}/Noise.cpp
../${PROJECT_NAME}/Color.cpp
../${PROJECT_NAME}/thread/tools.cpp
../${PROJECT_NAME}/math/Matrix4.cpp
../${PROJECT_NAME}/math/Vector2D.cpp
../${PROJECT_NAME}/math/Vector3D.cpp
../${PROJECT_NAME}/math/Vector4D.cpp
../${PROJECT_NAME}/os/FSNode.cpp
../${PROJECT_NAME}/os/FSNodeRight.cpp
../${PROJECT_NAME}/archive/Archive.cpp
../${PROJECT_NAME}/archive/Zip.cpp
)
set(CMAKE_CXX_FLAGS "-std=c++11 -D__CPP_VERSION__=2011 -D__TARGET_OS__Linux -DETK_EXTERN_FRAMEWORK_ROS")
## Specify libraries to link a library or executable target against
target_link_libraries(${PROJECT_NAME}
${catkin_LIBRARIES}
)
#############
## Install ##
#############
## Mark executables and/or libraries for installation
install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
)
## Mark cpp header files for installation
install(DIRECTORY ../${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h"
)

View File

@ -0,0 +1,4 @@
set(CMAKE_CXX_FLAGS "-std=c++11 -D__CPP_VERSION__=2011 -D__TARGET_OS__Linux -DETK_EXTERN_FRAMEWORK_ROS ${CMAKE_CXX_FLAGS}")

11
catkin/package.xml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0"?>
<package>
<name>etk</name>
<version>0.9.1</version>
<description>Ewol Tool kit</description>
<maintainer email="yui.heero@gmail.com">Edouard DUPIN</maintainer>
<license>Apache-2.0</license>
<build_depend>rosconsole</build_depend>
<buildtool_depend>catkin</buildtool_depend>
<run_depend>rosconsole</run_depend>
</package>

View File

@ -1,175 +1,167 @@
/** @file
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*
* @license APACHE v2.0 (see license file)
*/
#include <etk/types.hpp>
#include <etk/tool.hpp>
#include <etk/Color.hpp>
#include <etk/debug.hpp>
#include <etk/stdTools.hpp>
#include <etk/String.hpp>
#include <etk/typeInfo.hpp>
#include <etk/types.h>
#include <etk/tool.h>
#include <etk/Color.h>
#include <etk/debug.h>
#include <etk/stdTools.h>
#include <string>
#include <sstream>
#include <stdexcept>
#undef __class__
#define __class__ "Color"
class ColorList {
public:
const etk::String colorName;
etk::Color<> color;
};
ETK_DECLARE_TYPE(etk::Color<uint8_t,4>);
ETK_DECLARE_TYPE(etk::Color<double,4>);
ETK_DECLARE_TYPE(etk::Color<float,4>);
ETK_DECLARE_TYPE(etk::Color<uint32_t,4>);
ETK_DECLARE_TYPE(etk::Color<uint8_t,3>);
ETK_DECLARE_TYPE(etk::Color<double,3>);
ETK_DECLARE_TYPE(etk::Color<float,3>);
ETK_DECLARE_TYPE(etk::Color<uint32_t,3>);
typedef struct {
const char * colorName;
etk::Color<> color;
} colorList_ts;
static int32_t getColorSize();
static const ColorList* getColorList();
static const colorList_ts* getColorList();
etk::Color<uint8_t, 4> etk::parseStringStartWithSharp(const etk::String& _input) {
etk::Color<uint8_t, 4> etk::parseStringStartWithSharp(const std::string& _input) {
TK_VERBOSE("parseStringStartWithSharp('" << _input << "'");
//elog::displayBacktrace(false, 0);
size_t len = _input.size();
etk::Color<uint8_t, 4> outputValue(0,0,0,0);
if(len == 3) {
uint32_t red=0, green=0, blue=0;
int32_t red=0, green=0, blue=0;
if (sscanf(_input.c_str(), "%1x%1x%1x", &red, &green, &blue) == 3) {
outputValue.setR(red | red << 4);
outputValue.setG(green | green << 4);
outputValue.setB(blue | blue << 4);
outputValue.setA(0xFF);
} else {
TK_ERROR("Error in parsing the color : '" << _input << "'");
TK_ERROR(" pb in parsing the color : '" << _input << "'");
}
} else if (len==4) {
uint32_t red=0, green=0, blue=0, alpha=0;
int32_t red=0, green=0, blue=0, alpha=0;
if (sscanf(_input.c_str(), "%1x%1x%1x%1x", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(red | red << 4);
outputValue.setG(green | green << 4);
outputValue.setB(blue | blue << 4);
outputValue.setA(alpha | alpha << 4);
} else {
TK_ERROR("Error in parsing the color : '" << _input << "'");
TK_ERROR(" pb in parsing the color : '" << _input << "'");
}
} else if (len == 6) {
uint32_t red=0, green=0, blue=0;
int32_t red=0, green=0, blue=0;
if (sscanf(_input.c_str(), "%2x%2x%2x", &red, &green, &blue) == 3) {
outputValue.setR(red);
outputValue.setG(green);
outputValue.setB(blue);
outputValue.setA(0xFF);
} else {
TK_ERROR("Error in parsing the color : '" << _input << "'");
TK_ERROR(" pb in parsing the color : '" << _input << "'");
}
} else if (len == 8) {
uint32_t red=0, green=0, blue=0, alpha=0;
int32_t red=0, green=0, blue=0, alpha=0;
if (sscanf(_input.c_str(), "%2x%2x%2x%2x", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(red);
outputValue.setG(green);
outputValue.setB(blue);
outputValue.setA(alpha);
} else {
TK_ERROR("Error in parsing the color : '" << _input << "'");
TK_ERROR(" pb in parsing the color : '" << _input << "'");
}
} else {
TK_ERROR("Error in parsing the color : '" << _input << "' ==> unknown method ...");
TK_ERROR(" pb in parsing the color : '" << _input << "' ==> unknown methode ...");
}
TK_VERBOSE(" result: '" << outputValue << "'");
return outputValue;
}
etk::Color<uint8_t, 4> etk::parseStringStartWithRGBGen(const etk::String& _input) {
etk::Color<uint8_t, 4> etk::parseStringStartWithRGBGen(const std::string& _input) {
TK_VERBOSE("parseStringStartWithRGB('" << _input << "'");
etk::Color<uint8_t, 4> outputValue(0,0,0,0);
int32_t red=0, green=0, blue=0, alpha=0;
float float_red=0, float_green=0, float_blue=0, float_alpha=0;
float fred=0, fgreen=0, fblue=0, falpha=0;
if (sscanf(_input.c_str(), "%u,%u,%u,%u", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(etk::min(0xFF, red));
outputValue.setG(etk::min(0xFF, green));
outputValue.setB(etk::min(0xFF, blue));
outputValue.setA(etk::min(0xFF, alpha));
outputValue.setR(std::min(0xFF, red));
outputValue.setG(std::min(0xFF, green));
outputValue.setB(std::min(0xFF, blue));
outputValue.setA(std::min(0xFF, alpha));
} else if (sscanf(_input.c_str(), "%u,%u,%u", &red, &green, &blue) == 3) {
outputValue.setR(etk::min(0xFF, red));
outputValue.setG(etk::min(0xFF, green));
outputValue.setB(etk::min(0xFF, blue));
outputValue.setR(std::min(0xFF, red));
outputValue.setG(std::min(0xFF, green));
outputValue.setB(std::min(0xFF, blue));
} else if (sscanf(_input.c_str(), "%X,%X,%X,%X", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(etk::min(0xFF, red));
outputValue.setG(etk::min(0xFF, green));
outputValue.setB(etk::min(0xFF, blue));
outputValue.setA(etk::min(0xFF, alpha));
outputValue.setR(std::min(0xFF, red));
outputValue.setG(std::min(0xFF, green));
outputValue.setB(std::min(0xFF, blue));
outputValue.setA(std::min(0xFF, alpha));
} else if (sscanf(_input.c_str(), "%X,%X,%X", &red, &green, &blue) == 3) {
outputValue.setR(etk::min(0xFF, red));
outputValue.setG(etk::min(0xFF, green));
outputValue.setB(etk::min(0xFF, blue));
} else if (sscanf(_input.c_str(), "%f,%f,%f,%f", &float_red, &float_green, &float_blue, &float_alpha) == 4) {
float_red = etk::avg(0.0f, float_red, 1.0f);
float_green = etk::avg(0.0f, float_green, 1.0f);
float_blue = etk::avg(0.0f, float_blue, 1.0f);
float_alpha = etk::avg(0.0f, float_alpha, 1.0f);
outputValue.setR((uint8_t)(float_red * 255.f));
outputValue.setG((uint8_t)(float_green * 255.f));
outputValue.setB((uint8_t)(float_blue * 255.f));
outputValue.setR((uint8_t)(float_alpha * 255.f));
} else if (sscanf(_input.c_str(), "%f,%f,%f", &float_red, &float_green, &float_blue) == 3) {
float_red = etk::avg(0.0f, float_red, 1.0f);
float_green= etk::avg(0.0f, float_green, 1.0f);
float_blue = etk::avg(0.0f, float_blue, 1.0f);
outputValue.setR((uint8_t)(float_red * 255.f));
outputValue.setG((uint8_t)(float_green * 255.f));
outputValue.setB((uint8_t)(float_blue * 255.f));
outputValue.setR(std::min(0xFF, red));
outputValue.setG(std::min(0xFF, green));
outputValue.setB(std::min(0xFF, blue));
} else if (sscanf(_input.c_str(), "%f,%f,%f,%f", &fred, &fgreen, &fblue, &falpha) == 4) {
fred = std::avg(0.0f, fred, 1.0f);
fgreen = std::avg(0.0f, fgreen, 1.0f);
fblue = std::avg(0.0f, fblue, 1.0f);
falpha = std::avg(0.0f, falpha, 1.0f);
outputValue.setR((uint8_t)(fred * 255.f));
outputValue.setG((uint8_t)(fgreen * 255.f));
outputValue.setB((uint8_t)(fblue * 255.f));
outputValue.setR((uint8_t)(falpha * 255.f));
} else if (sscanf(_input.c_str(), "%f,%f,%f", &fred, &fgreen, &fblue) == 3) {
fred = std::avg(0.0f, fred, 1.0f);
fgreen= std::avg(0.0f, fgreen, 1.0f);
fblue = std::avg(0.0f, fblue, 1.0f);
outputValue.setR((uint8_t)(fred * 255.f));
outputValue.setG((uint8_t)(fgreen * 255.f));
outputValue.setB((uint8_t)(fblue * 255.f));
} else {
TK_ERROR("Error in parsing the color : '" << _input << "' ==> unknown method ...");
TK_ERROR(" pb in parsing the color : '" << _input << "' ==> unknown methode ...");
}
return outputValue;
}
etk::Color<double, 4> etk::parseStringStartWithRGB(const etk::String& _input) {
etk::Color<double, 4> etk::parseStringStartWithRGB(const std::string& _input) {
TK_VERBOSE("parseStringStartWithRGB('" << _input << "')");
etk::Color<double, 4> outputValue(0,0,0,0);
double float_red=0, float_green=0, float_blue=0, float_alpha=0;
double fred=0, fgreen=0, fblue=0, falpha=0;
int32_t red=0, green=0, blue=0, alpha=0;
if (sscanf(_input.c_str(), "%lf,%lf,%lf,%lf", &float_red, &float_green, &float_blue, &float_alpha) == 4) {
outputValue.setR(float_red);
outputValue.setG(float_green);
outputValue.setB(float_blue);
outputValue.setA(float_alpha);
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf", &float_red, &float_green, &float_blue) == 3) {
outputValue.setR(float_red);
outputValue.setG(float_green);
outputValue.setB(float_blue);
if (sscanf(_input.c_str(), "%lf,%lf,%lf,%lf", &fred, &fgreen, &fblue, &falpha) == 4) {
outputValue.setR(fred);
outputValue.setG(fgreen);
outputValue.setB(fblue);
outputValue.setA(falpha);
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf", &fred, &fgreen, &fblue) == 3) {
outputValue.setR(fred);
outputValue.setG(fgreen);
outputValue.setB(fblue);
} else if (sscanf(_input.c_str(), "%u,%u,%u,%u", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(etk::min(0xFF, red)/255.0);
outputValue.setG(etk::min(0xFF, green)/255.0);
outputValue.setB(etk::min(0xFF, blue)/255.0);
outputValue.setA(etk::min(0xFF, alpha)/255.0);
outputValue.setR(std::min(0xFF, red)/255.0);
outputValue.setG(std::min(0xFF, green)/255.0);
outputValue.setB(std::min(0xFF, blue)/255.0);
outputValue.setA(std::min(0xFF, alpha)/255.0);
} else if (sscanf(_input.c_str(), "%u,%u,%u", &red, &green, &blue) == 3) {
outputValue.setR(etk::min(0xFF, red)/255.0);
outputValue.setG(etk::min(0xFF, green)/255.0);
outputValue.setB(etk::min(0xFF, blue)/255.0);
outputValue.setR(std::min(0xFF, red)/255.0);
outputValue.setG(std::min(0xFF, green)/255.0);
outputValue.setB(std::min(0xFF, blue)/255.0);
} else if (sscanf(_input.c_str(), "%X,%X,%X,%X", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(etk::min(0xFF, red)/255.0);
outputValue.setG(etk::min(0xFF, green)/255.0);
outputValue.setB(etk::min(0xFF, blue)/255.0);
outputValue.setA(etk::min(0xFF, alpha)/255.0);
outputValue.setR(std::min(0xFF, red)/255.0);
outputValue.setG(std::min(0xFF, green)/255.0);
outputValue.setB(std::min(0xFF, blue)/255.0);
outputValue.setA(std::min(0xFF, alpha)/255.0);
} else if (sscanf(_input.c_str(), "%X,%X,%X", &red, &green, &blue) == 3) {
outputValue.setR(etk::min(0xFF, red)/255.0);
outputValue.setG(etk::min(0xFF, green)/255.0);
outputValue.setB(etk::min(0xFF, blue)/255.0);
outputValue.setR(std::min(0xFF, red)/255.0);
outputValue.setG(std::min(0xFF, green)/255.0);
outputValue.setB(std::min(0xFF, blue)/255.0);
} else {
TK_ERROR("Error in parsing the color : '" << _input << "' ==> unknown method ...");
TK_ERROR(" pb in parsing the color : '" << _input << "' ==> unknown methode ...");
}
return outputValue;
}
etk::Color<uint32_t, 4> etk::parseStringStartWithRGBUnsigned32(const etk::String& _input) {
etk::Color<uint32_t, 4> etk::parseStringStartWithRGBUnsigned32(const std::string& _input) {
etk::Color<uint32_t, 4> outputValue(0,0,0,0);
int32_t red=0, green=0, blue=0, alpha=0;
double float_red=0, float_green=0, float_blue=0, float_alpha=0;
double fred=0, fgreen=0, fblue=0, falpha=0;
if (sscanf(_input.c_str(), "%u,%u,%u,%u", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(red);
outputValue.setG(green);
@ -188,103 +180,103 @@ etk::Color<uint32_t, 4> etk::parseStringStartWithRGBUnsigned32(const etk::String
outputValue.setR(red);
outputValue.setG(green);
outputValue.setB(blue);
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf,%lf", &float_red, &float_green, &float_blue, &float_alpha) == 4) {
outputValue.setR((uint32_t)(etk::min(1.0, float_red)*0xFFFFFFFF));
outputValue.setG((uint32_t)(etk::min(1.0, float_green)*0xFFFFFFFF));
outputValue.setB((uint32_t)(etk::min(1.0, float_blue)*0xFFFFFFFF));
outputValue.setA((uint32_t)(etk::min(1.0, float_alpha)*0xFFFFFFFF));
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf", &float_red, &float_green, &float_blue) == 3) {
outputValue.setR((uint32_t)(etk::min(1.0, float_red)*0xFFFFFFFF));
outputValue.setG((uint32_t)(etk::min(1.0, float_green)*0xFFFFFFFF));
outputValue.setB((uint32_t)(etk::min(1.0, float_blue)*0xFFFFFFFF));
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf,%lf", &fred, &fgreen, &fblue, &falpha) == 4) {
outputValue.setR((uint32_t)(std::min(1.0, fred)*0xFFFFFFFF));
outputValue.setG((uint32_t)(std::min(1.0, fgreen)*0xFFFFFFFF));
outputValue.setB((uint32_t)(std::min(1.0, fblue)*0xFFFFFFFF));
outputValue.setA((uint32_t)(std::min(1.0, falpha)*0xFFFFFFFF));
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf", &fred, &fgreen, &fblue) == 3) {
outputValue.setR((uint32_t)(std::min(1.0, fred)*0xFFFFFFFF));
outputValue.setG((uint32_t)(std::min(1.0, fgreen)*0xFFFFFFFF));
outputValue.setB((uint32_t)(std::min(1.0, fblue)*0xFFFFFFFF));
} else {
TK_ERROR("Error in parsing the color : '" << _input << "' ==> unknown method ...");
TK_ERROR(" pb in parsing the color : '" << _input << "' ==> unknown methode ...");
}
return outputValue;
}
etk::Color<uint16_t, 4> etk::parseStringStartWithRGBUnsigned16(const etk::String& _input) {
etk::Color<uint16_t, 4> etk::parseStringStartWithRGBUnsigned16(const std::string& _input) {
etk::Color<uint16_t, 4> outputValue(0,0,0,0);
int32_t red=0, green=0, blue=0, alpha=0;
double float_red=0, float_green=0, float_blue=0, float_alpha=0;
double fred=0, fgreen=0, fblue=0, falpha=0;
if (sscanf(_input.c_str(), "%u,%u,%u,%u", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(etk::min(0xFFFF, red));
outputValue.setG(etk::min(0xFFFF, green));
outputValue.setB(etk::min(0xFFFF, blue));
outputValue.setA(etk::min(0xFFFF, alpha));
outputValue.setR(std::min(0xFFFF, red));
outputValue.setG(std::min(0xFFFF, green));
outputValue.setB(std::min(0xFFFF, blue));
outputValue.setA(std::min(0xFFFF, alpha));
} else if (sscanf(_input.c_str(), "%u,%u,%u", &red, &green, &blue) == 3) {
outputValue.setR(etk::min(0xFFFF, red));
outputValue.setG(etk::min(0xFFFF, green));
outputValue.setB(etk::min(0xFFFF, blue));
outputValue.setR(std::min(0xFFFF, red));
outputValue.setG(std::min(0xFFFF, green));
outputValue.setB(std::min(0xFFFF, blue));
} else if (sscanf(_input.c_str(), "%X,%X,%X,%X", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(etk::min(0xFFFF, red));
outputValue.setG(etk::min(0xFFFF, green));
outputValue.setB(etk::min(0xFFFF, blue));
outputValue.setA(etk::min(0xFFFF, alpha));
outputValue.setR(std::min(0xFFFF, red));
outputValue.setG(std::min(0xFFFF, green));
outputValue.setB(std::min(0xFFFF, blue));
outputValue.setA(std::min(0xFFFF, alpha));
} else if (sscanf(_input.c_str(), "%X,%X,%X", &red, &green, &blue) == 3) {
outputValue.setR(etk::min(0xFFFF, red));
outputValue.setG(etk::min(0xFFFF, green));
outputValue.setB(etk::min(0xFFFF, blue));
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf,%lf", &float_red, &float_green, &float_blue, &float_alpha) == 4) {
outputValue.setR((uint16_t)(etk::min(1.0, float_red)*0xFFFF));
outputValue.setG((uint16_t)(etk::min(1.0, float_green)*0xFFFF));
outputValue.setB((uint16_t)(etk::min(1.0, float_blue)*0xFFFF));
outputValue.setA((uint16_t)(etk::min(1.0, float_alpha)*0xFFFF));
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf", &float_red, &float_green, &float_blue) == 3) {
outputValue.setR((uint16_t)(etk::min(1.0, float_red)*0xFFFF));
outputValue.setG((uint16_t)(etk::min(1.0, float_green)*0xFFFF));
outputValue.setB((uint16_t)(etk::min(1.0, float_blue)*0xFFFF));
outputValue.setR(std::min(0xFFFF, red));
outputValue.setG(std::min(0xFFFF, green));
outputValue.setB(std::min(0xFFFF, blue));
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf,%lf", &fred, &fgreen, &fblue, &falpha) == 4) {
outputValue.setR((uint16_t)(std::min(1.0, fred)*0xFFFF));
outputValue.setG((uint16_t)(std::min(1.0, fgreen)*0xFFFF));
outputValue.setB((uint16_t)(std::min(1.0, fblue)*0xFFFF));
outputValue.setA((uint16_t)(std::min(1.0, falpha)*0xFFFF));
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf", &fred, &fgreen, &fblue) == 3) {
outputValue.setR((uint16_t)(std::min(1.0, fred)*0xFFFF));
outputValue.setG((uint16_t)(std::min(1.0, fgreen)*0xFFFF));
outputValue.setB((uint16_t)(std::min(1.0, fblue)*0xFFFF));
} else {
TK_ERROR("Error in parsing the color : '" << _input << "' ==> unknown method ...");
TK_ERROR(" pb in parsing the color : '" << _input << "' ==> unknown methode ...");
}
return outputValue;
}
etk::Color<uint8_t, 4> etk::parseStringStartWithRGBUnsigned8(const etk::String& _input) {
etk::Color<uint8_t, 4> etk::parseStringStartWithRGBUnsigned8(const std::string& _input) {
etk::Color<uint8_t, 4> outputValue(0,0,0,0);
int32_t red=0, green=0, blue=0, alpha=0;
double float_red=0, float_green=0, float_blue=0, float_alpha=0;
double fred=0, fgreen=0, fblue=0, falpha=0;
if (sscanf(_input.c_str(), "%u,%u,%u,%u", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(etk::min(0xFF, red));
outputValue.setG(etk::min(0xFF, green));
outputValue.setB(etk::min(0xFF, blue));
outputValue.setA(etk::min(0xFF, alpha));
outputValue.setR(std::min(0xFF, red));
outputValue.setG(std::min(0xFF, green));
outputValue.setB(std::min(0xFF, blue));
outputValue.setA(std::min(0xFF, alpha));
} else if (sscanf(_input.c_str(), "%u,%u,%u", &red, &green, &blue) == 3) {
outputValue.setR(etk::min(0xFF, red));
outputValue.setG(etk::min(0xFF, green));
outputValue.setB(etk::min(0xFF, blue));
outputValue.setR(std::min(0xFF, red));
outputValue.setG(std::min(0xFF, green));
outputValue.setB(std::min(0xFF, blue));
} else if (sscanf(_input.c_str(), "%X,%X,%X,%X", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(etk::min(0xFF, red));
outputValue.setG(etk::min(0xFF, green));
outputValue.setB(etk::min(0xFF, blue));
outputValue.setA(etk::min(0xFF, alpha));
outputValue.setR(std::min(0xFF, red));
outputValue.setG(std::min(0xFF, green));
outputValue.setB(std::min(0xFF, blue));
outputValue.setA(std::min(0xFF, alpha));
} else if (sscanf(_input.c_str(), "%X,%X,%X", &red, &green, &blue) == 3) {
outputValue.setR(etk::min(0xFF, red));
outputValue.setG(etk::min(0xFF, green));
outputValue.setB(etk::min(0xFF, blue));
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf,%lf", &float_red, &float_green, &float_blue, &float_alpha) == 4) {
outputValue.setR((uint8_t)(etk::min(1.0, float_red)*0xFF));
outputValue.setG((uint8_t)(etk::min(1.0, float_green)*0xFF));
outputValue.setB((uint8_t)(etk::min(1.0, float_blue)*0xFF));
outputValue.setA((uint8_t)(etk::min(1.0, float_alpha)*0xFF));
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf", &float_red, &float_green, &float_blue) == 3) {
outputValue.setR((uint8_t)(etk::min(1.0, float_red)*0xFF));
outputValue.setG((uint8_t)(etk::min(1.0, float_green)*0xFF));
outputValue.setB((uint8_t)(etk::min(1.0, float_blue)*0xFF));
outputValue.setR(std::min(0xFF, red));
outputValue.setG(std::min(0xFF, green));
outputValue.setB(std::min(0xFF, blue));
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf,%lf", &fred, &fgreen, &fblue, &falpha) == 4) {
outputValue.setR((uint8_t)(std::min(1.0, fred)*0xFF));
outputValue.setG((uint8_t)(std::min(1.0, fgreen)*0xFF));
outputValue.setB((uint8_t)(std::min(1.0, fblue)*0xFF));
outputValue.setA((uint8_t)(std::min(1.0, falpha)*0xFF));
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf", &fred, &fgreen, &fblue) == 3) {
outputValue.setR((uint8_t)(std::min(1.0, fred)*0xFF));
outputValue.setG((uint8_t)(std::min(1.0, fgreen)*0xFF));
outputValue.setB((uint8_t)(std::min(1.0, fblue)*0xFF));
} else {
TK_ERROR("Error in parsing the color : '" << _input << "' ==> unknown method ...");
TK_ERROR(" pb in parsing the color : '" << _input << "' ==> unknown methode ...");
}
return outputValue;
}
etk::Color<uint8_t, 4> etk::parseStringColorNamed(const etk::String& _input) {
etk::Color<uint8_t, 4> etk::parseStringColorNamed(const std::string& _input) {
// direct named color ...
for (int32_t iii=0; iii<getColorSize(); iii++) {
if (getColorList()[iii].colorName.compare(_input, false) == true) {
if (etk::compare_no_case(getColorList()[iii].colorName, _input) == true) {
return getColorList()[iii].color;
}
}
TK_ERROR("Error in parsing the color : '" << _input << "' not find ...");
TK_ERROR(" pb in parsing the color : '" << _input << "' not find ...");
return etk::Color<uint8_t, 4>(0,0,0,0);
}
@ -444,7 +436,7 @@ const etk::Color<> etk::color::whiteSmoke(0xF5, 0xF5, 0xF5, 0xFF);
const etk::Color<> etk::color::yellow(0xFF, 0xFF, 0x00, 0xFF);
const etk::Color<> etk::color::yellowGreen(0x9A, 0xCD, 0x32, 0xFF);
static const ColorList listOfColor[] = {
static const colorList_ts listOfColor[] = {
{ "none", etk::color::none},
{ "AliceBlue", etk::color::aliceBlue},
{ "AntiqueWhite", etk::color::antiqueWhite},
@ -595,15 +587,15 @@ static const ColorList listOfColor[] = {
{ "YellowGreen", etk::color::yellowGreen}
};
static const ColorList* getColorList()
static const colorList_ts* getColorList()
{
return listOfColor;
}
static int32_t getColorSize()
{
static const int32_t tmp = sizeof(listOfColor) / sizeof(ColorList);
return tmp;
static const int32_t tmpp = sizeof(listOfColor) / sizeof(colorList_ts);
return tmpp;
}
namespace etk {

679
color/etk-color/Color.h Normal file
View File

@ -0,0 +1,679 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#include <etk/types.h>
#ifndef __ETK_COLOR_H__
#define __ETK_COLOR_H__
#include <iomanip>
namespace etk {
/**
* @brief The color class is a template to abstract the color implementation choice.
*
* It is important to note that the color choice denpznd on the level of developent.
* For example :
* :** Graphic application use:
* ::** Image in 3/4 bytes for rgb(a)
* ::** Color description in char : '#F6780FFF' or the equivalent number:0xF6780FFF
* :** middleware will mainely use a the 4 separate value with 1 byte for each.
* :** graphic interface (openGL) store image in 1/2/3/4 bytes color and interpolate it in 'n' float. And note that the user color is sored in float.
*
* Then with this class we abstract the transformation format and set an easy same way to use the color independing of the developpement level.
*
* Some of the basic color is defined in the namespace: [namespace[etk::color]].
*
* @template-param MY_TYPE Type of the internal template value. The generic value is uint8_t and float
*/
template<typename MY_TYPE=uint8_t, int MY_TYPE_SIZE=4> class Color {
public:
static const Color<MY_TYPE, MY_TYPE_SIZE> emptyColor; // to auto fill with no data in all case
static const MY_TYPE defaultAlpha;
private:
MY_TYPE m_element[MY_TYPE_SIZE]; //!< all the color.
public:
/**
* @brief Constructor. It does not initialise element of class.
*/
Color() { };
/**
* @brief Contructor with request initialisation.
* @param[in] _r Red color.
* @param[in] _g Green color.
* @param[in] _b Blue color.
* @param[in] _a Alpha blending.
*/
Color(MY_TYPE _r, MY_TYPE _g, MY_TYPE _b, MY_TYPE _a) {
set(_r, _g, _b, _a);
};
//! @previous
Color(MY_TYPE _r, MY_TYPE _g, MY_TYPE _b) {
set(_r, _g, _b);
};
//! @previous
Color(MY_TYPE _r, MY_TYPE _g) {
set(_r, _g);
};
//! @previous
Color(MY_TYPE _r) {
set(_r);
};
/**
* @brief Copy contructor or convert contructor
* @param[in] _obj Element to copy in this new color class.
*/
template<typename MY_TYPE_2, int MY_TYPE_SIZE_2>
Color(const etk::Color<MY_TYPE_2, MY_TYPE_SIZE_2>& _obj);
/**
* @brief String extractor constructor.
* @param[in] _input Color string to parse. it can be : "#rrggbb", "rgb", "rrggbbaa", "rgba", "blueviolet" ...
*/
Color(const std::string& _input);
/**
* @brief Asignemement operator
* @param[in] _input Color object to set in this class.
* @return reference on this element.
*/
Color<MY_TYPE,MY_TYPE_SIZE>& operator=(const etk::Color<MY_TYPE,MY_TYPE_SIZE>& _input) {
for (size_t iii=0; iii<MY_TYPE_SIZE; ++iii) {
m_element[iii] = _input.m_element[iii];
}
return *this;
};
/**
* @brief Different comparaison operator.
* @param[in] _obj Color object to compare.
* @return true This is not the same color
* @return false This is the same color.
*/
bool operator!= (const etk::Color<MY_TYPE,MY_TYPE_SIZE>& _obj) const {
for (size_t iii=0; iii<MY_TYPE_SIZE; ++iii) {
if(m_element[iii] != _obj.m_element[iii]) {
return true;
}
}
return false;
}
/**
* @brief Equality comparaison operator.
* @param[in] _obj Color object to compare.
* @return true This is the same color.
* @return false The color are different.
*/
bool operator== (const etk::Color<MY_TYPE,MY_TYPE_SIZE>& _obj) const {
for (size_t iii=0; iii<MY_TYPE_SIZE; ++iii) {
if(m_element[iii] != _obj.m_element[iii]) {
return false;
}
}
return true;
}
/**
* @breif Get the Generic uint32_t value of the color
* @return Color in unsigned integer
*/
uint32_t get() const;
/**
* @brief Set the specified color elements.
* @param[in] _r Red color.
* @param[in] _g Green color.
* @param[in] _b Blue color.
* @param[in] _a Alpha blending.
*/
void set(MY_TYPE _r, MY_TYPE _g, MY_TYPE _b, MY_TYPE _a) {
if (MY_TYPE_SIZE >= 1) {
m_element[0] = _r;
}
if (MY_TYPE_SIZE >= 2) {
m_element[1] = _g;
}
if (MY_TYPE_SIZE >= 3) {
m_element[2] = _b;
}
if (MY_TYPE_SIZE >= 4) {
m_element[3] = _a;
}
};
//! @previous
void set(MY_TYPE _r, MY_TYPE _g, MY_TYPE _b) {
if (MY_TYPE_SIZE >= 1) {
m_element[0] = _r;
}
if (MY_TYPE_SIZE >= 2) {
m_element[1] = _g;
}
if (MY_TYPE_SIZE >= 3) {
m_element[2] = _b;
}
if (MY_TYPE_SIZE >= 4) {
m_element[3] = defaultAlpha;
}
};
//! @previous
void set(MY_TYPE _r, MY_TYPE _g) {
if (MY_TYPE_SIZE >= 1) {
m_element[0] = _r;
}
if (MY_TYPE_SIZE >= 2) {
m_element[1] = _g;
}
if (MY_TYPE_SIZE >= 3) {
m_element[2] = 0;
}
if (MY_TYPE_SIZE >= 4) {
m_element[3] = defaultAlpha;
}
};
//! @previous
void set(MY_TYPE _r) {
if (MY_TYPE_SIZE >= 1) {
m_element[0] = _r;
}
if (MY_TYPE_SIZE >= 2) {
m_element[1] = 0;
}
if (MY_TYPE_SIZE >= 3) {
m_element[2] = 0;
}
if (MY_TYPE_SIZE >= 4) {
m_element[3] = defaultAlpha;
}
};
/**
* @brief Convert the color in an hexedecimal string ("0xFEDCBA98")
* @return The formated string
*/
std::string getHexString() const {
std::ostringstream oss;
oss << "0x" << std::setw(8) << std::setfill('0') << std::hex << get();
return oss.str();
};
/**
* @brief Convert the color in an generic string value ("#FEDCBA98")
* @return The formated string
*/
std::string getString() const {
std::ostringstream oss;
oss << "#" << std::setw(8) << std::setfill('0') << std::hex << get();
return oss.str();
};
/**
* @brief Get red color.
* @return The red color.
*/
MY_TYPE r() const {
if (MY_TYPE_SIZE >= 1) {
return m_element[0];
} else {
return 0;
}
};
/**
* @brief Get green color.
* @return The green color.
*/
MY_TYPE g() const {
if (MY_TYPE_SIZE >= 2) {
return m_element[1];
} else {
return 0;
}
};
/**
* @brief Get blue color.
* @return The blue color.
*/
MY_TYPE b() const {
if (MY_TYPE_SIZE >= 3) {
return m_element[2];
} else {
return 0;
}
};
/**
* @brief Get alpha blending.
* @return The alpha blending.
*/
MY_TYPE a() const {
if (MY_TYPE_SIZE >= 4) {
return m_element[3];
} else {
return defaultAlpha;
}
};
/**
* @brief Set red color.
* @param[in] _r The red color to set.
*/
void setR(MY_TYPE _r) {
if (MY_TYPE_SIZE >= 1) {
m_element[0] = _r;
}
};
/**
* @brief Set green color.
* @param[in] _g The green color to set.
*/
void setG(MY_TYPE _g) {
if (MY_TYPE_SIZE >= 2) {
m_element[1] = _g;
}
};
/**
* @brief Set blue color.
* @param[in] _b The blue color to set.
*/
void setB(MY_TYPE _b) {
if (MY_TYPE_SIZE >= 3) {
m_element[2] = _b;
}
};
/**
* @brief Set alpha blending.
* @param[in] _a The alpha blending to set.
*/
void setA(MY_TYPE _a) {
if (MY_TYPE_SIZE >= 4) {
m_element[3] = _a;
}
};
};
etk::Color<uint8_t, 4> parseStringStartWithSharp(const std::string& _input);
etk::Color<uint8_t, 4> parseStringStartWithRGBGen(const std::string& _input);
etk::Color<double, 4> parseStringStartWithRGB(const std::string& _input);
etk::Color<uint32_t, 4> parseStringStartWithRGBUnsigned32(const std::string& _input);
etk::Color<uint16_t, 4> parseStringStartWithRGBUnsigned16(const std::string& _input);
etk::Color<uint8_t, 4> parseStringStartWithRGBUnsigned8(const std::string& _input);
etk::Color<uint8_t, 4> parseStringColorNamed(const std::string& _input);
template<> uint32_t Color<uint8_t, 4>::get() const;
template<typename MY_TYPE, int MY_TYPE_SIZE> uint32_t Color<MY_TYPE, MY_TYPE_SIZE>::get() const {
Color<uint8_t, 4> tmp(*this);
return tmp.get();
}
template<typename MY_TYPE, int MY_TYPE_SIZE> Color<MY_TYPE, MY_TYPE_SIZE>::Color(const std::string& _input) {
TK_VERBOSE("convert color string : '" << _input << "'");
const char* inputData = _input.c_str();
size_t len = _input.size();
if( len >=1
&& inputData[0] == '#') {
Color<uint8_t, 4> value = etk::parseStringStartWithSharp(std::string(_input, 1));
*this = value;
} else if(etk::start_with(_input, "rgb(", false) == true) {
Color<uint8_t, 4> value = etk::parseStringStartWithRGBGen(std::string(_input, 4, _input.size()-5));
*this = value;
} else if(etk::start_with(_input, "rgba(", false) == true) {
Color<uint8_t, 4> value = etk::parseStringStartWithRGBGen(std::string(_input, 5, _input.size()-6));
*this = value;
} else if(etk::start_with(_input, "rgb[FLOAT](", false) == true) {
Color<double, 4> value = etk::parseStringStartWithRGB(std::string(_input, 11, _input.size()-12));
*this = value;
} else if(etk::start_with(_input, "rgba[FLOAT](", false) == true) {
Color<double, 4> value = etk::parseStringStartWithRGB(std::string(_input, 12, _input.size()-13));
*this = value;
} else if(etk::start_with(_input, "rgb[DOUBLE](", false) == true) {
Color<double, 4> value = etk::parseStringStartWithRGB(std::string(_input, 12, _input.size()-13));
*this = value;
} else if(etk::start_with(_input, "rgba[DOUBLE](", false) == true) {
Color<double, 4> value = etk::parseStringStartWithRGB(std::string(_input, 13, _input.size()-14));
*this = value;
} else if(etk::start_with(_input, "rgb[U32](", false) == true) {
Color<uint32_t, 4> value = etk::parseStringStartWithRGBUnsigned32(std::string(_input, 9, _input.size()-10));
*this = value;
} else if(etk::start_with(_input, "rgba[U32](", false) == true) {
Color<uint32_t, 4> value = etk::parseStringStartWithRGBUnsigned32(std::string(_input, 10, _input.size()-11));
*this = value;
} else if(etk::start_with(_input, "rgb[U16](", false) == true) {
Color<uint16_t, 4> value = etk::parseStringStartWithRGBUnsigned16(std::string(_input, 9, _input.size()-10));
*this = value;
} else if(etk::start_with(_input, "rgba[U16](", false) == true) {
Color<uint16_t, 4> value = etk::parseStringStartWithRGBUnsigned16(std::string(_input, 10, _input.size()-11));
*this = value;
} else if(etk::start_with(_input, "rgb[U8](", false) == true) {
Color<uint8_t, 4> value = etk::parseStringStartWithRGBUnsigned8(std::string(_input, 8, _input.size()-9));
*this = value;
} else if(etk::start_with(_input, "rgba[U8](", false) == true) {
Color<uint8_t, 4> value = etk::parseStringStartWithRGBUnsigned8(std::string(_input, 9, _input.size()-10));
*this = value;
} else {
Color<uint8_t, 4> value = etk::parseStringColorNamed(_input);
*this = value;
}
//TK_VERBOSE(" ==> converted color string : '" << _input << "' ==> " << *this);
};
//! @not-in-doc
template<int MY_TYPE_SIZE> std::ostream& operator <<(std::ostream& _os, const Color<uint8_t, MY_TYPE_SIZE>& _obj) { // RGB & RGBA 8 bits
std::ostringstream oss;
if (MY_TYPE_SIZE >= 3) {
_os << "#";
oss << std::setw(2) << std::setfill('0') << std::hex << _obj.r();
if (MY_TYPE_SIZE >= 2) {
oss << std::setw(2) << std::setfill('0') << std::hex << _obj.g();
}
if (MY_TYPE_SIZE >= 3) {
oss << std::setw(2) << std::setfill('0') << std::hex << _obj.b();
}
if (MY_TYPE_SIZE >= 4) {
oss << std::setw(2) << std::setfill('0') << std::hex << _obj.a();
}
_os << oss.str();
} else {
if (MY_TYPE_SIZE >= 2) {
_os << "be";
} else {
_os << "Mono";
}
_os << "[U8](";
oss << "0x" << std::setw(2) << std::setfill('0') << std::hex << _obj.r();
if (MY_TYPE_SIZE >= 2) {
_os << ",";
oss << "0x" << std::setw(2) << std::setfill('0') << std::hex << _obj.g();
}
_os << oss.str();
_os << ")";
}
return _os;
}
//! @not-in-doc
template<int MY_TYPE_SIZE> std::ostream& operator <<(std::ostream& _os, const Color<uint16_t, MY_TYPE_SIZE>& _obj) { // RGB & RGBA 8 bits
std::ostringstream oss;
if (MY_TYPE_SIZE >= 4) {
_os << "rgba";
} else if (MY_TYPE_SIZE >= 3) {
_os << "rgb";
} else if (MY_TYPE_SIZE >= 2) {
_os << "be";
} else {
_os << "Mono";
}
_os << "[U16](";
oss << "0x" << std::setw(4) << std::setfill('0') << std::hex << _obj.r();
if (MY_TYPE_SIZE >= 2) {
oss << ",0x" << std::setw(4) << std::setfill('0') << std::hex << _obj.g();
}
if (MY_TYPE_SIZE >= 3) {
oss << ",0x" << std::setw(4) << std::setfill('0') << std::hex << _obj.b();
}
if (MY_TYPE_SIZE >= 4) {
oss << ",0x" << std::setw(4) << std::setfill('0') << std::hex << _obj.a();
}
_os << oss.str() << ")";
return _os;
}
//! @not-in-doc
template<int MY_TYPE_SIZE> std::ostream& operator <<(std::ostream& _os, const Color<uint32_t, MY_TYPE_SIZE>& _obj) { // RGB & RGBA 8 bits
std::ostringstream oss;
if (MY_TYPE_SIZE >= 4) {
_os << "rgba";
} else if (MY_TYPE_SIZE >= 3) {
_os << "rgb";
} else if (MY_TYPE_SIZE >= 2) {
_os << "be";
} else {
_os << "Mono";
}
_os << "[U32](";
oss << "0x" << std::setw(8) << std::setfill('0') << std::hex << _obj.r();
if (MY_TYPE_SIZE >= 2) {
oss << ",0x" << std::setw(8) << std::setfill('0') << std::hex << _obj.g();
}
if (MY_TYPE_SIZE >= 3) {
oss << ",0x" << std::setw(8) << std::setfill('0') << std::hex << _obj.b();
}
if (MY_TYPE_SIZE >= 4) {
oss << ",0x" << std::setw(8) << std::setfill('0') << std::hex << _obj.a();
}
_os << oss.str() << ")";
return _os;
}
//! @not-in-doc
template<int MY_TYPE_SIZE> std::ostream& operator <<(std::ostream& _os, const Color<float, MY_TYPE_SIZE>& _obj) { // RGB float & RGBA float
if (MY_TYPE_SIZE >= 4) {
_os << "rgba";
} else if (MY_TYPE_SIZE >= 3) {
_os << "rgb";
} else if (MY_TYPE_SIZE >= 2) {
_os << "be";
} else {
_os << "Mono";
}
_os << "[FLOAT](";
_os << _obj.r();
if (MY_TYPE_SIZE >= 2) {
_os << ",";
_os << _obj.g();
}
if (MY_TYPE_SIZE >= 3) {
_os << ",";
_os << _obj.b();
}
if (MY_TYPE_SIZE >= 4) {
_os << ",";
_os << _obj.a();
}
_os << ")";
return _os;
}
//! @not-in-doc
template<int MY_TYPE_SIZE> std::ostream& operator <<(std::ostream& _os, const Color<double, MY_TYPE_SIZE>& _obj) { // RGB & RGBA 8 bits
if (MY_TYPE_SIZE >= 4) {
_os << "rgba";
} else if (MY_TYPE_SIZE >= 3) {
_os << "rgb";
} else if (MY_TYPE_SIZE >= 2) {
_os << "be";
} else {
_os << "Mono";
}
_os << "[double](";
_os << _obj.r();
if (MY_TYPE_SIZE >= 2) {
_os << ",";
_os << _obj.g();
}
if (MY_TYPE_SIZE >= 3) {
_os << ",";
_os << _obj.b();
}
if (MY_TYPE_SIZE >= 4) {
_os << ",";
_os << _obj.a();
}
_os << ")";
return _os;
}
//! @not-in-doc
template<typename MY_TYPE, int MY_TYPE_SIZE> std::ostream& operator <<(std::ostream& _os, const std::vector<Color<MY_TYPE, MY_TYPE_SIZE> >& _obj) {
for (size_t iii = 0; iii < _obj.size(); ++iii) {
if (iii != 0) {
_os << " ";
}
_os << _obj[iii];
}
return _os;
};
/**
* @brief List of all native define colors ...
*/
namespace color {
extern const Color<> none; //!< No color (alpha = 0)
extern const Color<> aliceBlue; //!< ++ [color=aliceBlue] aliceBlue color [/color] ++
extern const Color<> antiqueWhite; //!< ++ [color=antiqueWhite] antiqueWhite color [/color] ++
extern const Color<> aqua; //!< ++ [color=aqua] aqua color [/color] ++
extern const Color<> aquamarine; //!< ++ [color=aquamarine] aquamarine color [/color] ++
extern const Color<> azure; //!< ++ [color=azure] azure color [/color] ++
extern const Color<> beige; //!< ++ [color=beige] beige color [/color] ++
extern const Color<> bisque; //!< ++ [color=bisque] bisque color [/color] ++
extern const Color<> black; //!< ++ [color=black] black color [/color] ++
extern const Color<> blanchedAlmond; //!< ++ [color=blanchedAlmond] blanchedAlmond color [/color] ++
extern const Color<> blue; //!< ++ [color=blue] blue color [/color] ++
extern const Color<> blueViolet; //!< ++ [color=blueViolet] blueViolet color [/color] ++
extern const Color<> brown; //!< ++ [color=brown] brown color [/color] ++
extern const Color<> burlyWood; //!< ++ [color=burlyWood] burlyWood color [/color] ++
extern const Color<> cadetBlue; //!< ++ [color=cadetBlue] cadetBlue color [/color] ++
extern const Color<> chartreuse; //!< ++ [color=chartreuse] chartreuse color [/color] ++
extern const Color<> chocolate; //!< ++ [color=chocolate] chocolate color [/color] ++
extern const Color<> coral; //!< ++ [color=coral] coral color [/color] ++
extern const Color<> cornflowerBlue; //!< ++ [color=cornflowerBlue] cornflowerBlue color [/color] ++
extern const Color<> cornsilk; //!< ++ [color=cornsilk] cornsilk color [/color] ++
extern const Color<> crimson; //!< ++ [color=crimson] crimson color [/color] ++
extern const Color<> cyan; //!< ++ [color=cyan] cyan color [/color] ++
extern const Color<> darkBlue; //!< ++ [color=darkBlue] darkBlue color [/color] ++
extern const Color<> darkCyan; //!< ++ [color=darkCyan] darkCyan color [/color] ++
extern const Color<> darkGoldenRod; //!< ++ [color=darkGoldenRod] darkGoldenRod color [/color] ++
extern const Color<> darkGray; //!< ++ [color=darkGray] darkGray color [/color] ++
extern const Color<> darkGrey; //!< ++ [color=darkGrey] darkGrey color [/color] ++
extern const Color<> darkGreen; //!< ++ [color=darkGreen] darkGreen color [/color] ++
extern const Color<> darkKhaki; //!< ++ [color=darkKhaki] darkKhaki color [/color] ++
extern const Color<> darkMagenta; //!< ++ [color=darkMagenta] darkMagenta color [/color] ++
extern const Color<> darkOliveGreen; //!< ++ [color=darkOliveGreen] darkOliveGreen color [/color] ++
extern const Color<> darkorange; //!< ++ [color=darkorange] darkorange color [/color] ++
extern const Color<> darkOrchid; //!< ++ [color=darkOrchid] darkOrchid color [/color] ++
extern const Color<> darkRed; //!< ++ [color=darkRed] darkRed color [/color] ++
extern const Color<> darkSalmon; //!< ++ [color=darkSalmon] darkSalmon color [/color] ++
extern const Color<> darkSeaGreen; //!< ++ [color=darkSeaGreen] darkSeaGreen color [/color] ++
extern const Color<> darkSlateBlue; //!< ++ [color=darkSlateBlue] darkSlateBlue color [/color] ++
extern const Color<> darkSlateGray; //!< ++ [color=darkSlateGray] darkSlateGray color [/color] ++
extern const Color<> darkSlateGrey; //!< ++ [color=darkSlateGrey] darkSlateGrey color [/color] ++
extern const Color<> darkTurquoise; //!< ++ [color=darkTurquoise] darkTurquoise color [/color] ++
extern const Color<> darkViolet; //!< ++ [color=darkViolet] darkViolet color [/color] ++
extern const Color<> deepPink; //!< ++ [color=deepPink] deepPink color [/color] ++
extern const Color<> deepSkyBlue; //!< ++ [color=deepSkyBlue] deepSkyBlue color [/color] ++
extern const Color<> dimGray; //!< ++ [color=dimGray] dimGray color [/color] ++
extern const Color<> dimGrey; //!< ++ [color=dimGrey] dimGrey color [/color] ++
extern const Color<> dodgerBlue; //!< ++ [color=dodgerBlue] dodgerBlue color [/color] ++
extern const Color<> fireBrick; //!< ++ [color=fireBrick] fireBrick color [/color] ++
extern const Color<> floralWhite; //!< ++ [color=floralWhite] floralWhite color [/color] ++
extern const Color<> forestGreen; //!< ++ [color=forestGreen] forestGreen color [/color] ++
extern const Color<> fuchsia; //!< ++ [color=fuchsia] fuchsia color [/color] ++
extern const Color<> gainsboro; //!< ++ [color=gainsboro] gainsboro color [/color] ++
extern const Color<> ghostWhite; //!< ++ [color=ghostWhite] ghostWhite color [/color] ++
extern const Color<> gold; //!< ++ [color=gold] gold color [/color] ++
extern const Color<> goldenRod; //!< ++ [color=goldenRod] goldenRod color [/color] ++
extern const Color<> gray; //!< ++ [color=gray] gray color [/color] ++
extern const Color<> grey; //!< ++ [color=grey] grey color [/color] ++
extern const Color<> green; //!< ++ [color=green] green color [/color] ++
extern const Color<> greenYellow; //!< ++ [color=greenYellow] greenYellow color [/color] ++
extern const Color<> honeyDew; //!< ++ [color=honeyDew] honeyDew color [/color] ++
extern const Color<> hotPink; //!< ++ [color=hotPink] hotPink color [/color] ++
extern const Color<> indianRed; //!< ++ [color=indianRed] indianRed color [/color] ++
extern const Color<> indigo; //!< ++ [color=indigo] indigo color [/color] ++
extern const Color<> ivory; //!< ++ [color=ivory] ivory color [/color] ++
extern const Color<> khaki; //!< ++ [color=khaki] khaki color [/color] ++
extern const Color<> lavender; //!< ++ [color=lavender] lavender color [/color] ++
extern const Color<> lavenderBlush; //!< ++ [color=lavenderBlush] lavenderBlush color [/color] ++
extern const Color<> lawnGreen; //!< ++ [color=lawnGreen] lawnGreen color [/color] ++
extern const Color<> lemonChiffon; //!< ++ [color=lemonChiffon] lemonChiffon color [/color] ++
extern const Color<> lightBlue; //!< ++ [color=lightBlue] lightBlue color [/color] ++
extern const Color<> lightCoral; //!< ++ [color=lightCoral] lightCoral color [/color] ++
extern const Color<> lightCyan; //!< ++ [color=lightCyan] lightCyan color [/color] ++
extern const Color<> lightGoldenRodYellow; //!< ++ [color=lightGoldenRodYellow] lightGoldenRodYellow color [/color] ++
extern const Color<> lightGray; //!< ++ [color=lightGray] lightGray color [/color] ++
extern const Color<> lightGrey; //!< ++ [color=lightGrey] lightGrey color [/color] ++
extern const Color<> lightGreen; //!< ++ [color=lightGreen] lightGreen color [/color] ++
extern const Color<> lightPink; //!< ++ [color=lightPink] lightPink color [/color] ++
extern const Color<> lightSalmon; //!< ++ [color=lightSalmon] lightSalmon color [/color] ++
extern const Color<> lightSeaGreen; //!< ++ [color=lightSeaGreen] lightSeaGreen color [/color] ++
extern const Color<> lightSkyBlue; //!< ++ [color=lightSkyBlue] lightSkyBlue color [/color] ++
extern const Color<> lightSlateGray; //!< ++ [color=lightSlateGray] lightSlateGray color [/color] ++
extern const Color<> lightSlateGrey; //!< ++ [color=lightSlateGrey] lightSlateGrey color [/color] ++
extern const Color<> lightSteelBlue; //!< ++ [color=lightSteelBlue] lightSteelBlue color [/color] ++
extern const Color<> lightYellow; //!< ++ [color=lightYellow] lightYellow color [/color] ++
extern const Color<> lime; //!< ++ [color=lime] lime color [/color] ++
extern const Color<> limeGreen; //!< ++ [color=limeGreen] limeGreen color [/color] ++
extern const Color<> linen; //!< ++ [color=linen] linen color [/color] ++
extern const Color<> magenta; //!< ++ [color=magenta] magenta color [/color] ++
extern const Color<> maroon; //!< ++ [color=maroon] maroon color [/color] ++
extern const Color<> mediumAquaMarine; //!< ++ [color=mediumAquaMarine] mediumAquaMarine color [/color] ++
extern const Color<> mediumBlue; //!< ++ [color=mediumBlue] mediumBlue color [/color] ++
extern const Color<> mediumOrchid; //!< ++ [color=mediumOrchid] mediumOrchid color [/color] ++
extern const Color<> mediumPurple; //!< ++ [color=mediumPurple] mediumPurple color [/color] ++
extern const Color<> mediumSeaGreen; //!< ++ [color=mediumSeaGreen] mediumSeaGreen color [/color] ++
extern const Color<> mediumSlateBlue; //!< ++ [color=mediumSlateBlue] mediumSlateBlue color [/color] ++
extern const Color<> mediumSpringGreen; //!< ++ [color=mediumSpringGreen] mediumSpringGreen color [/color] ++
extern const Color<> mediumTurquoise; //!< ++ [color=mediumTurquoise] mediumTurquoise color [/color] ++
extern const Color<> mediumVioletRed; //!< ++ [color=mediumVioletRed] mediumVioletRed color [/color] ++
extern const Color<> midnightBlue; //!< ++ [color=midnightBlue] midnightBlue color [/color] ++
extern const Color<> mintCream; //!< ++ [color=mintCream] mintCream color [/color] ++
extern const Color<> mistyRose; //!< ++ [color=mistyRose] mistyRose color [/color] ++
extern const Color<> moccasin; //!< ++ [color=moccasin] moccasin color [/color] ++
extern const Color<> navajoWhite; //!< ++ [color=navajoWhite] navajoWhite color [/color] ++
extern const Color<> navy; //!< ++ [color=navy] navy color [/color] ++
extern const Color<> oldLace; //!< ++ [color=oldLace] oldLace color [/color] ++
extern const Color<> olive; //!< ++ [color=olive] olive color [/color] ++
extern const Color<> oliveDrab; //!< ++ [color=oliveDrab] oliveDrab color [/color] ++
extern const Color<> orange; //!< ++ [color=orange] orange color [/color] ++
extern const Color<> orangeRed; //!< ++ [color=orangeRed] orangeRed color [/color] ++
extern const Color<> orchid; //!< ++ [color=orchid] orchid color [/color] ++
extern const Color<> paleGoldenRod; //!< ++ [color=paleGoldenRod] paleGoldenRod color [/color] ++
extern const Color<> paleGreen; //!< ++ [color=paleGreen] paleGreen color [/color] ++
extern const Color<> paleTurquoise; //!< ++ [color=paleTurquoise] paleTurquoise color [/color] ++
extern const Color<> paleVioletRed; //!< ++ [color=paleVioletRed] paleVioletRed color [/color] ++
extern const Color<> papayaWhip; //!< ++ [color=papayaWhip] papayaWhip color [/color] ++
extern const Color<> peachPuff; //!< ++ [color=peachPuff] peachPuff color [/color] ++
extern const Color<> peru; //!< ++ [color=peru] peru color [/color] ++
extern const Color<> pink; //!< ++ [color=pink] pink color [/color] ++
extern const Color<> plum; //!< ++ [color=plum] plum color [/color] ++
extern const Color<> powderBlue; //!< ++ [color=powderBlue] powderBlue color [/color] ++
extern const Color<> purple; //!< ++ [color=purple] purple color [/color] ++
extern const Color<> red; //!< ++ [color=red] red color [/color] ++
extern const Color<> rosyBrown; //!< ++ [color=rosyBrown] rosyBrown color [/color] ++
extern const Color<> royalBlue; //!< ++ [color=royalBlue] royalBlue color [/color] ++
extern const Color<> saddleBrown; //!< ++ [color=saddleBrown] saddleBrown color [/color] ++
extern const Color<> salmon; //!< ++ [color=salmon] salmon color [/color] ++
extern const Color<> sandyBrown; //!< ++ [color=sandyBrown] sandyBrown color [/color] ++
extern const Color<> seaGreen; //!< ++ [color=seaGreen] seaGreen color [/color] ++
extern const Color<> seaShell; //!< ++ [color=seaShell] seaShell color [/color] ++
extern const Color<> sienna; //!< ++ [color=sienna] sienna color [/color] ++
extern const Color<> silver; //!< ++ [color=silver] silver color [/color] ++
extern const Color<> skyBlue; //!< ++ [color=skyBlue] skyBlue color [/color] ++
extern const Color<> slateBlue; //!< ++ [color=slateBlue] slateBlue color [/color] ++
extern const Color<> slateGray; //!< ++ [color=slateGray] slateGray color [/color] ++
extern const Color<> slateGrey; //!< ++ [color=slateGrey] slateGrey color [/color] ++
extern const Color<> snow; //!< ++ [color=snow] snow color [/color] ++
extern const Color<> springGreen; //!< ++ [color=springGreen] springGreen color [/color] ++
extern const Color<> steelBlue; //!< ++ [color=steelBlue] steelBlue color [/color] ++
extern const Color<> tan; //!< ++ [color=tan] tan color [/color] ++
extern const Color<> teal; //!< ++ [color=teal] teal color [/color] ++
extern const Color<> thistle; //!< ++ [color=thistle] thistle color [/color] ++
extern const Color<> tomato; //!< ++ [color=tomato] tomato color [/color] ++
extern const Color<> turquoise; //!< ++ [color=turquoise] turquoise color [/color] ++
extern const Color<> violet; //!< ++ [color=violet] violet color [/color] ++
extern const Color<> wheat; //!< ++ [color=wheat] wheat color [/color] ++
extern const Color<> white; //!< ++ [color=white] white color [/color] ++
extern const Color<> whiteSmoke; //!< ++ [color=whiteSmoke] whiteSmoke color [/color] ++
extern const Color<> yellow; //!< ++ [color=yellow] yellow color [/color] ++
extern const Color<> yellowGreen; //!< ++ [color=yellowGreen] yellowGreen color [/color] ++
};
/*
template<> std::string etk::to_string<Color<MY_TYPE, MY_TYPE_SIZE>>(const Color<MY_TYPE, MY_TYPE_SIZE>& _val) {
return _val.getString();
}
template<> std::u32string etk::to_u32string<Color<MY_TYPE, MY_TYPE_SIZE>>(const Color<MY_TYPE, MY_TYPE_SIZE>& _val) {
return etk::to_u32string(_val.getString());
}
template<> bool etk::from_string<Color<MY_TYPE, MY_TYPE_SIZE>>(Color<MY_TYPE, MY_TYPE_SIZE>& _variableRet, const std::u32string& _value) {
_variableRet = Color<MY_TYPE, MY_TYPE_SIZE>(etk::to_string(_value));
return true;
}
template<> bool etk::from_string<Color<MY_TYPE, MY_TYPE_SIZE>>(Color<MY_TYPE, MY_TYPE_SIZE>& _variableRet, const std::string& _value) {
_variableRet = Color<MY_TYPE, MY_TYPE_SIZE>(_value);
return true;
}
*/
};
#endif

View File

@ -235,230 +235,230 @@ template<> template<> Color<uint16_t,4>::Color(const Color<uint32_t, 4>& _obj) {
// ===========================================================================================================
template<> template<> Color<uint16_t,1>::Color(const Color<float, 1>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
m_element[0] = (uint16_t)(std::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
}
template<> template<> Color<uint16_t,2>::Color(const Color<float, 1>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
m_element[0] = (uint16_t)(std::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
m_element[1] = 0;
}
template<> template<> Color<uint16_t,3>::Color(const Color<float, 1>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
m_element[0] = (uint16_t)(std::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
m_element[1] = 0;
m_element[2] = 0;
}
template<> template<> Color<uint16_t,4>::Color(const Color<float, 1>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
m_element[0] = (uint16_t)(std::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
m_element[1] = 0;
m_element[2] = 0;
m_element[3] = defaultAlpha;
}
template<> template<> Color<uint16_t,1>::Color(const Color<float, 2>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
m_element[0] = (uint16_t)(std::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
}
template<> template<> Color<uint16_t,2>::Color(const Color<float, 2>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
m_element[1] = (uint16_t)(etk::avg(0.0f, _obj.g(), 1.0f)*65535.0f);
m_element[0] = (uint16_t)(std::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
m_element[1] = (uint16_t)(std::avg(0.0f, _obj.g(), 1.0f)*65535.0f);
}
template<> template<> Color<uint16_t,3>::Color(const Color<float, 2>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
m_element[1] = (uint16_t)(etk::avg(0.0f, _obj.g(), 1.0f)*65535.0f);
m_element[0] = (uint16_t)(std::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
m_element[1] = (uint16_t)(std::avg(0.0f, _obj.g(), 1.0f)*65535.0f);
m_element[2] = 0;
}
template<> template<> Color<uint16_t,4>::Color(const Color<float, 2>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
m_element[1] = (uint16_t)(etk::avg(0.0f, _obj.g(), 1.0f)*65535.0f);
m_element[0] = (uint16_t)(std::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
m_element[1] = (uint16_t)(std::avg(0.0f, _obj.g(), 1.0f)*65535.0f);
m_element[2] = 0;
m_element[3] = defaultAlpha;
}
template<> template<> Color<uint16_t,1>::Color(const Color<float, 3>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
m_element[0] = (uint16_t)(std::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
}
template<> template<> Color<uint16_t,2>::Color(const Color<float, 3>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
m_element[1] = (uint16_t)(etk::avg(0.0f, _obj.g(), 1.0f)*65535.0f);
m_element[0] = (uint16_t)(std::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
m_element[1] = (uint16_t)(std::avg(0.0f, _obj.g(), 1.0f)*65535.0f);
}
template<> template<> Color<uint16_t,3>::Color(const Color<float, 3>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
m_element[1] = (uint16_t)(etk::avg(0.0f, _obj.g(), 1.0f)*65535.0f);
m_element[2] = (uint16_t)(etk::avg(0.0f, _obj.b(), 1.0f)*65535.0f);
m_element[0] = (uint16_t)(std::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
m_element[1] = (uint16_t)(std::avg(0.0f, _obj.g(), 1.0f)*65535.0f);
m_element[2] = (uint16_t)(std::avg(0.0f, _obj.b(), 1.0f)*65535.0f);
}
template<> template<> Color<uint16_t,4>::Color(const Color<float, 3>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
m_element[1] = (uint16_t)(etk::avg(0.0f, _obj.g(), 1.0f)*65535.0f);
m_element[2] = (uint16_t)(etk::avg(0.0f, _obj.b(), 1.0f)*65535.0f);
m_element[0] = (uint16_t)(std::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
m_element[1] = (uint16_t)(std::avg(0.0f, _obj.g(), 1.0f)*65535.0f);
m_element[2] = (uint16_t)(std::avg(0.0f, _obj.b(), 1.0f)*65535.0f);
m_element[3] = defaultAlpha;
}
template<> template<> Color<uint16_t,1>::Color(const Color<float, 4>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
m_element[0] = (uint16_t)(std::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
}
template<> template<> Color<uint16_t,2>::Color(const Color<float, 4>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
m_element[1] = (uint16_t)(etk::avg(0.0f, _obj.g(), 1.0f)*65535.0f);
m_element[0] = (uint16_t)(std::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
m_element[1] = (uint16_t)(std::avg(0.0f, _obj.g(), 1.0f)*65535.0f);
}
template<> template<> Color<uint16_t,3>::Color(const Color<float, 4>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
m_element[1] = (uint16_t)(etk::avg(0.0f, _obj.g(), 1.0f)*65535.0f);
m_element[2] = (uint16_t)(etk::avg(0.0f, _obj.b(), 1.0f)*65535.0f);
m_element[0] = (uint16_t)(std::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
m_element[1] = (uint16_t)(std::avg(0.0f, _obj.g(), 1.0f)*65535.0f);
m_element[2] = (uint16_t)(std::avg(0.0f, _obj.b(), 1.0f)*65535.0f);
}
template<> template<> Color<uint16_t,4>::Color(const Color<float, 4>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
m_element[1] = (uint16_t)(etk::avg(0.0f, _obj.g(), 1.0f)*65535.0f);
m_element[2] = (uint16_t)(etk::avg(0.0f, _obj.b(), 1.0f)*65535.0f);
m_element[3] = (uint16_t)(etk::avg(0.0f, _obj.a(), 1.0f)*65535.0f);
m_element[0] = (uint16_t)(std::avg(0.0f, _obj.r(), 1.0f)*65535.0f);
m_element[1] = (uint16_t)(std::avg(0.0f, _obj.g(), 1.0f)*65535.0f);
m_element[2] = (uint16_t)(std::avg(0.0f, _obj.b(), 1.0f)*65535.0f);
m_element[3] = (uint16_t)(std::avg(0.0f, _obj.a(), 1.0f)*65535.0f);
}
// ===========================================================================================================
template<> template<> Color<uint16_t,1>::Color(const Color<double, 1>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0, _obj.r(), 1.0)*65535.0);
m_element[0] = (uint16_t)(std::avg(0.0, _obj.r(), 1.0)*65535.0);
}
template<> template<> Color<uint16_t,2>::Color(const Color<double, 1>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0, _obj.r(), 1.0)*65535.0);
m_element[0] = (uint16_t)(std::avg(0.0, _obj.r(), 1.0)*65535.0);
m_element[1] = 0;
}
template<> template<> Color<uint16_t,3>::Color(const Color<double, 1>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0, _obj.r(), 1.0)*65535.0);
m_element[0] = (uint16_t)(std::avg(0.0, _obj.r(), 1.0)*65535.0);
m_element[1] = 0;
m_element[2] = 0;
}
template<> template<> Color<uint16_t,4>::Color(const Color<double, 1>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0, _obj.r(), 1.0)*65535.0);
m_element[0] = (uint16_t)(std::avg(0.0, _obj.r(), 1.0)*65535.0);
m_element[1] = 0;
m_element[2] = 0;
m_element[3] = defaultAlpha;
}
template<> template<> Color<uint16_t,1>::Color(const Color<double, 2>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0, _obj.r(), 1.0)*65535.0);
m_element[0] = (uint16_t)(std::avg(0.0, _obj.r(), 1.0)*65535.0);
}
template<> template<> Color<uint16_t,2>::Color(const Color<double, 2>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0, _obj.r(), 1.0)*65535.0);
m_element[1] = (uint16_t)(etk::avg(0.0, _obj.g(), 1.0)*65535.0);
m_element[0] = (uint16_t)(std::avg(0.0, _obj.r(), 1.0)*65535.0);
m_element[1] = (uint16_t)(std::avg(0.0, _obj.g(), 1.0)*65535.0);
}
template<> template<> Color<uint16_t,3>::Color(const Color<double, 2>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0, _obj.r(), 1.0)*65535.0);
m_element[1] = (uint16_t)(etk::avg(0.0, _obj.g(), 1.0)*65535.0);
m_element[0] = (uint16_t)(std::avg(0.0, _obj.r(), 1.0)*65535.0);
m_element[1] = (uint16_t)(std::avg(0.0, _obj.g(), 1.0)*65535.0);
m_element[2] = 0;
}
template<> template<> Color<uint16_t,4>::Color(const Color<double, 2>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0, _obj.r(), 1.0)*65535.0);
m_element[1] = (uint16_t)(etk::avg(0.0, _obj.g(), 1.0)*65535.0);
m_element[0] = (uint16_t)(std::avg(0.0, _obj.r(), 1.0)*65535.0);
m_element[1] = (uint16_t)(std::avg(0.0, _obj.g(), 1.0)*65535.0);
m_element[2] = 0;
m_element[3] = defaultAlpha;
}
template<> template<> Color<uint16_t,1>::Color(const Color<double, 3>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0, _obj.r(), 1.0)*65535.0);
m_element[0] = (uint16_t)(std::avg(0.0, _obj.r(), 1.0)*65535.0);
}
template<> template<> Color<uint16_t,2>::Color(const Color<double, 3>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0, _obj.r(), 1.0)*65535.0);
m_element[1] = (uint16_t)(etk::avg(0.0, _obj.g(), 1.0)*65535.0);
m_element[0] = (uint16_t)(std::avg(0.0, _obj.r(), 1.0)*65535.0);
m_element[1] = (uint16_t)(std::avg(0.0, _obj.g(), 1.0)*65535.0);
}
template<> template<> Color<uint16_t,3>::Color(const Color<double, 3>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0, _obj.r(), 1.0)*65535.0);
m_element[1] = (uint16_t)(etk::avg(0.0, _obj.g(), 1.0)*65535.0);
m_element[2] = (uint16_t)(etk::avg(0.0, _obj.b(), 1.0)*65535.0);
m_element[0] = (uint16_t)(std::avg(0.0, _obj.r(), 1.0)*65535.0);
m_element[1] = (uint16_t)(std::avg(0.0, _obj.g(), 1.0)*65535.0);
m_element[2] = (uint16_t)(std::avg(0.0, _obj.b(), 1.0)*65535.0);
}
template<> template<> Color<uint16_t,4>::Color(const Color<double, 3>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0, _obj.r(), 1.0)*65535.0);
m_element[1] = (uint16_t)(etk::avg(0.0, _obj.g(), 1.0)*65535.0);
m_element[2] = (uint16_t)(etk::avg(0.0, _obj.b(), 1.0)*65535.0);
m_element[0] = (uint16_t)(std::avg(0.0, _obj.r(), 1.0)*65535.0);
m_element[1] = (uint16_t)(std::avg(0.0, _obj.g(), 1.0)*65535.0);
m_element[2] = (uint16_t)(std::avg(0.0, _obj.b(), 1.0)*65535.0);
m_element[3] = defaultAlpha;
}
template<> template<> Color<uint16_t,1>::Color(const Color<double, 4>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0, _obj.r(), 1.0)*65535.0);
m_element[0] = (uint16_t)(std::avg(0.0, _obj.r(), 1.0)*65535.0);
}
template<> template<> Color<uint16_t,2>::Color(const Color<double, 4>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0, _obj.r(), 1.0)*65535.0);
m_element[1] = (uint16_t)(etk::avg(0.0, _obj.g(), 1.0)*65535.0);
m_element[0] = (uint16_t)(std::avg(0.0, _obj.r(), 1.0)*65535.0);
m_element[1] = (uint16_t)(std::avg(0.0, _obj.g(), 1.0)*65535.0);
}
template<> template<> Color<uint16_t,3>::Color(const Color<double, 4>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0, _obj.r(), 1.0)*65535.0);
m_element[1] = (uint16_t)(etk::avg(0.0, _obj.g(), 1.0)*65535.0);
m_element[2] = (uint16_t)(etk::avg(0.0, _obj.b(), 1.0)*65535.0);
m_element[0] = (uint16_t)(std::avg(0.0, _obj.r(), 1.0)*65535.0);
m_element[1] = (uint16_t)(std::avg(0.0, _obj.g(), 1.0)*65535.0);
m_element[2] = (uint16_t)(std::avg(0.0, _obj.b(), 1.0)*65535.0);
}
template<> template<> Color<uint16_t,4>::Color(const Color<double, 4>& _obj) {
m_element[0] = (uint16_t)(etk::avg(0.0, _obj.r(), 1.0)*65535.0);
m_element[1] = (uint16_t)(etk::avg(0.0, _obj.g(), 1.0)*65535.0);
m_element[2] = (uint16_t)(etk::avg(0.0, _obj.b(), 1.0)*65535.0);
m_element[3] = (uint16_t)(etk::avg(0.0, _obj.a(), 1.0)*65535.0);
m_element[0] = (uint16_t)(std::avg(0.0, _obj.r(), 1.0)*65535.0);
m_element[1] = (uint16_t)(std::avg(0.0, _obj.g(), 1.0)*65535.0);
m_element[2] = (uint16_t)(std::avg(0.0, _obj.b(), 1.0)*65535.0);
m_element[3] = (uint16_t)(std::avg(0.0, _obj.a(), 1.0)*65535.0);
}
// ===========================================================================================================
template<> etk::String toString<Color<uint16_t, 1> >(const Color<uint16_t, 1>& _val) {
template<> std::string to_string<Color<uint16_t, 1> >(const Color<uint16_t, 1>& _val) {
return _val.getString();
}
#if __cplusplus >= 201103L
template<> etk::UString toUString<Color<uint16_t, 1>>(const Color<uint16_t, 1>& _val) {
return toUString(_val.getString());
template<> std::u32string to_u32string<Color<uint16_t, 1>>(const Color<uint16_t, 1>& _val) {
return to_u32string(_val.getString());
}
template<> bool from_string<Color<uint16_t, 1>>(Color<uint16_t, 1>& _variableRet, const etk::UString& _value) {
_variableRet = Color<uint16_t, 1>(toString(_value));
template<> bool from_string<Color<uint16_t, 1>>(Color<uint16_t, 1>& _variableRet, const std::u32string& _value) {
_variableRet = Color<uint16_t, 1>(to_string(_value));
return true;
}
#endif
template<> bool from_string<Color<uint16_t, 1> >(Color<uint16_t, 1>& _variableRet, const etk::String& _value) {
template<> bool from_string<Color<uint16_t, 1> >(Color<uint16_t, 1>& _variableRet, const std::string& _value) {
_variableRet = Color<uint16_t, 1>(_value);
return true;
}
template<> etk::String toString<Color<uint16_t, 2> >(const Color<uint16_t, 2>& _val) {
template<> std::string to_string<Color<uint16_t, 2> >(const Color<uint16_t, 2>& _val) {
return _val.getString();
}
#if __cplusplus >= 201103L
template<> etk::UString toUString<Color<uint16_t, 2>>(const Color<uint16_t, 2>& _val) {
return toUString(_val.getString());
template<> std::u32string to_u32string<Color<uint16_t, 2>>(const Color<uint16_t, 2>& _val) {
return to_u32string(_val.getString());
}
template<> bool from_string<Color<uint16_t, 2>>(Color<uint16_t, 2>& _variableRet, const etk::UString& _value) {
_variableRet = Color<uint16_t, 2>(toString(_value));
template<> bool from_string<Color<uint16_t, 2>>(Color<uint16_t, 2>& _variableRet, const std::u32string& _value) {
_variableRet = Color<uint16_t, 2>(to_string(_value));
return true;
}
#endif
template<> bool from_string<Color<uint16_t, 2> >(Color<uint16_t, 2>& _variableRet, const etk::String& _value) {
template<> bool from_string<Color<uint16_t, 2> >(Color<uint16_t, 2>& _variableRet, const std::string& _value) {
_variableRet = Color<uint16_t, 2>(_value);
return true;
}
template<> etk::String toString<Color<uint16_t, 3> >(const Color<uint16_t, 3>& _val) {
template<> std::string to_string<Color<uint16_t, 3> >(const Color<uint16_t, 3>& _val) {
return _val.getString();
}
#if __cplusplus >= 201103L
template<> etk::UString toUString<Color<uint16_t, 3>>(const Color<uint16_t, 3>& _val) {
return toUString(_val.getString());
template<> std::u32string to_u32string<Color<uint16_t, 3>>(const Color<uint16_t, 3>& _val) {
return to_u32string(_val.getString());
}
template<> bool from_string<Color<uint16_t, 3>>(Color<uint16_t, 3>& _variableRet, const etk::UString& _value) {
_variableRet = Color<uint16_t, 3>(toString(_value));
template<> bool from_string<Color<uint16_t, 3>>(Color<uint16_t, 3>& _variableRet, const std::u32string& _value) {
_variableRet = Color<uint16_t, 3>(to_string(_value));
return true;
}
#endif
template<> bool from_string<Color<uint16_t, 3> >(Color<uint16_t, 3>& _variableRet, const etk::String& _value) {
template<> bool from_string<Color<uint16_t, 3> >(Color<uint16_t, 3>& _variableRet, const std::string& _value) {
_variableRet = Color<uint16_t, 3>(_value);
return true;
}
template<> etk::String toString<Color<uint16_t, 4> >(const Color<uint16_t, 4>& _val) {
template<> std::string to_string<Color<uint16_t, 4> >(const Color<uint16_t, 4>& _val) {
return _val.getString();
}
#if __cplusplus >= 201103L
template<> etk::UString toUString<Color<uint16_t, 4>>(const Color<uint16_t, 4>& _val) {
return toUString(_val.getString());
template<> std::u32string to_u32string<Color<uint16_t, 4>>(const Color<uint16_t, 4>& _val) {
return to_u32string(_val.getString());
}
template<> bool from_string<Color<uint16_t, 4>>(Color<uint16_t, 4>& _variableRet, const etk::UString& _value) {
_variableRet = Color<uint16_t, 4>(toString(_value));
template<> bool from_string<Color<uint16_t, 4>>(Color<uint16_t, 4>& _variableRet, const std::u32string& _value) {
_variableRet = Color<uint16_t, 4>(to_string(_value));
return true;
}
#endif
template<> bool from_string<Color<uint16_t, 4> >(Color<uint16_t, 4>& _variableRet, const etk::String& _value) {
template<> bool from_string<Color<uint16_t, 4> >(Color<uint16_t, 4>& _variableRet, const std::string& _value) {
_variableRet = Color<uint16_t, 4>(_value);
return true;
}

View File

@ -235,224 +235,224 @@ template<> template<> Color<uint32_t,4>::Color(const Color<uint32_t, 4>& _obj) {
// ===========================================================================================================
template<> template<> Color<uint32_t,1>::Color(const Color<float, 1>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
m_element[0] = (uint32_t)(std::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
}
template<> template<> Color<uint32_t,2>::Color(const Color<float, 1>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
m_element[0] = (uint32_t)(std::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
m_element[1] = 0;
}
template<> template<> Color<uint32_t,3>::Color(const Color<float, 1>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
m_element[0] = (uint32_t)(std::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
m_element[1] = 0;
m_element[2] = 0;
}
template<> template<> Color<uint32_t,4>::Color(const Color<float, 1>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
m_element[0] = (uint32_t)(std::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
m_element[1] = 0;
m_element[2] = 0;
m_element[3] = defaultAlpha;
}
template<> template<> Color<uint32_t,1>::Color(const Color<float, 2>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
m_element[0] = (uint32_t)(std::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
}
template<> template<> Color<uint32_t,2>::Color(const Color<float, 2>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
m_element[1] = (uint32_t)(etk::avg(0.0f, _obj.g(), 1.0f)*4294967295.0f);
m_element[0] = (uint32_t)(std::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
m_element[1] = (uint32_t)(std::avg(0.0f, _obj.g(), 1.0f)*4294967295.0f);
}
template<> template<> Color<uint32_t,3>::Color(const Color<float, 2>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
m_element[1] = (uint32_t)(etk::avg(0.0f, _obj.g(), 1.0f)*4294967295.0f);
m_element[0] = (uint32_t)(std::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
m_element[1] = (uint32_t)(std::avg(0.0f, _obj.g(), 1.0f)*4294967295.0f);
m_element[2] = 0;
}
template<> template<> Color<uint32_t,4>::Color(const Color<float, 2>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
m_element[1] = (uint32_t)(etk::avg(0.0f, _obj.g(), 1.0f)*4294967295.0f);
m_element[0] = (uint32_t)(std::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
m_element[1] = (uint32_t)(std::avg(0.0f, _obj.g(), 1.0f)*4294967295.0f);
m_element[2] = 0;
m_element[3] = defaultAlpha;
}
template<> template<> Color<uint32_t,1>::Color(const Color<float, 3>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
m_element[0] = (uint32_t)(std::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
}
template<> template<> Color<uint32_t,2>::Color(const Color<float, 3>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
m_element[1] = (uint32_t)(etk::avg(0.0f, _obj.g(), 1.0f)*4294967295.0f);
m_element[0] = (uint32_t)(std::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
m_element[1] = (uint32_t)(std::avg(0.0f, _obj.g(), 1.0f)*4294967295.0f);
}
template<> template<> Color<uint32_t,3>::Color(const Color<float, 3>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
m_element[1] = (uint32_t)(etk::avg(0.0f, _obj.g(), 1.0f)*4294967295.0f);
m_element[2] = (uint32_t)(etk::avg(0.0f, _obj.b(), 1.0f)*4294967295.0f);
m_element[0] = (uint32_t)(std::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
m_element[1] = (uint32_t)(std::avg(0.0f, _obj.g(), 1.0f)*4294967295.0f);
m_element[2] = (uint32_t)(std::avg(0.0f, _obj.b(), 1.0f)*4294967295.0f);
}
template<> template<> Color<uint32_t,4>::Color(const Color<float, 3>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
m_element[1] = (uint32_t)(etk::avg(0.0f, _obj.g(), 1.0f)*4294967295.0f);
m_element[2] = (uint32_t)(etk::avg(0.0f, _obj.b(), 1.0f)*4294967295.0f);
m_element[0] = (uint32_t)(std::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
m_element[1] = (uint32_t)(std::avg(0.0f, _obj.g(), 1.0f)*4294967295.0f);
m_element[2] = (uint32_t)(std::avg(0.0f, _obj.b(), 1.0f)*4294967295.0f);
m_element[3] = defaultAlpha;
}
template<> template<> Color<uint32_t,1>::Color(const Color<float, 4>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
m_element[0] = (uint32_t)(std::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
}
template<> template<> Color<uint32_t,2>::Color(const Color<float, 4>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
m_element[1] = (uint32_t)(etk::avg(0.0f, _obj.g(), 1.0f)*4294967295.0f);
m_element[0] = (uint32_t)(std::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
m_element[1] = (uint32_t)(std::avg(0.0f, _obj.g(), 1.0f)*4294967295.0f);
}
template<> template<> Color<uint32_t,3>::Color(const Color<float, 4>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
m_element[1] = (uint32_t)(etk::avg(0.0f, _obj.g(), 1.0f)*4294967295.0f);
m_element[2] = (uint32_t)(etk::avg(0.0f, _obj.b(), 1.0f)*4294967295.0f);
m_element[0] = (uint32_t)(std::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
m_element[1] = (uint32_t)(std::avg(0.0f, _obj.g(), 1.0f)*4294967295.0f);
m_element[2] = (uint32_t)(std::avg(0.0f, _obj.b(), 1.0f)*4294967295.0f);
}
template<> template<> Color<uint32_t,4>::Color(const Color<float, 4>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
m_element[1] = (uint32_t)(etk::avg(0.0f, _obj.g(), 1.0f)*4294967295.0f);
m_element[2] = (uint32_t)(etk::avg(0.0f, _obj.b(), 1.0f)*4294967295.0f);
m_element[3] = (uint32_t)(etk::avg(0.0f, _obj.a(), 1.0f)*4294967295.0f);
m_element[0] = (uint32_t)(std::avg(0.0f, _obj.r(), 1.0f)*4294967295.0f);
m_element[1] = (uint32_t)(std::avg(0.0f, _obj.g(), 1.0f)*4294967295.0f);
m_element[2] = (uint32_t)(std::avg(0.0f, _obj.b(), 1.0f)*4294967295.0f);
m_element[3] = (uint32_t)(std::avg(0.0f, _obj.a(), 1.0f)*4294967295.0f);
}
// ===========================================================================================================
template<> template<> Color<uint32_t,1>::Color(const Color<double, 1>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0, _obj.r(), 1.0)*4294967295.0);
m_element[0] = (uint32_t)(std::avg(0.0, _obj.r(), 1.0)*4294967295.0);
}
template<> template<> Color<uint32_t,2>::Color(const Color<double, 1>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0, _obj.r(), 1.0)*4294967295.0);
m_element[0] = (uint32_t)(std::avg(0.0, _obj.r(), 1.0)*4294967295.0);
m_element[1] = 0;
}
template<> template<> Color<uint32_t,3>::Color(const Color<double, 1>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0, _obj.r(), 1.0)*4294967295.0);
m_element[0] = (uint32_t)(std::avg(0.0, _obj.r(), 1.0)*4294967295.0);
m_element[1] = 0;
m_element[2] = 0;
}
template<> template<> Color<uint32_t,4>::Color(const Color<double, 1>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0, _obj.r(), 1.0)*4294967295.0);
m_element[0] = (uint32_t)(std::avg(0.0, _obj.r(), 1.0)*4294967295.0);
m_element[1] = 0;
m_element[2] = 0;
m_element[3] = 0xFFFFFF;
}
template<> template<> Color<uint32_t,1>::Color(const Color<double, 2>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0, _obj.r(), 1.0)*4294967295.0);
m_element[0] = (uint32_t)(std::avg(0.0, _obj.r(), 1.0)*4294967295.0);
}
template<> template<> Color<uint32_t,2>::Color(const Color<double, 2>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0, _obj.r(), 1.0)*4294967295.0);
m_element[1] = (uint32_t)(etk::avg(0.0, _obj.g(), 1.0)*4294967295.0);
m_element[0] = (uint32_t)(std::avg(0.0, _obj.r(), 1.0)*4294967295.0);
m_element[1] = (uint32_t)(std::avg(0.0, _obj.g(), 1.0)*4294967295.0);
}
template<> template<> Color<uint32_t,3>::Color(const Color<double, 2>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0, _obj.r(), 1.0)*4294967295.0);
m_element[1] = (uint32_t)(etk::avg(0.0, _obj.g(), 1.0)*4294967295.0);
m_element[0] = (uint32_t)(std::avg(0.0, _obj.r(), 1.0)*4294967295.0);
m_element[1] = (uint32_t)(std::avg(0.0, _obj.g(), 1.0)*4294967295.0);
m_element[2] = 0;
}
template<> template<> Color<uint32_t,4>::Color(const Color<double, 2>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0, _obj.r(), 1.0)*4294967295.0);
m_element[1] = (uint32_t)(etk::avg(0.0, _obj.g(), 1.0)*4294967295.0);
m_element[0] = (uint32_t)(std::avg(0.0, _obj.r(), 1.0)*4294967295.0);
m_element[1] = (uint32_t)(std::avg(0.0, _obj.g(), 1.0)*4294967295.0);
m_element[2] = 0;
m_element[3] = 0xFFFFFF;
}
template<> template<> Color<uint32_t,1>::Color(const Color<double, 3>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0, _obj.r(), 1.0)*4294967295.0);
m_element[0] = (uint32_t)(std::avg(0.0, _obj.r(), 1.0)*4294967295.0);
}
template<> template<> Color<uint32_t,2>::Color(const Color<double, 3>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0, _obj.r(), 1.0)*4294967295.0);
m_element[1] = (uint32_t)(etk::avg(0.0, _obj.g(), 1.0)*4294967295.0);
m_element[0] = (uint32_t)(std::avg(0.0, _obj.r(), 1.0)*4294967295.0);
m_element[1] = (uint32_t)(std::avg(0.0, _obj.g(), 1.0)*4294967295.0);
}
template<> template<> Color<uint32_t,3>::Color(const Color<double, 3>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0, _obj.r(), 1.0)*4294967295.0);
m_element[1] = (uint32_t)(etk::avg(0.0, _obj.g(), 1.0)*4294967295.0);
m_element[2] = (uint32_t)(etk::avg(0.0, _obj.b(), 1.0)*4294967295.0);
m_element[0] = (uint32_t)(std::avg(0.0, _obj.r(), 1.0)*4294967295.0);
m_element[1] = (uint32_t)(std::avg(0.0, _obj.g(), 1.0)*4294967295.0);
m_element[2] = (uint32_t)(std::avg(0.0, _obj.b(), 1.0)*4294967295.0);
}
template<> template<> Color<uint32_t,4>::Color(const Color<double, 3>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0, _obj.r(), 1.0)*4294967295.0);
m_element[1] = (uint32_t)(etk::avg(0.0, _obj.g(), 1.0)*4294967295.0);
m_element[2] = (uint32_t)(etk::avg(0.0, _obj.b(), 1.0)*4294967295.0);
m_element[0] = (uint32_t)(std::avg(0.0, _obj.r(), 1.0)*4294967295.0);
m_element[1] = (uint32_t)(std::avg(0.0, _obj.g(), 1.0)*4294967295.0);
m_element[2] = (uint32_t)(std::avg(0.0, _obj.b(), 1.0)*4294967295.0);
m_element[3] = 0xFFFFFF;
}
template<> template<> Color<uint32_t,1>::Color(const Color<double, 4>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0, _obj.r(), 1.0)*4294967295.0);
m_element[0] = (uint32_t)(std::avg(0.0, _obj.r(), 1.0)*4294967295.0);
}
template<> template<> Color<uint32_t,2>::Color(const Color<double, 4>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0, _obj.r(), 1.0)*4294967295.0);
m_element[1] = (uint32_t)(etk::avg(0.0, _obj.g(), 1.0)*4294967295.0);
m_element[0] = (uint32_t)(std::avg(0.0, _obj.r(), 1.0)*4294967295.0);
m_element[1] = (uint32_t)(std::avg(0.0, _obj.g(), 1.0)*4294967295.0);
}
template<> template<> Color<uint32_t,3>::Color(const Color<double, 4>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0, _obj.r(), 1.0)*4294967295.0);
m_element[1] = (uint32_t)(etk::avg(0.0, _obj.g(), 1.0)*4294967295.0);
m_element[2] = (uint32_t)(etk::avg(0.0, _obj.b(), 1.0)*4294967295.0);
m_element[0] = (uint32_t)(std::avg(0.0, _obj.r(), 1.0)*4294967295.0);
m_element[1] = (uint32_t)(std::avg(0.0, _obj.g(), 1.0)*4294967295.0);
m_element[2] = (uint32_t)(std::avg(0.0, _obj.b(), 1.0)*4294967295.0);
}
template<> template<> Color<uint32_t,4>::Color(const Color<double, 4>& _obj) {
m_element[0] = (uint32_t)(etk::avg(0.0, _obj.r(), 1.0)*4294967295.0);
m_element[1] = (uint32_t)(etk::avg(0.0, _obj.g(), 1.0)*4294967295.0);
m_element[2] = (uint32_t)(etk::avg(0.0, _obj.b(), 1.0)*4294967295.0);
m_element[3] = (uint32_t)(etk::avg(0.0, _obj.a(), 1.0)*4294967295.0);
m_element[0] = (uint32_t)(std::avg(0.0, _obj.r(), 1.0)*4294967295.0);
m_element[1] = (uint32_t)(std::avg(0.0, _obj.g(), 1.0)*4294967295.0);
m_element[2] = (uint32_t)(std::avg(0.0, _obj.b(), 1.0)*4294967295.0);
m_element[3] = (uint32_t)(std::avg(0.0, _obj.a(), 1.0)*4294967295.0);
}
// ===========================================================================================================
template<> etk::String toString<Color<uint32_t, 1> >(const Color<uint32_t, 1>& _val) {
template<> std::string to_string<Color<uint32_t, 1> >(const Color<uint32_t, 1>& _val) {
return _val.getString();
}
#if __cplusplus >= 201103L
template<> etk::UString toUString<Color<uint32_t, 1>>(const Color<uint32_t, 1>& _val) {
return toUString(_val.getString());
template<> std::u32string to_u32string<Color<uint32_t, 1>>(const Color<uint32_t, 1>& _val) {
return to_u32string(_val.getString());
}
template<> bool from_string<Color<uint32_t, 1>>(Color<uint32_t, 1>& _variableRet, const etk::UString& _value) {
_variableRet = Color<uint32_t, 1>(toString(_value));
template<> bool from_string<Color<uint32_t, 1>>(Color<uint32_t, 1>& _variableRet, const std::u32string& _value) {
_variableRet = Color<uint32_t, 1>(to_string(_value));
return true;
}
#endif
template<> bool from_string<Color<uint32_t, 1> >(Color<uint32_t, 1>& _variableRet, const etk::String& _value) {
template<> bool from_string<Color<uint32_t, 1> >(Color<uint32_t, 1>& _variableRet, const std::string& _value) {
_variableRet = Color<uint32_t, 1>(_value);
return true;
}
template<> etk::String toString<Color<uint32_t, 2> >(const Color<uint32_t, 2>& _val) {
template<> std::string to_string<Color<uint32_t, 2> >(const Color<uint32_t, 2>& _val) {
return _val.getString();
}
#if __cplusplus >= 201103L
template<> etk::UString toUString<Color<uint32_t, 2>>(const Color<uint32_t, 2>& _val) {
return toUString(_val.getString());
template<> std::u32string to_u32string<Color<uint32_t, 2>>(const Color<uint32_t, 2>& _val) {
return to_u32string(_val.getString());
}
template<> bool from_string<Color<uint32_t, 2>>(Color<uint32_t, 2>& _variableRet, const etk::UString& _value) {
_variableRet = Color<uint32_t, 2>(toString(_value));
template<> bool from_string<Color<uint32_t, 2>>(Color<uint32_t, 2>& _variableRet, const std::u32string& _value) {
_variableRet = Color<uint32_t, 2>(to_string(_value));
return true;
}
#endif
template<> bool from_string<Color<uint32_t, 2> >(Color<uint32_t, 2>& _variableRet, const etk::String& _value) {
template<> bool from_string<Color<uint32_t, 2> >(Color<uint32_t, 2>& _variableRet, const std::string& _value) {
_variableRet = Color<uint32_t, 2>(_value);
return true;
}
template<> etk::String toString<Color<uint32_t, 3> >(const Color<uint32_t, 3>& _val) {
template<> std::string to_string<Color<uint32_t, 3> >(const Color<uint32_t, 3>& _val) {
return _val.getString();
}
#if __cplusplus >= 201103L
template<> etk::UString toUString<Color<uint32_t, 3>>(const Color<uint32_t, 3>& _val) {
return toUString(_val.getString());
template<> std::u32string to_u32string<Color<uint32_t, 3>>(const Color<uint32_t, 3>& _val) {
return to_u32string(_val.getString());
}
template<> bool from_string<Color<uint32_t, 3>>(Color<uint32_t, 3>& _variableRet, const etk::UString& _value) {
_variableRet = Color<uint32_t, 3>(toString(_value));
template<> bool from_string<Color<uint32_t, 3>>(Color<uint32_t, 3>& _variableRet, const std::u32string& _value) {
_variableRet = Color<uint32_t, 3>(to_string(_value));
return true;
}
#endif
template<> bool from_string<Color<uint32_t, 3> >(Color<uint32_t, 3>& _variableRet, const etk::String& _value) {
template<> bool from_string<Color<uint32_t, 3> >(Color<uint32_t, 3>& _variableRet, const std::string& _value) {
_variableRet = Color<uint32_t, 3>(_value);
return true;
}
template<> etk::String toString<Color<uint32_t, 4> >(const Color<uint32_t, 4>& _val) {
template<> std::string to_string<Color<uint32_t, 4> >(const Color<uint32_t, 4>& _val) {
return _val.getString();
}
#if __cplusplus >= 201103L
template<> etk::UString toUString<Color<uint32_t, 4>>(const Color<uint32_t, 4>& _val) {
return toUString(_val.getString());
template<> std::u32string to_u32string<Color<uint32_t, 4>>(const Color<uint32_t, 4>& _val) {
return to_u32string(_val.getString());
}
template<> bool from_string<Color<uint32_t, 4>>(Color<uint32_t, 4>& _variableRet, const etk::UString& _value) {
_variableRet = Color<uint32_t, 4>(toString(_value));
template<> bool from_string<Color<uint32_t, 4>>(Color<uint32_t, 4>& _variableRet, const std::u32string& _value) {
_variableRet = Color<uint32_t, 4>(to_string(_value));
return true;
}
#endif
template<> bool from_string<Color<uint32_t, 4> >(Color<uint32_t, 4>& _variableRet, const etk::String& _value) {
template<> bool from_string<Color<uint32_t, 4> >(Color<uint32_t, 4>& _variableRet, const std::string& _value) {
_variableRet = Color<uint32_t, 4>(_value);
return true;
}

View File

@ -235,168 +235,168 @@ template<> template<> Color<uint8_t,4>::Color(const Color<uint32_t, 4>& _obj) {
// ===========================================================================================================
template<> template<> Color<uint8_t,1>::Color(const Color<float, 1>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0f, _obj.r(), 1.0f)*255.0f);
m_element[0] = (uint8_t)(std::avg(0.0f, _obj.r(), 1.0f)*255.0f);
}
template<> template<> Color<uint8_t,2>::Color(const Color<float, 1>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0f, _obj.r(), 1.0f)*255.0f);
m_element[0] = (uint8_t)(std::avg(0.0f, _obj.r(), 1.0f)*255.0f);
m_element[1] = 0;
}
template<> template<> Color<uint8_t,3>::Color(const Color<float, 1>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0f, _obj.r(), 1.0f)*255.0f);
m_element[0] = (uint8_t)(std::avg(0.0f, _obj.r(), 1.0f)*255.0f);
m_element[1] = 0;
m_element[2] = 0;
}
template<> template<> Color<uint8_t,4>::Color(const Color<float, 1>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0f, _obj.r(), 1.0f)*255.0f);
m_element[0] = (uint8_t)(std::avg(0.0f, _obj.r(), 1.0f)*255.0f);
m_element[1] = 0;
m_element[2] = 0;
m_element[3] = defaultAlpha;
}
template<> template<> Color<uint8_t,1>::Color(const Color<float, 2>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0f, _obj.r(), 1.0f)*255.0f);
m_element[0] = (uint8_t)(std::avg(0.0f, _obj.r(), 1.0f)*255.0f);
}
template<> template<> Color<uint8_t,2>::Color(const Color<float, 2>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0f, _obj.r(), 1.0f)*255.0f);
m_element[1] = (uint8_t)(etk::avg(0.0f, _obj.g(), 1.0f)*255.0f);
m_element[0] = (uint8_t)(std::avg(0.0f, _obj.r(), 1.0f)*255.0f);
m_element[1] = (uint8_t)(std::avg(0.0f, _obj.g(), 1.0f)*255.0f);
}
template<> template<> Color<uint8_t,3>::Color(const Color<float, 2>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0f, _obj.r(), 1.0f)*255.0f);
m_element[1] = (uint8_t)(etk::avg(0.0f, _obj.g(), 1.0f)*255.0f);
m_element[0] = (uint8_t)(std::avg(0.0f, _obj.r(), 1.0f)*255.0f);
m_element[1] = (uint8_t)(std::avg(0.0f, _obj.g(), 1.0f)*255.0f);
m_element[2] = 0;
}
template<> template<> Color<uint8_t,4>::Color(const Color<float, 2>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0f, _obj.r(), 1.0f)*255.0f);
m_element[1] = (uint8_t)(etk::avg(0.0f, _obj.g(), 1.0f)*255.0f);
m_element[0] = (uint8_t)(std::avg(0.0f, _obj.r(), 1.0f)*255.0f);
m_element[1] = (uint8_t)(std::avg(0.0f, _obj.g(), 1.0f)*255.0f);
m_element[2] = 0;
m_element[3] = defaultAlpha;
}
template<> template<> Color<uint8_t,1>::Color(const Color<float, 3>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0f, _obj.r(), 1.0f)*255.0f);
m_element[0] = (uint8_t)(std::avg(0.0f, _obj.r(), 1.0f)*255.0f);
}
template<> template<> Color<uint8_t,2>::Color(const Color<float, 3>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0f, _obj.r(), 1.0f)*255.0f);
m_element[1] = (uint8_t)(etk::avg(0.0f, _obj.g(), 1.0f)*255.0f);
m_element[0] = (uint8_t)(std::avg(0.0f, _obj.r(), 1.0f)*255.0f);
m_element[1] = (uint8_t)(std::avg(0.0f, _obj.g(), 1.0f)*255.0f);
}
template<> template<> Color<uint8_t,3>::Color(const Color<float, 3>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0f, _obj.r(), 1.0f)*255.0f);
m_element[1] = (uint8_t)(etk::avg(0.0f, _obj.g(), 1.0f)*255.0f);
m_element[2] = (uint8_t)(etk::avg(0.0f, _obj.b(), 1.0f)*255.0f);
m_element[0] = (uint8_t)(std::avg(0.0f, _obj.r(), 1.0f)*255.0f);
m_element[1] = (uint8_t)(std::avg(0.0f, _obj.g(), 1.0f)*255.0f);
m_element[2] = (uint8_t)(std::avg(0.0f, _obj.b(), 1.0f)*255.0f);
}
template<> template<> Color<uint8_t,4>::Color(const Color<float, 3>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0f, _obj.r(), 1.0f)*255.0f);
m_element[1] = (uint8_t)(etk::avg(0.0f, _obj.g(), 1.0f)*255.0f);
m_element[2] = (uint8_t)(etk::avg(0.0f, _obj.b(), 1.0f)*255.0f);
m_element[0] = (uint8_t)(std::avg(0.0f, _obj.r(), 1.0f)*255.0f);
m_element[1] = (uint8_t)(std::avg(0.0f, _obj.g(), 1.0f)*255.0f);
m_element[2] = (uint8_t)(std::avg(0.0f, _obj.b(), 1.0f)*255.0f);
m_element[3] = defaultAlpha;
}
template<> template<> Color<uint8_t,1>::Color(const Color<float, 4>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0f, _obj.r(), 1.0f)*255.0f);
m_element[0] = (uint8_t)(std::avg(0.0f, _obj.r(), 1.0f)*255.0f);
}
template<> template<> Color<uint8_t,2>::Color(const Color<float, 4>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0f, _obj.r(), 1.0f)*255.0f);
m_element[1] = (uint8_t)(etk::avg(0.0f, _obj.g(), 1.0f)*255.0f);
m_element[0] = (uint8_t)(std::avg(0.0f, _obj.r(), 1.0f)*255.0f);
m_element[1] = (uint8_t)(std::avg(0.0f, _obj.g(), 1.0f)*255.0f);
}
template<> template<> Color<uint8_t,3>::Color(const Color<float, 4>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0f, _obj.r(), 1.0f)*255.0f);
m_element[1] = (uint8_t)(etk::avg(0.0f, _obj.g(), 1.0f)*255.0f);
m_element[2] = (uint8_t)(etk::avg(0.0f, _obj.b(), 1.0f)*255.0f);
m_element[0] = (uint8_t)(std::avg(0.0f, _obj.r(), 1.0f)*255.0f);
m_element[1] = (uint8_t)(std::avg(0.0f, _obj.g(), 1.0f)*255.0f);
m_element[2] = (uint8_t)(std::avg(0.0f, _obj.b(), 1.0f)*255.0f);
}
template<> template<> Color<uint8_t,4>::Color(const Color<float, 4>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0f, _obj.r(), 1.0f)*255.0f);
m_element[1] = (uint8_t)(etk::avg(0.0f, _obj.g(), 1.0f)*255.0f);
m_element[2] = (uint8_t)(etk::avg(0.0f, _obj.b(), 1.0f)*255.0f);
m_element[3] = (uint8_t)(etk::avg(0.0f, _obj.a(), 1.0f)*255.0f);
m_element[0] = (uint8_t)(std::avg(0.0f, _obj.r(), 1.0f)*255.0f);
m_element[1] = (uint8_t)(std::avg(0.0f, _obj.g(), 1.0f)*255.0f);
m_element[2] = (uint8_t)(std::avg(0.0f, _obj.b(), 1.0f)*255.0f);
m_element[3] = (uint8_t)(std::avg(0.0f, _obj.a(), 1.0f)*255.0f);
}
// ===========================================================================================================
template<> template<> Color<uint8_t,1>::Color(const Color<double, 1>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0, _obj.r(), 1.0)*255.0);
m_element[0] = (uint8_t)(std::avg(0.0, _obj.r(), 1.0)*255.0);
}
template<> template<> Color<uint8_t,2>::Color(const Color<double, 1>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0, _obj.r(), 1.0)*255.0);
m_element[0] = (uint8_t)(std::avg(0.0, _obj.r(), 1.0)*255.0);
m_element[1] = 0;
}
template<> template<> Color<uint8_t,3>::Color(const Color<double, 1>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0, _obj.r(), 1.0)*255.0);
m_element[0] = (uint8_t)(std::avg(0.0, _obj.r(), 1.0)*255.0);
m_element[1] = 0;
m_element[2] = 0;
}
template<> template<> Color<uint8_t,4>::Color(const Color<double, 1>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0, _obj.r(), 1.0)*255.0);
m_element[0] = (uint8_t)(std::avg(0.0, _obj.r(), 1.0)*255.0);
m_element[1] = 0;
m_element[2] = 0;
m_element[3] = defaultAlpha;
}
template<> template<> Color<uint8_t,1>::Color(const Color<double, 2>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0, _obj.r(), 1.0)*255.0);
m_element[0] = (uint8_t)(std::avg(0.0, _obj.r(), 1.0)*255.0);
}
template<> template<> Color<uint8_t,2>::Color(const Color<double, 2>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0, _obj.r(), 1.0)*255.0);
m_element[1] = (uint8_t)(etk::avg(0.0, _obj.g(), 1.0)*255.0);
m_element[0] = (uint8_t)(std::avg(0.0, _obj.r(), 1.0)*255.0);
m_element[1] = (uint8_t)(std::avg(0.0, _obj.g(), 1.0)*255.0);
}
template<> template<> Color<uint8_t,3>::Color(const Color<double, 2>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0, _obj.r(), 1.0)*255.0);
m_element[1] = (uint8_t)(etk::avg(0.0, _obj.g(), 1.0)*255.0);
m_element[0] = (uint8_t)(std::avg(0.0, _obj.r(), 1.0)*255.0);
m_element[1] = (uint8_t)(std::avg(0.0, _obj.g(), 1.0)*255.0);
m_element[2] = 0;
}
template<> template<> Color<uint8_t,4>::Color(const Color<double, 2>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0, _obj.r(), 1.0)*255.0);
m_element[1] = (uint8_t)(etk::avg(0.0, _obj.g(), 1.0)*255.0);
m_element[0] = (uint8_t)(std::avg(0.0, _obj.r(), 1.0)*255.0);
m_element[1] = (uint8_t)(std::avg(0.0, _obj.g(), 1.0)*255.0);
m_element[2] = 0;
m_element[3] = defaultAlpha;
}
template<> template<> Color<uint8_t,1>::Color(const Color<double, 3>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0, _obj.r(), 1.0)*255.0);
m_element[0] = (uint8_t)(std::avg(0.0, _obj.r(), 1.0)*255.0);
}
template<> template<> Color<uint8_t,2>::Color(const Color<double, 3>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0, _obj.r(), 1.0)*255.0);
m_element[1] = (uint8_t)(etk::avg(0.0, _obj.g(), 1.0)*255.0);
m_element[0] = (uint8_t)(std::avg(0.0, _obj.r(), 1.0)*255.0);
m_element[1] = (uint8_t)(std::avg(0.0, _obj.g(), 1.0)*255.0);
}
template<> template<> Color<uint8_t,3>::Color(const Color<double, 3>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0, _obj.r(), 1.0)*255.0);
m_element[1] = (uint8_t)(etk::avg(0.0, _obj.g(), 1.0)*255.0);
m_element[2] = (uint8_t)(etk::avg(0.0, _obj.b(), 1.0)*255.0);
m_element[0] = (uint8_t)(std::avg(0.0, _obj.r(), 1.0)*255.0);
m_element[1] = (uint8_t)(std::avg(0.0, _obj.g(), 1.0)*255.0);
m_element[2] = (uint8_t)(std::avg(0.0, _obj.b(), 1.0)*255.0);
}
template<> template<> Color<uint8_t,4>::Color(const Color<double, 3>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0, _obj.r(), 1.0)*255.0);
m_element[1] = (uint8_t)(etk::avg(0.0, _obj.g(), 1.0)*255.0);
m_element[2] = (uint8_t)(etk::avg(0.0, _obj.b(), 1.0)*255.0);
m_element[0] = (uint8_t)(std::avg(0.0, _obj.r(), 1.0)*255.0);
m_element[1] = (uint8_t)(std::avg(0.0, _obj.g(), 1.0)*255.0);
m_element[2] = (uint8_t)(std::avg(0.0, _obj.b(), 1.0)*255.0);
m_element[3] = defaultAlpha;
}
template<> template<> Color<uint8_t,1>::Color(const Color<double, 4>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0, _obj.r(), 1.0)*255.0);
m_element[0] = (uint8_t)(std::avg(0.0, _obj.r(), 1.0)*255.0);
}
template<> template<> Color<uint8_t,2>::Color(const Color<double, 4>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0, _obj.r(), 1.0)*255.0);
m_element[1] = (uint8_t)(etk::avg(0.0, _obj.g(), 1.0)*255.0);
m_element[0] = (uint8_t)(std::avg(0.0, _obj.r(), 1.0)*255.0);
m_element[1] = (uint8_t)(std::avg(0.0, _obj.g(), 1.0)*255.0);
}
template<> template<> Color<uint8_t,3>::Color(const Color<double, 4>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0, _obj.r(), 1.0)*255.0);
m_element[1] = (uint8_t)(etk::avg(0.0, _obj.g(), 1.0)*255.0);
m_element[2] = (uint8_t)(etk::avg(0.0, _obj.b(), 1.0)*255.0);
m_element[0] = (uint8_t)(std::avg(0.0, _obj.r(), 1.0)*255.0);
m_element[1] = (uint8_t)(std::avg(0.0, _obj.g(), 1.0)*255.0);
m_element[2] = (uint8_t)(std::avg(0.0, _obj.b(), 1.0)*255.0);
}
template<> template<> Color<uint8_t,4>::Color(const Color<double, 4>& _obj) {
m_element[0] = (uint8_t)(etk::avg(0.0, _obj.r(), 1.0)*255.0);
m_element[1] = (uint8_t)(etk::avg(0.0, _obj.g(), 1.0)*255.0);
m_element[2] = (uint8_t)(etk::avg(0.0, _obj.b(), 1.0)*255.0);
m_element[3] = (uint8_t)(etk::avg(0.0, _obj.a(), 1.0)*255.0);
m_element[0] = (uint8_t)(std::avg(0.0, _obj.r(), 1.0)*255.0);
m_element[1] = (uint8_t)(std::avg(0.0, _obj.g(), 1.0)*255.0);
m_element[2] = (uint8_t)(std::avg(0.0, _obj.b(), 1.0)*255.0);
m_element[3] = (uint8_t)(std::avg(0.0, _obj.a(), 1.0)*255.0);
}
// ===========================================================================================================
template<> etk::String toString<Color<uint8_t, 1> >(const Color<uint8_t, 1>& _val) {
template<> std::string to_string<Color<uint8_t, 1> >(const Color<uint8_t, 1>& _val) {
return _val.getString();
}
#if __cplusplus >= 201103L
template<> etk::UString toUString<Color<uint8_t, 1>>(const Color<uint8_t, 1>& _val) {
return toUString(_val.getString());
template<> std::u32string to_u32string<Color<uint8_t, 1>>(const Color<uint8_t, 1>& _val) {
return to_u32string(_val.getString());
}
template<> bool from_string<Color<uint8_t, 1>>(Color<uint8_t, 1>& _variableRet, const etk::UString& _value) {
_variableRet = Color<uint8_t, 1>(toString(_value));
template<> bool from_string<Color<uint8_t, 1>>(Color<uint8_t, 1>& _variableRet, const std::u32string& _value) {
_variableRet = Color<uint8_t, 1>(to_string(_value));
return true;
}
#endif
template<> bool from_string<Color<uint8_t, 1> >(Color<uint8_t, 1>& _variableRet, const etk::String& _value) {
template<> bool from_string<Color<uint8_t, 1> >(Color<uint8_t, 1>& _variableRet, const std::string& _value) {
_variableRet = Color<uint8_t, 1>(_value);
return true;
}
@ -404,56 +404,56 @@ template<> bool from_string<Color<uint8_t, 1> >(Color<uint8_t, 1>& _variableRet,
template<> etk::String toString<Color<uint8_t, 2> >(const Color<uint8_t, 2>& _val) {
template<> std::string to_string<Color<uint8_t, 2> >(const Color<uint8_t, 2>& _val) {
return _val.getString();
}
#if __cplusplus >= 201103L
template<> etk::UString toUString<Color<uint8_t, 2>>(const Color<uint8_t, 2>& _val) {
return toUString(_val.getString());
template<> std::u32string to_u32string<Color<uint8_t, 2>>(const Color<uint8_t, 2>& _val) {
return to_u32string(_val.getString());
}
template<> bool from_string<Color<uint8_t, 2>>(Color<uint8_t, 2>& _variableRet, const etk::UString& _value) {
_variableRet = Color<uint8_t, 2>(toString(_value));
template<> bool from_string<Color<uint8_t, 2>>(Color<uint8_t, 2>& _variableRet, const std::u32string& _value) {
_variableRet = Color<uint8_t, 2>(to_string(_value));
return true;
}
#endif
template<> bool from_string<Color<uint8_t, 2> >(Color<uint8_t, 2>& _variableRet, const etk::String& _value) {
template<> bool from_string<Color<uint8_t, 2> >(Color<uint8_t, 2>& _variableRet, const std::string& _value) {
_variableRet = Color<uint8_t, 2>(_value);
return true;
}
template<> etk::String toString<Color<uint8_t, 3> >(const Color<uint8_t, 3>& _val) {
template<> std::string to_string<Color<uint8_t, 3> >(const Color<uint8_t, 3>& _val) {
return _val.getString();
}
#if __cplusplus >= 201103L
template<> etk::UString toUString<Color<uint8_t, 3>>(const Color<uint8_t, 3>& _val) {
return toUString(_val.getString());
template<> std::u32string to_u32string<Color<uint8_t, 3>>(const Color<uint8_t, 3>& _val) {
return to_u32string(_val.getString());
}
template<> bool from_string<Color<uint8_t, 3>>(Color<uint8_t, 3>& _variableRet, const etk::UString& _value) {
_variableRet = Color<uint8_t, 3>(toString(_value));
template<> bool from_string<Color<uint8_t, 3>>(Color<uint8_t, 3>& _variableRet, const std::u32string& _value) {
_variableRet = Color<uint8_t, 3>(to_string(_value));
return true;
}
#endif
template<> bool from_string<Color<uint8_t, 3> >(Color<uint8_t, 3>& _variableRet, const etk::String& _value) {
template<> bool from_string<Color<uint8_t, 3> >(Color<uint8_t, 3>& _variableRet, const std::string& _value) {
_variableRet = Color<uint8_t, 3>(_value);
return true;
}
template<> etk::String toString<Color<uint8_t, 4> >(const Color<uint8_t, 4>& _val) {
template<> std::string to_string<Color<uint8_t, 4> >(const Color<uint8_t, 4>& _val) {
return _val.getString();
}
#if __cplusplus >= 201103L
template<> etk::UString toUString<Color<uint8_t, 4>>(const Color<uint8_t, 4>& _val) {
return toUString(_val.getString());
template<> std::u32string to_u32string<Color<uint8_t, 4>>(const Color<uint8_t, 4>& _val) {
return to_u32string(_val.getString());
}
template<> bool from_string<Color<uint8_t, 4>>(Color<uint8_t, 4>& _variableRet, const etk::UString& _value) {
_variableRet = Color<uint8_t, 4>(toString(_value));
template<> bool from_string<Color<uint8_t, 4>>(Color<uint8_t, 4>& _variableRet, const std::u32string& _value) {
_variableRet = Color<uint8_t, 4>(to_string(_value));
return true;
}
#endif
template<> bool from_string<Color<uint8_t, 4> >(Color<uint8_t, 4>& _variableRet, const etk::String& _value) {
template<> bool from_string<Color<uint8_t, 4> >(Color<uint8_t, 4>& _variableRet, const std::string& _value) {
_variableRet = Color<uint8_t, 4>(_value);
return true;
}

View File

@ -385,19 +385,19 @@ template<> template<> Color<double,4>::Color(const Color<double, 4>& _obj) {
// ===========================================================================================================
template<> etk::String toString<Color<double, 1> >(const Color<double, 1>& _val) {
template<> std::string to_string<Color<double, 1> >(const Color<double, 1>& _val) {
return _val.getString();
}
#if __cplusplus >= 201103L
template<> etk::UString toUString<Color<double, 1>>(const Color<double, 1>& _val) {
return toUString(_val.getString());
template<> std::u32string to_u32string<Color<double, 1>>(const Color<double, 1>& _val) {
return to_u32string(_val.getString());
}
template<> bool from_string<Color<double, 1>>(Color<double, 1>& _variableRet, const etk::UString& _value) {
_variableRet = Color<double, 1>(toString(_value));
template<> bool from_string<Color<double, 1>>(Color<double, 1>& _variableRet, const std::u32string& _value) {
_variableRet = Color<double, 1>(to_string(_value));
return true;
}
#endif
template<> bool from_string<Color<double, 1> >(Color<double, 1>& _variableRet, const etk::String& _value) {
template<> bool from_string<Color<double, 1> >(Color<double, 1>& _variableRet, const std::string& _value) {
_variableRet = Color<double, 1>(_value);
return true;
}
@ -405,19 +405,19 @@ template<> bool from_string<Color<double, 1> >(Color<double, 1>& _variableRet, c
template<> etk::String toString<Color<double, 2> >(const Color<double, 2>& _val) {
template<> std::string to_string<Color<double, 2> >(const Color<double, 2>& _val) {
return _val.getString();
}
#if __cplusplus >= 201103L
template<> etk::UString toUString<Color<double, 2>>(const Color<double, 2>& _val) {
return toUString(_val.getString());
template<> std::u32string to_u32string<Color<double, 2>>(const Color<double, 2>& _val) {
return to_u32string(_val.getString());
}
template<> bool from_string<Color<double, 2>>(Color<double, 2>& _variableRet, const etk::UString& _value) {
_variableRet = Color<double, 2>(toString(_value));
template<> bool from_string<Color<double, 2>>(Color<double, 2>& _variableRet, const std::u32string& _value) {
_variableRet = Color<double, 2>(to_string(_value));
return true;
}
#endif
template<> bool from_string<Color<double, 2> >(Color<double, 2>& _variableRet, const etk::String& _value) {
template<> bool from_string<Color<double, 2> >(Color<double, 2>& _variableRet, const std::string& _value) {
_variableRet = Color<double, 2>(_value);
return true;
}
@ -425,38 +425,38 @@ template<> bool from_string<Color<double, 2> >(Color<double, 2>& _variableRet, c
template<> etk::String toString<Color<double, 3> >(const Color<double, 3>& _val) {
template<> std::string to_string<Color<double, 3> >(const Color<double, 3>& _val) {
return _val.getString();
}
#if __cplusplus >= 201103L
template<> etk::UString toUString<Color<double, 3>>(const Color<double, 3>& _val) {
return toUString(_val.getString());
template<> std::u32string to_u32string<Color<double, 3>>(const Color<double, 3>& _val) {
return to_u32string(_val.getString());
}
template<> bool from_string<Color<double, 3>>(Color<double, 3>& _variableRet, const etk::UString& _value) {
_variableRet = Color<double, 3>(toString(_value));
template<> bool from_string<Color<double, 3>>(Color<double, 3>& _variableRet, const std::u32string& _value) {
_variableRet = Color<double, 3>(to_string(_value));
return true;
}
#endif
template<> bool from_string<Color<double, 3> >(Color<double, 3>& _variableRet, const etk::String& _value) {
template<> bool from_string<Color<double, 3> >(Color<double, 3>& _variableRet, const std::string& _value) {
_variableRet = Color<double, 3>(_value);
return true;
}
template<> etk::String toString<Color<double, 4> >(const Color<double, 4>& _val) {
template<> std::string to_string<Color<double, 4> >(const Color<double, 4>& _val) {
return _val.getString();
}
#if __cplusplus >= 201103L
template<> etk::UString toUString<Color<double, 4>>(const Color<double, 4>& _val) {
return toUString(_val.getString());
template<> std::u32string to_u32string<Color<double, 4>>(const Color<double, 4>& _val) {
return to_u32string(_val.getString());
}
template<> bool from_string<Color<double, 4>>(Color<double, 4>& _variableRet, const etk::UString& _value) {
_variableRet = Color<double, 4>(toString(_value));
template<> bool from_string<Color<double, 4>>(Color<double, 4>& _variableRet, const std::u32string& _value) {
_variableRet = Color<double, 4>(to_string(_value));
return true;
}
#endif
template<> bool from_string<Color<double, 4> >(Color<double, 4>& _variableRet, const etk::String& _value) {
template<> bool from_string<Color<double, 4> >(Color<double, 4>& _variableRet, const std::string& _value) {
_variableRet = Color<double, 4>(_value);
return true;
}

View File

@ -383,73 +383,73 @@ template<> template<> Color<float,4>::Color(const Color<double, 4>& _obj) {
}
template<> etk::String toString<Color<float, 1> >(const Color<float, 1>& _val) {
template<> std::string to_string<Color<float, 1> >(const Color<float, 1>& _val) {
return _val.getString();
}
#if __cplusplus >= 201103L
template<> etk::UString toUString<Color<float, 1>>(const Color<float, 1>& _val) {
return toUString(_val.getString());
template<> std::u32string to_u32string<Color<float, 1>>(const Color<float, 1>& _val) {
return to_u32string(_val.getString());
}
template<> bool from_string<Color<float, 1>>(Color<float, 1>& _variableRet, const etk::UString& _value) {
_variableRet = Color<float, 1>(toString(_value));
template<> bool from_string<Color<float, 1>>(Color<float, 1>& _variableRet, const std::u32string& _value) {
_variableRet = Color<float, 1>(to_string(_value));
return true;
}
#endif
template<> bool from_string<Color<float, 1> >(Color<float, 1>& _variableRet, const etk::String& _value) {
template<> bool from_string<Color<float, 1> >(Color<float, 1>& _variableRet, const std::string& _value) {
_variableRet = Color<float, 1>(_value);
return true;
}
template<> etk::String toString<Color<float, 2> >(const Color<float, 2>& _val) {
template<> std::string to_string<Color<float, 2> >(const Color<float, 2>& _val) {
return _val.getString();
}
#if __cplusplus >= 201103L
template<> etk::UString toUString<Color<float, 2>>(const Color<float, 2>& _val) {
return toUString(_val.getString());
template<> std::u32string to_u32string<Color<float, 2>>(const Color<float, 2>& _val) {
return to_u32string(_val.getString());
}
template<> bool from_string<Color<float, 2>>(Color<float, 2>& _variableRet, const etk::UString& _value) {
_variableRet = Color<float, 2>(toString(_value));
template<> bool from_string<Color<float, 2>>(Color<float, 2>& _variableRet, const std::u32string& _value) {
_variableRet = Color<float, 2>(to_string(_value));
return true;
}
#endif
template<> bool from_string<Color<float, 2> >(Color<float, 2>& _variableRet, const etk::String& _value) {
template<> bool from_string<Color<float, 2> >(Color<float, 2>& _variableRet, const std::string& _value) {
_variableRet = Color<float, 2>(_value);
return true;
}
template<> etk::String toString<Color<float, 3> >(const Color<float, 3>& _val) {
template<> std::string to_string<Color<float, 3> >(const Color<float, 3>& _val) {
return _val.getString();
}
#if __cplusplus >= 201103L
template<> etk::UString toUString<Color<float, 3>>(const Color<float, 3>& _val) {
return toUString(_val.getString());
template<> std::u32string to_u32string<Color<float, 3>>(const Color<float, 3>& _val) {
return to_u32string(_val.getString());
}
template<> bool from_string<Color<float, 3>>(Color<float, 3>& _variableRet, const etk::UString& _value) {
_variableRet = Color<float, 3>(toString(_value));
template<> bool from_string<Color<float, 3>>(Color<float, 3>& _variableRet, const std::u32string& _value) {
_variableRet = Color<float, 3>(to_string(_value));
return true;
}
#endif
template<> bool from_string<Color<float, 3> >(Color<float, 3>& _variableRet, const etk::String& _value) {
template<> bool from_string<Color<float, 3> >(Color<float, 3>& _variableRet, const std::string& _value) {
_variableRet = Color<float, 3>(_value);
return true;
}
template<> etk::String toString<Color<float, 4> >(const Color<float, 4>& _val) {
template<> std::string to_string<Color<float, 4> >(const Color<float, 4>& _val) {
return _val.getString();
}
#if __cplusplus >= 201103L
template<> etk::UString toUString<Color<float, 4>>(const Color<float, 4>& _val) {
return toUString(_val.getString());
template<> std::u32string to_u32string<Color<float, 4>>(const Color<float, 4>& _val) {
return to_u32string(_val.getString());
}
template<> bool from_string<Color<float, 4>>(Color<float, 4>& _variableRet, const etk::UString& _value) {
_variableRet = Color<float, 4>(toString(_value));
template<> bool from_string<Color<float, 4>>(Color<float, 4>& _variableRet, const std::u32string& _value) {
_variableRet = Color<float, 4>(to_string(_value));
return true;
}
#endif
template<> bool from_string<Color<float, 4> >(Color<float, 4>& _variableRet, const etk::String& _value) {
template<> bool from_string<Color<float, 4> >(Color<float, 4>& _variableRet, const std::string& _value) {
_variableRet = Color<float, 4>(_value);
return true;
}

23
color/lutin_etk-color.py Normal file
View File

@ -0,0 +1,23 @@
#!/usr/bin/python
import lutin.module as module
import lutin.tools as tools
def get_desc():
return "etk color interface"
def get_license():
return "APACHE v2.0"
def create(target):
myModule = module.Module(__file__, 'etk-color', 'LIBRARY')
myModule.add_extra_compile_flags()
myModule.add_src_file([
"etk-color/Color.cpp"
])
myModule.add_module_depend(["etk-base"])
myModule.add_export_path(tools.get_current_path(__file__))
return myModule

21
createTag.sh Executable file
View File

@ -0,0 +1,21 @@
#!/bin/bash
usage()
{
echo -e "$0 [TAG]"
echo -e "\t\t[TAG] : Tag to set on the version"
exit -1
}
#verify all input parameters :
tag=""
if [ "$1" = "" ] ; then
usage
else
tag="$1"
fi
echo -n $tag > tag
git commit -a -m "Update version tag : $tag"
git tag $tag

View File

@ -1 +0,0 @@
file_hidden.txt

View File

@ -1 +0,0 @@
file_A_1.txt

View File

@ -1 +0,0 @@
file_C_1.txt

View File

@ -1 +0,0 @@
file_B_1.txt

View File

@ -1 +0,0 @@
file_B_2.txt

View File

@ -1 +0,0 @@
file_1.txt

View File

@ -1 +0,0 @@
file_2.txt

View File

@ -1 +0,0 @@
file_3.txt

Binary file not shown.

View File

View File

@ -1 +0,0 @@
plop

View File

@ -1,69 +0,0 @@
Build lib & build sample {#etk_build}
========================
@tableofcontents
Download: {#etk_build_download}
=========
etk use some tools to manage source and build it:
lutin (build-system): {#etk_build_download_lutin}
---------------------
```{.sh}
pip install lutin --user
# optionnal dependency of lutin (manage image changing size for application release
pip install pillow --user
```
dependency: {#etk_build_download_dependency}
-----------
```{.sh}
mkdir framework
cd framework
git clone https://github.com/atria-soft/elog.git
cd ..
```
sources: {#etk_build_download_sources}
--------
```{.sh}
cd framework
git clone https://github.com/atria-soft/etk.git
cd ..
```
Build: {#etk_build_build}
======
library: {#etk_build_build_library}
--------
```{.sh}
lutin -mdebug etk
```
test: {#etk_build_build_sample}
-----
```{.sh}
lutin -mdebug etk-test
```
Or simple:
```{.sh}
lutin -mdebug etk-*
```
Run sample: {#etk_build_run_sample}
===========
```{.sh}
lutin -mdebug etk-test?run
```

42
doc/index.bb Normal file
View File

@ -0,0 +1,42 @@
== [center]ETK library[/center] ==
__________________________________________________
===What is ETK, and how can I use it?===
ETK, or Ewol Tool kit is a simple abstraction layer for some elements like mutex, std missing element(in android or MacOS) and ...
We can simply say: Just a tool-box
ETK is composed of some part:
:** Log system interface
:** File access abstraction (for android, data are stored in a .apk (== zip file))
:** Mutex / semaphore abstraction (can not use pthread on windows)
:** Regular expression
:** Generic color interface
:** Std adding missing element on some platform.
===What languages are supported?===
ETK is written in C++.
===Are there any licensing restrictions?===
ETK is [b]FREE software[/b]
==== License (APACHE-2.0) ====
Copyright etk Edouard DUPIN
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -1,59 +0,0 @@
ETK library {#mainpage}
===========
What is ETK, and how can I use it? {#etk_mainpage_what}
==================================
ETK, or Ewol Tool kit is a simple abstraction layer for some elements like mutex, std missing element(in android or MacOS) and ...
We can simply say: Just a tool-box **(I use it to add many test prototyping ... and bad things ...)**
ETK is composed of some part:
- Log system interface
- File access abstraction (for android, data are stored in a .apk (== zip file))
- Mutex / semaphore abstraction (can not use pthread on windows)
- Regular expression
- Generic color interface
- Std adding missing element on some platform.
What languages are supported? {#etk_mainpage_langue}
=============================
ETK is written in C++.
Are there any licensing restrictions? {#etk_mainpage_dependency}
=====================================
ETK is **FREE software** and _all sub-library are FREE and staticly linkable !!!_
License (MPL v2.0) {#etk_mainpage_licence}
==================
Copyright etk Edouard DUPIN
Licensed under the Mozilla Public License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
<https://www.mozilla.org/MPL/2.0>
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Other pages {#etk_mainpage_sub_page}
===========
- @ref etk_build
- [**ewol coding style**](http://atria-soft.github.io/ewol/ewol_coding_style.html)

View File

@ -1,50 +0,0 @@
#!/usr/bin/python
import os
import doxy.module as module
import doxy.debug as debug
import doxy.tools as tools
def create(target, module_name):
my_module = module.Module(__file__, module_name)
my_module.set_version("version.txt")
my_module.set_title("Etk: Ewol Tool Kit")
my_module.set_website("http://atria-soft.github.io/" + module_name)
my_module.set_website_sources("http://github.com/atria-soft/" + module_name)
my_module.add_path([
module_name,
"doc",
])
my_module.add_data_path([
"data/dox",
])
my_module.add_depend([
'elog',
])
my_module.add_module_define([
"ETK_BUILD_MINIZIP",
])
my_module.add_exclude_symbols([
'*operator<<*',
'*string_to_*',
'*compare_no_case*',
'*end_with*',
'*extract_line*',
'*isIn*',
'*matRotate2*',
'*replace*',
'*sort*',
'*split*',
'*start_with*',
'tolower',
'toupper',
])
my_module.add_exclude_file([
'debug.hpp',
])
my_module.add_file_patterns([
'*.hpp',
'*.md',
])
return my_module

View File

@ -1,13 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etest/debug.hpp>
int32_t etest::getLogId() {
static int32_t g_val = elog::registerInstance("etest");
return g_val;
}

View File

@ -1,52 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <elog/log.hpp>
namespace etest {
int32_t getLogId();
};
#define ETEST_BASE(info,data) ELOG_BASE(etest::getLogId(),info,data)
#define ETEST_PRINT(data) ETEST_BASE(-1, data)
#define ETEST_CRITICAL(data) ETEST_BASE(1, data)
#define ETEST_ERROR(data) ETEST_BASE(2, data)
#define ETEST_WARNING(data) ETEST_BASE(3, data)
#ifdef DEBUG
#define ETEST_INFO(data) ETEST_BASE(4, data)
#define ETEST_DEBUG(data) ETEST_BASE(5, data)
#define ETEST_VERBOSE(data) ETEST_BASE(6, data)
#define ETEST_TODO(data) ETEST_BASE(4, "TODO : " << data)
#else
#define ETEST_INFO(data) do { } while(false)
#define ETEST_DEBUG(data) do { } while(false)
#define ETEST_VERBOSE(data) do { } while(false)
#define ETEST_TODO(data) do { } while(false)
#endif
#define ETEST_HIDDEN(data) do { } while(false)
#ifdef DEBUG
#define ETEST_CHECK_INOUT(condition) \
do { \
if (!(condition)) { \
ETEST_ERROR("Wrong condition : " #condition); \
} \
} while (0)
#else
#define ETEST_CHECK_INOUT(condition) do { } while(false)
#endif
#define ETEST_ASSERT(condition,data) \
do { \
if (!(condition)) { \
ETEST_CRITICAL(data); \
assert(!#condition); \
} \
} while (0)

View File

@ -1,422 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etest/etest.hpp>
#include <etest/debug.hpp>
#include <etk/Vector.hpp>
#include <elog/elog.hpp>
#include <echrono/Steady.hpp>
#include <echrono/Duration.hpp>
#include <etk/Allocator.hpp>
static int32_t nbTimeInit = 0;
static etk::Vector<etest::GenericTest*>& getListOfTest() {
static etk::Vector<etest::GenericTest*> s_listOfData;
return s_listOfData;
}
static etk::String filterGroup;
static etk::String filterTest;
static bool showAtTheEnd = false;
void etest::unInit() {
if (nbTimeInit > 1) {
nbTimeInit--;
// not the time to un-init
return;
}
nbTimeInit--;
if (nbTimeInit < 0) {
ETEST_ERROR("ETEST system un-init More un-init than init ...");
nbTimeInit = 0;
return;
}
ETEST_INFO("ETEST system un-init (BEGIN)");
ETEST_INFO("ETEST system un-init (END)");
elog::unInit();
}
static etk::Vector<etk::String> getListGroupSpecific(const etk::Vector<etest::GenericTest*>& _value) {
etk::Vector<etk::String> listGroup;
for (auto &it: _value) {
if (etk::isIn(it->getTestGroup(), listGroup) == true) {
continue;
}
listGroup.pushBack(it->getTestGroup());
}
return listGroup;
}
static etk::Vector<etk::String> getListGroup() {
return getListGroupSpecific(getListOfTest());
}
static etk::Vector<etest::GenericTest*> getListFiltered() {
if (filterGroup == "") {
return getListOfTest();
}
etk::Vector<etest::GenericTest*> out;
for (auto &it: getListOfTest()) {
if (it->getTestGroup() != filterGroup) {
continue;
}
if (filterTest == "") {
out.pushBack(it);
continue;
}
if (filterTest == it->getTestName()) {
out.pushBack(it);
continue;
}
}
return out;
}
static void listAllTest() {
ETEST_PRINT("We have " << getListOfTest().size() << " tests:");
etk::Vector<etk::String> listGroup = getListGroup();
for (auto &itGroup: listGroup) {
ETEST_PRINT("Group: " << itGroup);
for (auto &it: getListOfTest()) {
if (it->getTestGroup() == itGroup) {
ETEST_PRINT(" - " << itGroup << "." << it->getTestName());
}
}
}
}
static void listAllTestError() {
int32_t count = 0;
for (auto &it: getListOfTest()) {
if (it->getError() == true) {
count++;
break;
}
}
if (count == 0) {
return;
}
ETEST_PRINT("List all error test:");
etk::Vector<etk::String> listGroup = getListGroup();
for (auto &itGroup: listGroup) {
for (auto &it: getListOfTest()) {
if (it->getTestGroup() == itGroup) {
if (it->getError() == true) {
ETEST_PRINT(" - " << itGroup << "." << it->getTestName());
}
}
}
}
}
void etest::init(int32_t _argc, const char** _argv) {
if (nbTimeInit > 0) {
nbTimeInit++;
// already init
return;
}
nbTimeInit++;
elog::init(_argc, _argv, "etest");
//etk::initDefaultFolder("ewolApplNoName");
ETEST_INFO("ETEST system init (BEGIN) ");
for (int32_t iii=0; iii<_argc ; ++iii) {
etk::String data = _argv[iii];
if ( data == "-h"
|| data == "--help") {
ETEST_PRINT("etest - help : ");
if (_argc >= 1) {
ETEST_PRINT(" " << _argv[0] << " [options]");
ETEST_PRINT(" --etest-list List all test names");
ETEST_PRINT(" --etest-filter=XXX filter group or test: XXX or WWW.yyy");
ETEST_PRINT(" --etest-show Display at the end the list of test that fail");
}
ETEST_PRINT(" -h/--help: this help");
} else if (data == "--etest-list") {
listAllTest();
exit(0);
} else if (data == "--etest-filter=") {
ETEST_PRINT("Missing data in the filter list...");
exit(0);
} else if (data == "--etest-show") {
ETEST_PRINT("Display all error test at the end ...");
showAtTheEnd = true;
} else if (data.startWith("--etest-filter=") == true) {
etk::String filter = &data[15];
ETEST_PRINT(" Filter: " << filter);
etk::Vector<etk::String> tmp = filter.split(".");
if (tmp.size() == 1) {
// Filter only the groups
filterGroup = filter;
ETEST_VERBOSE("filter group:" << filterGroup);
} else if (tmp.size() == 2) {
filterGroup = tmp[0];
filterTest = tmp[1];
ETEST_VERBOSE("filter group:" << filterGroup << " & test:" << filterTest);
} else {
ETEST_CRITICAL("Can not parse the argument : '" << data << "' ==> more than 1 '.'");
}
} else if (data.startWith("--etest") == true) {
ETEST_ERROR("Can not parse the argument : '" << data << "'");
}
}
ETEST_INFO("ETEST system init (END)");
}
etest::GenericTest::GenericTest(const char* _file,
uint32_t _line,
const char* _testGroup,
const char* _testName):
m_file(_file),
m_line(_line),
m_testGroup(_testGroup),
m_testName(_testName) {
}
const etk::String& etest::GenericTest::getFileName() const {
return m_file;
}
uint32_t etest::GenericTest::getFileLine() const {
return m_line;
}
const etk::String& etest::GenericTest::getTestGroup() const {
return m_testGroup;
}
const etk::String& etest::GenericTest::getTestName() const {
return m_testName;
}
bool etest::GenericTest::getError() const {
return m_haveError;
}
uint32_t etest::GenericTest::getNumberCheck() const {
return m_numberCheck;
}
uint32_t etest::GenericTest::getNumberCheckError() const {
return m_numberCheckFail;
}
uint32_t etest::GenericTest::getNumberCheckNotImplemented() const {
return m_numberCheckNotImplemented;
}
void etest::GenericTest::testNotImplemented(uint32_t _line) {
ETEST_ERROR("Not implemented: " << m_file << ":" << _line << ":");
m_haveError = true;
m_numberCheckNotImplemented++;
}
void etest::GenericTest::testResult(bool _result,
const etk::String& _test1Value,
const etk::String& _test1,
const etk::String& _test2Value,
const etk::String& _test2,
uint32_t _line) {
if (_result == true) {
return;
}
ETEST_ERROR("Detect an error: " << m_file << ":" << _line << ":");
if (_test1 != _test1Value) {
ETEST_ERROR(" have: " << _test1 << " = " << _test1Value);
} else {
ETEST_ERROR(" have: " << _test1);
}
if (_test2 != _test2Value) {
ETEST_ERROR(" expect: " << _test2 << " = " << _test2Value);
} else {
ETEST_ERROR(" expect: " << _test2);
}
m_haveError = true;
m_numberCheckFail++;
}
void etest::GenericTest::testCatchThrow(const etk::Exception& exeption, uint32_t _line) {
ETEST_ERROR("Detect an error: " << m_file << ":" << _line << ": Catch etk::Exception");
ETEST_ERROR(" what='" << exeption.what() << "'");
ETEST_ERROR(" which='" << exeption.which() << "'");
ETEST_ERROR(" file='" << exeption.file() << "'");
ETEST_ERROR(" line=" << exeption.line());
ETEST_ERROR(" function='" << exeption.function() << "'");
m_haveError = true;
m_numberCheckFail++;
}
void etest::GenericTest::testCatchThrow(uint32_t _line) {
ETEST_ERROR("Detect an error: " << m_file << ":" << _line << ": Catch Unknow exception");
m_haveError = true;
m_numberCheckFail++;
}
void etest::GenericTest::clearLocal() {
m_haveError = false;
m_numberCheck = 0;
m_numberCheckFail = 0;
m_numberCheckNotImplemented = 0;
}
etest::GenericTest* etest::g_currentTest = null;
int32_t etest::runAllTest() {
int32_t errorCount = 0;
etk::Vector<etest::GenericTest*> runList = getListFiltered();
etk::Vector<etk::String> listGroup = getListGroupSpecific(runList);
ETEST_PRINT("[==========] Running " << runList.size() << " tests from " << listGroup.size() << " test group.");
echrono::Steady tic = echrono::Steady::now();
uint32_t nbTotalCheck = 0;
uint32_t nbTotalCheckFail = 0;
uint32_t nbTotalCheckNotImplemented = 0;
for (auto &itGroup: listGroup) {
int32_t count = 0;
for (auto &it: getListOfTest()) {
if (it->getTestGroup() == itGroup) {
count++;
}
}
ETEST_PRINT("[++++++++++] " << count << " test from " << itGroup << ":");
uint32_t nbCheck = 0;
uint32_t nbCheckFail = 0;
uint32_t nbCheckNotImplemented = 0;
echrono::Steady ticGroup = echrono::Steady::now();
for (auto &it: runList) {
if (it->getTestGroup() != itGroup) {
continue;
}
bool localFail = false;
#if ETK_MEMORY_CHECKER > 0
uint64_t* memorySnapShoot = etk::memory::createSnapshoot();
#endif
{
ETEST_PRINT("[ RUN ] " << itGroup << "." << it->getTestName());
it->clearLocal();
g_currentTest = it;
echrono::Steady ticTest = echrono::Steady::now();
try {
it->addCheck();
it->run();
} catch ( etk::Exception e ) {
it->testCatchThrow(e, __LINE__);
} catch ( ... ) {
it->testCatchThrow(__LINE__);
}
echrono::Steady tocTest = echrono::Steady::now();
g_currentTest = null;
if (it->getError() == true) {
ETEST_PRINT("[ FAIL ] " << itGroup << "." << it->getTestName() << " (" << (tocTest - ticTest) << ") " << it->getNumberCheckError() << " fails");
errorCount++;
localFail = true;
} else {
ETEST_PRINT("[ OK ] " << itGroup << "." << it->getTestName() << " (" << (tocTest - ticTest) << ")");
}
nbCheck += it->getNumberCheck();
nbCheckFail += it->getNumberCheckError();
nbCheckNotImplemented += it->getNumberCheckNotImplemented();
}
#if ETK_MEMORY_CHECKER > 0
ETEST_DEBUG("[ MEM ] CHECK memory properties");
bool ret = etk::memory::checkSnapshoot(memorySnapShoot);
etk::memory::clearSnapshoot(memorySnapShoot);
memorySnapShoot = null;
ETEST_DEBUG("[ MEM ] CHECK memory properties (done)");
nbCheck++;
if (ret == false) {
if (localFail == false) {
errorCount++;
}
ETEST_PRINT("[ FAIL ] " << itGroup << "." << it->getTestName() << " ==> in memory LEAK test");
nbCheckFail++;
}
#endif
}
echrono::Steady tocGroup = echrono::Steady::now();
etk::String notImplemented = "";
if (nbCheckNotImplemented != 0) {
notImplemented = " / " + etk::toString(nbCheckNotImplemented) + " Not Implemented";
}
ETEST_PRINT("[++++++++++] " << count << " test [" << nbCheck << " check / " << nbCheckFail << " fails " << notImplemented << "] from " << itGroup << " (" << (tocGroup - ticGroup) << ")");
nbTotalCheck += nbCheck;
nbTotalCheckFail += nbCheckFail;
nbTotalCheckNotImplemented += nbCheckNotImplemented;
}
echrono::Steady toc = echrono::Steady::now();
etk::String notImplementedFull = "";
if (nbTotalCheckNotImplemented != 0) {
notImplementedFull = " / " + etk::toString(nbTotalCheckNotImplemented) + " Not Implemented";
}
ETEST_PRINT("[==========] All done [" << nbTotalCheck << " check / " << nbTotalCheckFail << " fails" << notImplementedFull << "] in " << (toc - tic));
if (errorCount != 0) {
ETEST_PRINT("[== FAIL ==] Have " << errorCount << " test fail ");
}
ETK_MEM_SHOW_LOG();
if (showAtTheEnd == true) {
listAllTestError();
}
return -errorCount;
}
uint32_t etest::registerTest(etest::GenericTest* _element) {
if (_element == null) {
return -1;
}
getListOfTest().pushBack(_element);
return getListOfTest().size()-1;
}
/*
7h55'30 [P] elog | Log in file: '/tmp/elog_etk-test.log'
[==========] Running 13 tests from 4 test cases.
[----------] Global test environment set-up.
[----------] 1 test from TestEtkColor
[ RUN ] TestEtkColor.RGBA8
[ OK ] TestEtkColor.RGBA8 (0 ms)
[----------] 1 test from TestEtkColor (0 ms total)
[----------] 1 test from TestEtkFSNode
[ RUN ] TestEtkFSNode.checkType
[ OK ] TestEtkFSNode.checkType (1 ms)
[----------] 1 test from TestEtkFSNode (1 ms total)
[----------] 8 tests from TestEtkHash
[ RUN ] TestEtkHash.Creation
[ OK ] TestEtkHash.Creation (0 ms)
[ RUN ] TestEtkHash.AddElement
[ OK ] TestEtkHash.AddElement (0 ms)
[ RUN ] TestEtkHash.OverWriteElement
[ OK ] TestEtkHash.OverWriteElement (0 ms)
[ RUN ] TestEtkHash.RemoveElement
[ OK ] TestEtkHash.RemoveElement (0 ms)
[ RUN ] TestEtkHash.ExistElement
[ OK ] TestEtkHash.ExistElement (0 ms)
[ RUN ] TestEtkHash.clear
[ OK ] TestEtkHash.clear (0 ms)
[ RUN ] TestEtkHash.getKey
[ OK ] TestEtkHash.getKey (0 ms)
[ RUN ] TestEtkHash.getKeys
[ OK ] TestEtkHash.getKeys (0 ms)
[----------] 8 tests from TestEtkHash (0 ms total)
[----------] 3 tests from TestSTDSharedPtr
[ RUN ] TestSTDSharedPtr.testBaseLocal
create Example [0]
Remove Example [0]
[ OK ] TestSTDSharedPtr.testBaseLocal (0 ms)
[ RUN ] TestSTDSharedPtr.testBaseShared
create Example [1]
Remove Example [1]
[ OK ] TestSTDSharedPtr.testBaseShared (0 ms)
[ RUN ] TestSTDSharedPtr.testBaseSharedDouble
create Example [2]
Remove Example [2]
[ OK ] TestSTDSharedPtr.testBaseSharedDouble (0 ms)
[----------] 3 tests from TestSTDSharedPtr (0 ms total)
[----------] Global test environment tear-down
[==========] 13 tests from 4 test cases ran. (2 ms total)
[ PASSED ] 13 tests.
*/

View File

@ -1,341 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <etk/String.hpp>
#include <etest/debug.hpp>
#define TEST_CLASS_NAME(groupName, localName) \
groupName##_##localName##_test
/*
template <typename T>
class hasEtkStreamExporter {
typedef char one;
typedef long two;
//template <typename C> static one test( decltype(T::toString()) );
template <typename C> static one test( decltype(&etk::operator<<(etk::Stream&,const T&)) );
template <typename C> static two test(...);
public:
enum { value = sizeof(test<T>(0)) == sizeof(char) };
};
*/
template <typename T>
class hasMemberToString {
typedef char one;
typedef long two;
template <typename C> static one test( decltype(T::toString()) );
template <typename C> static two test(...);
public:
enum { value = sizeof(test<T>(0)) == sizeof(char) };
};
template<typename T>
struct hasEtkStreamExporter {
typedef char yes[1];
typedef char no[2];
template<typename U> static yes& test( U& );
template<typename U> static no& test(...);
static etk::Stream &s;
static T const &t;
static bool const value = sizeof( test( s << t ) ) == sizeof( yes ); // line 48
};
namespace has_insertion_operator_impl {
typedef char no;
typedef char yes[2];
struct any_t {
template<typename T> any_t( T const& );
};
no operator<<( etk::Stream&, any_t const& );
yes& test( etk::Stream& );
no test( no );
template<typename T>
struct has_insertion_operator {
static etk::Stream &s;
static T const &t;
static bool const value = sizeof( test(s << t) ) == sizeof( yes );
};
}
template<typename T>
struct has_insertion_operator :
has_insertion_operator_impl::has_insertion_operator<T> {
};
namespace etest {
template<class ETEST_TYPE,
typename etk::EnableIf<etk::IsSame<ETEST_TYPE,etk::NullPtr>::value, int>::type = 0 >
etk::String exportResultToString(const ETEST_TYPE& _element) {
return "null";
}
template<class ETEST_TYPE,
typename etk::EnableIf< !etk::IsSame<ETEST_TYPE,etk::NullPtr>::value
&& has_insertion_operator<ETEST_TYPE>::value, int>::type = 0 >
etk::String exportResultToString(const ETEST_TYPE& _element) {
etk::Stream tmp;
tmp << _element;
return tmp.str();
}
template<class ETEST_TYPE,
typename etk::EnableIf< !etk::IsSame<ETEST_TYPE,etk::NullPtr>::value
&& !has_insertion_operator<ETEST_TYPE>::value, int>::type = 0 >
etk::String exportResultToString(const ETEST_TYPE& _element) {
return "---";
}
class GenericTest {
private:
etk::String m_file;
uint32_t m_line;
etk::String m_testGroup;
etk::String m_testName;
bool m_haveError;
protected:
uint32_t m_numberCheck;
uint32_t m_numberCheckFail;
uint32_t m_numberCheckNotImplemented;
public:
GenericTest(const char* _file,
uint32_t _line,
const char* _testGroup,
const char* _testName);
virtual ~GenericTest() = default;
const etk::String& getFileName() const;
uint32_t getFileLine() const;
const etk::String& getTestGroup() const;
const etk::String& getTestName() const;
/**
* @brief Get if an error occured during the test
* @return true an error occured, false otherwise
*/
bool getError() const;
/**
* @brief Get the number of check done in the test
* @return simple count of test done
*/
uint32_t getNumberCheck() const;
/**
* @brief Get the number of check done in the test
* @return simple count of test done with error
*/
uint32_t getNumberCheckError() const;
/**
* @brief Get the number of check marked as not implemented
* @return simple count of test not implemented with error
*/
uint32_t getNumberCheckNotImplemented() const;
void addCheck() {
m_numberCheck++;
}
void testNotImplemented(uint32_t _line);
void testResult(bool _result,
const etk::String& _test1Value,
const etk::String& _test1,
const etk::String& _test2Value,
const etk::String& _test2,
uint32_t _line);
void testCatchThrow(const etk::Exception& exeption, uint32_t _line);
void testCatchThrow(uint32_t _line);
void clearLocal();
virtual void run() = 0;
};
void unInit();
void init(int32_t _argc, const char *_argv[]);
int32_t runAllTest();
uint32_t registerTest(etest::GenericTest* _element);
extern GenericTest* g_currentTest;
}
#define TEST(groupName,localName) \
class TEST_CLASS_NAME(groupName, localName) : public etest::GenericTest { \
protected: \
static uint32_t registerElement; \
public: \
TEST_CLASS_NAME(groupName, localName)(): \
etest::GenericTest(__FILE__, __LINE__, #groupName, #localName) { \
\
} \
void run() override; \
}; \
\
uint32_t TEST_CLASS_NAME(groupName, localName)::registerElement = etest::registerTest(\
etk::memory::allocatorNewFull<TEST_CLASS_NAME(groupName, localName)>("etest_test_class", null, __LINE__, __FILE__)); \
\
void TEST_CLASS_NAME(groupName, localName)::run()
// This all is to be compatible with the gtest API (in main lines).
#define RUN_ALL_TESTS etest::runAllTest
#define TEST_NOT_IMPLEMENTED() \
do { \
etest::g_currentTest->addCheck(); \
etest::g_currentTest->testNotImplemented(__LINE__); \
/* Force exit of the function */ \
return; \
} while (false)
#define EXPECT_EQ(element, result) \
do { \
try { \
etest::g_currentTest->addCheck(); \
ETEST_DEBUG(" [ SUB-RUN ] EXPECT_EQ(" << #element << ", " << #result << ");"); \
auto ETEST_VARIABLE_TMP_element = (element); \
auto ETEST_VARIABLE_TMP_result = (result); \
bool ETEST_VARIABLE_TMP_res = (ETEST_VARIABLE_TMP_element == ETEST_VARIABLE_TMP_result); \
if (etest::g_currentTest == null) { \
ETEST_CRITICAL("Not in a test"); \
} else { \
etest::g_currentTest->testResult(ETEST_VARIABLE_TMP_res, \
etest::exportResultToString(ETEST_VARIABLE_TMP_element), \
#element, \
etest::exportResultToString(ETEST_VARIABLE_TMP_result), \
#result, \
__LINE__); \
} \
ETEST_DEBUG(" [ SUB-DONE ]"); \
} catch ( etk::Exception e ) { \
etest::g_currentTest->testCatchThrow(e, __LINE__); \
} catch ( ... ) {\
etest::g_currentTest->testCatchThrow(__LINE__); \
} \
} while (false)
#define EXPECT_NE(element, result) \
do { \
try { \
etest::g_currentTest->addCheck(); \
ETEST_DEBUG(" [ SUB-RUN ] EXPECT_NE(" << #element << ", " << #result << ");"); \
auto ETEST_VARIABLE_TMP_element = (element); \
auto ETEST_VARIABLE_TMP_result = (result); \
bool ETEST_VARIABLE_TMP_res = (ETEST_VARIABLE_TMP_element != ETEST_VARIABLE_TMP_result); \
if (etest::g_currentTest == null) { \
ETEST_CRITICAL("Not in a test"); \
} else { \
etest::g_currentTest->testResult(ETEST_VARIABLE_TMP_res, \
etest::exportResultToString(ETEST_VARIABLE_TMP_element), \
#element, \
etest::exportResultToString(ETEST_VARIABLE_TMP_result), \
#result, \
__LINE__); \
} \
ETEST_DEBUG(" [ SUB-DONE ]"); \
} catch ( etk::Exception e ) { \
etest::g_currentTest->testCatchThrow(e, __LINE__); \
} catch ( ... ) {\
etest::g_currentTest->testCatchThrow(__LINE__); \
} \
} while (false)
#define ASSERT_NE(element, result) \
do { \
try { \
etest::g_currentTest->addCheck(); \
ETEST_DEBUG(" [ SUB-RUN ] ASSERT_NE(" << #element << ", " << #result << ");"); \
auto ETEST_VARIABLE_TMP_element = (element); \
auto ETEST_VARIABLE_TMP_result = (result); \
bool ETEST_VARIABLE_TMP_res = (ETEST_VARIABLE_TMP_element != ETEST_VARIABLE_TMP_result); \
if (etest::g_currentTest == null) { \
ETEST_CRITICAL("Not in a test"); \
} else { \
etest::g_currentTest->testResult(ETEST_VARIABLE_TMP_res, \
etest::exportResultToString(ETEST_VARIABLE_TMP_element), \
#element, \
etest::exportResultToString(ETEST_VARIABLE_TMP_result), \
#result, \
__LINE__); \
} \
ETEST_DEBUG(" [ SUB-DONE ]"); \
if (ETEST_VARIABLE_TMP_res == true) { \
return; \
} \
} catch ( etk::Exception e ) { \
etest::g_currentTest->testCatchThrow(e, __LINE__); \
} catch ( ... ) {\
etest::g_currentTest->testCatchThrow(__LINE__); \
} \
} while (false)
#define EXPECT_FLOAT_EQ_DELTA(element, result, delta) \
do { \
try { \
etest::g_currentTest->addCheck(); \
ETEST_DEBUG(" [ SUB-RUN ] EXPECT_FLOAT_EQ(" << #element << ", " << #result << ");"); \
auto ETEST_VARIABLE_TMP_element = (element); \
auto ETEST_VARIABLE_TMP_result = (result); \
float ETEST_VARIABLE_TMP_res2 = (ETEST_VARIABLE_TMP_element - ETEST_VARIABLE_TMP_result); \
bool ETEST_VARIABLE_TMP_res = false; \
if (ETEST_VARIABLE_TMP_res2 < delta && ETEST_VARIABLE_TMP_res2 > -delta) { \
ETEST_VARIABLE_TMP_res = true; \
} \
if (etest::g_currentTest == null) { \
ETEST_CRITICAL("Not in a test"); \
} else { \
etest::g_currentTest->testResult(ETEST_VARIABLE_TMP_res, \
etest::exportResultToString(ETEST_VARIABLE_TMP_element), \
#element, \
etest::exportResultToString(ETEST_VARIABLE_TMP_result), \
#result, \
__LINE__); \
} \
ETEST_DEBUG(" [ SUB-DONE ]"); \
} catch ( etk::Exception e ) { \
etest::g_currentTest->testCatchThrow(e, __LINE__); \
} catch ( ... ) {\
etest::g_currentTest->testCatchThrow(__LINE__); \
} \
} while (false)
#define EXPECT_FLOAT_EQ(element, result) \
EXPECT_FLOAT_EQ_DELTA(element, result, 0.00001f)
#define EXPECT_THROW(element, typeThrow) \
do { \
try { \
etest::g_currentTest->addCheck(); \
ETEST_DEBUG(" [ SUB-RUN ] EXPECT_THROW(" << #element << ", " << #typeThrow << ");"); \
element; \
if (etest::g_currentTest == null) { \
ETEST_CRITICAL("Not in a test"); \
} else { \
etest::g_currentTest->testResult(false, \
"", \
#element, \
"--- Not throw ---", \
#typeThrow, \
__LINE__); \
} \
ETEST_DEBUG(" [ SUB-DONE ]"); \
} catch ( typeThrow e ) { \
/*Normale Case ...*/ \
if (etest::g_currentTest == null) { \
ETEST_CRITICAL("Not in a test"); \
} else { \
etest::g_currentTest->testResult(true, \
"", \
#element, \
"--- Have Throw ---", \
#typeThrow, \
__LINE__); \
} \
ETEST_DEBUG(" [ SUB-DONE ]"); \
} catch ( etk::Exception e ) { \
etest::g_currentTest->testCatchThrow(e, __LINE__); \
} catch ( ... ) {\
etest::g_currentTest->testCatchThrow(__LINE__); \
} \
} while (false)

View File

@ -1,800 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2017, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/Allocator.hpp>
#include <stdlib.h>
void* operator new (size_t _size) {
void* data = malloc(_size);
return data;
}
void* operator new[] (size_t _size) {
void* data = malloc(_size);
return data;
}
void operator delete (void* ptr) {
free(ptr);
}
void operator delete[] (void* ptr) {
free(ptr);
}
#if ETK_MEMORY_CHECKER > 0
#include <pthread.h>
#define ETK_MEM_DEBUG_LEVEL 4
#define ETK_MEMORY_PRINT(...) \
do { \
printf("[PRINT] "); \
printf(__VA_ARGS__); \
printf("\n"); \
} while (false)
#if ETK_MEM_DEBUG_LEVEL > 0
#define ETK_MEMORY_ERROR(...) \
do { \
printf("[ERROR] "); \
printf(__VA_ARGS__); \
printf("\n"); \
} while (false)
#else
#define ETK_MEMORY_ERROR(...) do {} while (false)
#endif
#if ETK_MEM_DEBUG_LEVEL > 1
#define ETK_MEMORY_WARNING(...) \
do { \
printf("[WARNING] "); \
printf(__VA_ARGS__); \
printf("\n"); \
} while (false)
#else
#define ETK_MEMORY_WARNING(...) do {} while (false)
#endif
#if ETK_MEM_DEBUG_LEVEL > 2
#define ETK_MEMORY_INFO(...) \
do { \
printf("[INFO] "); \
printf(__VA_ARGS__); \
printf("\n"); \
} while (false)
#else
#define ETK_MEMORY_INFO(...) do {} while (false)
#endif
#if ETK_MEM_DEBUG_LEVEL > 3
#define ETK_MEMORY_DEBUG(...) \
do { \
printf("[DEBUG] "); \
printf(__VA_ARGS__); \
printf("\n"); \
} while (false)
#else
#define ETK_MEMORY_DEBUG(...) do {} while (false)
#endif
#if ETK_MEM_DEBUG_LEVEL > 4
#define ETK_MEMORY_VERBOSE(...) \
do { \
printf("[VERBOSE] "); \
printf(__VA_ARGS__); \
printf("\n"); \
} while (false)
#else
#define ETK_MEMORY_VERBOSE(...) do {} while (false)
#endif
#if ETK_MEMORY_CHECKER > 1
// Max stric size of filename, variable Name, and fonction Name
#define ETK_MEM_MAX_STRING_SIZE (77)
#endif
/**
* @brief Class to save allocation elements
*/
class MemoryElementSystem {
public:
bool used; //!< for list system
char* pointerAllocated; //!< pointer really allocated
char* pointerGiveToUser; //!< pointer sent to the USER (in case of check of memory overflow)
size_t sizeUser; //!< User request size
size_t sizeAllocate; //!< data size really allocated by the tool
size_t sizeData; //!< current data size of allocated memory
size_t id; //!< Element ID to know the allocation Order
#if ETK_MEMORY_CHECKER > 1
const char* variableName; //!< Variable name when allocate
const char* functionName; //!< function name that allocate this buffer
const char* fileName; //!< function name that allocate this buffer
size_t functionLine; //!< function line where the buffer was allocated
#endif
};
class memoryAllocatorHandle {
private:
// to prevent double access:
pthread_mutex_t m_mutex;
#if ETK_MEMORY_CHECKER > 1
// Basic header to check the memory everflow (abstract element)
uint8_t* m_blockCheckMemory;
// To know the size of pre header and Post-header
uint32_t m_checkBorneSize;
#endif
// To do statictic memory allocation (Total of memory allocate from the start of program)
uint64_t m_totalMemAllocated;
// To do statictic memory allocation (Current size of allocated memory)
uint64_t m_currentMemAllocated;
// To do statictic memory allocation (Current size of allocated memory)
int64_t m_currentMemAllocatedCount;
int64_t m_currentMemAllocatedCountSize[64];
int64_t m_totalMemAllocatedCountSize[64];
// To do statictic memory allocation (Max of memory allocated in the same Time)
uint64_t m_maxMemoryAllocated;
// To do statictic memory allocation (number of allocation)
int64_t m_dynamicID;
// To know if this memory system is initialized
bool m_memSystemInitialize;
// List of element to remember allocate...
size_t m_memListElementSize;
MemoryElementSystem* m_memListElements;
public:
memoryAllocatorHandle():
m_mutex(PTHREAD_MUTEX_INITIALIZER),
#if ETK_MEMORY_CHECKER > 1
// Basic header to check the memory everflow (abstract element)
m_blockCheckMemory(null),
m_checkBorneSize(10*8),
#endif
m_totalMemAllocated(0),
m_currentMemAllocated(0),
m_currentMemAllocatedCount(0),
m_maxMemoryAllocated(0),
m_dynamicID(0),
m_memSystemInitialize(false),
m_memListElementSize(1024),
m_memListElements(null) {
#if ETK_MEMORY_CHECKER > 1
static const uint8_t blockCheckMemory[] = {
0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88,
0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00,
0x55, 0xAA, 0x5A, 0xA5, 0x11, 0xFF, 0x15, 0xB2,
0x55, 0xAA, 0x5A, 0xA5, 0x11, 0xFF, 0x15, 0xB2,
0x55, 0xAA, 0x5A, 0xA5, 0x11, 0xFF, 0x15, 0xB2,
0x55, 0xAA, 0x5A, 0xA5, 0x11, 0xFF, 0x15, 0xB2,
0x55, 0xAA, 0x5A, 0xA5, 0x11, 0xFF, 0x15, 0xB2,
0x55, 0xAA, 0x5A, 0xA5, 0x11, 0xFF, 0x15, 0xB2,
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
};
m_blockCheckMemory = (uint8_t*)blockCheckMemory;
#endif
lock();
memset(m_totalMemAllocatedCountSize, 0, sizeof(m_totalMemAllocatedCountSize));
memset(m_currentMemAllocatedCountSize, 0, sizeof(m_currentMemAllocatedCountSize));
if (m_memSystemInitialize == true) {
return;
}
int systemRet;
if (m_memListElements == null) {
m_memListElements = new MemoryElementSystem[m_memListElementSize];
}
for (size_t iii=0; iii<m_memListElementSize; ++iii) {
m_memListElements[iii].used = false;
}
m_memSystemInitialize = true;
unLock();
}
/**
* @brief Update statistique
* @param[in] _dataSize Allocated size
*/
void addMemory(size_t _dataSize) {
m_totalMemAllocated += _dataSize;
m_currentMemAllocated += _dataSize;
if (m_currentMemAllocated > m_maxMemoryAllocated) {
m_maxMemoryAllocated = m_currentMemAllocated;
}
m_currentMemAllocatedCount++;
for (int32_t iii=0; iii<64; ++iii) {
if (_dataSize <= (uint64_t(1) << iii)) {
m_totalMemAllocatedCountSize[iii]++;
break;
}
}
for (int32_t iii=0; iii<64; ++iii) {
if (_dataSize <= (uint64_t(1) << iii)) {
m_currentMemAllocatedCountSize[iii]++;
break;
}
}
}
void lock() {
pthread_mutex_lock(&m_mutex);
}
void unLock() {
pthread_mutex_unlock(&m_mutex);
}
/**
* @brief Update memory statistique
* @param[in] dataSize Removed size.
*/
void removeMemory(size_t _dataSize) {
m_currentMemAllocated -= _dataSize;
m_currentMemAllocatedCount--;
for (int32_t iii=0; iii<64; ++iii) {
if (_dataSize <= (uint64_t(1) << iii)) {
m_currentMemAllocatedCountSize[iii]--;
break;
}
}
}
/**
* @brief Get a current free element of the structure
* @return the free Element find or null
*/
MemoryElementSystem* getFreeElement() {
for (size_t iii=0; iii<m_memListElementSize; ++iii) {
if (m_memListElements[iii].used == false) {
return &(m_memListElements[iii]);
}
}
// resize Linker size:
m_memListElementSize *= 2;
ETK_MEMORY_DEBUG("Realloate the allocator memory system: %ld", uint64_t(m_memListElementSize));
MemoryElementSystem* tmp = new MemoryElementSystem[m_memListElementSize];
if (tmp == null) {
m_memListElementSize /= 2;
return null;
}
for (size_t iii=0; iii<m_memListElementSize; ++iii) {
tmp[iii].used = false;
}
memcpy(tmp, m_memListElements, sizeof(MemoryElementSystem) * m_memListElementSize / 2);
delete[] m_memListElements;
m_memListElements = tmp;
ETK_MEMORY_DEBUG("Realloate the allocator memory system: %ld (done)", uint64_t(m_memListElementSize));
// try again
for (size_t iii=0; iii<m_memListElementSize; ++iii) {
if (m_memListElements[iii].used == false) {
return &(m_memListElements[iii]);
}
}
return null;
}
/**
* @brief Get the element structure reference if it existed
* @param[in] pointerAdresse pointer to retreave the element
* @return get the element reference for the curent adress pointer
*/
MemoryElementSystem *getAdressedElement(char* _pointerAdresse) {
for (size_t iii=0; iii<m_memListElementSize; ++iii) {
if (m_memListElements[iii].used == true) {
if (m_memListElements[iii].pointerGiveToUser == _pointerAdresse) {
return &(m_memListElements[iii]);
}
}
}
return null;
}
#if ETK_MEMORY_CHECKER > 1
/**
* @brief Verify the curent Memory header
* This function vereify the memeory with the common header and header size.
* @param[in] pointerAdresse Start pointer to verify data
* @return the check result :
* - true : if an error existe
* - false : if no error
*/
bool checkMem(char* _pointerAdresse) {
uint8_t *pointer = (uint8_t*)_pointerAdresse;
for (size_t iii=0; iii<m_checkBorneSize; ++iii) {
if (*(pointer++) != m_blockCheckMemory[iii]) {
return true;
}
}
return false;
}
#endif
#if ETK_MEMORY_CHECKER > 1
/**
* @brief Display the current buffer to check error.
* Desactivated by debault (only for extreme debug)
* @param[in] _pointerAdresse pointer to start the print
* @param[in] _size number of char to display
*/
void displayBuffer(char* _pointerAdresse, uint32_t _size) {
/*
uint8_t *pointer = (uint8_t *)_pointerAdresse;
uint32_t i;
for (i=0; i<_size ;i++) {
if (i%50 == 0) {
printf("\n");
}
printf("%02X ", pointer[i]);
}
printf("\n");
*/
}
#endif
#if ETK_MEMORY_CHECKER > 1
/**
* @brief Get the filename (without all the Path)
* @param[in] _fileLink pointer on the name with the Path
* @return The last pointer of the filename
*/
const char *getFileName(const char* _fileLink) {
const char *element_2 = _fileLink;
const char *element_1 = _fileLink;
const char *element_0 = _fileLink;
const char * pch = null;
pch = _fileLink;
while (pch != null) {
element_2 = element_1;
element_1 = element_0;
element_0 = pch;
pch = strchr(pch+1, '/');
}
return element_2;
}
#endif
void displayMemoryProperty(MemoryElementSystem& _element) {
#if ETK_MEMORY_CHECKER > 1
bool errorOccured = false;
ETK_MEMORY_WARNING("Not FREE : %p ==> %p : %ld Bytes var=%s id=%ld",
_element.pointerAllocated,
_element.pointerGiveToUser,
_element.sizeUser,
(_element.variableName==null?"---":_element.variableName),
_element.id);
ETK_MEMORY_WARNING("%8d : %s() line=%ld file=%s",
(uint32_t)_element.id,
(_element.functionName==null?"---":_element.functionName),
_element.functionLine,
(_element.fileName==null?"---":_element.fileName));
if (checkMem(_element.pointerAllocated) == true) {
ETK_MEMORY_ERROR("MEM LOG (L): %s : %ld Bytes @ %p ==> user @ %p (depassement pre)",
(_element.variableName==null?"---":_element.variableName),
_element.sizeUser,
_element.pointerAllocated,
_element.pointerGiveToUser);
errorOccured = true;
}
if (checkMem(_element.pointerAllocated + _element.sizeUser + m_checkBorneSize) == true) {
ETK_MEMORY_ERROR("MEM LOG (L): %s : %ld Bytes @ %p ==> user @ %p (depassement post)",
(_element.variableName==null?"---":_element.variableName),
_element.sizeUser,
_element.pointerAllocated,
_element.pointerGiveToUser);
errorOccured = true;
}
if (errorOccured == true) {
displayBuffer(_element.pointerAllocated,
_element.sizeAllocate);
assert(false);
}
#else
ETK_MEMORY_WARNING("Not LOG : %p ==> %p : %ld Bytes",
_element.pointerAllocated,
_element.pointerGiveToUser,
uint64_t(_element.sizeUser));
#endif
}
uint64_t* createSnapshoot() {
lock();
size_t countElement = 0;
for (size_t iii=0; iii<m_memListElementSize; ++iii) {
if (m_memListElements[iii].used == true) {
countElement++;
}
}
if (countElement == 0) {
unLock();
return null;
}
ETK_MEMORY_VERBOSE("find %ld element in memory", (uint64_t)countElement);
uint64_t* out = new uint64_t[countElement+10];
memset(out, 0, sizeof(uint64_t)*(countElement+10));
countElement = 0;
for (size_t iii=0; iii<m_memListElementSize; ++iii) {
if (m_memListElements[iii].used == true) {
out[countElement++] = uint64_t(m_memListElements[iii].id);
}
}
unLock();
return out;
}
bool checkSnapshoot(uint64_t* _handle) {
if (_handle == null) {
return false;
}
lock();
bool haveError = false;
for (size_t iii=0; iii<m_memListElementSize; ++iii) {
if (m_memListElements[iii].used == true) {
uint64_t* dataBase = _handle;
bool find = false;
size_t jjj = 0;
while (dataBase[jjj] != 0) {
if (dataBase[jjj] == uint64_t(m_memListElements[iii].id)) {
find = true;
break;
}
jjj++;
//dataBase++;
}
if (find == false) {
haveError = true;
displayMemoryProperty(m_memListElements[iii]);
}
}
}
unLock();
return haveError == false;
}
void flipID(void* _pointer1, void* _pointer2) {
MemoryElementSystem* handle1 = getAdressedElement((char*)_pointer1);
MemoryElementSystem* handle2 = getAdressedElement((char*)_pointer2);
if ( handle1 == null
|| handle2 == null) {
ETK_MEMORY_WARNING("MEM flip error %p %p", _pointer1, _pointer2);
return;
}
etk::swap(handle1->id, handle2->id);
}
void clearSnapshoot(uint64_t* _handle) {
if (_handle == null) {
return;
}
delete[] (uint64_t*)_handle;
}
void* allocate(size_t _num,
size_t _size,
const char* _variableName,
const char* _functionName,
int32_t _line,
const char* _fileName) {
MemoryElementSystem* myElement;
lock();
m_dynamicID++;
myElement = getFreeElement();
// check free handle
if (myElement != null) {
#if ETK_MEMORY_CHECKER > 1
const char *fileNameShort = null;
#endif
myElement->id = m_dynamicID;
// if an element is free :
myElement->sizeUser = _size * _num;
myElement->sizeData = _size;
#if ETK_MEMORY_CHECKER > 1
myElement->sizeAllocate = myElement->sizeUser + m_checkBorneSize*2;
myElement->variableName = _variableName;
myElement->functionName = _functionName;
myElement->fileName = _fileName;
//fileNameShort = getFileName(_fileName);
myElement->functionLine = _line;
#else
myElement->sizeAllocate = myElement->sizeUser;
#endif
myElement->pointerAllocated = null;
myElement->pointerGiveToUser = null;
// real allocation :
myElement->pointerAllocated = new char[myElement->sizeAllocate];
if (myElement->pointerAllocated != null) {
// set edded memory
addMemory(myElement->sizeUser);
// save curent pointer
#if ETK_MEMORY_CHECKER > 1
myElement->pointerGiveToUser = myElement->pointerAllocated + m_checkBorneSize;
#else
myElement->pointerGiveToUser = myElement->pointerAllocated;
#endif
ETK_MEMORY_VERBOSE("MEM allocate (L): %s : %ld Bytes @ %p ==> user @ %p id=%ld", _variableName, _num*_size, myElement->pointerAllocated, myElement->pointerGiveToUser, myElement->id);
// set bornes:
#if ETK_MEMORY_CHECKER > 1
memcpy(myElement->pointerAllocated, m_blockCheckMemory, m_checkBorneSize);
#endif
#if ETK_MEMORY_CHECKER > 1
memcpy(myElement->pointerAllocated + myElement->sizeUser + m_checkBorneSize, m_blockCheckMemory, m_checkBorneSize);
#endif
// add to the elements list
myElement->used = true;
} else {
ETK_MEMORY_VERBOSE("MEM allocate (L): %s : %ld Bytes @ (ERROR)", _variableName, uint64_t(myElement->sizeUser));
}
unLock();
// else : no memory allocated ==> nothing to save
return myElement->pointerGiveToUser;
} else {
// if no free handle:
void * localPointer = null;
localPointer = new char[_num * _size];
if (localPointer != null) {
if (_variableName == null) {
ETK_MEMORY_VERBOSE("MEM allocate (-): --- : %lu Bytes @ %p (No log...)", _num*_size, localPointer);
} else {
ETK_MEMORY_VERBOSE("MEM allocate (-): %s : %lu Bytes @ %p (No log...)", _variableName, _num*_size, localPointer);
}
// set edded memory
//addMemory(_num * _size); // not availlable can not un add memory
m_totalMemAllocated += _num * _size;
} else {
if (_variableName == null) {
ETK_MEMORY_VERBOSE("MEM allocate (-): --- : %lu Bytes @ (ERROR)", _num*_size);
} else {
ETK_MEMORY_VERBOSE("MEM allocate (-): %s : %lu Bytes @ (ERROR)", _variableName, _num*_size);
}
}
unLock();
return localPointer;
}
}
void remove(void* _pointerData, const char* _variableName, const char* _functionName, int32_t _line, const char* _fileName) {
MemoryElementSystem * myElement;
lock();
char* asyncFree = null;
myElement = getAdressedElement((char*)_pointerData);
// check free handle
if (myElement != null) {
bool errorOccured = false;
// We know this element :
#if ETK_MEMORY_CHECKER > 1
// check end and Start :
if (checkMem(myElement->pointerAllocated) == true) {
if (_variableName == null) {
ETK_MEMORY_ERROR("MEM free (L): --- : %ld Bytes @ %p ==> user @ %p (depassement pre)", uint64_t(myElement->sizeUser), myElement->pointerAllocated, myElement->pointerGiveToUser);
} else {
ETK_MEMORY_ERROR("MEM free (L): %s : %ld Bytes @ %p ==> user @ %p (depassement pre)", _variableName, uint64_t(myElement->sizeUser), myElement->pointerAllocated, myElement->pointerGiveToUser);
}
errorOccured = true;
}
if (checkMem(myElement->pointerAllocated + myElement->sizeUser + m_checkBorneSize) == true) {
if (_variableName == null) {
ETK_MEMORY_ERROR("MEM free (L): --- : %ld Bytes @ %p ==> user @ %p (depassement post)", uint64_t(myElement->sizeUser), myElement->pointerAllocated, myElement->pointerGiveToUser);
} else {
ETK_MEMORY_ERROR("MEM free (L): %s : %ld Bytes @ %p ==> user @ %p (depassement post)", _variableName, uint64_t(myElement->sizeUser), myElement->pointerAllocated, myElement->pointerGiveToUser);
}
errorOccured = true;
}
if (errorOccured == false) {
if (_variableName == null) {
ETK_MEMORY_VERBOSE("MEM free (L): --- : %ld Bytes @ %p ==> user @ %p", uint64_t(myElement->sizeUser), myElement->pointerAllocated, myElement->pointerGiveToUser);
} else {
ETK_MEMORY_VERBOSE("MEM free (L): %s : %ld Bytes @ %p ==> user @ %p", _variableName, uint64_t(myElement->sizeUser), myElement->pointerAllocated, myElement->pointerGiveToUser);
}
} else {
displayBuffer(myElement->pointerAllocated, myElement->sizeAllocate);
//ETK_ASSERT(1 == 0, "Memory error detected");
}
#else
if (_variableName == null) {
ETK_MEMORY_VERBOSE("MEM free (L): --- : %ld Bytes @ %p ==> user @ %p", uint64_t(myElement->sizeUser), myElement->pointerAllocated, myElement->pointerGiveToUser);
} else {
ETK_MEMORY_VERBOSE("MEM free (L): %s : %ld Bytes @ %p ==> user @ %p", _variableName, uint64_t(myElement->sizeUser), myElement->pointerAllocated, myElement->pointerGiveToUser);
}
#endif
asyncFree = myElement->pointerAllocated;
myElement->pointerAllocated = null;
removeMemory(myElement->sizeUser);
myElement->used = false;
}
unLock();
if (asyncFree != null) {
// free Buffer:
delete[] asyncFree;
return;
}
//Unknown element
if (_variableName == null) {
ETK_MEMORY_WARNING("MEM free (-): --- : ?? Bytes @ %p ==> unsaved element", _pointerData);
} else {
ETK_MEMORY_WARNING("MEM free (-): %s : ?? Bytes @ %p ==> unsaved element", _variableName, _pointerData);
}
lock();
for (size_t iii=0; iii<m_memListElementSize; ++iii) {
if (m_memListElements[iii].used == false) {
if (m_memListElements[iii].pointerGiveToUser == _pointerData) {
ETK_MEMORY_ERROR("MEM free (D): --- : user @ %p (double 'free' detected)", m_memListElements[iii].pointerGiveToUser);
}
}
}
unLock();
delete (char*)_pointerData;
}
void displayMemorySize(size_t _size, const char* _name) {
if (_size > 1024*1024*1024) {
uint32_t teraByte = _size/(1024*1024*1024);
uint32_t megaByte = (_size/(1024*1024)%1024);
uint32_t kiloByte = (_size/1024) % 1024;
uint32_t byte = _size % 1024;
ETK_MEMORY_DEBUG("MEM : %s: %4dT %4dM %4dk %4dB", _name, teraByte, megaByte, kiloByte, byte);
} else if (_size > 1024*1024) {
uint32_t megaByte = _size/(1024*1024);
uint32_t kiloByte = (_size/1024) % 1024;
uint32_t byte = _size % 1024;
ETK_MEMORY_DEBUG("MEM : %s: %4dM %4dk %4dB", _name, megaByte, kiloByte, byte);
} else if (m_totalMemAllocated > 1024) {
uint32_t megaByte = _size/(1024*1024);
uint32_t kiloByte = (_size/1024) % 1024;
uint32_t byte = _size % 1024;
ETK_MEMORY_DEBUG("MEM : %s: %4dk %4dB", _name, kiloByte, byte);
} else {
uint32_t megaByte = _size/(1024*1024);
uint32_t kiloByte = (_size/1024) % 1024;
uint32_t byte = _size % 1024;
ETK_MEMORY_DEBUG("MEM : %s: %4dB", _name, byte);
}
}
void display(bool _statusOnly) {
lock();
ETK_MEMORY_DEBUG("MEM: Log : ------------------------------");
ETK_MEMORY_DEBUG("MEM: (current/total) allocation: %ld / %ld ", int64_t(m_currentMemAllocatedCount), uint64_t(m_dynamicID));
for (int32_t iii=0; iii<64; ++iii) {
if (m_currentMemAllocatedCountSize[iii] != 0) {
ETK_MEMORY_DEBUG("MEM: Number (current/Total) of allocation: 2<<%2d: %8ld / %8ld %9ld Bytes",
iii,
uint64_t(m_currentMemAllocatedCountSize[iii]),
uint64_t(m_totalMemAllocatedCountSize[iii]),
(uint64_t(1)<<iii));
}
}
ETK_MEMORY_DEBUG("MEM: number of element that can be registered %ld", m_memListElementSize);
displayMemorySize(m_memListElementSize*sizeof(MemoryElementSystem) + sizeof(memoryAllocatorHandle), "System allocator ");
displayMemorySize(m_totalMemAllocated, "Total allocated ");
displayMemorySize(m_currentMemAllocated, "Total Current Use ");
displayMemorySize(m_maxMemoryAllocated, "Max simultaneous Use ");
if (_statusOnly == true) {
unLock();
return;
}
ETK_MEMORY_DEBUG("MEM : Log : ----------- Memory -----------");
for (size_t iii=0; iii<m_memListElementSize; ++iii) {
if (m_memListElements[iii].used == true) {
displayMemoryProperty(m_memListElements[iii]);
}
}
ETK_MEMORY_DEBUG("MEM : -----------------------------------");
unLock();
}
bool check() {
bool detectError = false;
lock();
for (size_t iii=0; iii<m_memListElementSize; ++iii) {
if (m_memListElements[iii].used == true) {
#if ETK_MEMORY_CHECKER > 1
bool errorOccured = false;
if (checkMem(m_memListElements[iii].pointerAllocated) == true) {
const char* tmp = m_memListElements[iii].variableName;
if (tmp == null) {
tmp = "---";
}
ETK_MEMORY_ERROR("MEM CHECK (L): %s : %ld Bytes @ %p ==> user @ %p (depassement pre)", tmp, uint64_t(m_memListElements[iii].sizeUser), m_memListElements[iii].pointerAllocated, m_memListElements[iii].pointerGiveToUser);
errorOccured = true;
}
if (checkMem(m_memListElements[iii].pointerAllocated + m_memListElements[iii].sizeUser + m_checkBorneSize) == true) {
const char* tmp = m_memListElements[iii].variableName;
if (tmp == null) {
tmp = "---";
}
ETK_MEMORY_ERROR("MEM CHECK (L): %s : %ld Bytes @ %p ==> user @ %p (depassement post)", tmp, uint64_t(m_memListElements[iii].sizeUser), m_memListElements[iii].pointerAllocated, m_memListElements[iii].pointerGiveToUser);
errorOccured = true;
}
if (errorOccured == true) {
detectError = true;
displayBuffer(m_memListElements[iii].pointerAllocated, m_memListElements[iii].sizeAllocate);
// Clean all the erreor to prevent the other error display
memcpy(m_memListElements[iii].pointerAllocated, m_blockCheckMemory, m_checkBorneSize);
// Clean all the erreor to prevent the other error display
memcpy(m_memListElements[iii].pointerAllocated + m_memListElements[iii].sizeUser + m_checkBorneSize, m_blockCheckMemory, m_checkBorneSize);
}
#endif
}
}
unLock();
return detectError;
}
bool checkPointer(void* _pointer) {
lock();
for (size_t iii=0; iii<m_memListElementSize; ++iii) {
if (m_memListElements[iii].used == true) {
bool find = false;
if (m_memListElements[iii].pointerAllocated == _pointer) {
find = true;
}
if (m_memListElements[iii].pointerGiveToUser == _pointer) {
find = true;
}
if (find == true) {
unLock();
return true;
}
}
}
unLock();
ETK_MEMORY_ERROR("MEM Check pointer: Can not find the pointer in the system DB...");
return false;
}
};
// This permit to initialize the handle just in time ...
static memoryAllocatorHandle& getHandle() {
static memoryAllocatorHandle tmp;
return tmp;
}
uint64_t* etk::memory::createSnapshoot() {
return getHandle().createSnapshoot();
}
bool etk::memory::checkSnapshoot(uint64_t* _handle) {
return getHandle().checkSnapshoot(_handle);
}
void etk::memory::clearSnapshoot(uint64_t* _handle) {
getHandle().clearSnapshoot(_handle);
}
void etk::memory::flipID(void* _pointer1, void* _pointer2) {
getHandle().flipID(_pointer1, _pointer2);
}
void* etk::memory::allocate(size_t _num,
size_t _size,
const char* _variableName,
const char* _functionName,
int32_t _line,
const char* _fileName) {
/*
if ( (_num * _size ) > 100*1024*1024) {
printf("-------------------------------------------------------------------------------------------\n");
printf("== %s:%d %s %s\n", _fileName, _fileName, _functionName, _variableName);
printf("-------------------------------------------------------------------------------------------\n");
assert(false);
}
*/
return getHandle().allocate(_num, _size, _variableName, _functionName, _line, _fileName);
}
void etk::memory::remove(void* _pointerData, const char* _variableName, const char* _functionName, int32_t _line, const char* _fileName) {
getHandle().remove(_pointerData, _variableName, _functionName, _line, _fileName);
}
void etk::memory::display(bool _statusOnly) {
getHandle().display(_statusOnly);
}
bool etk::memory::check() {
return getHandle().check();
}
bool etk::memory::checkPointer(void* _pointer) {
return getHandle().checkPointer(_pointer);
}
#endif

View File

@ -1,201 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2017, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
// it is define bu generic "include <new>" ==> no double define of placement new
#ifndef _NEW
// Default placement versions of operator new (use char* instead of void* to permit no multiple definition).
inline void* operator new(size_t, char* _p) throw() {
return _p;
}
inline void operator delete (void*, char*) throw() {
}
#endif
//#define ETK_MEMORY_CHECKER 2
#ifndef ETK_MEMORY_CHECKER
#define ETK_MEMORY_CHECKER 0
#endif
#if ETK_MEMORY_CHECKER > 0
namespace etk {
namespace memory {
/**
* @brief Create an allocation memory and set start and stop header. Log in the curent structure.
* If no more free element in the basic structure, the system allocate without saving information and header start and stop
* @param[in] _num number of alament needed to allocate
* @param[in] _size Size of one element to allocate
* @param[in] _variableName Variable name to allocate (must be a real static cont never removed)
* @param[in] _functionName Fonction Name where allocation is done (must be a real static cont never removed)
* @param[in] _line Line where allocation is done.
* @param[in] _fileName File where allocation is done. (must be a real static cont never removed)
* @return pointer on the current memory allocation. (or NULL if an error occured)
*/
void* allocate(size_t _num, size_t _size, const char* _variableName, const char* _functionName, int32_t _line, const char* _fileName);
/**
* @brief Free Memory with the dedicate pointer
* If the memory is not saved the current pointer is free, else we get the real pointer and free it
* @param[in,out] _pointerData User pointer Data.
* @param[in] _variableName Variable name where free is done. (must be a real static cont never removed)
* @param[in] _functionName Fonction name where free is done. (must be a real static cont never removed)
* @param[in] _line line where free is done.
* @param[in] _fileName file where free is done. (must be a real static cont never removed)
*/
void remove(void* _pointerData, const char* _variableName, const char* _functionName, int32_t _line, const char* _fileName);
/**
* @brief Display all memory not free by this system.
* @param[in] _statusOnly Display only the memory allocation status.
*/
void display(bool _statusOnly=true);
/**
* @brief Check if memory have not write out of the range.
*/
bool check();
/**
* @brief Check if the pointer is already register in the allocator (can not predist the size, but permti to know where the error came from in debug mode
* @param[in] _pointerPointer on the data to check
* @return true the pointer is set
* @return false the pointer is not set
*/
bool checkPointer(void* _pointer);
/**
* @brief Create a snapshoot of the memory
* @return handle on the snapshoot
*/
uint64_t* createSnapshoot();
/**
* @brief Check if a snapshoot is correct (no change)
* @param[in] _handle Handle on the snapshoot
* @return true the memory is identical
*/
bool checkSnapshoot(uint64_t* _handle);
/**
* @brief Free the snapshoot handle
* @param[in] _handle Handle on the snapshoot
*/
void clearSnapshoot(uint64_t* _handle);
/**
* @brief When reallocate data and permit to the allocator to not warning when check the the snapshoot
*/
void flipID(void* _pointer1, void* _pointer2);
template<class ETK_TYPE,
class... ETK_MEMORY_ARGS>
ETK_TYPE* allocatorNew(ETK_MEMORY_ARGS&& ... _args) {
char* tmp = (char*)etk::memory::allocate(1, sizeof(ETK_TYPE), "new", __func__, __LINE__, __FILE__);
return new (tmp) ETK_TYPE(etk::forward<ETK_MEMORY_ARGS>(_args)...);
}
template<class ETK_TYPE,
class... ETK_MEMORY_ARGS>
ETK_TYPE* allocatorNewSize(size_t _size, ETK_MEMORY_ARGS&& ... _args) {
char* tmp = (char*)etk::memory::allocate(_size, sizeof(ETK_TYPE), "new", __func__, __LINE__, __FILE__);
return new (tmp) ETK_TYPE(etk::forward<ETK_MEMORY_ARGS>(_args)...);
}
template<class ETK_TYPE,
class... ETK_MEMORY_ARGS>
ETK_TYPE* allocatorNewFull(const char* _variableName,
const char* _functionName,
int32_t _line,
const char* _fileName,
ETK_MEMORY_ARGS&& ... _args) {
char* tmp = (char*)etk::memory::allocate(1, sizeof(ETK_TYPE), _variableName, _functionName, _line, _fileName);
return new (tmp) ETK_TYPE(etk::forward<ETK_MEMORY_ARGS>(_args)...);
}
template<class ETK_TYPE>
void allocatorDelete(ETK_TYPE* _element,
const char* _variableName = "",
const char* _functionName = "",
int32_t _line = __LINE__,
const char* _fileName = __FILE__) {
if (_element == null) {
return;
}
_element->~ETK_TYPE();
etk::memory::remove((void*)_element, _variableName, _functionName, _line, _fileName);
_element = null;
}
}
}
#define ETK_NEW(type, ...) \
new ((char*)etk::memory::allocate(1, sizeof(type), #type, __func__, __LINE__, __FILE__)) type(__VA_ARGS__)
#define ETK_DELETE(type, pointerData) \
etk::memory::allocatorDelete((type*)(pointerData), #type, __func__, __LINE__, __FILE__)
#define ETK_MALLOC(type, nbElements) \
((type *)etk::memory::allocate( (nbElements), sizeof(type), #type, __func__, __LINE__, __FILE__))
#define ETK_FREE(type, pointerData) \
etk::memory::remove( (pointerData), #type, __func__, __LINE__, __FILE__)
#define ETK_MEM_SHOW_LOG(...) \
etk::memory::display(__VA_ARGS__)
#define ETK_MEM_CHECK() \
etk::memory::check()
#define ETK_MEM_CHECK_POINTER(pointer) \
etk::memory::checkPointer(pointer)
#define ETK_MEM_FLIP_ID(pointer1, pointer2) \
etk::memory::flipID((void*)pointer1, (void*)pointer2)
#else
namespace etk {
namespace memory {
template<class ETK_TYPE,
class... ETK_MEMORY_ARGS>
ETK_TYPE* allocatorNew(ETK_MEMORY_ARGS&& ... _args) {
return new ETK_TYPE(etk::forward<ETK_MEMORY_ARGS>(_args)...);
}
template<class ETK_TYPE,
class... ETK_MEMORY_ARGS>
ETK_TYPE* allocatorNewFull(const char* _variableName,
const char* _functionName,
int32_t _line,
const char* _fileName,
ETK_MEMORY_ARGS&& ... _args) {
return new ETK_TYPE(etk::forward<ETK_MEMORY_ARGS>(_args)...);
}
template<class ETK_TYPE>
void allocatorDelete(ETK_TYPE* _element,
const char* _variableName = "",
const char* _functionName = "",
int32_t _line = __LINE__,
const char* _fileName = __FILE__) {
delete _element;
}
}
}
#define ETK_NEW(type, ...) \
new type(__VA_ARGS__)
#define ETK_DELETE(type, pointerData) \
delete ((type*)(pointerData))
#define ETK_MALLOC(dataType, nbElements) \
(dataType *)new dataType[nbElements]
#define ETK_FREE(type, pointerData) \
delete[] (type*)pointerData
#define ETK_MEM_SHOW_LOG(...) \
do { } while(false)
#define ETK_MEM_CHECK() \
do {} while(false)
#define ETK_MEM_CHECK_POINTER(pointer) \
do {} while(false)
#define ETK_MEM_FLIP_ID(pointer1, pointer2) \
do {} while(false)
#endif

View File

@ -1,884 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL-2 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <etk/Stream.hpp>
#include <etk/Allocator.hpp>
#include <etk/Exception.hpp>
//#define ETK_ARRAY_DEBUG(...) printf(__VA_ARGS__)
#define ETK_ARRAY_DEBUG(...) do {} while (false)
namespace etk {
class Stream;
/**
* @brief Array class ...
*
* @param[in] ETK_ARRAY_TYPE class type of the current element.
*
* m_data
* <------------ m_dataSize ------------>
* ----------------------------------------
* | 0 |
* |--------------------------------------|
* | 1 |
* |--------------------------------------|
* | 2 |
* |--------------------------------------|
* m_size | 3 |
* |--------------------------------------|
* | x |
* |--------------------------------------|
* | x |
* |--------------------------------------|
* | x |
* |--------------------------------------|
* | x |
* |--------------------------------------|
* | x |
* |--------------------------------------|
* | x |
* |--------------------------------------|
* | x |
* |--------------------------------------|
* ETK_ARRAY_SIZE | x |
* ----------------------------------------
*/
template<class ETK_ARRAY_TYPE, size_t ETK_ARRAY_SIZE=1> class Array {
public:
class Iterator {
private:
size_t m_current; //!< current Id on the Array
Array<ETK_ARRAY_TYPE, ETK_ARRAY_SIZE>* m_array; //!< Pointer on the current element of the ArrayBin
public:
/**
* @brief Basic iterator constructor with no link with an etk::Array
*/
Iterator():
m_current(0),
m_array(null) {
// nothing to do ...
}
/**
* @brief Recopy constructor on a specific etkArray.
* @param[in] _obj The Iterator that might be copy
*/
Iterator(const Iterator & _obj):
m_current(_obj.m_current),
m_array(_obj.m_array) {
// nothing to do ...
}
/**
* @brief Assignation operator.
* @param[in] _otherIterator The Iterator that might be copy
* @return reference on the current Iterator
*/
Iterator& operator=(const Iterator & _otherIterator) {
m_current = _otherIterator.m_current;
m_array = _otherIterator.m_array;
return *this;
}
/**
* @brief Basic destructor
*/
~Iterator() {
m_current = 0;
m_array = null;
}
/**
* @brief basic boolean cast
* @return true if the element is present in the etkArray size
*/
operator bool () {
return (m_current < m_array->size());
}
/**
* @brief != Comparaison operator
* @param[in] _obj Object to compare
* @return true if the element are different
*/
bool operator!= (const Iterator& _obj) {
if ( m_array != _obj.m_array
|| m_current != _obj.m_current) {
return true;
}
return false;
}
/**
* @brief == Comparaison operator.
* @param[in] _obj Object to compare.
* @return true if the element are identical.
*/
bool operator== (const Iterator& _obj) {
if ( m_array == _obj.m_array
&& m_current == _obj.m_current) {
return true;
}
return false;
}
/**
* @brief Incremental operator
* @return Reference on the current iterator increment
*/
Iterator& operator++ () {
if ( m_array != null
&& m_current < m_array->size() )
{
m_current++;
}
return *this;
}
/**
* @brief Decremental operator
* @return Reference on the current iterator decrement
*/
Iterator& operator-- () {
if ( m_array != null
&& m_current > 0) {
m_current--;
}
return *this;
}
/**
* @brief Incremental operator
* @return Reference on a new iterator and increment the other one
*/
Iterator operator++ (int32_t) {
Iterator it(*this);
++(*this);
return it;
}
/**
* @brief Decremental operator
* @return Reference on a new iterator and decrement the other one
*/
Iterator operator-- (int32_t) {
Iterator it(*this);
--(*this);
return it;
}
Iterator& operator-= (size_t _offset) {
m_current -= _offset;
return *this;
}
Iterator operator- (size_t _offset) const {
Iterator tmp(*this);
tmp -= _offset;
return tmp;
}
Iterator& operator-= (int _offset) {
m_current -= _offset;
return *this;
}
Iterator operator- (int _offset) const {
Iterator tmp(*this);
tmp -= _offset;
return tmp;
}
Iterator& operator-= (int64_t _offset) {
m_current -= _offset;
return *this;
}
Iterator operator- (int64_t _offset) const {
Iterator tmp(*this);
tmp -= _offset;
return tmp;
}
Iterator& operator+= (size_t _offset) {
m_current += _offset;
return *this;
}
Iterator operator+ (size_t _offset) const {
Iterator tmp(*this);
tmp += _offset;
return tmp;
}
Iterator& operator+= (int _offset) {
m_current += _offset;
return *this;
}
Iterator operator+ (int _offset) const {
Iterator tmp(*this);
tmp += _offset;
return tmp;
}
Iterator& operator+= (int64_t _offset) {
m_current += _offset;
return *this;
}
Iterator operator+ (int64_t _offset) const {
Iterator tmp(*this);
tmp += _offset;
return tmp;
}
/**
* @brief Get reference on the current Element
* @return the reference on the current Element
*/
ETK_ARRAY_TYPE* operator-> () const {
return &m_array->get(m_current);
}
/**
* @brief Get reference on the current Element
* @return the reference on the current Element
*/
ETK_ARRAY_TYPE& operator* () const {
return m_array->get(m_current);
}
private:
Iterator(const Array<ETK_ARRAY_TYPE, ETK_ARRAY_SIZE> * _obj, int32_t _pos):
m_current(_pos),
m_array(const_cast<Array<ETK_ARRAY_TYPE, ETK_ARRAY_SIZE> *>(_obj)) {
// nothing to do ...
}
size_t getCurrent() const {
return m_current;
}
friend class Array;
};
private:
uint8_t m_rawData[ETK_ARRAY_SIZE*sizeof(ETK_ARRAY_TYPE)]; //!< pointer on the current table of Data (static allocated ==> can not change)
ETK_ARRAY_TYPE* m_data = (ETK_ARRAY_TYPE*)m_rawData; //!< pointer on the current table of Data (static allocated ==> can not change)
size_t m_size = 0; //!< Number of element in the buffer
const size_t m_allocated = ETK_ARRAY_SIZE; //!< Current allocated size
public:
/**
* @brief Create an empty Array
*/
Array() {
}
/**
* @brief List initializer (ex: etk::Array<etk::String> plop = {"hello", world"}
* @param[in] _element element to add in the Array
*/
template<typename... ETK_ARRAY_TYPE_2>
Array(const ETK_ARRAY_TYPE_2& ... _args) {
int32_t nbElement = int32_t(sizeof...(ETK_ARRAY_TYPE_2));
if (nbElement >= m_allocated) {
ETK_THROW_EXCEPTION(etk::exception::InvalidArgument("Size too big ..."));
return;
}
pushBackN(_args...);
}
/**
* @brief Re-copy constructor (copy all needed data)
* @param[in] _obj Array that might be copy
*/
Array(const etk::Array<ETK_ARRAY_TYPE, ETK_ARRAY_SIZE>& _obj) {
for(size_t iii=0; iii<_obj.m_size; iii++) {
new ((char*)&m_data[iii]) ETK_ARRAY_TYPE(etk::move(_obj.m_data[iii]));
}
m_size = _obj.m_size;
}
/**
* @brief Move operator of elements
* @param[in] _obj Object to move
*/
// TODO: This is a little complicated ...
Array(etk::Array<ETK_ARRAY_TYPE, ETK_ARRAY_SIZE>&& _obj) {
swap(_obj);
}
/**
* @brief Destructor of the current class
*/
~Array() {
for(size_t iii=0; iii<m_size; iii++) {
m_data[iii].~ETK_ARRAY_TYPE();
#ifdef DEBUG
// we place bad data to permit to detect stipid thing that is done in C++ code when developement is in progress.
// Only in debug this is really slow ... and for the real allocation of memory
for (size_t kkk=iii*sizeof(ETK_ARRAY_TYPE); kkk<sizeof(ETK_ARRAY_TYPE)*(iii+1); ++kkk) {
((char*)m_data)[kkk] = 0xA5;
}
#endif
}
m_size = 0;
}
/**
* @brief Swap the data of 2 Arrays
* @param[in] _obj second Array to swap data.
*/
void swap(etk::Array<ETK_ARRAY_TYPE, ETK_ARRAY_SIZE>& _obj) {
// avoid Swap of itself
if(this != &_obj) {
if (_obj.size() < size()) {
_obj.swap(*this);
return;
}
for (size_t iii=0; iii<etk::min(size(), _obj.size()); ++iii) {
etk::swap(m_data[iii], _obj.m_data[iii]);
}
for (size_t iii=size(); iii<_obj.size(); ++iii) {
// Construc new local object
new ((char*)&m_data[iii]) ETK_ARRAY_TYPE(etk::move(_obj.m_data[iii]));
// destruct remote object
_obj.m_data[iii].~ETK_ARRAY_TYPE();
}
for (size_t iii=_obj.size(); iii<size(); ++iii) {
// Construc new local object
new ((char*)&_obj.m_data[iii]) ETK_ARRAY_TYPE(etk::move(m_data[iii]));
// destruct remote object
m_data[iii].~ETK_ARRAY_TYPE();
}
etk::swap(m_size, _obj.m_size);
}
}
/**
* @brief Move operator
* @param[in] _obj Array that might be copy
* @return reference on the current re-copy Array
*/
Array& operator=(etk::Array<ETK_ARRAY_TYPE, ETK_ARRAY_SIZE>&& _obj) {
if(this != &_obj) {
etk::swap(this, _obj);
}
// Return the current pointer
return *this;
}
/**
* @brief Re-copy operator
* @param[in] _obj Array that might be copy
* @return reference on the current re-copy Array
*/
Array& operator=(const etk::Array<ETK_ARRAY_TYPE, ETK_ARRAY_SIZE>& _obj) {
// remove all previous elements
clear();
for(size_t iii=0; iii<_obj.m_size; iii++) {
new ((char*)&m_data[iii]) ETK_ARRAY_TYPE(etk::move(_obj.m_data[iii]));
}
m_size = _obj.m_size;
// Return the current pointer
return *this;
}
/**
* @brief Get the number of element in the Array
* @return The number requested
*/
size_t size() const {
return m_size;
}
/**
* @brief Check if the container have some element
* @return true The container is empty
* @return famse The container have some element
*/
bool empty() const {
return m_size == 0;
}
/**
* @brief Get the Allocated size in the Array
* @return The size of allocation
*/
size_t allocatedSize() const {
return m_allocated;
}
/**
* @brief Get a current element in the Array
* @param[in] _pos Desired position read
* @return Reference on the Element
*/
ETK_ARRAY_TYPE& get(const size_t _pos) {
return m_data[_pos];
}
/**
* @brief Get an copy Element an a special position
* @param[in] _pos Position in the Array that might be get [0..Size()]
* @return An reference on the copy of selected element
*/
ETK_ARRAY_TYPE& operator[] (const size_t _pos) {
return m_data[_pos];
}
/**
* @brief Get an Element an a special position
* @param[in] _pos Position in the Array that might be get [0..Size()]
* @return An reference on the selected element
*/
const ETK_ARRAY_TYPE& operator[] (const size_t _pos) const {
return m_data[_pos];
}
/**
* @brief Get the last element of the Array
* @return An reference on the element
*/
ETK_ARRAY_TYPE& back() {
return m_data[m_size-1];
}
const ETK_ARRAY_TYPE& back() const {
return m_data[m_size-1];
}
/**
* @brief Get the first element of the Array
* @return An reference on the element
*/
ETK_ARRAY_TYPE& front() {
return m_data[0];
}
const ETK_ARRAY_TYPE& front() const {
return m_data[0];
}
/**
* @brief Add at the First position of the Array
* @param[in] _item Element to add at the end of Array
*/
void pushFront(const ETK_ARRAY_TYPE& _item) {
insert(0, &_item, 1);
}
/**
* @brief Add at the Last position of the Array
* @param[in] _item Pointer on a list of Element to add at the start of Array
* @param[in] _nbElement Number of element to add.
*/
void pushFront(const ETK_ARRAY_TYPE * _item, size_t _nbElement) {
insert(0, _item, _nbElement);
}
/**
* @brief Add at the Last position of the Array (move push)
* @param[in] _item Element to add at the end of Array
*/
void pushBack(ETK_ARRAY_TYPE&& _item) {
if (m_size == ETK_ARRAY_SIZE) {
ETK_THROW_EXCEPTION(etk::exception::OverflowError("try add to much data in array"));
}
new ((char*)&m_data[m_size]) ETK_ARRAY_TYPE(etk::move(_item));
m_size += 1;
}
/**
* @brief Add at the Last position of the Array
* @param[in] _item Element to add at the end of Array
*/
void pushBack(const ETK_ARRAY_TYPE& _item) {
if (m_size == ETK_ARRAY_SIZE) {
ETK_THROW_EXCEPTION(etk::exception::OverflowError("try add to much data in array"));
}
new ((char*)&m_data[m_size]) ETK_ARRAY_TYPE(etk::move(_item));
m_size += 1;
}
/**
* @brief Add at the Last position of the Array
* @param[in] _item Pointer on a list of Element to add at the end of Array
* @param[in] _nbElement Number of element to add.
*/
void pushBack(const ETK_ARRAY_TYPE * _item, size_t _nbElement) {
if (_item == null) {
return;
}
if (m_size+_nbElement > ETK_ARRAY_SIZE) {
ETK_THROW_EXCEPTION(etk::exception::OverflowError("try add to much data in array"));
}
for (size_t iii=0; iii<_nbElement; iii++) {
new ((char*)&m_data[m_size+iii]) ETK_ARRAY_TYPE(_item[iii]);
m_size += 1;
}
}
private:
void pushBackN(const ETK_ARRAY_TYPE& _value) {
pushBack(_value);
}
template<typename... ETK_ARRAY_TYPE_2>
void pushBackN(const ETK_ARRAY_TYPE& _value, const ETK_ARRAY_TYPE_2& ... _args) {
pushBack(_value);
pushBackN(_args...);
}
public:
/**
* @brief Remove the first element of the Array
*/
void popFront() {
if(m_size>0) {
eraseLen(0, 1);
}
}
/**
* @brief Remove the last element of the Array
*/
void popBack() {
if(m_size>0) {
resizeDown(m_size-1);
}
}
/**
* @brief Remove all element in the current Array
*/
void clear() {
if(m_size>0) {
resizeDown(0);
}
}
/**
* @brief Insert N element in the Array.
* @param[in] _pos Position to add the elements.
* @param[in] _item Pointer on a table of the elements to add.
* @param[in] _nbElement Number of element to add in the Array
*/
void insert(size_t _pos, const ETK_ARRAY_TYPE * _item, size_t _nbElement) {
if (_pos > m_size) {
//TK_WARNING(" can not insert Element at this position : " << _pos << " > " << m_size << " add it at the end ... ");
pushBack(_item, _nbElement);
return;
}
// move current data (after the position)
size_t sizeToMove = (m_size - _pos);
if (sizeToMove > 0) {
for (size_t iii=1; iii<=sizeToMove; iii++) {
// placement allocate of the element
new ((char*)&m_data[m_size+_nbElement-iii]) ETK_ARRAY_TYPE(etk::move(m_data[m_size-iii]));
// Remove previous element ==> simplify code.
m_data[m_size-iii].~ETK_ARRAY_TYPE();
#ifdef DEBUG
// we place bad data to permit to detect stipid thing that is done in C++ code when developement is in progress.
// Only in debug this is really slow ... and for the real allocation of memory
for (size_t kkk=(m_size-iii)*sizeof(ETK_ARRAY_TYPE); kkk<sizeof(ETK_ARRAY_TYPE)*((m_size-iii)+1); ++kkk) {
((char*)m_data)[kkk] = 0xA5;
}
#endif
}
}
// affectation of all input element
for (size_t iii=0; iii<_nbElement; iii++) {
new ((char*)&m_data[_pos-iii]) ETK_ARRAY_TYPE(etk::move(_item[iii]));
}
m_size += _nbElement;
}
/**
* @brief Insert one element in the Array at a specific position
* @param[in] _pos Position to add the elements.
* @param[in] _item Element to add.
*/
void insert(size_t _pos, const ETK_ARRAY_TYPE& _item) {
insert(_pos, &_item, 1);
}
/**
* @brief Insert one element in the Array at a specific position
* @param[in] _pos Position to add the elements.
* @param[in] _item Element to add.
*/
void insert(const Iterator& _pos, const ETK_ARRAY_TYPE& _item) {
insert(_pos.getCurrent(), _item);
}
/**
* @brief Remove N element
* @param[in] _pos Position to remove the data
* @param[in] _nbElement number of element to remove
*/
void eraseLen(size_t _pos, size_t _nbElement) {
ETK_ARRAY_DEBUG("Erase len %zu %zu\n", _pos, _nbElement);
if (_pos > m_size) {
//TK_ERROR(" can not Erase Len Element at this position : " << _pos << " > " << m_size);
return;
}
if (m_size+_nbElement > ETK_ARRAY_SIZE) {
ETK_THROW_EXCEPTION(etk::exception::OverflowError("try add to much data in array"));
}
if (_pos + _nbElement > m_size) {
_nbElement = m_size - _pos;
}
ETK_ARRAY_DEBUG("Erase len %zu %zu\n", _pos, _nbElement);
size_t idElement = m_size;
// move current data
size_t sizeToMove = (idElement - (_pos+_nbElement));
if ( 0 < sizeToMove) {
for (size_t iii=0; iii<sizeToMove; iii++) {
etk::swap(m_data[_pos+iii], m_data[_pos+_nbElement+iii]);
}
}
// Request resize of the current buffer
resizeDown(m_size-_nbElement);
}
/**
* @brief Remove one element
* @param[in] _pos Position to remove the data
*/
inline void erase(size_t _pos) {
eraseLen(_pos, 1);
}
/**
* @brief Remove one element
* @param[in] _it Iterator on the element to remove
* @return An iterator on the new element at this position.
*/
Iterator erase(const Iterator& _it) {
ETK_ARRAY_DEBUG("Erase IT \n");
eraseLen(_it.getCurrent(), 1);
return position(_it.getCurrent());
}
/**
* @brief Remove one element
* @param[in] _pos Position to remove the data
*/
inline void remove(size_t _pos) {
eraseLen(_pos, 1);
}
/**
* @brief Remove N elements
* @param[in] _pos Position to remove the data
* @param[in] _posEnd Last position number
*/
void erase(size_t _pos, size_t _posEnd) {
if (_pos > m_size) {
//TK_ERROR(" can not Erase Element at this position : " << _pos << " > " << m_size);
return;
}
if (_posEnd > m_size) {
_posEnd = m_size;
}
size_t nbElement = m_size - _pos;
size_t tmpSize = m_size;
// move current data (to the end) ==> auto removed by the resize()
size_t sizeToMove = (tmpSize - (_pos+nbElement));
if ( 0 < sizeToMove) {
for (size_t iii=0; iii<sizeToMove; iii++) {
etk::swap(m_data[_pos+iii], m_data[_pos+nbElement+iii]);
}
}
// Request resize of the current buffer
resizeDown(m_size-nbElement);
}
void erase(const Iterator& _pos, const Iterator& _posEnd) {
erase(_pos.getCurrent(), _posEnd.getCurrent());
}
/**
* @brief Get the pointer on the data
* @return the type pointer on data
*/
ETK_ARRAY_TYPE* dataPointer() {
return &m_data[0];
}
/**
* @brief Get an iterator an an specific position
* @param[in] _pos Requested position of the iterator in the Array
* @return The Iterator
*/
Iterator position(size_t _pos) {
return Iterator(this, _pos);
}
const Iterator position(size_t _pos) const {
return Iterator(this, _pos);
}
/**
* @brief Get an Iterator on the start position of the Array
* @return The Iterator
*/
Iterator begin() {
return position(0);
}
const Iterator begin() const {
return position(0);
}
/**
* @brief Get an Iterator on the end position of the Array
* @return The Iterator
*/
Iterator end() {
return position(size());
}
const Iterator end() const {
return position(size());
}
/**
* @brief Resize the Array with a basic element
* @param[in] _newSize New size of the Array
*/
void resize(size_t _newSize, const ETK_ARRAY_TYPE& _basicElement) {
if (_newSize > ETK_ARRAY_SIZE) {
ETK_THROW_EXCEPTION(etk::exception::OverflowError("try resize with larger size in array"));
}
// Reallocate memory
if (_newSize > m_size) {
for (size_t iii=m_size; iii<_newSize; ++iii) {
new ((char*)&m_data[iii]) ETK_ARRAY_TYPE(_basicElement);
}
m_size = _newSize;
return;
} else if (_newSize == m_size) {
return;
}
for (size_t iii=m_size; iii<_newSize; ++iii) {
m_data[iii].~ETK_ARRAY_TYPE();
#ifdef DEBUG
// we place bad data to permit to detect stipid thing that is done in C++ code when developement is in progress.
// Only in debug this is really slow ... and for the real allocation of memory
for (size_t kkk=iii*sizeof(ETK_ARRAY_TYPE); kkk<sizeof(ETK_ARRAY_TYPE)*(iii+1); ++kkk) {
((char*)m_data)[kkk] = 0xA5;
}
#endif
}
m_size = _newSize;
}
/**
* @brief Change the current size of the Array
* @param[in] _newSize New requested size of element in the Array
*/
void resize(size_t _newSize) {
ETK_ARRAY_DEBUG("Resize %zu => %zu\n", m_size, _newSize);
if (_newSize > ETK_ARRAY_SIZE) {
ETK_THROW_EXCEPTION(etk::exception::OverflowError("try resize with larger size in array"));
}
// Reallocate memory
if (_newSize > m_size) {
for (size_t iii=m_size; iii<_newSize; ++iii) {
new ((char*)&m_data[iii]) ETK_ARRAY_TYPE();
}
} else if (_newSize == m_size) {
return;
}
ETK_ARRAY_DEBUG("Reduce %zu => %zu\n", m_size, _newSize);
for (size_t iii=_newSize; iii<m_size; ++iii) {
m_data[iii].~ETK_ARRAY_TYPE();
#ifdef DEBUG
// we place bad data to permit to detect stipid thing that is done in C++ code when developement is in progress.
// Only in debug this is really slow ... and for the real allocation of memory
for (size_t kkk=iii*sizeof(ETK_ARRAY_TYPE); kkk<sizeof(ETK_ARRAY_TYPE)*(iii+1); ++kkk) {
((char*)m_data)[kkk] = 0xA5;
}
#endif
}
m_size = _newSize;
}
private:
void resizeDown(size_t _newSize) {
ETK_ARRAY_DEBUG("Resize %zu => %zu\n", m_size, _newSize);
for (size_t iii=_newSize; iii<m_size; ++iii) {
m_data[iii].~ETK_ARRAY_TYPE();
#ifdef DEBUG
// we place bad data to permit to detect stipid thing that is done in C++ code when developement is in progress.
// Only in debug this is really slow ... and for the real allocation of memory
for (size_t kkk=iii*sizeof(ETK_ARRAY_TYPE); kkk<sizeof(ETK_ARRAY_TYPE)*(iii+1); ++kkk) {
((char*)m_data)[kkk] = 0xA5;
}
#endif
}
m_size = _newSize;
}
public:
/*****************************************************
* == operator
*****************************************************/
bool operator== (const Array<ETK_ARRAY_TYPE, ETK_ARRAY_SIZE>& _obj) const {
// check if it was the same pointer
if( this == &_obj ) {
return true;
}
// first step : check the size ...
if (m_size != _obj.m_size) {
return false;
}
if( m_data == null
|| _obj.m_data == null) {
return false;
}
for (size_t iii=0; iii<m_size; iii++) {
if (m_data[iii]!=_obj.m_data[iii]) {
return false;
}
}
return true;
}
/*****************************************************
* != operator
*****************************************************/
bool operator!= (const Array<ETK_ARRAY_TYPE, ETK_ARRAY_SIZE>& _obj) const {
// check if it was the same pointer
if( this == &_obj ) {
return false;
}
// first step : check the size ...
if (m_size != _obj.m_size) {
return true;
}
if( m_data == null
|| _obj.m_data == null) {
return false;
}
for (size_t iii=0; iii<m_size; iii++) {
if (m_data[iii]!=_obj.m_data[iii]) {
return true;
}
}
return false;
}
/*****************************************************
* >= operator
*****************************************************/
bool operator>= (const Array<ETK_ARRAY_TYPE, ETK_ARRAY_SIZE>& _obj) const {
// TODO : Later
return false;
}
/*****************************************************
* > operator
*****************************************************/
bool operator> (const Array<ETK_ARRAY_TYPE, ETK_ARRAY_SIZE>& _obj) const {
// TODO : Later
return false;
}
/*****************************************************
* <= operator
*****************************************************/
bool operator<= (const Array<ETK_ARRAY_TYPE, ETK_ARRAY_SIZE>& _obj) const {
// TODO : Later
return false;
}
/*****************************************************
* > operator
*****************************************************/
bool operator< (const Array<ETK_ARRAY_TYPE, ETK_ARRAY_SIZE>& _obj) const {
// TODO : Later
return false;
}
void sort(size_t _start, size_t _stop, bool (*_comparator)(const ETK_ARRAY_TYPE&, const ETK_ARRAY_TYPE&)) {
if (_stop > m_size) {
_stop = m_size;
}
if (_start > m_size) {
_start = m_size;
}
if (_start > _stop) {
size_t start = _start;
_start = _stop;
_stop = start;
}
for (size_t iii=_start; iii<_stop; ++iii) {
bool swapped = false;
for (size_t jjj=_start; jjj<_stop - (iii+1); ++jjj) {
if (_comparator(m_data[jjj], m_data[jjj+1]) == false) {
etk::swap(m_data[jjj], m_data[jjj+1]);
swapped = true;
}
}
if (swapped == false) {
break;
}
}
}
};
//! @not_in_doc
template<typename ETK_ARRAY_TYPE_1, typename ETK_ARRAY_TYPE_2, size_t ETK_ARRAY_SIZE>
bool isIn(const ETK_ARRAY_TYPE_1& _val, const etk::Array<ETK_ARRAY_TYPE_2, ETK_ARRAY_SIZE>& _list) {
for (size_t iii=0; iii<_list.size(); ++iii) {
if (_list[iii] == _val) {
return true;
}
}
return false;
}
class Stream;
//! @not_in_doc
template<class ETK_ARRAY_TYPE, size_t ETK_ARRAY_SIZE>
etk::Stream& operator <<(etk::Stream& _os, const etk::Array<ETK_ARRAY_TYPE, ETK_ARRAY_SIZE>& _obj) {
_os << "{";
for (size_t iii=0; iii< _obj.size(); iii++) {
if (iii>0) {
_os << ";";
}
_os << _obj[iii];
}
_os << "}";
return _os;
}
}

View File

@ -1,78 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2017, Edouard DUPIN, all right reserved
* @license MPL-2 (see license file)
*/
#include <etk/Exception.hpp>
#include <etk/String.hpp>
etk::Exception::Exception():
m_type("UNKNOW") {
}
etk::Exception::Exception(const char* _type, const etk::String& _what):
m_type(_type),
m_what(_what) {
}
etk::Exception::Exception(const etk::String& _what):
m_type("ETK_EXCEPTION"),
m_what(_what) {
}
const char* etk::Exception::which() const {
return m_type;
}
const etk::String etk::Exception::what() const {
return m_what;
}
const char* etk::Exception::file() const {
return m_file;
}
size_t etk::Exception::line() const {
return m_line;
}
const char* etk::Exception::function() const {
return m_function;
}
etk::Exception& etk::Exception::setFile(const char* _value) {
m_file = _value;
return *this;
}
etk::Exception& etk::Exception::setLine(size_t _value) {
m_line = _value;
return *this;
}
etk::Exception& etk::Exception::setFunction(const char* _value) {
m_function = _value;
return *this;
}
etk::String etk::Exception::toString() const {
etk::String out = "exception{";
out += m_type;
out += ":";
out += m_what;
if (m_function != null) {
out += " on ";
out += m_function;
}
if (m_file != null) {
out += " in ";
out += m_file;
out += ":";
out += etk::toString(m_line);
}
out += "}";
return out;
}

View File

@ -1,220 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2017, Edouard DUPIN, all right reserved
* @license MPL-2 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <etk/String.hpp>
namespace etk {
/**
* @brief Global exception handle
*/
class Exception {
private:
const char* m_type = null; //!< type of the exception
const etk::String m_what = "? ? ?"; //!< problem exception type
const char* m_function = null; //!< Function where the exception is generated
const char* m_file = null; //!< File where the excepton append
size_t m_line = 0; //!< Line of the exception
public:
/**
* @brief Default constructor.
*/
Exception();
/**
* @brief Generic Constructor (direct generic exception.
* @param[in] _what The explanation of the problem.
*/
Exception(const etk::String& _what);
/**
* @brief Generic Constructor.
* @param[in] _type Type of the exception
* @param[in] _what The explanation of the problem.
*/
Exception(const char* _type, const etk::String& _what);
/**
* @brief virtualize destructor.
*/
virtual ~Exception() = default;
/**
* @brief Get the type of the exception.
* @return String name of the exception.
*/
const char* which() const;
/**
* @brief Get the explanation of the problem.
* @return Descriptive string.
*/
const etk::String what() const;
/**
* @brief Get the Name of the file where the exception is generated.
* @return File string or null
*/
const char* file() const;
/**
* @brief Set the file Name.
* @param[in] _value File string or null
*/
etk::Exception& setFile(const char* _value);
/**
* @brief Get the Name of the fuction where the exception is generated.
* @return Function string or null
*/
const char* function() const;
/**
* @brief Set the function Name.
* @param[in] _value Function string or null
*/
etk::Exception& setFunction(const char* _value);
/**
* @brief Line Index in the file where thre throw append
* @return Line in the file
*/
size_t line() const;
/**
* @brief Set the file line.
* @param[in] _value File line.
*/
etk::Exception& setLine(size_t _value);
/**
* @brief Convert the class in String.
* @return generating desription of class
*/
etk::String toString() const;
};
#define ETK_THROW_EXCEPTION(ex) do { \
auto tmp = ex; \
tmp.setFunction(__PRETTY_FUNCTION__); \
tmp.setFile(__FILE__); \
tmp.setLine(__LINE__); \
throw tmp; \
} while(false)
//! @brief Generic
namespace exception {
class InvalidArgument : public etk::Exception {
public:
/**
* @brief Contructor of an generic Exception.
* @param[in] _what The explanation of the problem.
*/
InvalidArgument(const etk::String& _what):
etk::Exception("INVALID-ARGUMENT", _what) {
}
};
class DomainError : public etk::Exception {
public:
/**
* @brief Contructor of an generic Exception.
* @param[in] _what The explanation of the problem.
*/
DomainError(const etk::String& _what):
etk::Exception("DOMAIN-ERROR", _what) {
}
};
class LengthError : public etk::Exception {
public:
/**
* @brief Contructor of an generic Exception.
* @param[in] _what The explanation of the problem.
*/
LengthError(const etk::String& _what):
etk::Exception("LENGTH-ERROR", _what) {
}
};
class OutOfRange : public etk::Exception {
public:
/**
* @brief Contructor of an generic Exception.
* @param[in] _what The explanation of the problem.
*/
OutOfRange(const etk::String& _what):
etk::Exception("OUT-OF-RANGE", _what) {
}
};
class RangeError : public etk::Exception {
public:
/**
* @brief Contructor of an generic Exception.
* @param[in] _what The explanation of the problem.
*/
RangeError(const etk::String& _what):
etk::Exception("RANGE-ERROR", _what) {
}
};
class OverflowError : public etk::Exception {
public:
/**
* @brief Contructor of an generic Exception.
* @param[in] _what The explanation of the problem.
*/
OverflowError(const etk::String& _what):
etk::Exception("OVERFLOW-ERROR", _what) {
}
};
class UnderflowError : public etk::Exception {
public:
/**
* @brief Contructor of an generic Exception.
* @param[in] _what The explanation of the problem.
*/
UnderflowError(const etk::String& _what):
etk::Exception("UNDERFLOW-ERROR", _what) {
}
};
class CastError : public etk::Exception {
public:
/**
* @brief Contructor of an generic Exception.
* @param[in] _what The explanation of the problem.
*/
CastError(const etk::String& _what):
etk::Exception("CAST-ERROR", _what) {
}
};
class AllocationError : public etk::Exception {
public:
/**
* @brief Contructor of an generic Exception.
* @param[in] _what The explanation of the problem.
*/
AllocationError(const etk::String& _what):
etk::Exception("ALLOCATION-ERROR", _what) {
}
};
class RuntimeError : public etk::Exception {
public:
/**
* @brief Contructor of an generic Exception.
* @param[in] _what The explanation of the problem.
*/
RuntimeError(const etk::String& _what):
etk::Exception("RUNTIME-ERROR", _what) {
}
};
class NullPointerError : public etk::Exception {
public:
/**
* @brief Contructor of an generic Exception.
* @param[in] _what The explanation of the problem.
*/
NullPointerError(const etk::String& _what):
etk::Exception("NULL-POINTER-ERROR", _what) {
}
};
}
}

View File

@ -1,9 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/Function.hpp>
uint32_t etk::MM___pppppp = 0;

View File

@ -1,259 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2017, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <etk/String.hpp>
#include <etk/Exception.hpp>
// TO facilitate debug when have a problem ...
#define ETK_FUNCTION_DEBUG(...) do {} while(false)
//#define ETK_FUNCTION_DEBUG printf
namespace etk {
template <typename ETK_TYPE_FUNCTOR, typename ETK_TYPE_FUNCTION>
class FunctionPrivateLambda;
template <typename ETK_TYPE_FUNCTION>
class FunctionPrivateFunction;
template <typename ETK_TYPE_FUNCTION>
class FunctionPrivate;
template <typename ETK_TYPE_FUNCTION_RETURN, typename... ETK_TYPE_FUNCTION_ARGS>
class FunctionPrivate<ETK_TYPE_FUNCTION_RETURN(ETK_TYPE_FUNCTION_ARGS...)> {
public:
virtual ~FunctionPrivate() {
}
virtual ETK_TYPE_FUNCTION_RETURN operator()(ETK_TYPE_FUNCTION_ARGS... _args) const = 0;
virtual FunctionPrivate<ETK_TYPE_FUNCTION_RETURN(ETK_TYPE_FUNCTION_ARGS...)>* copy() {
ETK_FUNCTION_DEBUG(" COPY NULLPTR \n");
return null;
}
virtual void copyIn(char* _buffer) {
ETK_FUNCTION_DEBUG(" COPY NULLPTR \n");
return;
}
};
template <typename ETK_TYPE_FUNCTION_FUNCTOR, typename ETK_TYPE_FUNCTION_RETURN, typename... ETK_TYPE_FUNCTION_ARGS>
class FunctionPrivateLambda<ETK_TYPE_FUNCTION_FUNCTOR, ETK_TYPE_FUNCTION_RETURN(ETK_TYPE_FUNCTION_ARGS...)>:
public FunctionPrivate<ETK_TYPE_FUNCTION_RETURN(ETK_TYPE_FUNCTION_ARGS...)> {
private:
mutable ETK_TYPE_FUNCTION_FUNCTOR m_dataPointer;
public:
FunctionPrivateLambda(ETK_TYPE_FUNCTION_FUNCTOR _functor):
m_dataPointer(_functor) {
ETK_FUNCTION_DEBUG(" CREATE FunctionPrivateLambda \n");
}
/*
FunctionPrivateLambda(const ETK_TYPE_FUNCTION_FUNCTOR& _functor):
m_dataPointer(_functor) {
ETK_FUNCTION_DEBUG(" CREATE FunctionPrivateLambda \n");
}
*/
~FunctionPrivateLambda() {
}
ETK_TYPE_FUNCTION_RETURN operator()(ETK_TYPE_FUNCTION_ARGS... _args) const {
return m_dataPointer(etk::forward<ETK_TYPE_FUNCTION_ARGS>(_args)...);
}
FunctionPrivate<ETK_TYPE_FUNCTION_RETURN(ETK_TYPE_FUNCTION_ARGS...)>* copy() {
ETK_FUNCTION_DEBUG(" COPY FunctionPrivateLambda \n");
return ETK_NEW(FunctionPrivateLambda, m_dataPointer);
}
virtual void copyIn(char* _buffer) {
ETK_FUNCTION_DEBUG(" COPY NULLPTR \n");
new (_buffer) FunctionPrivateLambda(m_dataPointer);
return;
}
};
template <typename ETK_TYPE_FUNCTION>
class Function;
extern uint32_t MM___pppppp;
template <typename ETK_TYPE_FUNCTION_RETURN, typename... ETK_TYPE_FUNCTION_ARGS>
class Function<ETK_TYPE_FUNCTION_RETURN(ETK_TYPE_FUNCTION_ARGS...)> {
private:
typedef FunctionPrivate<ETK_TYPE_FUNCTION_RETURN(ETK_TYPE_FUNCTION_ARGS...)> FunctionPrivateTypedef;
FunctionPrivateTypedef* m_pointerPrivate;
bool m_local;
char m_buffer[16];
uint32_t m_pppppp;
public:
Function():
m_pointerPrivate(null),
m_local(false) {
memset(m_buffer, 0, sizeof(m_buffer));
m_pppppp = MM___pppppp++;
ETK_FUNCTION_DEBUG("[%d=0X%lx] create Function 1 \n", m_pppppp, (uint64_t)this);
}
Function(const etk::NullPtr&):
m_pointerPrivate(null),
m_local(false) {
memset(m_buffer, 0, sizeof(m_buffer));
m_pppppp = MM___pppppp++;
ETK_FUNCTION_DEBUG("[%d=0X%lx] create Function 2\n", m_pppppp, (uint64_t)this);
}
Function(const Function& _obj):
m_pointerPrivate(null),
m_local(false) {
memset(m_buffer, 0, sizeof(m_buffer));
m_pppppp = MM___pppppp++;
ETK_FUNCTION_DEBUG("[%d=0X%lx] create Function (copy constructor) ---------------------- [%d=0X%lx]\n", m_pppppp, (uint64_t)this, _obj.m_pppppp, (uint64_t)&_obj);
if (_obj.m_local == true) {
((FunctionPrivateTypedef*)_obj.m_buffer)->copyIn(m_buffer);
m_local = true;
} else if (_obj.m_pointerPrivate != null) {
m_pointerPrivate = _obj.m_pointerPrivate->copy();
}
ETK_FUNCTION_DEBUG("[%d=0X%lx] create Function (copy constructor) ------- (done) ------- [%d=0X%lx]\n", m_pppppp, (uint64_t)this, _obj.m_pppppp, (uint64_t)&_obj);
}
Function(Function&& _obj):
m_pointerPrivate(null),
m_local(false) {
memset(m_buffer, 0, sizeof(m_buffer));
m_pppppp = MM___pppppp++;
ETK_FUNCTION_DEBUG("[%d] create Function 2\n", m_pppppp);
_obj.swap(*this);
ETK_FUNCTION_DEBUG("[%d] create Function 2 (done)\n", m_pppppp);
}
template <typename ETK_TYPE_FUNCTION_FUNCTOR,
typename etk::EnableIf< !etk::IsSame<ETK_TYPE_FUNCTION_FUNCTOR,Function>::value
&& !etk::IsSame<ETK_TYPE_FUNCTION_FUNCTOR,etk::NullPtr>::value, int
>::type = 0
>
Function(ETK_TYPE_FUNCTION_FUNCTOR _functor):
m_pointerPrivate(null),
m_local(false) {
memset(m_buffer, 0, sizeof(m_buffer));
m_pppppp = MM___pppppp++;
ETK_FUNCTION_DEBUG("[%d=0X%lx] create Function 4 \n", m_pppppp, (uint64_t)this);
typedef FunctionPrivateLambda<ETK_TYPE_FUNCTION_FUNCTOR, ETK_TYPE_FUNCTION_RETURN(ETK_TYPE_FUNCTION_ARGS...)> FunctionPrivateLambdaTypedef;
if (sizeof(FunctionPrivateLambdaTypedef) <= sizeof(m_buffer)) {
new(m_buffer) FunctionPrivateLambdaTypedef(_functor);
m_local = true;
} else {
m_pointerPrivate = ETK_NEW(FunctionPrivateLambdaTypedef, _functor);
}
ETK_FUNCTION_DEBUG("[%d=0X%lx] create Function 4 (done)\n", m_pppppp, (uint64_t)this);
}
~Function() {
ETK_FUNCTION_DEBUG("[%d=0X%lx] DELETE Function \n", m_pppppp, (uint64_t)this);
ETK_DELETE(FunctionPrivateTypedef, m_pointerPrivate);
m_pointerPrivate = null;
if (m_local == true) {
// force the cast:
FunctionPrivateTypedef* tmp = (FunctionPrivateTypedef*)m_buffer;
tmp->~FunctionPrivate();
m_local = false;
memset(m_buffer, 0, sizeof(m_buffer));
}
}
ETK_TYPE_FUNCTION_RETURN operator()(ETK_TYPE_FUNCTION_ARGS... _args) const {
if ( m_pointerPrivate == null
&& m_local == false) {
ETK_FUNCTION_DEBUG("[%d=0X%lx] call Function (With null !!! ==> must assert ...)\n", m_pppppp, (uint64_t)this);
ETK_THROW_EXCEPTION(etk::exception::NullPointerError("etk::Function call empty pointer"));
}
ETK_FUNCTION_DEBUG("[%d=0X%lx] call Function \n", m_pppppp, (uint64_t)this);
if (m_local == true) {
return (*((FunctionPrivateTypedef*)m_buffer))(etk::forward<ETK_TYPE_FUNCTION_ARGS>(_args)...);
}
return (*m_pointerPrivate)(etk::forward<ETK_TYPE_FUNCTION_ARGS>(_args)...);
}
Function& operator= (const Function& _obj) {
ETK_FUNCTION_DEBUG("[%d=0X%lx] operator=(set) Function [%d=0X%lx]\n", m_pppppp, (uint64_t)this, _obj.m_pppppp, (uint64_t)&_obj);
Function(_obj).swap(*this);
ETK_FUNCTION_DEBUG("[%d=0X%lx] operator=(set) Function [%d=0X%lx] (done)\n", m_pppppp, (uint64_t)this, _obj.m_pppppp, (uint64_t)&_obj);
return *this;
}
Function& operator= (Function&& _obj) {
ETK_FUNCTION_DEBUG("[%d=0X%lx] operator=(move) Function [%d=0X%lx]\n", m_pppppp, (uint64_t)this, _obj.m_pppppp, (uint64_t)&_obj);
Function(etk::move(_obj)).swap(*this);
ETK_FUNCTION_DEBUG("[%d=0X%lx] operator=(move) Function [%d=0X%lx] (done)\n", m_pppppp, (uint64_t)this, _obj.m_pppppp, (uint64_t)&_obj);
return *this;
}
Function& operator= (etk::NullPtr _obj) {
ETK_DELETE(FunctionPrivateTypedef, m_pointerPrivate);
m_pointerPrivate = null;
if (m_local == true) {
// force the cast:
FunctionPrivateTypedef* tmp = (FunctionPrivateTypedef*)m_buffer;
tmp->~FunctionPrivate();
m_local = false;
memset(m_buffer, 0, sizeof(m_buffer));
}
ETK_FUNCTION_DEBUG("[%d=0X%lx] operator = null 0X%lx\n", m_pppppp, (uint64_t)this, (uint64_t)m_pointerPrivate);
return *this;
}
void swap(Function& _obj) {
ETK_FUNCTION_DEBUG("[%d=0X%lx] swap [%d=0X%lx]\n", m_pppppp, (uint64_t)this, _obj.m_pppppp, (uint64_t)_obj);
etk::swap(m_pointerPrivate, _obj.m_pointerPrivate);
etk::swap(m_pppppp, _obj.m_pppppp);
etk::swap(m_local, _obj.m_local);
// TODO : This is dangerous ==> to check ...
for (size_t iii=0; iii<sizeof(m_buffer); ++iii) {
char tmp = m_buffer[iii];
m_buffer[iii] = _obj.m_buffer[iii];
_obj.m_buffer[iii] = tmp;
}
ETK_FUNCTION_DEBUG("[%d=0X%lx] swap [%d=0X%lx] (done)\n", m_pppppp, (uint64_t)this, _obj.m_pppppp, (uint64_t)_obj);
}
template <typename ETK_TYPE_FUNCTION_FUNCTOR,
typename etk::EnableIf< !etk::IsSame<ETK_TYPE_FUNCTION_FUNCTOR,Function>::value
&& !etk::IsSame<ETK_TYPE_FUNCTION_FUNCTOR,etk::NullPtr>::value, int
>::type = 0
>
Function& operator= (ETK_TYPE_FUNCTION_FUNCTOR&& _functor){
ETK_FUNCTION_DEBUG("[%d=0X%lx] operator = FUNCTOR \n", m_pppppp, (uint64_t)this);
Function(etk::forward<ETK_TYPE_FUNCTION_FUNCTOR>(_functor)).swap(*this);
ETK_FUNCTION_DEBUG("[%d=0X%lx] operator = FUNCTOR (done)\n", m_pppppp, (uint64_t)this);
return *this;
}
template <typename ETK_TYPE_FUNCTION_FUNCTOR,
typename etk::EnableIf< !etk::IsSame<ETK_TYPE_FUNCTION_FUNCTOR,Function>::value
&& !etk::IsSame<ETK_TYPE_FUNCTION_FUNCTOR,etk::NullPtr>::value, int
>::type = 0
>
Function& operator= (const ETK_TYPE_FUNCTION_FUNCTOR& _functor){
ETK_FUNCTION_DEBUG("[%d=0X%lx] operator = const FUNCTOR& \n", m_pppppp, (uint64_t)this);
Function(_functor).swap(*this);
ETK_FUNCTION_DEBUG("[%d=0X%lx] operator = const FUNCTOR& (done)\n", m_pppppp, (uint64_t)this);
return *this;
}
operator bool() const {
return m_pointerPrivate != null
|| m_local == true ;
}
bool operator!= (etk::NullPtr) const {
ETK_FUNCTION_DEBUG("[%d=0X%lx] operator != null ==> 0X%lx %s\n", m_pppppp, (uint64_t)this, (uint64_t)m_pointerPrivate, (m_pointerPrivate != null)?"true":"false");
return m_pointerPrivate != null
|| m_local == true;
}
bool operator== (etk::NullPtr) const {
ETK_FUNCTION_DEBUG("[%d=0X%lx] operator == null ==> 0X%lx %s\n", m_pppppp, (uint64_t)this, (uint64_t)m_pointerPrivate, (m_pointerPrivate == null)?"true":"false");
return m_pointerPrivate == null
&& m_local == false;
}
etk::String toString() const {
etk::String out = "etk::Function<..(...)>(@";
if (m_local == true) {
out += etk::toString((uint64_t)m_buffer);
} else {
out += etk::toString((uint64_t)m_pointerPrivate);
}
out += ")";
return out;
}
};
//! @not_in_doc
template <typename ETK_TYPE_FUNCTION_RETURN, typename... ETK_TYPE_FUNCTION_ARGS>
etk::Stream& operator <<(etk::Stream& _os, const etk::Function<ETK_TYPE_FUNCTION_RETURN(ETK_TYPE_FUNCTION_ARGS...)>& _obj) {
_os << _obj.toString();
return _os;
}
}

View File

@ -1,638 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <etk/Pair.hpp>
#include <etk/Vector.hpp>
#include <etk/Allocator.hpp>
#include <etk/Exception.hpp>
#include <etk/algorithm.hpp>
namespace etk {
/**
* @brief Map table template is a simple classical Map interface.
* A Map table is a equivalent of the dictionary in python, this is a
* simple interface between a name and a value:
* - "name" : 19
* - "name 2" : 99
*
* @note The name is unique and the value is what you want
*
* @note The index are all time available since they are created. The order is the the one created
*
* A simple example of use:
* @code{.cpp}
* // Create a integer Map table
* Map<int> myValue;
* // add some element (note add and set is the same function)
* myValue.add("example", 98837);
* myValue.add("plop", 88);
* // Display an element:
* printf("my value is : %d", myValue["example"]);
* // Change value of an element:
* myValue.set("example", 99);
* // Remove an element:
* myValue.remove("plop");
* //Clean all the table:
* myValue.clear();
* @endcode
*/
template<class ETK_MAP_TYPE_KEY, class ETK_MAP_TYPE_DATA> class Map {
public:
class Iterator {
private:
size_t m_current; //!< current Id on the vector
Map<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA>* m_map; //!< Pointer on the current element of the vectorBin
public:
/**
* @brief Basic iterator constructor with no link with an etk::Vector
*/
Iterator():
m_current(0),
m_map(null) {
// nothing to do ...
}
/**
* @brief Recopy constructor on a specific etkVector.
* @param[in] _obj The Iterator that might be copy
*/
Iterator(const Iterator & _obj):
m_current(_obj.m_current),
m_map(_obj.m_map) {
// nothing to do ...
}
/**
* @brief Assignation operator.
* @param[in] _otherIterator The Iterator that might be copy
* @return reference on the current Iterator
*/
Iterator& operator=(const Iterator & _obj) {
m_current = _obj.m_current;
m_map = _obj.m_map;
return *this;
}
/**
* @brief Basic destructor
*/
~Iterator() {
m_current = 0;
m_map = null;
}
/**
* @brief basic boolean cast
* @return true if the element is present in the etkVector size
*/
operator bool () {
return (m_current < m_map->size());
}
/**
* @brief Incremental operator
* @return Reference on the current iterator increment
*/
Iterator& operator++ () {
if ( m_map != null
&& m_current < m_map->size() )
{
m_current++;
}
return *this;
}
/**
* @brief Decremental operator
* @return Reference on the current iterator decrement
*/
Iterator& operator-- () {
if ( m_map != null
&& m_current > 0) {
m_current--;
}
return *this;
}
/**
* @brief Incremental operator
* @return Reference on an iterator and increment the other one
*/
Iterator operator++ (int32_t) {
Iterator it(*this);
++(*this);
return it;
}
/**
* @brief Decremental operator
* @return Reference on an iterator and decrement the other one
*/
Iterator operator-- (int32_t) {
Iterator it(*this);
--(*this);
return it;
}
Iterator& operator-= (size_t _offset) {
m_current -= _offset;
return *this;
}
Iterator operator- (size_t _offset) const {
Iterator tmp(*this);
tmp -= _offset;
return tmp;
}
Iterator& operator-= (int _offset) {
m_current -= _offset;
return *this;
}
Iterator operator- (int _offset) const {
Iterator tmp(*this);
tmp -= _offset;
return tmp;
}
Iterator& operator-= (int64_t _offset) {
m_current -= _offset;
return *this;
}
Iterator operator- (int64_t _offset) const {
Iterator tmp(*this);
tmp -= _offset;
return tmp;
}
Iterator& operator+= (size_t _offset) {
m_current += _offset;
return *this;
}
Iterator operator+ (size_t _offset) const {
Iterator tmp(*this);
tmp += _offset;
return tmp;
}
Iterator& operator+= (int _offset) {
m_current += _offset;
return *this;
}
Iterator operator+ (int _offset) const {
Iterator tmp(*this);
tmp += _offset;
return tmp;
}
Iterator& operator+= (int64_t _offset) {
m_current += _offset;
return *this;
}
Iterator operator+ (int64_t _offset) const {
Iterator tmp(*this);
tmp += _offset;
return tmp;
}
/**
* @brief Get reference on the current Element
* @return the reference on the current Element
*/
etk::Pair<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA>* operator-> () const {
//TK_CHECK_INOUT(m_current < m_map->size());
return &m_map->getContent(m_current);
}
/**
* @brief Get reference on the current Element
* @return the reference on the current Element
*/
etk::Pair<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA>& operator* () const {
return m_map->getContent(m_current);
}
/**
* @brief Get Key on the current Element
* @return the Key on the current Element
*/
const ETK_MAP_TYPE_KEY& getKey () const {
return m_map->getKey(m_current);
}
/**
* @brief Get Key on the current Element
* @return the Key on the current Element
*/
const ETK_MAP_TYPE_DATA& getValue () const {
return m_map->getValue(m_current);
}
/**
* @brief Get Key on the current Element
* @return the Key on the current Element
*/
ETK_MAP_TYPE_DATA& getValue () {
return m_map->getValue(m_current);
}
bool operator== (const Iterator& _obj) const{
return m_map == _obj.m_map
&& m_current == _obj.m_current;
}
bool operator!= (const Iterator& _obj) const {
return m_map != _obj.m_map
|| m_current != _obj.m_current;
}
private:
Iterator(const etk::Map<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA> * _obj, int32_t _pos):
m_current(_pos),
m_map(const_cast<etk::Map<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA> *>(_obj)) {
// nothing to do ...
}
friend class Map;
};
/*
static bool defaultSort(etk::Pair<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA>* const & _key1,
etk::Pair<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA>* const & _key2) {
return _key1->first < _key2->first;
}
*/
typedef bool (*sortFunction)(etk::Pair<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA>* const & _key1,
etk::Pair<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA>* const & _key2);
private:
typedef etk::Pair<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA> pairType;
etk::Vector<pairType*> m_data; //!< Data of the Map ==> the Map table is composed of pointer, this permit to have high speed when resize the vector ...
sortFunction m_comparator;
bool m_ordered;
public:
/**
* @brief Set the comparator of the set.
* @param[in] _comparator comparing function.
*/
void setComparator(sortFunction _comparator) {
m_comparator = _comparator;
sort();
}
/**
* @brief Set the ordering of the Map.
* @param[in] _ordered Order the map or not.
*/
void setOrdered(bool _ordered) {
m_ordered = _ordered;
sort();
}
private:
/**
* @brief Order the Set with the corect functor and if needed
*/
void sort() {
if (m_ordered == false) {
return;
}
if (m_comparator != null) {
etk::algorithm::quickSort(m_data, 0, m_data.size(), m_comparator);
} else {
sortFunction tmp = [](etk::Pair<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA>* const & _key1,
etk::Pair<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA>* const & _key2) {
return _key1->first < _key2->first;
};
etk::algorithm::quickSort(m_data,
0,
m_data.size(),
tmp);
}
}
public:
/**
* @brief Constructor of the Map table.
* @param[in] _count Number of basic element in the table.
* @param[in] _ordered select an ordered map or an onordered map.
* @param[in] _comparator Comparator to use in comparing the elements;
*/
Map(size_t _count = 0,
bool _ordered = true,
sortFunction _comparator = null) :
m_data(),
m_comparator(etk::move(_comparator)),
m_ordered(_ordered) {
m_data.reserve(_count);
}
/**
* @brief Move constructor
* @param[in] _obj Other Map to move
*/
Map(Map&& _obj):
m_data(),
m_comparator(null),
m_ordered(true) {
_obj.swap(*this);
}
/**
* @brief Copy constructor
* @param[in] _obj Other Map to copy
*/
Map(const Map& _obj) :
m_data(),
m_comparator(_obj.m_comparator),
m_ordered(_obj.m_ordered) {
m_data.reserve(_obj.m_data.size());
for (auto &it : _obj.m_data) {
if (it == null) {
continue;
}
m_data.pushBack(ETK_NEW(pairType, it->first, it->second));
}
}
/**
* @brief Destructor of the Map table (clear all element in the table)
*/
~Map() {
clear();
}
/**
* @brief Swap two map
* @param[in] _obj Other Map to swap with
*/
void swap(Map& _obj) {
etk::swap(m_data, _obj.m_data);
etk::swap(m_comparator, _obj.m_comparator);
etk::swap(m_ordered, _obj.m_ordered);
}
/**
* @brief Move operator
* @param[in] _obj Other Map to move
*/
Map& operator=(Map&& _obj) {
_obj.swap(*this);
return *this;
}
/**
* @brief Copy operator
* @param[in] _obj Other Map to copy
*/
Map& operator=(const Map& _obj) {
Map tmp(_obj);
tmp.swap(*this);
return *this;
}
/**
* @brief Remove all entry in the Map table.
* @note It does not delete pointer if your value is a pointer type...
*/
void clear() {
for (auto &it : m_data) {
if (it != null) {
ETK_DELETE(pairType, it);
it=null;
}
}
m_data.clear();
}
/**
* @brief Get a current element ID in the Map table
* @param[in] _key Name of the Map requested
* @return Id of the element in the table or -1 of it does not existed
*/
int64_t getId(const ETK_MAP_TYPE_KEY& _key) const {
if (m_ordered == true) {
// TODO: search in a dichotomic way.
}
for (size_t iii=0; iii<m_data.size(); iii++) {
if (m_data[iii] != null) {
if (m_data[iii]->first == _key) {
return iii;
}
}
}
return -1;
}
/**
* @brief Check if an element exist or not
* @param[in] _name Name of the Map requested
* @return true if the element exist
*/
bool exist(const ETK_MAP_TYPE_KEY& _name) const {
int64_t elementId = getId(_name);
if (elementId<0) {
return false;
}
return true;
}
/**
* @brief Get a current element in the Map table, with his name.
* @param[in] _key Name of the Map requested
* @return Reference on the Element
*/
ETK_MAP_TYPE_DATA& get(const ETK_MAP_TYPE_KEY& _key) const {
int64_t elementId = getId(_key);
if (elementId<0) {
ETK_THROW_EXCEPTION(etk::exception::InvalidArgument("Can not find the key: " + etk::toString(_key)));
}
return m_data[elementId]->second;
}
/**
* @brief Get an copy Element an a special position
* @param[in] _key Name of the Map requested
* @return An reference on the copy of selected element
*/
ETK_MAP_TYPE_DATA& operator[] (const ETK_MAP_TYPE_KEY& _key) {
return get(_key);
}
/**
* @brief Get an copy Element an a special position
* @param[in] _key Name of the Map requested
* @return An reference on the copy of selected element
*/
const ETK_MAP_TYPE_DATA& operator[] (const ETK_MAP_TYPE_KEY& _key) const {
return get(_key);
}
/**
* @brief Add an element OR set an element value
* @note add and set is the same function.
* @param[in] _key Name of the value to set in the Map table.
* @param[in] _value Value to set in the Map table.
*/
void add(const ETK_MAP_TYPE_KEY& _key, const ETK_MAP_TYPE_DATA& _value) {
int64_t elementId = getId(_key);
if (elementId <0) {
etk::Pair<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA>* tmp = ETK_NEW(pairType, etk::move(_key), etk::move(_value));
if (tmp == null) {
return;
}
m_data.pushBack(tmp);
// Order data if needed.
sort();
return;
}
m_data[elementId]->second = _value;
}
//! @previous
void add(const ETK_MAP_TYPE_KEY& _key, ETK_MAP_TYPE_DATA&& _value) {
int64_t elementId = getId(_key);
if (elementId <0) {
etk::Pair<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA>* tmp = ETK_NEW(pairType, etk::move(_key), etk::move(_value));
if (tmp == null) {
return;
}
m_data.pushBack(tmp);
// Order data if needed.
sort();
return;
}
m_data[elementId]->second = etk::move(_value);
}
/**
* @brief Set an element value
* @note add and set is the same function.
* @param[in] _key Name of the value to set in the Map table.
* @param[in] _value Value to set in the Map table.
*/
void set(const ETK_MAP_TYPE_KEY& _key, const ETK_MAP_TYPE_DATA& _value) {
add(etk::move(_key), etk::move(_value));
}
//! @previous
void set(const ETK_MAP_TYPE_KEY& _key, ETK_MAP_TYPE_DATA&& _value) {
add(etk::move(_key), etk::move(_value));
}
/**
* @brief Remove an element in the Map table.
* @param[in] _key Name of the element to remove.
*/
void erase(const ETK_MAP_TYPE_KEY& _key) {
int64_t elementId = getId(_key);
if (elementId <0) {
//nothing to do ==> not existed
return;
}
ETK_DELETE(pairType, m_data[elementId]);
m_data[elementId] = null;
m_data.erase(m_data.begin()+elementId);
}
/**
* @brief Remove an element in the Map table.
* @param[in] _it Iterator on the element.
*/
Iterator erase(const Iterator& _it) {
int64_t elementId = _it.m_current;
ETK_DELETE(pairType, m_data[elementId]);
m_data[elementId] = null;
m_data.erase(m_data.begin()+elementId);
return position(elementId);
}
/**
* @brief Get the number of element in the Map table
* @return number of elements
*/
size_t size() const {
return m_data.size();
}
const etk::Pair<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA>& getContent(size_t _pos) const {
return *m_data[_pos];
}
etk::Pair<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA>& getContent(size_t _pos) {
return *m_data[_pos];
}
/**
* @brief Get the name of the element at a specific position.
* @param[in] _pos Position of the element in the Map table.
* @return name of the element (key).
*/
const ETK_MAP_TYPE_KEY& getKey(size_t _pos) const {
return m_data[_pos]->first;
}
/**
* @brief Get all the element name (keys).
* @return a vector of all name (key).
*/
etk::Vector<ETK_MAP_TYPE_KEY> getKeys() const {
etk::Vector<ETK_MAP_TYPE_KEY> keys;
for (auto &it : m_data) {
if (it != null) {
keys.pushBack(it->first);
}
}
return etk::move(keys);
}
/**
* @brief Get a value of the Map table at a specific position.
* @param[in] _pos of the element in the Map table.
* @return Value available at this position.
*/
const ETK_MAP_TYPE_DATA& getValue(size_t _pos) const {
return m_data[_pos]->second;
}
/**
* @copydoc getValue (size_t)
*/
ETK_MAP_TYPE_DATA& getValue(size_t _pos) {
return m_data[_pos]->second;
}
/**
* @brief Get an iterator an an specific position
* @param[in] _pos Requested position of the iterator in the vector
* @return The Iterator
*/
Iterator position(size_t _pos) {
return Iterator(this, _pos);
}
const Iterator position(size_t _pos) const {
return Iterator(this, _pos);
}
/**
* @brief Get an Iterator on the start position of the Map
* @return The Iterator
*/
Iterator begin() {
return position(0);
}
const Iterator begin() const {
return position(0);
}
/**
* @brief Get an Iterator on the end position of the Map
* @return The Iterator
*/
Iterator end() {
return position(size());
}
const Iterator end() const {
return position(size());
}
/**
* @brief Get the last element in the Map or end()
* @return The Iterator
*/
Iterator back() {
if (size() > 0) {
return position(size()-1);
}
return position(size());
}
const Iterator back() const {
if (size() > 0) {
return position(size()-1);
}
return position(size());
}
Iterator find(const ETK_MAP_TYPE_KEY& _key) {
int64_t elementId = getId(_key);
if (elementId <0) {
return end();
}
return position(elementId);
}
const Iterator find(const ETK_MAP_TYPE_KEY& _key) const {
int64_t elementId = getId(_key);
if (elementId <0) {
return end();
}
return position(elementId);
}
/**
* @brief Count the number of occurence of a specific element.
* @param[in] _key Name of the element to count iterence
* @return 0 No element was found
* @return 1 One element was found
*/
size_t count(const ETK_MAP_TYPE_KEY& _key) const {
// TODO: search in a dichotomic way.
for (size_t iii=0; iii<m_data.size(); iii++) {
if (m_data[iii] == null) {
continue;
}
if (m_data[iii]->first == _key) {
return 1;
}
}
return 0;
}
};
}

View File

@ -1,79 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2017, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
namespace etk {
class NullPtr {
public:
template<class T>
operator T*() const {
return 0;
}
template<class C, class T>
operator T C::*() const {
return 0;
}
typedef void* (etk::NullPtr::*bool_)() const;
template <typename ETK_TYPE_FUNCTION_RETURN, typename... ETK_TYPE_FUNCTION_ARGS>
ETK_TYPE_FUNCTION_RETURN operator()(ETK_TYPE_FUNCTION_ARGS... _args) {
throw;
}
};
inline NullPtr getNullPointer() {
// etk::null exists.
NullPtr n = { };
return n;
}
}
// We does not use null ==> specific STD, can not be overload, and this permit to have a compatibility with STD
#if !defined(null)
#define null etk::getNullPointer()
#endif
template<class T>
inline bool operator==(T* p, const etk::NullPtr) {
return p == 0;
}
template<class T>
inline bool operator==(const etk::NullPtr, T* p) {
return p == 0;
}
template<class T, class U>
inline bool operator==(T U::* p, const etk::NullPtr) {
return p == 0;
}
template<class T, class U>
inline bool operator==(const etk::NullPtr, T U::* p) {
return p == 0;
}
inline bool operator==(const etk::NullPtr, const etk::NullPtr) {
return true;
}
inline bool operator!=(const etk::NullPtr, const etk::NullPtr) {
return false;
}
inline bool operator<(const etk::NullPtr, const etk::NullPtr) {
return false;
}
inline bool operator>(const etk::NullPtr, const etk::NullPtr) {
return false;
}
inline bool operator<=(const etk::NullPtr, const etk::NullPtr) {
return true;
}
inline bool operator>=(const etk::NullPtr, const etk::NullPtr) {
return true;
}

View File

@ -1,102 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL-2 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <etk/move.hpp>
#include <etk/Stream.hpp>
namespace etk {
template<class ETK_PAIR_TYPE_1, class ETK_PAIR_TYPE_2>
class Pair {
public:
// this is bad for coding rules, but an idiom of c++ pair imposed by the STL
ETK_PAIR_TYPE_1 first;
ETK_PAIR_TYPE_2 second;
Pair():
first(),
second() {
}
Pair(ETK_PAIR_TYPE_1&& _obj1, ETK_PAIR_TYPE_2&& _obj2):
first(etk::move(_obj1)),
second(etk::move(_obj2)) {
}
Pair(const ETK_PAIR_TYPE_1& _obj1, ETK_PAIR_TYPE_2&& _obj2):
first(_obj1),
second(etk::move(_obj2)) {
}
Pair(const ETK_PAIR_TYPE_1& _obj1, const ETK_PAIR_TYPE_2& _obj2):
first(_obj1),
second(_obj2) {
}
Pair(const Pair<ETK_PAIR_TYPE_1, ETK_PAIR_TYPE_2>& _obj):
first(_obj.first),
second(_obj.second) {
}
Pair(Pair<ETK_PAIR_TYPE_1, ETK_PAIR_TYPE_2>&& _obj):
first(),
second() {
_obj.swap(*this);
}
template<class ETK_PAIR_UNDER_TYPE_1, class ETK_PAIR_UNDER_TYPE_2>
Pair(const Pair<ETK_PAIR_UNDER_TYPE_1, ETK_PAIR_UNDER_TYPE_2>& _pair):
first(_pair.first),
second(_pair.second) {
}
bool operator== (const Pair<ETK_PAIR_TYPE_1, ETK_PAIR_TYPE_2>& _obj) const{
return first == _obj.first
&& second == _obj.second;
}
bool operator!= (const Pair<ETK_PAIR_TYPE_1, ETK_PAIR_TYPE_2>& _obj) const{
return first != _obj.first
|| second != _obj.second;
}
void swap(Pair<ETK_PAIR_TYPE_1, ETK_PAIR_TYPE_2>& _obj) {
etk::swap(first, _obj.first);
etk::swap(second, _obj.second);
}
Pair& operator=(const Pair<ETK_PAIR_TYPE_1, ETK_PAIR_TYPE_2>& _obj) {
Pair<ETK_PAIR_TYPE_1, ETK_PAIR_TYPE_2>(_obj).swap(*this);
return *this;
}
Pair& operator=(Pair<ETK_PAIR_TYPE_1, ETK_PAIR_TYPE_2>&& _obj) {
Pair<ETK_PAIR_TYPE_1, ETK_PAIR_TYPE_2>(etk::move(_obj)).swap(*this);
return *this;
}/*
template<class ETK_PAIR_UNDER_TYPE_1, class ETK_PAIR_UNDER_TYPE_2>
Pair& operator=(Pair<ETK_PAIR_UNDER_TYPE_1, ETK_PAIR_UNDER_TYPE_2>&& _obj) {
Pair<ETK_PAIR_TYPE_1, ETK_PAIR_TYPE_2>(etk::move(_obj)).swap(*this);
return *this;
}*/
};
template<class ETK_PAIR_TYPE_1, class ETK_PAIR_TYPE_2>
Pair<ETK_PAIR_TYPE_1, ETK_PAIR_TYPE_2> makePair(ETK_PAIR_TYPE_1 _obj1, ETK_PAIR_TYPE_2 _obj2) {
return etk::move(etk::Pair<ETK_PAIR_TYPE_1, ETK_PAIR_TYPE_2>(etk::forward<ETK_PAIR_TYPE_1>(_obj1), etk::forward<ETK_PAIR_TYPE_2>(_obj2)));
}
template<class ETK_PAIR_TYPE_1, class ETK_PAIR_TYPE_2>
etk::Stream& operator <<(etk::Stream& _os, const etk::Pair<ETK_PAIR_TYPE_1, ETK_PAIR_TYPE_2>& _obj) {
_os << "(";
_os << _obj.first;
_os << ";";
_os << _obj.second;
_os << ")";
return _os;
}
template<class ETK_PAIR_TYPE_1, class ETK_PAIR_TYPE_2>
bool operator< (const Pair<ETK_PAIR_TYPE_1, ETK_PAIR_TYPE_2>& _obj1, const Pair<ETK_PAIR_TYPE_1, ETK_PAIR_TYPE_2>& _obj2) {
if (_obj1.first == _obj2.first) {
return _obj1.second < _obj2.second;
}
return _obj1.first < _obj2.first;
}
};

View File

@ -1,496 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <etk/Pair.hpp>
#include <etk/Vector.hpp>
#include <etk/algorithm.hpp>
namespace etk {
/**
* @brief Set table template is a simple classical "Set" interface.
* A Set contain a list of sorted single element
* - 1 2 3 4 19 55 4356345
* - "aaa" "AABB" "ZZ"
*
* A simple example of use:
* @code{.cpp}
* // Create a integer Set table
* etk::Set<int> myValue;
* // add some element (note add and set is the same function)
* myValue.add(98837);
* myValue.set(88);
* // Display an element:
* printf("my value is : %d", myValue[2]);
* // Change value of an element:
* size_t position = myValue.set(99);
* // Remove an element:
* myValue.remove(99);
* //Clean all the table:
* myValue.clear();
* // number of elements:
* size_t size = myValue.size();
* @endcode
*/
template<class ETK_SET_TYPE, int STATIC_ALLOCATION_SIZE = -1>
class Set {
public:
class Iterator {
private:
size_t m_current; //!< current Id on the vector
Set<ETK_SET_TYPE>* m_set; //!< Pointer on the current element of the vectorBin
public:
/**
* @brief Basic iterator constructor with no link with an etk::Vector
*/
Iterator():
m_current(0),
m_set(null) {
// nothing to do ...
}
/**
* @brief Recopy constructor on a specific etkVector.
* @param[in] _obj The Iterator that might be copy
*/
Iterator(const Iterator & _obj):
m_current(_obj.m_current),
m_set(_obj.m_set) {
// nothing to do ...
}
/**
* @brief Assignation operator.
* @param[in] _otherIterator The Iterator that might be copy
* @return reference on the current Iterator
*/
Iterator& operator=(const Iterator & _obj) {
m_current = _obj.m_current;
m_set = _obj.m_set;
return *this;
}
/**
* @brief Basic destructor
*/
~Iterator() {
m_current = 0;
m_set = null;
}
/**
* @brief basic boolean cast
* @return true if the element is present in the etkVector size
*/
operator bool () {
return (m_current < m_set->size());
}
/**
* @brief Incremental operator
* @return Reference on the current iterator increment
*/
Iterator& operator++ () {
if ( m_set != null
&& m_current < m_set->size() )
{
m_current++;
}
return *this;
}
/**
* @brief Decremental operator
* @return Reference on the current iterator decrement
*/
Iterator& operator-- () {
if ( m_set != null
&& m_current > 0) {
m_current--;
}
return *this;
}
/**
* @brief Incremental operator
* @return Reference on a new iterator and increment the other one
*/
Iterator operator++ (int32_t) {
Iterator it(*this);
++(*this);
return it;
}
/**
* @brief Decremental operator
* @return Reference on a new iterator and decrement the other one
*/
Iterator operator-- (int32_t) {
Iterator it(*this);
--(*this);
return it;
}
Iterator& operator-= (size_t _offset) {
m_current -= _offset;
return *this;
}
Iterator operator- (size_t _offset) const {
Iterator tmp(*this);
tmp -= _offset;
return tmp;
}
Iterator& operator-= (int _offset) {
m_current -= _offset;
return *this;
}
Iterator operator- (int _offset) const {
Iterator tmp(*this);
tmp -= _offset;
return tmp;
}
Iterator& operator-= (int64_t _offset) {
m_current -= _offset;
return *this;
}
Iterator operator- (int64_t _offset) const {
Iterator tmp(*this);
tmp -= _offset;
return tmp;
}
Iterator& operator+= (size_t _offset) {
m_current += _offset;
return *this;
}
Iterator operator+ (size_t _offset) const {
Iterator tmp(*this);
tmp += _offset;
return tmp;
}
Iterator& operator+= (int _offset) {
m_current += _offset;
return *this;
}
Iterator operator+ (int _offset) const {
Iterator tmp(*this);
tmp += _offset;
return tmp;
}
Iterator& operator+= (int64_t _offset) {
m_current += _offset;
return *this;
}
Iterator operator+ (int64_t _offset) const {
Iterator tmp(*this);
tmp += _offset;
return tmp;
}
/**
* @brief Get reference on the current Element
* @return the reference on the current Element
*/
const ETK_SET_TYPE* operator-> () const {
//TK_CHECK_INOUT(m_current < m_set->size());
return &(*m_set)[m_current];
}
ETK_SET_TYPE* operator-> () {
//TK_CHECK_INOUT(m_current < m_set->size());
return &(*m_set)[m_current];
}
/**
* @brief Get reference on the current Element
* @return the reference on the current Element
*/
const ETK_SET_TYPE& operator* () const {
//TK_CHECK_INOUT(m_current < m_set->size());
return (*m_set)[m_current];
}
ETK_SET_TYPE& operator* () {
//TK_CHECK_INOUT(m_current < m_set->size());
return (*m_set)[m_current];
}
bool operator== (const Iterator& _obj) const{
return m_set == _obj.m_set
&& m_current == _obj.m_current;
}
bool operator!= (const Iterator& _obj) const {
return m_set != _obj.m_set
|| m_current != _obj.m_current;
}
private:
Iterator(const etk::Set<ETK_SET_TYPE> * _obj, int32_t _pos):
m_current(_pos),
m_set(const_cast<etk::Set<ETK_SET_TYPE>*>(_obj)) {
// nothing to do ...
}
size_t getCurrent() const {
return m_current;
}
friend class Set;
};
typedef bool (*sortFunction)(const ETK_SET_TYPE& _key1, const ETK_SET_TYPE& _key2);
private:
etk::Vector<ETK_SET_TYPE> m_data; //!< Data of the Set ==> the Set table is composed of pointer, this permit to have high speed when resize the vector ...
sortFunction m_comparator;
public:
/**
* @brief Set the comparator of the set.
* @param[in] _comparator comparing function.
*/
void setComparator(sortFunction _comparator) {
m_comparator = _comparator;
sort();
}
private:
/**
* @brief Order the Set with the corect functor
*/
void sort() {
if (m_comparator != null) {
etk::algorithm::quickSort(m_data, m_comparator);
} else {
sortFunction comparator = [](const ETK_SET_TYPE& _key1, const ETK_SET_TYPE& _key2) { return _key1 < _key2; };
etk::algorithm::quickSort(m_data, comparator);
}
}
public:
/**
* @brief Constructor of the Set table.
* @param[in] _count Number of basic element (pre-allocated) in the table.
*/
Set(int32_t _count = 0) :
m_data(),
m_comparator(null) {
m_data.reserve(_count);
// nothing to do
}
/**
* @brief List initializer (ex: etk::Vector<etk::String> plop = {"hello", world"}
* @param[in] _element element to add in the vector
*/
template<typename... ETK_SET_TYPE_2>
Set(const ETK_SET_TYPE_2& ... _args):
m_data(),
m_comparator(null) {
add(_args...);
}
/**
* @brief Destructor of the Set table (clear all element in the table)
*/
~Set() {
clear();
}
/**
* @brief Remove the first element of the vector
*/
void popFront() {
m_data.popFront();
}
/**
* @brief Remove the last element of the vector
*/
void popBack() {
m_data.popBack();
}
/**
* @brief Remove all entry in the Set table.
* @note It does not delete pointer if your value is a pointer type...
*/
void clear() {
m_data.clear();
}
/**
* @brief Check if an element exist or not
* @param[in] _key Name of the Set requested
* @return true if the element exist
*/
bool exist(const ETK_SET_TYPE& _key) const {
Iterator it = find(_key);
if (it == end()) {
return false;
}
return true;
}
/**
* @brief Get Element an a special position
* @param[in] _position Position in the Set
* @return An reference on the selected element
*/
ETK_SET_TYPE& operator[] (size_t _position) {
return m_data[_position];
}
/**
* @brief Get Element an a special position
* @param[in] _position Position in the Set
* @return An reference on the selected element
*/
const ETK_SET_TYPE& operator[] (size_t _position) const {
return m_data[_position];
}
private:
template<typename... ETK_SET_TYPE_2>
void add(const ETK_SET_TYPE& _value, const ETK_SET_TYPE_2& ... _args) {
add(_value);
add(_args...);
}
public:
/**
* @brief Add an element OR set an element value
* @note add and set is the same function.
* @param[in] _key Name of the value to set in the Set table.
* @param[in] _value Value to set in the Set table.
*/
void add(const ETK_SET_TYPE& _key) {
if (m_comparator != null) {
for (size_t iii=0; iii<m_data.size(); ++iii) {
if (_key == m_data[iii]) {
return;
}
if (m_comparator(_key, m_data[iii]) == true) {
// Find a position
m_data.insert(iii, etk::move(_key));
return;
}
}
} else {
for (size_t iii=0; iii<m_data.size(); ++iii) {
if (_key == m_data[iii]) {
return;
}
if (_key < m_data[iii]) {
// Find a position
m_data.insert(iii, etk::move(_key));
return;
}
}
}
m_data.pushBack(etk::move(_key));
}
/**
* @brief Set an element value
* @note add and set is the same function.
* @param[in] _key Name of the value to set in the Set table.
* @param[in] _value Value to set in the Set table.
*/
void set(const ETK_SET_TYPE& _key) {
add(etk::move(_key));
}
/**
* @brief Remove an element in the Set table.
* @param[in] _key Name of the element to remove.
*/
/*
// TODO: this is dangerous ...
void erase(const ETK_SET_TYPE& _key) {
Iterator it = find(_key);
if (it == end()) {
return;
}
m_data.erase(m_data.begin() + it.getCurrent());
}
*/
/**
* @brief Remove an element in the Set table.
* @param[in] _it Iterator on the element.
*/
Iterator erase(const Iterator& _it) {
if (_it != end()) {
m_data.erase(m_data.begin() + _it.getCurrent());
return position(_it.getCurrent());
}
return _it;
}
/**
* @brief Get the number of element in the Set table
* @return number of elements
*/
size_t size() const {
return m_data.size();
}
/**
* @brief Check if the container have some element
* @return true The container is empty
* @return famse The container have some element
*/
bool empty() const {
return m_data.size() == 0;
}
/**
* @brief Swap generic function
* @param[in,out] _obj Object to swap data & control...
*/
void swap(Set& _obj) {
etk::swap(m_data, _obj.m_data);
etk::swap(m_comparator, _obj.m_comparator);
}
/**
* @brief Get an iterator an an specific position
* @param[in] _pos Requested position of the iterator in the vector
* @return The Iterator
*/
Iterator position(size_t _pos) {
return Iterator(this, _pos);
}
const Iterator position(size_t _pos) const {
return Iterator(this, _pos);
}
/**
* @brief Get an Iterator on the start position of the Vector
* @return The Iterator
*/
Iterator begin() {
return position(0);
}
const Iterator begin() const {
return position(0);
}
/**
* @brief Get an Iterator on the end position of the Vector
* @return The Iterator
*/
Iterator end() {
return position(size());
}
const Iterator end() const {
return position(size());
}
/**
* @brief Find an element position the the Set table
* @param[in] _key Name of the element to find
* @return Iterator on the element find or end()
*/
const Iterator find(const ETK_SET_TYPE& _key) const {
// TODO: search in a dichotomic way.
for (size_t iii=0; iii<m_data.size(); iii++) {
if (m_data[iii] == _key) {
return position(iii);
}
}
return end();
}
Iterator find(const ETK_SET_TYPE& _key) {
// TODO: search in a dichotomic way.
for (size_t iii=0; iii<m_data.size(); iii++) {
if (m_data[iii] == _key) {
return position(iii);
}
}
return end();
}
/**
* @brief Count the number of occurence of a specific element.
* @param[in] _key Name of the element to count iterence
* @return 0 No element was found
* @return 1 One element was found
*/
size_t count(const ETK_SET_TYPE& _key) const {
// TODO: search in a dichotomic way.
for (size_t iii=0; iii<m_data.size(); iii++) {
if (m_data[iii] == _key) {
return 1;
}
}
return 0;
}
};
}

View File

@ -1,90 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL-2 (see license file)
*/
#include <etk/Stream.hpp>
#include <etk/String.hpp>
etk::Stream::Stream(size_t _basicSize) :
m_data(ETK_NEW(etk::String)) {
m_data->reserve(_basicSize);
}
etk::Stream::~Stream() {
ETK_DELETE(etk::String, m_data);
m_data = null;
}
etk::Stream& etk::Stream::operator<< (const char* _data) {
*m_data += _data;
return *this;
}
etk::Stream& etk::Stream::operator<< (const bool& _data) {
*m_data += etk::toString(_data);
return *this;
}
etk::Stream& etk::Stream::operator<< (const int8_t& _data) {
*m_data += etk::toString(_data);
return *this;
}
etk::Stream& etk::Stream::operator<< (const int16_t& _data) {
*m_data += etk::toString(_data);
return *this;
}
etk::Stream& etk::Stream::operator<< (const int32_t& _data) {
*m_data += etk::toString(_data);
return *this;
}
etk::Stream& etk::Stream::operator<< (const int64_t& _data) {
*m_data += etk::toString(_data);
return *this;
}
etk::Stream& etk::Stream::operator<< (const uint8_t& _data) {
*m_data += etk::toString(_data);
return *this;
}
etk::Stream& etk::Stream::operator<< (const uint16_t& _data) {
*m_data += etk::toString(_data);
return *this;
}
etk::Stream& etk::Stream::operator<< (const uint32_t& _data) {
*m_data += etk::toString(_data);
return *this;
}
etk::Stream& etk::Stream::operator<< (const uint64_t& _data) {
*m_data += etk::toString(_data);
return *this;
}
#if defined(__TARGET_OS__MacOs) \
|| defined(__TARGET_OS__IOs)
etk::Stream& etk::Stream::operator<< (const size_t& _data) {
*m_data += etk::toString(_data);
return *this;
}
#endif
etk::Stream& etk::Stream::operator<< (const float& _data) {
*m_data += etk::toString(_data);
return *this;
}
etk::Stream& etk::Stream::operator<< (const double& _data) {
*m_data += etk::toString(_data);
return *this;
}
etk::Stream& etk::Stream::operator<< (const etk::NullPtr& _data) {
*m_data += "null";
return *this;
}
const char* etk::Stream::c_str() const {
return m_data->c_str();
}
const size_t etk::Stream::size() const {
return m_data->size();
}
const etk::String& etk::Stream::str() const {
return *m_data;
}

View File

@ -1,45 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL-2 (see license file)
*/
#pragma once
#include <etk/types.hpp>
namespace etk {
class String;
/**
* @brief string class ...
*/
class Stream {
private:
// remove dependency of etk::String and vector
etk::String* m_data;
public:
Stream(size_t _basicSize=0);
~Stream();
Stream& operator<< (const char* _data);
Stream& operator<< (const bool& _data);
Stream& operator<< (const int8_t& _data);
Stream& operator<< (const int16_t& _data);
Stream& operator<< (const int32_t& _data);
Stream& operator<< (const int64_t& _data);
Stream& operator<< (const uint8_t& _data);
Stream& operator<< (const uint16_t& _data);
Stream& operator<< (const uint32_t& _data);
Stream& operator<< (const uint64_t& _data);
#if defined(__TARGET_OS__MacOs) \
|| defined(__TARGET_OS__IOs)
Stream& operator<< (const size_t& _data);
#endif
Stream& operator<< (const float& _data);
Stream& operator<< (const double& _data);
Stream& operator<< (const etk::NullPtr& _data);
const char* c_str() const;
const etk::String& str() const;
const size_t size() const;
};
}

File diff suppressed because it is too large Load Diff

View File

@ -1,608 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL-2 (see license file)
*/
#pragma once
#include <etk/types.hpp>
//#include <etk/debug.hpp>
#include <etk/Vector.hpp>
// This permit to define a minimal size in the string to permit to optimise the unneeded allocation of memory (32 remove allocation of 1 byte and 64 remove multiple allocation of 16 bytes (common)
#ifndef ETK_ENABLE_INTERNAL_DATA_IN_STRING
// TODO: NOTE: This is really not functionnal for now...
//#define ETK_ENABLE_INTERNAL_DATA_IN_STRING 64
#endif
namespace etk {
/**
* @brief string class ...
*/
class String {
public:
class Iterator {
private:
size_t m_current = 0; //!< current Id on the string
String* m_string = null; //!< Pointer on the current element of the string
public:
/**
* @brief Basic iterator constructor with no link with an etk::String
*/
Iterator() {
// nothing to do ...
}
/**
* @brief Recopy constructor on a specific etk::String.
* @param[in] _obj The Iterator that might be copy
*/
Iterator(const Iterator & _obj):
m_current(_obj.m_current),
m_string(_obj.m_string) {
// nothing to do ...
}
/**
* @brief Assignation operator.
* @param[in] _otherIterator The Iterator that might be copy
* @return reference on the current Iterator
*/
Iterator& operator=(const Iterator & _otherIterator) {
m_current = _otherIterator.m_current;
m_string = _otherIterator.m_string;
return *this;
}
/**
* @brief Basic destructor
*/
~Iterator() {
m_current = 0;
m_string = null;
}
/**
* @brief basic boolean cast
* @return true if the element is present in the etk::String size
*/
operator bool () {
return (m_current < m_string->size());
}
/**
* @brief Incremental operator
* @return Reference on the current iterator increment
*/
Iterator& operator++ () {
if ( m_string != null
&& m_current < m_string->size() )
{
m_current++;
}
return *this;
}
/**
* @brief Decremental operator
* @return Reference on the current iterator decrement
*/
Iterator& operator-- () {
if ( m_string != null
&& m_current > 0) {
m_current--;
}
return *this;
}
/**
* @brief Incremental operator
* @return Reference on a new iterator and increment the other one
*/
Iterator operator++ (int) {
Iterator it(*this);
++(*this);
return it;
}
/**
* @brief Decremental operator
* @return Reference on a new iterator and decrement the other one
*/
Iterator operator-- (int) {
Iterator it(*this);
--(*this);
return it;
}
Iterator& operator-= (size_t _offset) {
m_current -= _offset;
return *this;
}
Iterator operator- (size_t _offset) const {
Iterator tmp(*this);
tmp -= _offset;
return tmp;
}
Iterator& operator-= (int _offset) {
m_current -= _offset;
return *this;
}
Iterator operator- (int _offset) const {
Iterator tmp(*this);
tmp -= _offset;
return tmp;
}
Iterator& operator+= (size_t _offset) {
m_current += _offset;
return *this;
}
Iterator operator+ (size_t _offset) const {
Iterator tmp(*this);
tmp += _offset;
return tmp;
}
Iterator& operator+= (int _offset) {
m_current += _offset;
return *this;
}
Iterator operator+ (int _offset) const {
Iterator tmp(*this);
tmp += _offset;
return tmp;
}
/**
* @brief Get reference on the current Element
* @return the reference on the current Element
*/
char operator* () const {
//TK_ASSERT(m_current < m_string->size(), "out of range");
return m_string->get(m_current);
}
/**
* @brief Get reference on the current Element
* @return the reference on the current Element
*/
char& operator* () {
//TK_ASSERT(m_current < m_string->size(), "out of range");
return m_string->get(m_current);
}
/*****************************************************
* == operator
*****************************************************/
bool operator== (const Iterator& _obj) const {
// check if it was the same pointer
if( this == &_obj ) {
return true;
}
if (m_current != _obj.m_current) {
return false;
}
if (m_string != _obj.m_string) {
return false;
}
return true;
}
/*****************************************************
* != operator
*****************************************************/
bool operator!= (const Iterator& _obj) const {
// check if it was the same pointer
if( this == &_obj ) {
return false;
}
if (m_current != _obj.m_current) {
return true;
}
if (m_string != _obj.m_string) {
return true;
}
return false;
}
private:
Iterator(const String* _obj, int32_t _pos):
m_current(_pos),
m_string(const_cast<String*>(_obj)) {
// nothing to do ...
}
size_t getCurrent() const {
return m_current;
}
friend class String;
};
private:
etk::Vector<char> m_data; //!< pointer on the current data (contain all time 1 element '\0')
#if ETK_ENABLE_INTERNAL_DATA_IN_STRING >= 32
char m_localData[ETK_ENABLE_INTERNAL_DATA_IN_STRING-sizeof(etk::Vector<char>)]; //!< Reserve the memory to have all time a buffer of N byte to remove un-needed allocation
static const size_t m_sizeLocal;
#endif
public:
static const size_t npos = size_t(-1);
/**
* @brief Create an empty string
*/
String();
/**
* @brief Copy constructor (copy all data)
* @param[in] _obj String that might be copy
*/
String(const etk::String& _obj);
/**
* @brief Partial copy constructor (copy all needed data)
* @param[in] _obj String that might be copy (part of it)
* @param[in] _pos Start position to copy data
* @param[in] _size Number of element to copy in the string
*/
String(const etk::String& _obj, size_t _pos, size_t _size = etk::String::npos);
/**
* @brief Copy the null-terminated C string.
* @param[in] _obj C string that might be copy (end by '\0')
*/
String(const char* _obj);
// TODO : remove this when ready
//////// String(const etk::String _obj);
/**
* @brief Partial copy of the null-terminated C string.
* @param[in] _obj String that might be copyC string that might be copy (end by '\0')
* @param[in] _size Number of element to copy.
*/
String(const char* _obj, size_t _size);
/**
* @brief Fills the string with _size consecutive copies of character _val.
* @param[in] _size Number of element in the string
* @param[in] _val Value to set in the string
*/
String(size_t _size, char _val);
/**
* @brief Copy all element betewwen the 2 iterator of the new string.
* @param[in] _start Start iterator of adding value.
* @param[in] _stop Start iterator of adding value.
*/
String(Iterator _start, Iterator _stop);
/**
* @brief Move constructor
* @param[in] _obj String that might be move inside
*/
String(String&& _obj) noexcept;
/**
* @brief Set constructor
* @param[in] _value Char element to set in the string
*/
String(char _value);
/**
* @brief Destructor of the current Class
*/
~String();
/**
* @brief Swap the data of 2 Strings
* @param[in] _obj second string to swap data.
*/
void swap(etk::String& _obj);
/**
* @brief Re-copy operator
* @param[in] _obj String that might be copy
* @return reference on the current re-copy string
*/
String& operator=(const etk::String& _obj);
/**
* @brief Re-copy operator
* @param[in] _obj C string terminated with '\0'
* @return reference on the current re-copy string
*/
String& operator=(const char* _obj);
/**
* @brief Re-copy operator
* @param[in] _value Char value to set in the string
* @return reference on the current re-copy string
*/
String& operator=(char _value);
/**
* @brief Add at the Last position of the String
* @param[in] _obj Element to add at the end of string
*/
String& operator+= (const etk::String& _obj);
/**
* @brief Add at the Last position of the String
* @param[in] _obj C string terminated with '\0'
*/
String& operator+= (const char* _obj);
/**
* @brief Add at the Last position of the String
* @param[in] _value Simple character to add.
*/
String& operator+= (char _value);
/**
* @brief Get the number of element in the string
* @return The number requested
*/
size_t size() const;
/**
* @brief Check if the container have some element
* @return true The container is empty
* @return famse The container have some element
*/
bool empty() const {
return size() == 0;
}
/// @previous
bool isEmpty() const {
return empty();
}
/**
* @brief Get a current element in the string
* @param[in] _pos Desired position read
* @return Reference on the Element
*/
char& get(size_t _pos);
/**
* @brief Get an copy Element an a special position
* @param[in] _pos Position in the string that might be get [0..Size()]
* @return An reference on the copy of selected element
*/
char& operator[] (size_t _pos);
/**
* @brief Get an Element an a special position
* @param[in] _pos Position in the string that might be get [0..Size()]
* @return An reference on the selected element
*/
const char& operator[] (size_t _pos) const;
/**
* @brief Add at the First position of the String
* @param[in] _item Element to add at the end of string
*/
void pushFront(char _item);
/**
* @brief Add at the Last position of the String
* @param[in] _item Pointer on a list of Element to add at the start of string
* @param[in] _nbElement Number of element to add.
*/
void pushFront(const char * _item, size_t _nbElement);
/**
* @brief Add at the Last position of the String
* @param[in] _item Element to add at the end of string
*/
void pushBack(const char _item);
/**
* @brief Add at the Last position of the String
* @param[in] _item Pointer on a list of Element to add at the end of string
* @param[in] _nbElement Number of element to add.
*/
void pushBack(const char* _item, size_t _nbElement);
/**
* @brief Remove the last element of the string
*/
void popBack();
/**
* @brief Get the last element of the String
* @return An reference on the last char
*/
char& back();
const char& back() const;
/**
* @brief Force the container to have a minimum size in memory allocation
* @param[in] _size Size in byte that is requested.
*/
void reserve(size_t _size);
/**
* @brief Remove all element in the current string
*/
void clear();
/**
* @brief Insert N element in the String.
* @param[in] _pos Position to add the elements.
* @param[in] _item Pointer on a table of the elements to add.
* @param[in] _nbElement Number of element to add in the String
*/
void insert(size_t _pos, const char* _item, size_t _nbElement);
//! @previous
void insert(const Iterator& _pos, const char* _item, size_t _nbElement) {
insert(_pos.getCurrent(), _item, _nbElement);
};
/**
* @brief Insert one element in the String at a specific position
* @param[in] _pos Position to add the elements.
* @param[in] _item Element to add.
*/
void insert(size_t _pos, const char _item);
//! @previous
void insert(const Iterator& _pos, const char _item) {
insert(_pos.getCurrent(), _item);
}
/**
* @brief Insert one element in the String at a specific position
* @param[in] _pos Position to add the elements.
* @param[in] _item Element to add.
*/
void insert(size_t _pos, const String& _value);
//! @previous
void insert(const Iterator& _pos, const String& _value) {
insert(_pos.getCurrent(), _value);
}
/**
* @brief Remove N element
* @param[in] _pos Position to remove the data
* @param[in] _nbElement number of element to remove
*/
void erase(size_t _pos, size_t _nbElement=1);
//! @previous
void erase(const Iterator& _pos) {
erase(_pos.getCurrent(), 1);
}
/**
* @brief Remove N elements
* @param[in] _start Position to remove the data
* @param[in] _stop Last position number
*/
void eraseRange(size_t _start, size_t _stop);
//! @previous
void erase(const Iterator& _start, const Iterator& _stop) {
eraseRange(_start.getCurrent(), _stop.getCurrent());
}
/**
* @brief extract data between two point :
* @param[in] _posStart start position to extract data
* @param[in] _posEnd End position to extract data
* @return the extracted string
*/
etk::String extract(size_t _posStart = 0, size_t _posEnd=etk::String::npos) const;
//! @previous
etk::String extract(const Iterator& _start, const Iterator& _stop) const {
return extract(_start.getCurrent(), _stop.getCurrent());
}
/**
* @brief Get the pointer on the data
* @return pointer on the "C" string
*/
const char* c_str() const;
/**
* @brief Get an iterator an an specific position
* @param[in] _pos Requested position of the iterator in the string
* @return The Iterator
*/
Iterator position(size_t _pos);
//! @previous
const Iterator position(size_t _pos) const;
/**
* @brief Get an Iterator on the start position of the String
* @return The Iterator
*/
Iterator begin();
//! @previous
const Iterator begin() const;
/**
* @brief Get an Iterator on the end position of the String
* @return The Iterator
*/
Iterator end();
//! @previous
const Iterator end() const;
/**
* @brief Change the current size of the string
* @param[in] _newSize New requested size of element in the string
* @param[in] _value Value to set at the new element
*/
void resize(size_t _newSize, char _value = '\0');
void append(Iterator _start, Iterator _stop);
/*****************************************************
* == operator
*****************************************************/
bool operator== (const String& _obj) const;
/*****************************************************
* != operator
*****************************************************/
bool operator!= (const String& _obj) const;
size_t find(char _value, size_t _pos=0) const;
size_t find(const etk::String& _value, size_t _pos=0) const;
size_t rfind(char _value, size_t _pos=etk::String::npos) const;
size_t rfind(const etk::String& _value, size_t _pos=etk::String::npos) const;
etk::String& replace(size_t _pos, size_t _len, char _replace);
etk::String& replace(size_t _pos, size_t _len, const etk::String& _replace);
etk::String& replace(char _val, char _replace);
etk::String& replace(const etk::String& _val, const etk::String& _replace);
etk::String getLine(int32_t _pos) const;
etk::String toLower() const;
etk::String& lower();
etk::String toUpper() const;
etk::String& upper();
bool compare(const etk::String& _val, bool _caseSensitive = true) const;
bool endWith(const etk::String& _val, bool _caseSensitive = true) const;
bool startWith(const etk::String& _val, bool _caseSensitive = true) const;
etk::Vector<etk::String> split(char _val) const;
etk::Vector<etk::String> split(etk::String _val) const;
/**
* @brief Template that permit to convert string in everythings you want
* @param[in] ETK_STRING_TYPE Template type of the convertion output
*/
template <class ETK_STRING_TYPE>
ETK_STRING_TYPE to() const;
};
char toLower(char _value);
char toUpper(char _value);
bool operator> (const String& _left, const String& _right);
bool operator>= (const String& _left, const String& _right);
bool operator< (const String& _left, const String& _right);
bool operator<= (const String& _left, const String& _right);
String operator+ (const String& _left, const String& _right);
String operator+ (const String& _left, const char* _right);
String operator+ (const char* _left, const String& _right);
String operator+ (const String& _left, char _right);
String operator+ (char _left, const String& _right);
inline bool operator== (const char* _left, const String& _right) {
return _right == _left;
}
inline bool operator!= (const char* _left, const String& _right) {
return _right != _left;
}
inline bool operator> (const char* _left, const String& _right) {
return _right > _left;
}
inline bool operator>= (const char* _left, const String& _right) {
return _right >= _left;
}
inline bool operator< (const char* _left, const String& _right) {
return _right < _left;
}
inline bool operator<= (const char* _left, const String& _right) {
return _right <= _left;
}
//! @not_in_doc
etk::Stream& operator <<(etk::Stream& _os, const etk::String& _obj);
/**
* @brief Template to declare conversion from anything in etk::String
* @param[in] _variable Variable to convert
* @return String of the value
*/
template <class TYPE>
etk::String toString(const TYPE& _variable);
/**
* @brief Template to declare conversion from string to anything
* @param[out] _variableRet Output value
* @param[in] _value input property
* @return true if the can be converted.
*/
template <class TYPE>
bool from_string(TYPE& _variableRet, const etk::String& _value);
void sort(etk::Vector<etk::String *>& _list);
void sort(etk::Vector<etk::String>& _list);
// TODO: DEPRECATED function:
long double string_to_long_double(const etk::String& _obj);
double string_to_double(const etk::String& _obj);
float string_to_float(const etk::String& _obj);
int8_t string_to_int8_t(const etk::String& _obj);
int16_t string_to_int16_t(const etk::String& _obj);
int32_t string_to_int32_t(const etk::String& _obj);
int64_t string_to_int64_t(const etk::String& _obj);
uint8_t string_to_uint8_t(const etk::String& _obj);
uint16_t string_to_uint16_t(const etk::String& _obj);
uint32_t string_to_uint32_t(const etk::String& _obj);
uint64_t string_to_uint64_t(const etk::String& _obj);
uint64_t hexaString_to_uint64_t(const etk::String& _obj);
uint64_t bitString_to_uint64_t(const etk::String& _obj);
uint64_t octalString_to_uint64_t(const etk::String& _obj);
bool string_to_bool(const etk::String& _obj);
etk::String toLower(etk::String _obj);
etk::String toUpper(etk::String _obj);
bool compare_no_case(const etk::String& _obj, const etk::String& _val);
bool end_with(const etk::String& _obj, const etk::String& _val, bool _caseSensitive = true);
bool start_with(const etk::String& _obj, const etk::String& _val, bool _caseSensitive = true);
etk::String replace(const etk::String& _obj, char _val, char _replace);
etk::String extract_line(const etk::String& _obj, int32_t _pos);
etk::Vector<etk::String> split(const etk::String& _obj, char _val);
/**
* @brief Template to declare conversion from etk::Vector<anything> in etk::String
* @param[in] _list Variable to convert
* @return String of the value: {...,...,...}
*/
template <class TYPE>
etk::String toString(const etk::Vector<TYPE>& _list) {
etk::String out = "{";
for (size_t iii=0; iii<_list.size(); ++iii) {
if (iii!=0) {
out += ";";
}
out+= etk::toString(_list[iii]);
}
out += "}";
return out;
}
char toHexChar(uint8_t _value);
etk::String toHex(uint64_t _value, uint32_t _size = 2);
etk::String toBin(uint64_t _value, uint32_t _size = 1);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,566 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL-2 (see license file)
*/
#pragma once
#include <etk/types.hpp>
//#include <etk/debug.hpp>
#include <etk/Vector.hpp>
#include <etk/utf8.hpp>
#include <etk/stdTools.hpp>
namespace etk {
/**
* @brief string class ...
*/
class UString {
public:
class Iterator {
private:
size_t m_current = 0; //!< current Id on the string
UString* m_string = null; //!< Pointer on the current element of the stringBin
public:
/**
* @brief Basic iterator constructor with no link with an etk::UString
*/
Iterator() {
// nothing to do ...
}
/**
* @brief Recopy constructor on a specific etk::UString.
* @param[in] _obj The Iterator that might be copy
*/
Iterator(const Iterator & _obj):
m_current(_obj.m_current),
m_string(_obj.m_string) {
// nothing to do ...
}
/**
* @brief Assignation operator.
* @param[in] _otherIterator The Iterator that might be copy
* @return reference on the current Iterator
*/
Iterator& operator=(const Iterator & _otherIterator) {
m_current = _otherIterator.m_current;
m_string = _otherIterator.m_string;
return *this;
}
/**
* @brief Basic destructor
*/
~Iterator() {
m_current = 0;
m_string = null;
}
/**
* @brief basic boolean cast
* @return true if the element is present in the etk::UString size
*/
operator bool () {
return (m_current < m_string->size());
}
/**
* @brief Incremental operator
* @return Reference on the current iterator increment
*/
Iterator& operator++ () {
if ( m_string != null
&& m_current < m_string->size() )
{
m_current++;
}
return *this;
}
/**
* @brief Decremental operator
* @return Reference on the current iterator decrement
*/
Iterator& operator-- () {
if ( m_string != null
&& m_current > 0) {
m_current--;
}
return *this;
}
/**
* @brief Incremental operator
* @return Reference on a new iterator and increment the other one
*/
Iterator operator++ (int) {
Iterator it(*this);
++(*this);
return it;
}
/**
* @brief Decremental operator
* @return Reference on a new iterator and decrement the other one
*/
Iterator operator-- (int) {
Iterator it(*this);
--(*this);
return it;
}
Iterator& operator-= (size_t _offset) {
m_current -= _offset;
return *this;
}
Iterator operator- (size_t _offset) const {
Iterator tmp(*this);
tmp -= _offset;
return tmp;
}
Iterator& operator-= (int _offset) {
m_current -= _offset;
return *this;
}
Iterator operator- (int _offset) const {
Iterator tmp(*this);
tmp -= _offset;
return tmp;
}
Iterator& operator+= (size_t _offset) {
m_current += _offset;
return *this;
}
Iterator operator+ (size_t _offset) const {
Iterator tmp(*this);
tmp += _offset;
return tmp;
}
Iterator& operator+= (int _offset) {
m_current += _offset;
return *this;
}
Iterator operator+ (int _offset) const {
Iterator tmp(*this);
tmp += _offset;
return tmp;
}
/**
* @brief Get reference on the current Element
* @return the reference on the current Element
*/
char32_t operator* () const {
//TK_ASSERT(m_current < m_string->size(), "out of range");
return m_string->get(m_current);
}
/**
* @brief Get reference on the current Element
* @return the reference on the current Element
*/
char32_t& operator* () {
//TK_ASSERT(m_current < m_string->size(), "out of range");
return m_string->get(m_current);
}
/*****************************************************
* == operator
*****************************************************/
bool operator== (const Iterator& _obj) const {
// check if it was the same pointer
if( this == &_obj ) {
return true;
}
if (m_current != _obj.m_current) {
return false;
}
if (m_string != _obj.m_string) {
return false;
}
return true;
}
/*****************************************************
* != operator
*****************************************************/
bool operator!= (const Iterator& _obj) const {
// check if it was the same pointer
if( this == &_obj ) {
return false;
}
if (m_current != _obj.m_current) {
return true;
}
if (m_string != _obj.m_string) {
return true;
}
return false;
}
private:
Iterator(const UString* _obj, int32_t _pos):
m_current(_pos),
m_string(const_cast<UString*>(_obj)) {
// nothing to do ...
}
size_t getCurrent() const {
return m_current;
}
friend class UString;
};
private:
etk::Vector<char32_t> m_data; //!< pointer on the current data (contain all time 1 element '\0')
public:
static const size_t npos = size_t(-1);
/**
* @brief Create an empty string
*/
UString();
/**
* @brief Copy constructor (copy all data)
* @param[in] _obj String that might be copy
*/
UString(const etk::UString& _obj);
/**
* @brief Partial copy constructor (copy all needed data)
* @param[in] _obj String that might be copy (part of it)
* @param[in] _pos Start position to copy data
* @param[in] _size Number of element to copy in the string
*/
UString(const etk::UString& _obj, size_t _pos, size_t _size = etk::UString::npos);
/**
* @brief Copy the null-terminated C string.
* @param[in] _obj C string that might be copy (end by '\0')
*/
UString(const char32_t* _obj);
/**
* @brief Partial copy of the null-terminated C string.
* @param[in] _obj String that might be copyC string that might be copy (end by '\0')
* @param[in] _size Number of element to copy.
*/
UString(const char32_t* _obj, size_t _size);
/**
* @brief Fills the string with _size consecutive copies of character _val.
* @param[in] _size Number of element in the string
* @param[in] _val Value to set in the string
*/
UString(size_t _size, char32_t _val);
/**
* @brief Copy all element betewwen the 2 iterator of the new string.
* @param[in] _start Start iterator of adding value.
* @param[in] _stop Start iterator of adding value.
*/
UString(Iterator _start, Iterator _stop);
/**
* @brief Move constructor
* @param[in] _obj String that might be move inside
*/
UString(etk::UString&& _obj) noexcept;
/**
* @brief Set constructor
* @param[in] _value Char element to set in the string
*/
UString(char32_t _value);
/**
* @brief Destructor of the current Class
*/
~UString();
/**
* @brief Swap the data of 2 Strings
* @param[in] _obj second string to swap data.
*/
void swap(etk::UString& _obj);
/**
* @brief Re-copy operator
* @param[in] _obj String that might be copy
* @return reference on the current re-copy string
*/
UString& operator=(const etk::UString& _obj);
/**
* @brief Re-copy operator
* @param[in] _obj C string terminated with '\0'
* @return reference on the current re-copy string
*/
UString& operator=(const char32_t* _obj);
/**
* @brief Re-copy operator
* @param[in] _value char32_t value to set in the string
* @return reference on the current re-copy string
*/
UString& operator=(char32_t _value);
/**
* @brief Add at the Last position of the String
* @param[in] _obj Element to add at the end of string
*/
UString& operator+= (const etk::UString& _obj);
/**
* @brief Add at the Last position of the String
* @param[in] _obj C string terminated with '\0'
*/
UString& operator+= (const char32_t* _obj);
/**
* @brief Add at the Last position of the String
* @param[in] _value Simple character to add.
*/
UString& operator+= (char32_t _value);
/**
* @brief Get the number of element in the string
* @return The number requested
*/
size_t size() const;
/**
* @brief Check if the container have some element
* @return true The container is empty
* @return famse The container have some element
*/
bool empty() const {
return size() == 0;
}
/// @previous
bool isEmpty() const {
return empty();
}
/**
* @brief Get a current element in the string
* @param[in] _pos Desired position read
* @return Reference on the Element
*/
char32_t& get(size_t _pos) {
return m_data[_pos];
}
/**
* @brief Get an copy Element an a special position
* @param[in] _pos Position in the string that might be get [0..Size()]
* @return An reference on the copy of selected element
*/
char32_t& operator[] (size_t _pos) {
return m_data[_pos];
}
/**
* @brief Get an Element an a special position
* @param[in] _pos Position in the string that might be get [0..Size()]
* @return An reference on the selected element
*/
const char32_t& operator[] (size_t _pos) const {
return m_data[_pos];
}
/**
* @brief Add at the First position of the String
* @param[in] _item Element to add at the end of string
*/
void pushFront(char32_t _item);
/**
* @brief Add at the Last position of the String
* @param[in] _item Pointer on a list of Element to add at the start of string
* @param[in] _nbElement Number of element to add.
*/
void pushFront(const char32_t* _item, size_t _nbElement);
/**
* @brief Add at the Last position of the String
* @param[in] _item Element to add at the end of string
*/
void pushBack(const char32_t _item);
/**
* @brief Add at the Last position of the String
* @param[in] _item Pointer on a list of Element to add at the end of string
* @param[in] _nbElement Number of element to add.
*/
void pushBack(const char32_t* _item, size_t _nbElement);
/**
* @brief Remove the last element of the string
*/
void popBack();
/**
* @brief Force the container to have a minimum size in memory allocation
* @param[in] _size Size in byte that is requested.
*/
void reserve(size_t _size);
/**
* @brief Remove all element in the current string
*/
void clear();
/**
* @brief Insert N element in the String.
* @param[in] _pos Position to add the elements.
* @param[in] _item Pointer on a table of the elements to add.
* @param[in] _nbElement Number of element to add in the String
*/
void insert(size_t _pos, const char32_t* _item, size_t _nbElement);
//! @previous
void insert(const Iterator& _pos, const char32_t* _item, size_t _nbElement) {
insert(_pos.getCurrent(), _item, _nbElement);
};
/**
* @brief Insert one element in the String at a specific position
* @param[in] _pos Position to add the elements.
* @param[in] _item Element to add.
*/
void insert(size_t _pos, const char32_t _item);
//! @previous
void insert(const Iterator& _pos, const char32_t _item) {
insert(_pos.getCurrent(), _item);
}
/**
* @brief Insert one element in the String at a specific position
* @param[in] _pos Position to add the elements.
* @param[in] _item Element to add.
*/
void insert(size_t _pos, const etk::UString& _value);
//! @previous
void insert(const Iterator& _pos, const UString& _value) {
insert(_pos.getCurrent(), _value);
}
/**
* @brief Remove N element
* @param[in] _pos Position to remove the data
* @param[in] _nbElement number of element to remove
*/
void erase(size_t _pos, size_t _nbElement=1);
//! @previous
void erase(const Iterator& _pos) {
erase(_pos.getCurrent(), 1);
}
/**
* @brief Remove N elements
* @param[in] _start Position to remove the data
* @param[in] _stop Last position number
*/
void eraseRange(size_t _start, size_t _stop);
//! @previous
void erase(const Iterator& _start, const Iterator& _stop) {
eraseRange(_start.getCurrent(), _stop.getCurrent());
}
/**
* @brief extract data between two point :
* @param[in] _posStart start position to extract data
* @param[in] _posEnd End position to extract data
* @return the extracted string
*/
etk::UString extract(size_t _posStart = 0, size_t _posEnd=etk::UString::npos) const;
//! @previous
etk::UString extract(const Iterator& _start, const Iterator& _stop) const {
return extract(_start.getCurrent(), _stop.getCurrent());
}
/**
* @brief Get the pointer on the data
* @return pointer on the "C" string
*/
const char32_t* c_str() const;
/**
* @brief Get an iterator an an specific position
* @param[in] _pos Requested position of the iterator in the string
* @return The Iterator
*/
Iterator position(size_t _pos);
const Iterator position(size_t _pos) const;
/**
* @brief Get an Iterator on the start position of the String
* @return The Iterator
*/
Iterator begin();
const Iterator begin() const;
/**
* @brief Get an Iterator on the end position of the String
* @return The Iterator
*/
Iterator end();
const Iterator end() const;
/**
* @brief Change the current size of the string
* @param[in] _newSize New requested size of element in the string
* @param[in] _value Value to set at the new element
*/
void resize(size_t _newSize, char32_t _value = '\0');
/*****************************************************
* == operator
*****************************************************/
bool operator== (const etk::UString& _obj) const;
/*****************************************************
* != operator
*****************************************************/
bool operator!= (const etk::UString& _obj) const;
size_t find(char32_t _value, size_t _pos=0) const;
size_t find(const etk::UString& _value, size_t _pos=0) const;
size_t rfind(char32_t _value, size_t _pos=etk::UString::npos) const;
size_t rfind(const etk::UString& _value, size_t _pos=etk::UString::npos) const;
etk::UString& replace(size_t _pos, size_t _len, char32_t _replace);
etk::UString& replace(size_t _pos, size_t _len, const etk::UString& _replace);
etk::UString& replace(char32_t _val, char32_t _replace);
etk::UString& replace(const etk::UString& _val, const etk::UString& _replace);
etk::UString getLine(int32_t _pos) const;
etk::UString toLower() const;
etk::UString& lower();
etk::UString toUpper() const;
etk::UString& upper();
bool compare(const etk::UString& _val, bool _caseSensitive = true) const;
bool endWith(const etk::UString& _val, bool _caseSensitive = true) const;
bool startWith(const etk::UString& _val, bool _caseSensitive = true) const;
etk::Vector<etk::UString> split(char32_t _val) const;
etk::Vector<etk::UString> split(etk::UString _val) const;
/**
* @brief Template that permit to convert string in everythings you want
* @param[in] ETK_STRING_TYPE Template type of the convertion output
*/
template <class ETK_STRING_TYPE>
ETK_STRING_TYPE to() const;
};
bool operator> (const UString& _left, const UString& _right);
bool operator>= (const UString& _left, const UString& _right);
bool operator< (const UString& _left, const UString& _right);
bool operator<= (const UString& _left, const UString& _right);
UString operator+ (const UString& _left, const UString& _right);
UString operator+ (const UString& _left, const char32_t* _right);
UString operator+ (const char32_t* _left, const UString& _right);
UString operator+ (const UString& _left, char32_t _right);
UString operator+ (char32_t _left, const UString& _right);
/**
* @brief Template to declare conversion from anything in etk::UString
* @param[in] _variable Variable to convert
* @return String of the value
*/
template <class TYPE>
etk::UString toUString(const TYPE& _variable);
//! @not_in_doc
etk::Stream& operator <<(etk::Stream& _os, const etk::UString& _obj);
/**
* @brief Template to declare conversion from string to anything
* @param[out] _variableRet Output value
* @param[in] _value input property
* @return true if the can be converted.
*/
template <class TYPE>
bool from_string(TYPE& _variableRet, const etk::UString& _value);
void sort(etk::Vector<etk::UString *>& _list);
void sort(etk::Vector<etk::UString>& _list);
// TODO: DEPRECATED function:
long double string_to_long_double(const etk::UString& _obj);
double string_to_double(const etk::UString& _obj);
float string_to_float(const etk::UString& _obj);
int8_t string_to_int8_t(const etk::UString& _obj);
int16_t string_to_int16_t(const etk::UString& _obj);
int32_t string_to_int32_t(const etk::UString& _obj);
int64_t string_to_int64_t(const etk::UString& _obj);
uint8_t string_to_uint8_t(const etk::UString& _obj);
uint16_t string_to_uint16_t(const etk::UString& _obj);
uint32_t string_to_uint32_t(const etk::UString& _obj);
uint64_t string_to_uint64_t(const etk::UString& _obj);
bool string_to_bool(const etk::UString& _obj);
etk::UString toLower(etk::UString _obj);
etk::UString toUpper(etk::UString _obj);
bool compare_no_case(const etk::UString& _obj, const etk::UString& _val);
bool end_with(const etk::UString& _obj, const etk::UString& _val, bool _caseSensitive = true);
bool start_with(const etk::UString& _obj, const etk::UString& _val, bool _caseSensitive = true);
etk::UString replace(const etk::UString& _obj, char32_t _val, char32_t _replace);
etk::UString extract_line(const etk::UString& _obj, int32_t _pos);
etk::Vector<etk::UString> split(const etk::UString& _obj, char32_t _val);
/**
* @brief Template to declare conversion from etk::Vector<anything> in etk::String
* @param[in] _list Variable to convert
* @return String of the value: {...,...,...}
*/
template <class TYPE>
etk::UString toUString(const etk::Vector<TYPE>& _list) {
etk::UString out = U"{";
for (size_t iii=0; iii<_list.size(); ++iii) {
if (iii!=0) {
out += U";";
}
out+= etk::toUString(_list[iii]);
}
out += U"}";
return out;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,79 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL-2 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <etk/Stream.hpp>
#include <etk/Allocator.hpp>
namespace etk {
namespace algorithm {
namespace detail {
template<class ETK_VECTOR_TYPE>
int64_t quickSortPartition (etk::Vector<ETK_VECTOR_TYPE>& _data,
int64_t _low,
int64_t _high,
bool (*_comparator)(const ETK_VECTOR_TYPE&, const ETK_VECTOR_TYPE&)) {
int64_t iii = (_low - 1);
for (int64_t jjj = _low; jjj < _high; ++jjj) {
if (_comparator(_data[jjj], _data[_high]) == true) {
iii++;
etk::swap(_data[iii], _data[jjj]);
}
}
etk::swap(_data[iii + 1], _data[_high]);
return (iii + 1);
}
template<class ETK_VECTOR_TYPE>
void quickSort(etk::Vector<ETK_VECTOR_TYPE>& _data,
int64_t _low,
int64_t _high,
bool (*_comparator)(const ETK_VECTOR_TYPE&, const ETK_VECTOR_TYPE&)) {
if (_low >= _high) {
return;
}
// pi is partitioning index, arr[p] is now at right place
int64_t pi = detail::quickSortPartition(_data, _low, _high, _comparator);
// Separately sort elements before partition and after partition
//if (pi != 0) {
detail::quickSort(_data, _low, pi - 1, _comparator);
//}
detail::quickSort(_data, pi + 1, _high, _comparator);
}
}
/**
* @brief: QuickSort implementation of sorting vector.
* @param[in,out] _data Vector to sort.
* @param[in] _low Lowest element to sort.
* @param[in] _high Highest element to sort.
* @param[in] _high Comparator function of this element.
*/
template<class ETK_VECTOR_TYPE>
void quickSort(etk::Vector<ETK_VECTOR_TYPE>& _data,
size_t _low,
size_t _high,
bool (*_comparator)(ETK_VECTOR_TYPE const &, ETK_VECTOR_TYPE const &)) {
if (_high >= _data.size()) {
_high = _data.size()-1;
}
/*if (_low >= _data.size()) {
_low = _data.size()-1;
}*/
detail::quickSort(_data, _low, _high, _comparator);
}
/**
* @brief: QuickSort implementation of sorting vector (all elements.
* @param[in,out] _data Vector to sort.
* @param[in] _high Comparator function of this element.
*/
template<class ETK_VECTOR_TYPE>
void quickSort(etk::Vector<ETK_VECTOR_TYPE>& _data,
bool (*_comparator)(ETK_VECTOR_TYPE const &, ETK_VECTOR_TYPE const &)) {
detail::quickSort(_data, 0, _data.size()-1, _comparator);
}
}
}

View File

@ -1,54 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL-2 (see license file)
*/
#pragma once
#include <etk/typeTrait.hpp>
namespace etk {
template<class ETK_MOVE_TYPE>
struct RemoveReference {
// remove reference
typedef ETK_MOVE_TYPE m_type;
};
template<class ETK_MOVE_TYPE>
struct RemoveReference<ETK_MOVE_TYPE&> {
// remove reference
typedef ETK_MOVE_TYPE m_type;
};
template<class ETK_MOVE_TYPE>
struct RemoveReference<ETK_MOVE_TYPE&&> {
// remove rvalue reference
typedef ETK_MOVE_TYPE m_type;
};
template<typename ETK_MOVE_TYPE>
inline typename etk::RemoveReference<ETK_MOVE_TYPE>::m_type&& move(ETK_MOVE_TYPE&& _obj) {
// forward _Arg as movable
return (typename etk::RemoveReference<ETK_MOVE_TYPE>::m_type&&)_obj;
}
template<typename ETK_SWAP_TYPE,
typename etk::EnableIf<etk::Is_swap_MemberFunctionExists<ETK_SWAP_TYPE>::value,int>::type = 0>
inline void swap(ETK_SWAP_TYPE& _obj1, ETK_SWAP_TYPE& _obj2) {
_obj1.swap(_obj2);
}
template<typename ETK_SWAP_TYPE,
typename etk::EnableIf<!etk::Is_swap_MemberFunctionExists<ETK_SWAP_TYPE>::value,int>::type = 0>
inline void swap(ETK_SWAP_TYPE& _obj1, ETK_SWAP_TYPE& _obj2) {
ETK_SWAP_TYPE tmp = etk::move(_obj1);
_obj1 = etk::move(_obj2);
_obj2 = etk::move(tmp);
}
template <class ETK_FORWARD_TYPE>
inline ETK_FORWARD_TYPE&& forward(typename etk::RemoveReference<ETK_FORWARD_TYPE>::m_type& _obj) noexcept {
return static_cast<ETK_FORWARD_TYPE&&>(_obj);
}
template <class ETK_FORWARD_TYPE>
inline ETK_FORWARD_TYPE&& forward(typename etk::RemoveReference<ETK_FORWARD_TYPE>::m_type&& _obj) noexcept {
static_assert(!etk::IsLeftValueReference<ETK_FORWARD_TYPE>::type, "Can not forward a right value as a left value.");
return static_cast<ETK_FORWARD_TYPE&&>(_obj);
}
}

View File

@ -1,3 +0,0 @@
#include <etk/types.hpp>

View File

@ -1,126 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2017, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
extern "C" {
#include <math.h>
}
namespace etk {
inline float cos(float _value) {
return ::cosf(_value);
}
inline float sin(float _value) {
return ::sinf(_value);
}
inline float tan(float _value) {
return ::tanf(_value);
}
inline float acos(float _value) {
return ::acosf(_value);
}
inline float asin(float _value) {
return ::asinf(_value);
}
inline float atan(float _value) {
return ::atanf(_value);
}
inline float atan2(float _value, float _value2) {
return ::atan2f(_value, _value2);
}
inline float sqrt(float _value) {
return ::sqrtf(_value);
}
inline float pow(float _xxx, float _yyy) {
return ::powf(_xxx, _yyy);
}
inline float log(float _value) {
return ::logf(_value);
}
inline float log10(float _value) {
return ::log10f(_value);
}
inline float exp(float _value) {
return ::expf(_value);
}
inline double cos(double _value) {
return ::cos(_value);
}
inline double sin(double _value) {
return ::sin(_value);
}
inline double tan(double _value) {
return ::tan(_value);
}
inline double acos(double _value) {
return ::acos(_value);
}
inline double asin(double _value) {
return ::asin(_value);
}
inline double atan(double _value) {
return ::atan(_value);
}
inline double atan2(double _value, double _value2) {
return ::atan2(_value, _value2);
}
inline double sqrt(double _value) {
return ::sqrt(_value);
}
inline double pow(double _xxx, double _yyy) {
return ::pow(_xxx, _yyy);
}
inline double log(double _value) {
return ::log(_value);
}
inline double log10(double _value) {
return ::log10(_value);
}
inline double exp(double _value) {
return ::exp(_value);
}
template <class TYPE> const TYPE& min(const TYPE& _val1, const TYPE& _val2) {
return (_val1 > _val2) ? _val2 : _val1;
}
template <class TYPE> const TYPE& max(const TYPE& _val1, const TYPE& _val2) {
return (_val1 > _val2) ? _val1 : _val2;
}
template <class TYPE> TYPE abs(const TYPE& _value) {
return (_value >= 0) ? _value : -_value;
}
/**
* @brief in std, we have min, max but not avg ==> it is missing... the Define of avg template.
* @param[in] _min Minimum value of the range
* @param[in] _val The value that we want a min/max
* @param[in] _max Maximum value of the range
* @return Value that min/max applied
*/
template <class TYPE> const TYPE& avg(const TYPE& _min, const TYPE& _val, const TYPE& _max) {
return etk::min(etk::max(_min,_val),_max);
}
template<class ETK_ITERATOR_TYPE>
size_t distance(const ETK_ITERATOR_TYPE& _start, const ETK_ITERATOR_TYPE& _stop) {
size_t out = 0;
ETK_ITERATOR_TYPE tmp = _start;
ETK_ITERATOR_TYPE tmp2 = _stop;
while (tmp != tmp2) {
out++;
++tmp;
}
return out;
}
template<class ETK_ITERATOR_TYPE_1, class ETK_ITERATOR_TYPE_2>
ETK_ITERATOR_TYPE_1 find(ETK_ITERATOR_TYPE_1 _start, ETK_ITERATOR_TYPE_1 _stop, const ETK_ITERATOR_TYPE_2& _value) {
while (_start != _stop) {
if (*_start == _value) {
return _start;
}
++_start;
}
return _stop;
}
}

View File

@ -1,30 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/Exception.hpp>
#include <etk/system.hpp>
#include <stdio.h>
etk::String etk::exec(const etk::String& _cmd) {
FILE* pipe = popen(_cmd.c_str(), "r");
if (!pipe) {
ETK_THROW_EXCEPTION(etk::exception::RuntimeError("popen() failed!"));
return "";
}
etk::String out;
try {
char buffer[128];
while (fgets(buffer, 128, pipe) != NULL) {
out += buffer;
}
} catch (...) {
pclose(pipe);
ETK_THROW_EXCEPTION(etk::exception::RuntimeError("Broken pipe"));
}
pclose(pipe);
return out;
}

View File

@ -1,14 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/types.hpp>
#pragma once
namespace etk {
etk::String exec(const etk::String& _cmd);
}

View File

@ -1,68 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/typeInfo.hpp>
#include <etk/String.hpp>
#include <etk/UString.hpp>
#include <etk/Stream.hpp>
#include <etk/Map.hpp>
static etk::Map<const char*, size_t>& getListElement() {
static etk::Map<const char*, size_t> s_list(0, true, [](etk::Pair<const char*, size_t>* const & _key1,
etk::Pair<const char*, size_t>* const & _key2) {
return strcoll(_key1->first, _key2->first) < 0;
});
return s_list;
}
etk::Vector<const char*> etk::getListDeclaredType() {
return getListElement().getKeys();
}
size_t etk::addType(const char* _name) {
size_t id = getListElement().size()+1;
getListElement().set(_name, id);
return id;
// return size_t(_name);
// return getListType().size();
}
// declare all type of etk-base ...
ETK_DECLARE_TYPE(int8_t);
ETK_DECLARE_TYPE(int16_t);
ETK_DECLARE_TYPE(int32_t);
ETK_DECLARE_TYPE(int64_t);
ETK_DECLARE_TYPE(uint8_t);
ETK_DECLARE_TYPE(uint16_t);
ETK_DECLARE_TYPE(uint32_t);
ETK_DECLARE_TYPE(uint64_t);
ETK_DECLARE_TYPE(char32_t);
ETK_DECLARE_TYPE(bool);
ETK_DECLARE_TYPE(float);
ETK_DECLARE_TYPE(double);
ETK_DECLARE_TYPE(etk::String);
ETK_DECLARE_TYPE(etk::UString);
ETK_DECLARE_TYPE(etk::Stream);
ETK_DECLARE_TYPE(etk::NullPtr);
#include <etk/Exception.hpp>
ETK_DECLARE_TYPE(etk::Exception);
ETK_DECLARE_TYPE(etk::exception::InvalidArgument);
ETK_DECLARE_TYPE(etk::exception::DomainError);
ETK_DECLARE_TYPE(etk::exception::LengthError);
ETK_DECLARE_TYPE(etk::exception::OutOfRange);
ETK_DECLARE_TYPE(etk::exception::RangeError);
ETK_DECLARE_TYPE(etk::exception::OverflowError);
ETK_DECLARE_TYPE(etk::exception::UnderflowError);
ETK_DECLARE_TYPE(etk::exception::CastError);
ETK_DECLARE_TYPE(etk::exception::AllocationError);
ETK_DECLARE_TYPE(etk::exception::RuntimeError);
ETK_DECLARE_TYPE(etk::exception::NullPointerError);

View File

@ -1,44 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/types.hpp>
#include <etk/Vector.hpp>
#pragma once
namespace etk {
template<typename ETK_TYPE>
class TypeTraitInfo {
public:
// Name of the type
static const char* m_name;
// Size of the type
static const size_t m_size;
// Dynamic unique ID of the Type
static const size_t m_id;
};
/**
* @brief Get list of all type declared in this software.
* @return A static list of all register type in the system.
*/
etk::Vector<const char*> getListDeclaredType();
/**
* @brief Add an element declared type in the system database.
* @param[in] Name of the type
* @return The Id of the Object (create a unique ID)
*/
size_t addType(const char* _name);
}
#define ETK_DECLARE_TYPE(...) template<> \
const char* etk::TypeTraitInfo<__VA_ARGS__>::m_name = #__VA_ARGS__; \
template<> const size_t etk::TypeTraitInfo<__VA_ARGS__>::m_size = sizeof(__VA_ARGS__); \
template<> const size_t etk::TypeTraitInfo<__VA_ARGS__>::m_id = etk::addType(#__VA_ARGS__);
#define ETK_GET_TYPE_NAME(...) etk::TypeTraitInfo<__VA_ARGS__>::m_name
#define ETK_GET_TYPE_SIZE(...) etk::TypeTraitInfo<__VA_ARGS__>::m_size
#define ETK_GET_TYPE_ID(...) etk::TypeTraitInfo<__VA_ARGS__>::m_id

View File

@ -1,251 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL-2 (see license file)
*/
#pragma once
namespace etk {
template<class ETK_TYPE, ETK_TYPE val>
struct IntegralConstant {
static constexpr ETK_TYPE value = val;
typedef ETK_TYPE typeValue;
// using injected-class-name
typedef IntegralConstant type;
constexpr operator typeValue() const noexcept {
return value;
}
constexpr typeValue operator()() const noexcept {
return value;
}
};
typedef etk::IntegralConstant<bool, true> typeTrue;
typedef etk::IntegralConstant<bool, false> typeFalse;
template<class ETK_TYPE>
struct IsLeftValueReference:
etk::typeFalse {
};
template<class ETK_TYPE>
struct IsLeftValueReference<ETK_TYPE&>:
etk::typeTrue {
};
template<bool B, class ETK_TYPE = void>
struct EnableIf {
};
template<class ETK_TYPE>
struct EnableIf<true, ETK_TYPE> {
typedef ETK_TYPE type;
};
template<class ETK_TYPE, class ETK_TYPE_2>
struct IsSame :
etk::typeFalse {
};
template<class ETK_TYPE>
struct IsSame<ETK_TYPE, ETK_TYPE> :
etk::typeTrue {
};
template<class ETK_TYPE>
struct RemoveConst {
typedef ETK_TYPE type;
};
template<class ETK_TYPE>
struct RemoveConst<const ETK_TYPE> {
typedef ETK_TYPE type;
};
template<class ETK_TYPE>
struct RemoveVolatile {
typedef ETK_TYPE type;
};
template<class ETK_TYPE>
struct RemoveVolatile<volatile ETK_TYPE> {
typedef ETK_TYPE type;
};
template<class ETK_TYPE>
struct RemoveConstVolatile {
typedef typename etk::RemoveVolatile<typename etk::RemoveConst<ETK_TYPE>::type>::type type;
};
template<class ETK_TYPE>
struct IsVoid :
etk::IsSame<void, typename etk::RemoveConstVolatile<ETK_TYPE>::type> {
};
template<typename ETK_TYPE>
struct IsEnum:
public etk::IntegralConstant<bool, __is_enum(ETK_TYPE)> {
};
template<typename ETK_TYPE>
struct IsUnion:
public etk::IntegralConstant<bool, __is_union(ETK_TYPE)> {
};
template<typename ETK_TYPE>
struct IsClass:
public etk::IntegralConstant<bool, __is_class(ETK_TYPE)> {
};
template<typename ETK_TYPE, typename ETK_TYPE_DERIVED>
struct IsBaseOf:
public etk::IntegralConstant<bool, __is_base_of(ETK_TYPE, ETK_TYPE_DERIVED)> {
};
template<typename>
struct IsFunction;
template<typename>
struct IsFunction :
public etk::typeFalse {
};
template<typename ETK_TYPE_RETURN, typename... ETK_TYPE_ARGS>
struct IsFunction<ETK_TYPE_RETURN(ETK_TYPE_ARGS...)>:
public etk::typeTrue {
};
template<typename ETK_TYPE_RETURN, typename... ETK_TYPE_ARGS>
struct IsFunction<ETK_TYPE_RETURN(ETK_TYPE_ARGS...)&>:
public etk::typeTrue {
};
template<typename ETK_TYPE_RETURN, typename... ETK_TYPE_ARGS>
struct IsFunction<ETK_TYPE_RETURN(ETK_TYPE_ARGS...)&&>:
public etk::typeTrue {
};
template<typename ETK_TYPE_RETURN, typename... ETK_TYPE_ARGS>
struct IsFunction<ETK_TYPE_RETURN(ETK_TYPE_ARGS...) const>:
public etk::typeTrue {
};
template<typename ETK_TYPE_RETURN, typename... ETK_TYPE_ARGS>
struct IsFunction<ETK_TYPE_RETURN(ETK_TYPE_ARGS...) const &>:
public etk::typeTrue {
};
template<typename ETK_TYPE_RETURN, typename... ETK_TYPE_ARGS>
struct IsFunction<ETK_TYPE_RETURN(ETK_TYPE_ARGS...) const &&>:
public etk::typeTrue {
};
#define DEFINE_METHOD_CHECKER(RETURN_TYPE, METHOD_NAME, PARAMETERS) \
template<typename ETK_TYPE> \
struct Is_ ## METHOD_NAME ## _MemberFunctionExists { \
private: \
typedef char True; \
typedef char (&False)[2]; \
template<typename U, RETURN_TYPE (U::*)PARAMETERS = &U::METHOD_NAME> \
struct Checker { \
typedef True Type; \
}; \
template<typename U> \
static typename Checker<U>::Type Tester(const U*); \
static False Tester(...); \
public: \
enum { value = (sizeof(Tester(static_cast<const ETK_TYPE*>(0))) == sizeof(True)) }; \
} \
// Use example:
// Is_swap_MemberFunctionExists<T>::value
DEFINE_METHOD_CHECKER(void, swap, (ETK_TYPE&));
class String;
DEFINE_METHOD_CHECKER(etk::String, toString, ());
/*
#if 0
template<typename T>
struct hasEtkStreamExporter {
typedef char yes[1];
typedef char no[2];
template<typename U> static yes& test( U& );
template<typename U> static no& test(...);
static etk::Stream &s;
static T const &t;
static bool const value = sizeof( test( s << t ) ) == sizeof( yes ); // line 48
};
#else
namespace hasEtkStreamExporterImpl {
typedef char no;
typedef char yes[2];
struct AnyType {
template<typename ETK_TYPE> AnyType(const ETK_TYPE&);
};
no operator<<( etk::Stream&, const AnyType& );
yes& test( etk::Stream& );
no test( no );
template<typename ETK_TYPE>
struct hasEtkStreamExporter {
static etk::Stream& sss;
static const ETK_TYPE& ttt;
static bool const value = sizeof( test(sss << ttt) ) == sizeof( yes );
};
}
template<typename ETK_TYPE>
struct hasEtkStreamExporter:
etk::hasEtkStreamExporterImpl::hasEtkStreamExporter<ETK_TYPE> {
};
#endif
#if 1
template <typename T>
class hasMemberToString {
typedef char one;
typedef long two;
template <typename C> static one test( decltype(T::toString()) );
template <typename C> static two test(...);
public:
enum { value = sizeof(test<T>(0)) == sizeof(char) };
};
#else
namespace hasMemberToStringImpl {
typedef char no;
typedef char yes[2];
struct AnyType {
template<typename ETK_TYPE> AnyType(const ETK_TYPE&);
};
no operator<<( etk::Stream&, const AnyType& );
yes& test( etk::Stream& );
no test( no );
template<typename ETK_TYPE>
struct hasMemberToString {
static etk::Stream& sss;
static const ETK_TYPE& ttt;
static bool const value = sizeof( test(sss << ttt) ) == sizeof( yes );
};
}
template<typename ETK_TYPE>
struct hasMemberToString:
etk::hasMemberToStringImpl::hasMemberToString<ETK_TYPE> {
};
#endif
*/
}

View File

@ -1,139 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
extern "C" {
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <assert.h>
// defien type : uintXX_t and intXX_t
#define __STDC_LIMIT_MACROS
// note in android include the macro of min max are overwitten
#include <stdint.h>
#include <stddef.h>
}
#if !defined(__TARGET_OS__MacOs)
#ifndef size_t
using size_t=uint64_t;
#endif
#endif
#define ETK_CONSTRUCTOR_COPY_DEFAULT(ETK_TYPE_CLASS) \
ETK_TYPE_CLASS(const ETK_TYPE_CLASS& ) = default; \
ETK_TYPE_CLASS& operator= (const ETK_TYPE_CLASS& ) = default
#define ETK_CONSTRUCTOR_COPY_DELETE(ETK_TYPE_CLASS) \
ETK_TYPE_CLASS(const ETK_TYPE_CLASS& ) = delete; \
ETK_TYPE_CLASS& operator= (const ETK_TYPE_CLASS& ) = delete
#define ETK_CONSTRUCTOR_MOVE_DEFAULT(ETK_TYPE_CLASS) \
ETK_TYPE_CLASS(ETK_TYPE_CLASS&& ) = default; \
ETK_TYPE_CLASS& operator= (ETK_TYPE_CLASS&& ) = default
#define ETK_CONSTRUCTOR_MOVE_DELETE(ETK_TYPE_CLASS) \
ETK_TYPE_CLASS(ETK_TYPE_CLASS&& ) = delete; \
ETK_TYPE_CLASS& operator= (ETK_TYPE_CLASS&& ) = delete
// DEfine 2 basic type that depend on the machine word size. uint_t is better than size_t because whe have the usigned dual.
using int_t = int;
using uint_t = unsigned int;
#ifndef INT8_MIN
#define INT8_MIN (-128)
#endif
#ifndef INT8_MAX
#define INT8_MAX (127)
#endif
#ifndef UINT8_MAX
#define UINT8_MAX (255U)
#endif
#ifndef INT16_MIN
#define INT16_MIN (-32768)
#endif
#ifndef INT16_MAX
#define INT16_MAX (32767)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX (65535U)
#endif
#ifndef INT32_MIN
#define INT32_MIN (-2147483647-1)
#endif
#ifndef INT32_MAX
#define INT32_MAX (2147483647)
#endif
#ifndef UINT32_MAX
#define UINT32_MAX (4294967295U)
#endif
#ifndef INT64_MIN
#define INT64_MIN (__INT64_C(-9223372036854775807)-1)
#endif
#ifndef INT64_MAX
#define INT64_MAX (__INT64_C(9223372036854775807))
#endif
#ifndef UINT64_MAX
#define UINT64_MAX (__UINT64_C(18446744073709551615))
#endif
#ifndef FLT_EPSILON
#define FLT_EPSILON (1.192092896e-07f)
#endif
#ifndef FLT_MAX
#define FLT_MAX (3.402823466e+38f)
#endif
#ifndef FLT_MIN
#define FLT_MIN (1.175494351e-38f)
#endif
#ifndef DBL_EPSILON
#define DBL_EPSILON (2.2204460492503131e-016)
#endif
#ifndef DBL_MAX
#define DBL_MAX (1.7976931348623158e+308)
#endif
#ifndef DBL_MIN
#define DBL_MIN (2.2250738585072014e-308)
#endif
#ifndef ETK_BUILD_LINEARMATH
//! @brief If not using linear math from bullet lib, we need to define the basic element of a btScalar (float)
using btScalar = float;
#endif
#ifndef _WIN32
extern "C" {
#include <math.h>
}
#ifndef _MATH_H_MATHDEF
//! @brief Generate a basic type for floating point unit selection (not finished)
using float_t = float;
#endif
#endif
#ifdef _WIN32
//#define ETK_EXPORT_API extern "C" __declspec( dllimport )
#define ETK_EXPORT_API
#else
#define ETK_EXPORT_API extern "C" __attribute__ ((visibility ("default")))
#endif
#ifdef _WIN32
#define ETK_EXPORT_VISIBILITY
#else
#define ETK_EXPORT_VISIBILITY __attribute__ ((visibility ("default")))
#endif
#if (defined(__TARGET_OS__Windows))
#define M_PI 3.14159265358979323846
#endif
#include <etk/NullPtr.hpp>
#include <etk/stdTools.hpp>
#include <etk/move.hpp>
//#include <etk/Stream.hpp>

View File

@ -1,356 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/utf8.hpp>
//#include <etk/debug.hpp>
#include <etk/String.hpp>
#include <etk/UString.hpp>
const char32_t u32char::Null('\0');
const char32_t u32char::Return('\n');
const char32_t u32char::CarrierReturn('\r');
const char32_t u32char::Tabulation('\t');
const char32_t u32char::Suppress((const char)127);
const char32_t u32char::Delete((const char)8);
const char32_t u32char::Space(' ');
const char32_t u32char::Escape((const char)27);
bool u32char::isWhiteChar(char32_t _val) {
if( _val == ' '
|| _val == '\t'
|| _val == '\n'
|| _val == '\r') {
return true;
}
return false;
}
bool u32char::isSpecialChar(char32_t _val) {
if( _val < '0'
|| (_val > '9' && _val < 'A')
|| (_val > 'Z' && _val < 'a')
|| (_val > 'z' && _val < 0xFF) ) {
return true;
}
return false;
}
bool u32char::isInteger(char32_t _val) {
if( _val >= (uint32_t)'0'
&& _val <= (uint32_t)'9') {
return true;
}
return false;
}
int32_t u32char::toInt(char32_t _val) {
return _val - (uint32_t)'0';
}
char32_t u32char::changeOrder(char32_t _val) {
if (_val >= 'A' && _val <= 'Z') {
return (_val - (uint32_t)'A')*2 + 'A';
}
if (_val >= 'a' && _val <= 'z') {
return (_val - (uint32_t)'a')*2 + 'A' + 1;
}
if (_val >= ':' && _val <= '@') {
return _val + 52;
}
if (_val >= '[' && _val <= '`') {
return _val +26;
}
return _val;
}
int8_t u32char::convertUtf8(char32_t _val, char _output[7]) {
if (_val <= 127) {
// input ==> -------- -------- -------- -1111111
// output ==> 00000000 00000000 00000000 00000000 00000000 0xxxxxxx
_output[0] = (char)_val;
_output[1] = 0;
return 1;
} else if (_val <= 0x000007FF) {
// input ==> -------- -------- -----222 22111111
// output ==> 00000000 00000000 00000000 00000000 110xxxxx 10xxxxxx
_output[0] = 0xC0 | ( (_val & 0x000007C0) >> 6 );
_output[1] = 0x80 | ( (_val & 0x0000003F) );
_output[2] = 0;
return 2;
} else if (_val <= 0x0000FFFF) {
// input ==> -------- -------- 33332222 22111111
// output ==> 00000000 00000000 00000000 1110xxxx 10xxxxxx 10xxxxxx
_output[0] = 0xE0 | ( (_val & 0x0000F000) >> 12 );
_output[1] = 0x80 | ( (_val & 0x00000FC0) >> 6 );
_output[2] = 0x80 | ( (_val & 0x0000003F) );
_output[3] = 0;
return 3;
} else if (_val <= 0x001FFFFF) {
// input ==> -------- ---44433 33332222 22111111
// output ==> 00000000 00000000 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
_output[0] = 0xF0 | ( (_val & 0x001C0000) >> 18 );
_output[1] = 0x80 | ( (_val & 0x0003F000) >> 12 );
_output[2] = 0x80 | ( (_val & 0x00000FC0) >> 6 );
_output[3] = 0x80 | ( (_val & 0x0000003F) );
_output[4] = 0;
return 4;
// the next element is my personal interpretation...
} else if (_val <= 0x03FFFFFF) {
// input ==> ------55 44444433 33332222 22111111
// output ==> 00000000 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
_output[0] = 0xF8 | ( (_val & 0x03000000) >> 24 );
_output[1] = 0x80 | ( (_val & 0x00FC0000) >> 18 );
_output[2] = 0x80 | ( (_val & 0x0003F000) >> 12 );
_output[3] = 0x80 | ( (_val & 0x00000FC0) >> 6 );
_output[4] = 0x80 | ( (_val & 0x0000003F) );
_output[5] = 0;
return 5;
} else {
// input ==> 66555555 44444433 33332222 22111111
// output ==> 111111xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
_output[0] = 0xFC | ( (_val & 0xC0000000) >> 30 );
_output[1] = 0x80 | ( (_val & 0x3F000000) >> 24 );
_output[2] = 0x80 | ( (_val & 0x00FC0000) >> 18 );
_output[3] = 0x80 | ( (_val & 0x0003F000) >> 12 );
_output[4] = 0x80 | ( (_val & 0x00000FC0) >> 6 );
_output[5] = 0x80 | ( (_val & 0x0000003F) );
_output[6] = 0;
return 6;
}
}
etk::String u32char::convertToUtf8(const etk::UString& _input) {
return etk::toString(_input);
}
etk::String u32char::convertToUtf8(char32_t _input) {
return etk::toString(etk::UString(_input));
}
size_t u32char::strlen(const char32_t* _input) {
uint32_t out = 0;
while (*_input != 0) {
out++;
_input++;
}
return out;
}
class DoubleChar {
public:
char32_t lower;
char32_t upper;
};
DoubleChar conversionTable[] = {
{U'ç', U'Ç'},
{U'á', U'Á'}, {U'à', U'À'}, {U'ä', U'Ä'}, {U'â', U'Â'}, {U'å', U'Å'}, {U'ã', U'Ã'},
{U'é', U'É'}, {U'è', U'È'}, {U'ë', U'Ë'}, {U'ê', U'Ê'},
{U'ú', U'Ú'}, {U'ù', U'Ù'}, {U'ü', U'Ü'}, {U'û', U'Û'},
{U'í', U'Í'}, {U'ì', U'Ì'}, {U'ï', U'Ï'}, {U'î', U'Î'},
{U'ó', U'Ó'}, {U'ò', U'Ò'}, {U'ö', U'Ö'}, {U'ô', U'Ô'}, {U'õ', U'Õ'},
{U'ý', U'Ý'}, {U'', U''}, {U'ÿ', U'Ÿ'}, {U'ŷ', U'Ŷ'},
{U'ñ', U'Ñ'}, {U'ǹ', U'Ǹ'},
{U'', U''}, {U'ĥ', U'Ĥ'},
{U'', U''}, {U'ŵ', U'Ŵ'}, {U'', U''},
{U'', U''},
{U'æ', U'Æ'},
{U'ð', U'Ð'},
{U'ø', U'Ø'}
};
size_t conversionTableSize = sizeof(conversionTable)/sizeof(DoubleChar);
char32_t u32char::toUpper(char32_t _input) {
if (_input >= 'a' && _input <= 'z') {
return _input + ((int)'A'-(int)'a');
}
for (size_t iii = 0; iii < conversionTableSize; ++iii) {
if (conversionTable[iii].lower == _input) {
return conversionTable[iii].upper;
}
}
return _input;
}
char32_t u32char::toLower(char32_t _input) {
if (_input >= 'A' && _input <= 'Z') {
return _input + ((int)'a'-(int)'A');
}
for (size_t iii = 0; iii < conversionTableSize; ++iii) {
if (conversionTable[iii].upper == _input) {
return conversionTable[iii].lower;
}
}
return _input;
}
static uint8_t sizeElement(const char* _data, int32_t _lenMax) {
uint8_t size = 1;
//TK_ASSERT(0 <= _lenMax, "size can not be < 0 ...");
if (0 > _lenMax) {
return 0;
}
//4 case
if( _lenMax >= 1
&& (_data[0] & 0x80) == 0x00 ) {
// One Char Element
size = 1;
} else if( _lenMax >= 2
&& (_data[0] & 0xE0) == 0xC0
&& (_data[1] & 0xC0) == 0x80) {
size = 2;
} else if( _lenMax >= 3
&& (_data[0] & 0xF0) == 0xE0
&& (_data[1] & 0xC0) == 0x80
&& (_data[2] & 0xC0) == 0x80) {
size = 3;
} else if( _lenMax >= 4
&& (_data[0] & 0xF8) == 0xF0
&& (_data[1] & 0xC0) == 0x80
&& (_data[2] & 0xC0) == 0x80
&& (_data[3] & 0xC0) == 0x80) {
size = 4;
} else if( _lenMax >= 5
&& (_data[0] & 0xFC) == 0xF8
&& (_data[1] & 0xC0) == 0x80
&& (_data[2] & 0xC0) == 0x80
&& (_data[3] & 0xC0) == 0x80
&& (_data[4] & 0xC0) == 0x80) {
size = 5;
} else if( _lenMax >= 6
&& (_data[0] & 0xFC) == 0xFC
&& (_data[1] & 0xC0) == 0x80
&& (_data[2] & 0xC0) == 0x80
&& (_data[3] & 0xC0) == 0x80
&& (_data[4] & 0xC0) == 0x80
&& (_data[5] & 0xC0) == 0x80) {
size = 6;
}
return size;
}
char32_t utf8::convertChar32(const char* _input) {
char32_t value = 0;
if (null == _input) {
return value;
}
int32_t len = strlen(_input);
len = sizeElement(_input, len);
switch (len) {
case 1:
// input ==> 00000000 00000000 00000000 00000000 00000000 0xxxxxxx
// output ==> -------- -------- -------- -1111111
value = (uint8_t)(_input[0]) & 0x7F;
return value;
case 2:
// input ==> 00000000 00000000 00000000 00000000 110xxxxx 10xxxxxx
// output ==> -------- -------- -----222 22111111
value = (((uint8_t)_input[0]) & 0x1F)<< 6;
value += (((uint8_t)_input[1]) & 0x3F);
return value;
case 3:
// input ==> 00000000 00000000 00000000 1110xxxx 10xxxxxx 10xxxxxx
// output ==> -------- -------- 33332222 22111111
value = (((uint8_t)_input[0]) & 0x0F)<< 12;
value += (((uint8_t)_input[1]) & 0x3F)<< 6;
value += (((uint8_t)_input[2]) & 0x3F);
return value;
case 4:
// input ==> 00000000 00000000 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
// output ==> -------- ---44433 33332222 22111111
value = (((uint8_t)_input[0]) & 0x07)<< 18;
value += (((uint8_t)_input[1]) & 0x3F)<< 12;
value += (((uint8_t)_input[2]) & 0x3F)<< 6;
value += (((uint8_t)_input[3]) & 0x3F);
return value;
case 5:
// input ==> 00000000 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
// output ==> ------55 44444433 33332222 22111111
value = (((uint8_t)_input[0]) & 0x03)<< 24;
value += (((uint8_t)_input[1]) & 0x3F)<< 18;
value += (((uint8_t)_input[2]) & 0x3F)<< 12;
value += (((uint8_t)_input[3]) & 0x3F)<< 6;
value += (((uint8_t)_input[4]) & 0x3F);
return value;
case 6:
// input ==> 111111xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
// output ==> 66555555 44444433 33332222 22111111
value = (((uint8_t)_input[0]) & 0x03)<< 30;
value += (((uint8_t)_input[1]) & 0x3F)<< 24;
value += (((uint8_t)_input[2]) & 0x3F)<< 18;
value += (((uint8_t)_input[3]) & 0x3F)<< 12;
value += (((uint8_t)_input[4]) & 0x3F)<< 6;
value += (((uint8_t)_input[5]) & 0x3F);
return value;
}
// An error occurred...
value = _input[0];
return value;
}
int8_t utf8::length(const char _input) {
if((_input&0x80) == 0x00 ) {
return 1;
}
if((_input&0xE0) == 0xC0) {
return 2;
}
if((_input&0xF0) == 0xE0) {
return 3;
}
if((_input&0xF8) == 0xF0) {
return 4;
}
if((_input&0xFC) == 0xF8) {
return 5;
}
if((_input&0xFC) == 0xFC) {
return 5;
}
return 1;
}
bool utf8::first(const char _input) {
// When started with the bit 0 then the size is single element.
if((_input&0x80) == 0x00 ) {
return true;
}
// for multiple element size, we just need to check the second element (might be != 1)
if((_input&0x40) == 0x40 ) {
return true;
}
return false;
}
etk::UString utf8::convertUnicode(const char* _input) {
if (_input == null) {
return U"";
}
etk::UString out;
char tmpData[20];
int64_t pos = 0;
int64_t inputLen = strlen(_input);
while (pos < inputLen) {
int32_t lenMax = inputLen - pos;
uint8_t tmpPos = sizeElement(&_input[pos], lenMax);
out += utf8::convertChar32(&_input[pos]);
pos += tmpPos;
}
return out;
}
etk::UString utf8::convertUnicode(const etk::String& _input) {
return utf8::convertUnicode(_input.c_str());
}

View File

@ -1,444 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <etk/String.hpp>
#include <etk/Vector.hpp>
#include <etk/stdTools.hpp>
namespace etk {
class UString;
}
/**
* @brief Unicode simple wrapper interface
*/
namespace u32char {
extern const char32_t Null; //!< Value '\\0'
extern const char32_t Return; //!< Value '\\n'
extern const char32_t CarrierReturn; //!< Value '\\r' CR
extern const char32_t Tabulation; //!< Value '\\t' TAB
extern const char32_t Suppress; //!< Value BS (SUPPRESS)
extern const char32_t Delete; //!< Value DEL
extern const char32_t Space; //!< Value ' ' SPACE
extern const char32_t Escape; //!< Value ESC Escape
/**
* @brief check if the current element is white or not : '\\t' '\\n' '\\r' ' '
* @param[in] _val Value to interpret
* @return true if it is white char
* @return false otherwise
*/
bool isWhiteChar(char32_t _val);
/**
* @brief check if the current element is NOT [a-zA-Z0-9]
* @param[in] _val Value to interpret
* @return true Not in the previous list
* @return false otherwise
*/
bool isSpecialChar(char32_t _val);
/**
* @brief check if the current element is number or not [0-9]
* @param[in] _val Value to interpret
* @return true if it is a number char
* @return false otherwise
*/
bool isInteger(char32_t _val);
/**
* @brief Convert char32_t in an integer
* @param[in] _val Value to interpret
* @return The parsed Value or ...
*/
int32_t toInt(char32_t _val);
/**
* @brief Change order of the value to have an order of display with A->Z and after a->z and after 0->9 and after all the rest ....
* @param[in] _val Value in unicode
* @return A value usable in integer only ... to check order...
*/
char32_t changeOrder(char32_t _val);
/**
* @brief Convert unicode in UTF8 value
* @param[in] _val Value to convert
* @param[out] _output Char data converted
* @return Number of char in utf8
*/
int8_t convertUtf8(char32_t _val, char _output[7]);
etk::String convertToUtf8(const etk::UString& _input);
etk::String convertToUtf8(char32_t _input);
char32_t toUpper(char32_t _input);
char32_t toLower(char32_t _input);
size_t strlen(const char32_t* _input);
};
/**
* @brief UTF-8 simple wrapper interface
*/
namespace utf8 {
/**
* @brief Get the size of an utf8 char with his first char.
* @param[in] _input Char to parse
* @return number of char needed
*/
int8_t length(const char _input);
/**
* @brief When parsing a string in a reverse mode, we need to know if we get the first char
* @param[in] _input Char to parse.
* @return true if it was the first char.
*/
bool first(const char _input);
/**
* @brief Convert a char* in a unicode value
* @param[in] _input pointer on a string C (utf-8) to convert
* @return Converted Value
*/
char32_t convertChar32(const char* _input);
etk::UString convertUnicode(const char* _input);
etk::UString convertUnicode(const etk::String& _input);
/**
* @brief Iterator on a simple etk::String that contain utf8 value
*/
class Iterator {
private:
char32_t m_value; //!< store value to prevent multiple calculation of getting the data
etk::String* m_data; //!< Pointer on the current Buffer
int64_t m_current; //!< current Id in the Buffer
public:
/**
* @brief Basic constructor that is not link on a string
*/
Iterator():
m_value(u32char::Null),
m_data(null),
m_current(0) {
// nothing to do ...
};
/**
* @brief Basic begin constructor link at the start of the string
* @param[in] _str reference on the string to inspect.
*/
Iterator(etk::String& _str) :
m_value(u32char::Null),
m_data(&_str),
m_current(0) {
// nothing to do ...
};
/**
* @brief Basic position constructor link at the _pos position of the string
* @param[in] _str reference on the string to inspect.
* @param[in] _pos Iterator position on the string.
*/
Iterator(etk::String& _str, const etk::String::Iterator& _pos) :
m_value(u32char::Null),
m_data(&_str),
m_current(0) {
if (m_data != null) {
m_current = etk::distance(m_data->begin(), _pos);
}
};
/**
* @brief Basic position constructor link at the _pos position of the string
* @param[in] _str reference on the string to inspect.
* @param[in] _pos Position on the string (in AINSI value).
*/
Iterator(etk::String& _str, size_t _pos) :
m_value(u32char::Null),
m_data(&_str),
m_current(0) {
if (m_data != null) {
if (_pos > m_data->size()) {
m_current = m_data->size();
} else {
m_current = _pos;
}
}
};
/**
* @brief Basic position constructor link at the _pos position of the string
* @param[in] _str Pointer on the string to inspect.
* @param[in] _pos Iterator position on the string.
*/
Iterator(etk::String* _str, const etk::String::Iterator& _pos) :
m_value(u32char::Null),
m_data(_str),
m_current(0) {
if (m_data != null) {
m_current = etk::distance(m_data->begin(), _pos);
}
};
/**
* @brief Basic position constructor link at the _pos position of the string
* @param[in] _str Pointer on the string to inspect.
* @param[in] _pos Position on the string (in AINSI value).
*/
Iterator(etk::String* _str, size_t _pos) :
m_value(u32char::Null),
m_data(_str),
m_current(0) {
if (m_data != null) {
if (_pos > m_data->size()) {
m_current = m_data->size();
} else {
m_current = _pos;
}
}
};
/**
* @brief Recopy constructor.
* @param[in] _obj The Iterator that might be copy
*/
Iterator(const Iterator& _obj):
m_value(u32char::Null),
m_data(_obj.m_data),
m_current(_obj.m_current) {
// nothing to do ...
};
/**
* @brief Assignation operator.
* @param[in] _obj The Iterator that might be copy
* @return reference on the current Iterator
*/
Iterator& operator=(const Iterator & _obj) {
m_current = _obj.m_current;
m_data = _obj.m_data;
m_value = u32char::Null;
return *this;
};
/**
* @brief Basic destructor
*/
virtual ~Iterator() {
m_current = 0;
m_data = null;
m_value = u32char::Null;
};
/**
* @brief basic boolean cast
* @return true if the element is present in buffer
*/
operator size_t () const {
if (m_data == null) {
return 0;
}
if (m_current < 0) {
return 0;
}
if (m_current > (int64_t)m_data->size()) {
return m_data->size();
}
return (size_t)m_current;
};
/**
* @brief Incremental operator
* @return Reference on the current Iterator increment
*/
Iterator& operator++ ();
/**
* @brief Decremental operator
* @return Reference on the current Iterator decrement
*/
Iterator& operator-- ();
/**
* @brief Incremental operator
* @return Reference on a new Iterator and increment the other one
*/
Iterator operator++ (int32_t) {
Iterator it(*this);
++(*this);
return it;
};
/**
* @brief Decremental operator
* @return Reference on a new Iterator and decrement the other one
*/
Iterator operator-- (int32_t) {
Iterator it(*this);
--(*this);
return it;
};
/**
* @brief equality Iterator
* @param[in] _obj Iterator to compare
* @return true if the Iterator is identical pos
*/
bool operator== (const Iterator& _obj) const {
if ( m_current == _obj.m_current
&& m_data == _obj.m_data) {
return true;
}
return false;
};
/**
* @brief equality Iterator
* @param[in] _obj Iterator to compare
* @return true if the Iterator is identical pos
*/
bool operator!= (const Iterator& _obj) const {
if ( m_current != _obj.m_current
|| m_data != _obj.m_data) {
return true;
}
return false;
};
/**
* @brief <= Iterator
* @param[in] _obj Iterator to compare
* @return true if the Iterator is identical pos
*/
bool operator<= (const Iterator& _obj) const {
if (m_data != _obj.m_data) {
return false;
}
if (m_current <= _obj.m_current) {
return true;
}
return false;
};
/**
* @brief >= Iterator
* @param[in] _obj Iterator to compare
* @return true if the Iterator is identical pos
*/
bool operator>= (const Iterator& _obj) const {
if (m_data != _obj.m_data) {
return false;
}
if (m_current >= _obj.m_current) {
return true;
}
return false;
};
/**
* @brief < Iterator
* @param[in] _obj Iterator to compare
* @return true if the Iterator is identical pos
*/
bool operator< (const Iterator& _obj) const {
if (m_data != _obj.m_data) {
return false;
}
if (m_current < _obj.m_current) {
return true;
}
return false;
};
/**
* @brief > Iterator
* @param[in] _obj Iterator to compare
* @return true if the Iterator is identical pos
*/
bool operator> (const Iterator& _obj) const {
if (m_data != _obj.m_data) {
return false;
}
if (m_current > _obj.m_current) {
return true;
}
return false;
};
/**
* @brief Get the value on the current element
* @return The request element value
*/
char32_t operator* ();
/**
* @brief Get the position in the buffer
* @return The requested position.
*/
size_t getPos() const {
if (m_data == null) {
return 0;
}
if (m_current < 0) {
return 0;
}
if (m_current >= (int64_t)m_data->size()) {
return m_data->size()-1;
}
return (size_t)m_current;
};
/**
* @brief move the element position
* @param[in] _val Value to add on the Iterator
* @return a new Iterator.
*/
Iterator operator+ (const int64_t _val) const {
Iterator tmp(*this);
for (int64_t iii=0; iii<_val; ++iii) {
++tmp;
}
return tmp;
};
/**
* @copydoc utf8::Iterator::operator+ (const int64_t)
*/
Iterator operator+ (const int32_t _val) const {
Iterator tmp(*this);
for (int64_t iii=0; iii<_val; ++iii) {
++tmp;
}
return tmp;
}
/**
* @copydoc utf8::Iterator::operator+ (const int64_t)
*/
Iterator operator+ (const size_t _val) const {
Iterator tmp(*this);
for (int64_t iii=0; iii<(int64_t)_val; ++iii) {
++tmp;
}
return tmp;
}
/**
* @brief move the element position
* @param[in] _val Value to remove on the Iterator
* @return a new Iterator.
*/
Iterator operator- (const int64_t _val) const {
Iterator tmp(*this);
for (int64_t iii=0; iii<_val; ++iii) {
--tmp;
}
return tmp;
}
/**
* @copydoc utf8::Iterator::operator- (const int64_t)
*/
Iterator operator- (const int32_t _val) const {
Iterator tmp(*this);
for (int64_t iii=0; iii<_val; ++iii) {
--tmp;
}
return tmp;
}
/**
* @copydoc utf8::Iterator::operator- (const int64_t)
*/
Iterator operator- (const size_t _val) const {
Iterator tmp(*this);
for (int64_t iii=0; iii<(int64_t)_val; ++iii) {
--tmp;
}
return tmp;
}
/*
Iterator begin() const {
return Iterator(m_data);
}
Iterator end() const {
return --Iterator(m_data, m_data.end());
}
*/
};
}
/**
* @brief Calculate the size of a string (unicode)
* @param[in] _data Data to parse to find the end of string
* @return The Number of char32_t before the '\\0' value
*/
int32_t strlen(const char32_t* _data);

Some files were not shown because too many files have changed in this diff Show More