Compare commits
108 Commits
0.9.5
...
types2rele
| Author | SHA1 | Date | |
|---|---|---|---|
|
6274605961
|
|||
|
1fa9305867
|
|||
|
d9ffe9b00a
|
|||
|
51a61925d3
|
|||
|
bfb41cf50b
|
|||
|
ca37997809
|
|||
|
da8c33b14c
|
|||
|
0de5623182
|
|||
|
6def06c647
|
|||
|
d6ca791fbc
|
|||
|
3001707c69
|
|||
|
5814bfca0d
|
|||
| 369cefacdf | |||
| 43fbf3b56c | |||
| d023abce74 | |||
| 3095d2d31f | |||
| 08da4a56b8 | |||
| cd4d8e025d | |||
| a03e3f5d21 | |||
| c31c7dfb63 | |||
| 0c058d4313 | |||
| d8692f6ed5 | |||
| b047a10e8d | |||
| a983698e3d | |||
| 6a8cb019f5 | |||
| b0afdf7f0f | |||
| b956f1c401 | |||
| 5e47313af8 | |||
| 44407c2a4b | |||
| ae6a5c52a1 | |||
| 9f416d31de | |||
| b9b9a881e0 | |||
| 995cccdace | |||
| 849b3e9ecc | |||
| acb42f453c | |||
| c2283f70d4 | |||
| 3926793a17 | |||
| 5bd8eef3f2 | |||
| 16bce07c75 | |||
| 87ee461dd1 | |||
| 526d57b72e | |||
| eda276356f | |||
| e442ee4720 | |||
| 615bad7372 | |||
| 9c4fe51790 | |||
| d76bb9349b | |||
| 4a64336864 | |||
| abb60def6e | |||
| 9022d4a5fc | |||
| e6fd9aad37 | |||
| 3b858650f2 | |||
| 052f803eac | |||
| 0bcaca4770 | |||
| 0ac8e05c04 | |||
| 6f6df9524c | |||
| cd1c24d0a5 | |||
| d1a15ad153 | |||
| 29c7163d9b | |||
| b289aa7f0a | |||
| 9e82aa9bcf | |||
| 632c81812f | |||
| 1e85922d4e | |||
| bf62d44346 | |||
| a6b767a223 | |||
| c825c85878 | |||
| 54387e43bb | |||
| eace4d41cc | |||
| 363605bde5 | |||
| 18696d412b | |||
| 2190fae789 | |||
| 0e99ded5b8 | |||
| a1ea2e3ccd | |||
| 0dc807dbff | |||
| c3deb960c5 | |||
| 7b6f7ad328 | |||
| 76490d4c19 | |||
| 6b42cdf76e | |||
| b519c79a3e | |||
| 6f1e2eb518 | |||
| ad50c01b15 | |||
| 0a7bd3159a | |||
| 6bd8889456 | |||
| 03fe124ad9 | |||
| 6f9f274e08 | |||
| 2fca5f3492 | |||
| ad2fb11a5c | |||
| 00f8af232b | |||
| 429021f687 | |||
| 71c5bd11d5 | |||
| b5faf171e3 | |||
| fd75a1f119 | |||
| d9a8426ebc | |||
| 759be64379 | |||
| ef16ae4ebd | |||
| 417e52a5a1 | |||
| 5de31cfe41 | |||
| 9215130b9d | |||
| 23ce3e83df | |||
| ac37982ee7 | |||
| 68c1fb8ef8 | |||
| 787b5e99b2 | |||
| 4fc842ad91 | |||
| 8e85a398d6 | |||
| 4480268172 | |||
| 71bec1049b | |||
| a728f86e05 | |||
| 2c3a2160af | |||
| faaac0de8a |
21
.editorconfig
Normal file
21
.editorconfig
Normal file
@@ -0,0 +1,21 @@
|
||||
# EditorConfig
|
||||
# https://editorconfig.org/
|
||||
# https://editorconfig-specification.readthedocs.io/
|
||||
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
# Unix-style newlines with a newline ending every file
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
|
||||
# 4 space indentation
|
||||
[*.{h,cpp,html,css,js,conf,txt}]
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
|
||||
# Tab indentation (no size specified)
|
||||
[Makefile]
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
.cproject
|
||||
.project
|
||||
.settings/
|
||||
*.o
|
||||
*.a
|
||||
/.clangd
|
||||
/.qtcreator/
|
||||
/.qtc_clangd/
|
||||
2
.templates/.clangd
Normal file
2
.templates/.clangd
Normal file
@@ -0,0 +1,2 @@
|
||||
CompileFlags:
|
||||
Add: [-pthread, -std=c++20, -I%%%CURRENT_DIR%%%/src, -I%%%GLOBAL_WORKING_DIR%%%/pikotools/src, -I%%%GLOBAL_WORKING_DIR%%%/morm/src, -I/usr/include, -I/usr/local/include, -DEZC_HAS_MORM_LIBRARY]
|
||||
1
.templates/.qtcreator/ezc.cflags
Normal file
1
.templates/.qtcreator/ezc.cflags
Normal file
@@ -0,0 +1 @@
|
||||
-std=c20
|
||||
1
.templates/.qtcreator/ezc.config
Normal file
1
.templates/.qtcreator/ezc.config
Normal file
@@ -0,0 +1 @@
|
||||
#define EZC_HAS_MORM_LIBRARY 1
|
||||
1
.templates/.qtcreator/ezc.creator
Normal file
1
.templates/.qtcreator/ezc.creator
Normal file
@@ -0,0 +1 @@
|
||||
[General]
|
||||
184
.templates/.qtcreator/ezc.creator.user
Normal file
184
.templates/.qtcreator/ezc.creator.user
Normal file
@@ -0,0 +1,184 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 14.0.1, 2024-09-20T16:21:10. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
<value type="QByteArray">%%%QT_ENVIRONMENT_ID%%%</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.ActiveTarget</variable>
|
||||
<value type="qlonglong">0</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.EditorSettings</variable>
|
||||
<valuemap type="QVariantMap">
|
||||
<value type="bool" key="EditorConfiguration.AutoIndent">true</value>
|
||||
<value type="bool" key="EditorConfiguration.AutoSpacesForTabs">false</value>
|
||||
<value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
|
||||
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
|
||||
<value type="QString" key="language">Cpp</value>
|
||||
<valuemap type="QVariantMap" key="value">
|
||||
<value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
|
||||
</valuemap>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
|
||||
<value type="QString" key="language">QmlJS</value>
|
||||
<valuemap type="QVariantMap" key="value">
|
||||
<value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
|
||||
</valuemap>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="EditorConfiguration.CodeStyle.Count">2</value>
|
||||
<value type="QByteArray" key="EditorConfiguration.Codec">UTF-8</value>
|
||||
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
|
||||
<value type="int" key="EditorConfiguration.IndentSize">4</value>
|
||||
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
|
||||
<value type="int" key="EditorConfiguration.MarginColumn">80</value>
|
||||
<value type="bool" key="EditorConfiguration.MouseHiding">true</value>
|
||||
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
|
||||
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
|
||||
<value type="int" key="EditorConfiguration.PreferAfterWhitespaceComments">0</value>
|
||||
<value type="bool" key="EditorConfiguration.PreferSingleLineComments">false</value>
|
||||
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
|
||||
<value type="bool" key="EditorConfiguration.ShowMargin">false</value>
|
||||
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
|
||||
<value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
|
||||
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
|
||||
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
|
||||
<value type="int" key="EditorConfiguration.TabSize">8</value>
|
||||
<value type="bool" key="EditorConfiguration.UseGlobal">true</value>
|
||||
<value type="bool" key="EditorConfiguration.UseIndenter">false</value>
|
||||
<value type="int" key="EditorConfiguration.Utf8BomBehavior">2</value>
|
||||
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
|
||||
<value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
|
||||
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
|
||||
<value type="QString" key="EditorConfiguration.ignoreFileTypes">*.md, *.MD, Makefile</value>
|
||||
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
|
||||
<value type="bool" key="EditorConfiguration.skipTrailingWhitespace">true</value>
|
||||
<value type="bool" key="EditorConfiguration.tintMarginArea">true</value>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.PluginSettings</variable>
|
||||
<valuemap type="QVariantMap">
|
||||
<valuemap type="QVariantMap" key="AutoTest.ActiveFrameworks">
|
||||
<value type="bool" key="AutoTest.Framework.Boost">true</value>
|
||||
<value type="bool" key="AutoTest.Framework.CTest">false</value>
|
||||
<value type="bool" key="AutoTest.Framework.Catch">true</value>
|
||||
<value type="bool" key="AutoTest.Framework.GTest">true</value>
|
||||
<value type="bool" key="AutoTest.Framework.QtQuickTest">true</value>
|
||||
<value type="bool" key="AutoTest.Framework.QtTest">true</value>
|
||||
</valuemap>
|
||||
<value type="bool" key="AutoTest.ApplyFilter">false</value>
|
||||
<valuemap type="QVariantMap" key="AutoTest.CheckStates"/>
|
||||
<valuelist type="QVariantList" key="AutoTest.PathFilters"/>
|
||||
<value type="int" key="AutoTest.RunAfterBuild">0</value>
|
||||
<value type="bool" key="AutoTest.UseGlobal">true</value>
|
||||
<valuemap type="QVariantMap" key="ClangTools">
|
||||
<value type="bool" key="ClangTools.AnalyzeOpenFiles">true</value>
|
||||
<value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value>
|
||||
<value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value>
|
||||
<value type="int" key="ClangTools.ParallelJobs">3</value>
|
||||
<value type="bool" key="ClangTools.PreferConfigFile">true</value>
|
||||
<valuelist type="QVariantList" key="ClangTools.SelectedDirs"/>
|
||||
<valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
|
||||
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
|
||||
<value type="bool" key="ClangTools.UseGlobalSettings">true</value>
|
||||
</valuemap>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.Target.0</variable>
|
||||
<valuemap type="QVariantMap">
|
||||
<value type="QString" key="DeviceType">Desktop</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">%%%QT_DEFAULT_PROFILE_ID%%%</value>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">%%%CURRENT_DIR%%%</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
|
||||
<value type="QString">all</value>
|
||||
</valuelist>
|
||||
<value type="QString" key="GenericProjectManager.GenericMakeStep.MakeCommand">/usr/local/bin/gmake</value>
|
||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
|
||||
<value type="QString">clean</value>
|
||||
</valuelist>
|
||||
<value type="QString" key="GenericProjectManager.GenericMakeStep.MakeCommand">/usr/local/bin/gmake</value>
|
||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
|
||||
</valuemap>
|
||||
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
|
||||
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
|
||||
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
|
||||
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
|
||||
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Default</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericBuildConfiguration</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Deploy</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
|
||||
</valuemap>
|
||||
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
|
||||
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
|
||||
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
|
||||
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
|
||||
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
|
||||
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
|
||||
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
||||
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
||||
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
|
||||
<value type="QString" key="PerfRecordArgsId">-e cpu-cycles --call-graph dwarf,4096 -F 250</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
|
||||
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
|
||||
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.TargetCount</variable>
|
||||
<value type="qlonglong">1</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
|
||||
<value type="int">22</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>Version</variable>
|
||||
<value type="int">22</value>
|
||||
</data>
|
||||
</qtcreator>
|
||||
1
.templates/.qtcreator/ezc.cxxflags
Normal file
1
.templates/.qtcreator/ezc.cxxflags
Normal file
@@ -0,0 +1 @@
|
||||
-std=c++20
|
||||
1
.templates/.qtcreator/ezc.files
Normal file
1
.templates/.qtcreator/ezc.files
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
0
.templates/.qtcreator/ezc.includes
Normal file
0
.templates/.qtcreator/ezc.includes
Normal file
30
.templates/install_clangd.sh
Executable file
30
.templates/install_clangd.sh
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/bin/sh
|
||||
|
||||
CURRENT_DIR=$(pwd)
|
||||
GLOBAL_WORKING_DIR=$(realpath ${CURRENT_DIR}/..)
|
||||
|
||||
# ----------
|
||||
|
||||
# make sure the current directory is correct
|
||||
if [ ! -d ${CURRENT_DIR}/.templates ] ; then
|
||||
echo "this script should be called by make: make clangd (one level up)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# change / to \/ in paths
|
||||
CURRENT_DIR_FOR_SED=$(echo ${CURRENT_DIR} | sed 's/\//\\\//g')
|
||||
GLOBAL_WORKING_DIR_FOR_SED=$(echo ${GLOBAL_WORKING_DIR} | sed 's/\//\\\//g')
|
||||
|
||||
|
||||
if [ -f "${CURRENT_DIR}/.templates/.clangd" ] ; then
|
||||
if [ ! -f "${CURRENT_DIR}/.clangd" ] ; then
|
||||
cat "${CURRENT_DIR}/.templates/.clangd" | \
|
||||
sed -e "s/%%%CURRENT_DIR%%%/${CURRENT_DIR_FOR_SED}/g" \
|
||||
-e "s/%%%GLOBAL_WORKING_DIR%%%/${GLOBAL_WORKING_DIR_FOR_SED}/g" > \
|
||||
${CURRENT_DIR}/.clangd
|
||||
|
||||
echo "added a ${CURRENT_DIR}/.clangd file"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
99
.templates/install_qtcreator.sh
Executable file
99
.templates/install_qtcreator.sh
Executable file
@@ -0,0 +1,99 @@
|
||||
#!/bin/sh
|
||||
|
||||
CURRENT_DIR=$(pwd)
|
||||
GLOBAL_WORKING_DIR=$(realpath ${CURRENT_DIR}/..)
|
||||
QTCREATOR_DIR=${CURRENT_DIR}/.qtcreator
|
||||
|
||||
# ----------
|
||||
|
||||
# make sure the current directory is correct
|
||||
if [ ! -d ${CURRENT_DIR}/.templates ] ; then
|
||||
echo "this script should be called by make: make qtcreator (one level up)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
qtcreatorini=~/.config/QtProject/QtCreator.ini
|
||||
qtprofiles=~/.config/QtProject/qtcreator/profiles.xml
|
||||
|
||||
if [ ! -f "$qtcreatorini" ] ; then
|
||||
echo "I cannot find a $qtcreatorini file"
|
||||
echo "this file is needed to take an EnvironmentId parameter"
|
||||
echo "if QTCreator was recently installed make sure you have opened it at least once"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ ! -f "$qtprofiles" ] ; then
|
||||
echo "I cannot find a $qtprofiles file"
|
||||
echo "this file is needed to take a default profile id parameter"
|
||||
echo "if QTCreator was recently installed make sure you have opened it at least once"
|
||||
exit 3
|
||||
fi
|
||||
|
||||
qtenvironmentid=`grep -F 'Settings\EnvironmentId' "$qtcreatorini" | grep -Eo '\{[a-zA-Z0-9-]+\}'`
|
||||
qtdefaultprofileid=`grep -A 1 -F '<variable>Profile.Default</variable>' "$qtprofiles" | tail -n 1 | grep -Eo '\{[a-zA-Z0-9-]+\}'`
|
||||
|
||||
if [ -z "$qtenvironmentid" ] ; then
|
||||
echo "I cannot read a Settings\EnvironmentId parameter from $qtcreatorini file"
|
||||
exit 4
|
||||
fi
|
||||
|
||||
if [ -z "$qtdefaultprofileid" ] ; then
|
||||
echo "I cannot read a Profile.Default parameter from $qtprofiles file"
|
||||
exit 5
|
||||
fi
|
||||
|
||||
# change / to \/ in paths
|
||||
CURRENT_DIR_FOR_SED=$(echo ${CURRENT_DIR} | sed 's/\//\\\//g')
|
||||
GLOBAL_WORKING_DIR_FOR_SED=$(echo ${GLOBAL_WORKING_DIR} | sed 's/\//\\\//g')
|
||||
|
||||
was_qtcreator_dir=0
|
||||
|
||||
if [ -d "${QTCREATOR_DIR}" ] ; then
|
||||
was_qtcreator_dir=1
|
||||
else
|
||||
echo "Your QTCreator EnvironmentId is: $qtenvironmentid"
|
||||
echo "Your QTCreator default profile id is: $qtdefaultprofileid"
|
||||
mkdir -p "${QTCREATOR_DIR}"
|
||||
fi
|
||||
|
||||
if [ -d "${QTCREATOR_DIR}" ] ; then
|
||||
|
||||
if [ -d ${CURRENT_DIR}/.templates/.qtcreator ] ; then
|
||||
cd ${CURRENT_DIR}/.templates/.qtcreator
|
||||
|
||||
if [ $? -eq 0 ] ; then
|
||||
|
||||
for i in * ; do
|
||||
if [ ! -f "${QTCREATOR_DIR}/$i" ] ; then
|
||||
cat "$i" | \
|
||||
sed -e "s/%%%CURRENT_DIR%%%/${CURRENT_DIR_FOR_SED}/g" \
|
||||
-e "s/%%%GLOBAL_WORKING_DIR%%%/${GLOBAL_WORKING_DIR_FOR_SED}/g" \
|
||||
-e "s/%%%QT_ENVIRONMENT_ID%%%/${qtenvironmentid}/g" \
|
||||
-e "s/%%%QT_DEFAULT_PROFILE_ID%%%/${qtdefaultprofileid}/g" > \
|
||||
"${QTCREATOR_DIR}/$i"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ $was_qtcreator_dir -eq 0 ] ; then
|
||||
echo "QTCreator files generated to ${QTCREATOR_DIR} directory"
|
||||
echo "select an 'open project...' option and find a ${QTCREATOR_DIR}/*.creator file"
|
||||
fi
|
||||
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
find ${QTCREATOR_DIR} -name "*.files" | while read projectfiles ; do
|
||||
|
||||
cd ${CURRENT_DIR}/src
|
||||
|
||||
if [ $? -eq 0 ] ; then
|
||||
find ../src -type f \( -iname "*.cpp" -o -iname "*.h" \) | sort > ${projectfiles}
|
||||
echo "file ${projectfiles} has been updated"
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
fi
|
||||
|
||||
|
||||
@@ -1,28 +1,24 @@
|
||||
Copyright (c) 2007-2010, Tomasz Sowa
|
||||
Copyright (c) 2007-2022, Tomasz Sowa
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name Tomasz Sowa nor the names of contributors to this
|
||||
project may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
THE POSSIBILITY OF SUCH DAMAGE.
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
32
Makefile
Normal file
32
Makefile
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
|
||||
export CXX
|
||||
export CXXFLAGS
|
||||
export AR
|
||||
|
||||
|
||||
all: src
|
||||
|
||||
|
||||
src: FORCE
|
||||
$(MAKE) -C src
|
||||
|
||||
|
||||
clean: FORCE
|
||||
$(MAKE) -C src clean
|
||||
|
||||
|
||||
depend: FORCE
|
||||
$(MAKE) -C src depend
|
||||
|
||||
|
||||
clangd: FORCE
|
||||
@.templates/install_clangd.sh
|
||||
|
||||
|
||||
qtcreator: clangd
|
||||
@.templates/install_qtcreator.sh
|
||||
|
||||
|
||||
FORCE:
|
||||
|
||||
49
src/Makefile
Executable file → Normal file
49
src/Makefile
Executable file → Normal file
@@ -1,26 +1,45 @@
|
||||
include Makefile.o.dep
|
||||
sourcefiles:=$(shell find . -name "*.cpp")
|
||||
objfiles:=$(patsubst %.cpp,%.o,$(sourcefiles))
|
||||
|
||||
|
||||
all: ezc.a
|
||||
|
||||
ezc.a: $(o)
|
||||
ar rcs ezc.a $(o)
|
||||
ifndef CXX
|
||||
CXX = g++
|
||||
endif
|
||||
|
||||
ifndef CXXFLAGS
|
||||
CXXFLAGS = -Wall -pedantic -O2 -std=c++20 -I../../pikotools/src -I/usr/local/include
|
||||
endif
|
||||
|
||||
ifndef AR
|
||||
AR = ar
|
||||
endif
|
||||
|
||||
|
||||
|
||||
|
||||
libname = ezc.a
|
||||
|
||||
|
||||
all: $(libname)
|
||||
|
||||
|
||||
$(libname): $(objfiles)
|
||||
$(AR) rcs $(libname) $(objfiles)
|
||||
|
||||
|
||||
%.o: %.cpp
|
||||
$(CXX) -c $(CXXFLAGS) $<
|
||||
|
||||
|
||||
|
||||
depend:
|
||||
makedepend $(CXXFLAGS) -Y. -f- *.cpp > Makefile.dep
|
||||
echo -n "o = " > Makefile.o.dep
|
||||
ls -1 *.cpp | xargs -I foo echo -n foo " " | sed -E "s/([^\.]*)\.cpp[ ]/\1\.o/g" >> Makefile.o.dep
|
||||
$(CXX) -c $(CXXFLAGS) -o $@ $<
|
||||
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
rm -f *.a
|
||||
rm -f $(objfiles)
|
||||
rm -f $(libname)
|
||||
|
||||
|
||||
include Makefile.dep
|
||||
depend:
|
||||
makedepend -w 10 -Y. -I../../pikotools/src -f- $(sourcefiles) | sort -u > Makefile.dep
|
||||
|
||||
|
||||
-include Makefile.dep
|
||||
|
||||
|
||||
88
src/Makefile.dep
Executable file → Normal file
88
src/Makefile.dep
Executable file → Normal file
@@ -1,28 +1,62 @@
|
||||
# DO NOT DELETE
|
||||
|
||||
edanticitem.o: item.h funinfo.h
|
||||
edanticpattern.o: pattern.h item.h funinfo.h functions.h stringconv.h utf8.h
|
||||
edanticpattern.o: /home/tomek/roboczy/winix/core/log.h
|
||||
edanticpattern.o: /home/tomek/roboczy/winix/core/textstream.h
|
||||
edanticpattern.o: /home/tomek/roboczy/winix/core/misc.h
|
||||
edanticpattern.o: /home/tomek/roboczy/winix/core/requesttypes.h
|
||||
edanticpattern.o: /home/tomek/roboczy/winix/core/logmanipulators.h
|
||||
edanticpattern.o: /home/tomek/roboczy/winix/core/slog.h
|
||||
edanticpattern.o: /home/tomek/roboczy/winix/core/cur.h
|
||||
edanticpattern.o: /home/tomek/roboczy/winix/core/request.h
|
||||
edanticpattern.o: /usr/local/include/fcgiapp.h
|
||||
edanticpattern.o: /home/tomek/roboczy/winix/core/error.h
|
||||
edanticpattern.o: /home/tomek/roboczy/winix/core/config.h
|
||||
edanticpattern.o: /home/tomek/roboczy/winix/core/confparser.h
|
||||
edanticpattern.o: /home/tomek/roboczy/winix/core/htmlfilter.h
|
||||
edanticpattern.o: /home/tomek/roboczy/winix/templates/htmltextstream.h
|
||||
edanticpattern.o: /home/tomek/roboczy/winix/core/textstream.h
|
||||
edanticpattern.o: /home/tomek/roboczy/winix/core/session.h
|
||||
edanticpattern.o: /home/tomek/roboczy/winix/core/user.h
|
||||
edanticpattern.o: /home/tomek/roboczy/winix/core/plugindata.h
|
||||
edanticpattern.o: /home/tomek/roboczy/winix/core/rebus.h
|
||||
edanticpattern.o: /home/tomek/roboczy/winix/core/mount.h
|
||||
edanticpattern.o: /home/tomek/roboczy/winix/templates/locale.h
|
||||
edanticpattern.o: /home/tomek/roboczy/winix/core/confparser.h
|
||||
edanticstringconv.o: stringconv.h
|
||||
edanticutf8.o: utf8.h
|
||||
./blocks.o: ../../pikotools/src/textstream/stream.h
|
||||
./blocks.o: ../../pikotools/src/utf8/utf8.h
|
||||
./blocks.o: blocks.h
|
||||
./blocks.o: cache.h
|
||||
./blocks.o: env.h
|
||||
./blocks.o: functions.h
|
||||
./blocks.o: item.h
|
||||
./blocks.o: objects.h
|
||||
./cache.o: ../../pikotools/src/textstream/stream.h
|
||||
./cache.o: ../../pikotools/src/utf8/utf8.h
|
||||
./cache.o: blocks.h
|
||||
./cache.o: cache.h
|
||||
./cache.o: env.h
|
||||
./cache.o: functions.h
|
||||
./cache.o: item.h
|
||||
./cache.o: objects.h
|
||||
./functions.o: ../../pikotools/src/textstream/stream.h
|
||||
./functions.o: ../../pikotools/src/utf8/utf8.h
|
||||
./functions.o: env.h
|
||||
./functions.o: functions.h
|
||||
./functions.o: item.h
|
||||
./item.o: item.h
|
||||
./models.o: models.h
|
||||
./objects.o: ../../pikotools/src/textstream/stream.h
|
||||
./objects.o: ../../pikotools/src/utf8/utf8.h
|
||||
./objects.o: objects.h
|
||||
./pattern.o: ../../pikotools/src/textstream/stream.h
|
||||
./pattern.o: ../../pikotools/src/utf8/utf8.h
|
||||
./pattern.o: blocks.h
|
||||
./pattern.o: cache.h
|
||||
./pattern.o: env.h
|
||||
./pattern.o: functions.h
|
||||
./pattern.o: item.h
|
||||
./pattern.o: objects.h
|
||||
./pattern.o: pattern.h
|
||||
./patternparser.o: ../../pikotools/src/convert/convert.h
|
||||
./patternparser.o: ../../pikotools/src/convert/double.h
|
||||
./patternparser.o: ../../pikotools/src/convert/inttostr.h
|
||||
./patternparser.o: ../../pikotools/src/convert/misc.h
|
||||
./patternparser.o: ../../pikotools/src/convert/patternreplacer.h
|
||||
./patternparser.o: ../../pikotools/src/convert/strtoint.h
|
||||
./patternparser.o: ../../pikotools/src/convert/text.h
|
||||
./patternparser.o: ../../pikotools/src/date/date.h
|
||||
./patternparser.o: ../../pikotools/src/log/filelog.h
|
||||
./patternparser.o: ../../pikotools/src/log/log.h
|
||||
./patternparser.o: ../../pikotools/src/membuffer/membuffer.h
|
||||
./patternparser.o: ../../pikotools/src/space/space.h
|
||||
./patternparser.o: ../../pikotools/src/textstream/stream_private.h
|
||||
./patternparser.o: ../../pikotools/src/textstream/stream.h
|
||||
./patternparser.o: ../../pikotools/src/textstream/textstream.h
|
||||
./patternparser.o: ../../pikotools/src/textstream/types.h
|
||||
./patternparser.o: ../../pikotools/src/utf8/utf8.h
|
||||
./patternparser.o: blocks.h
|
||||
./patternparser.o: cache.h
|
||||
./patternparser.o: env.h
|
||||
./patternparser.o: functions.h
|
||||
./patternparser.o: item.h
|
||||
./patternparser.o: objects.h
|
||||
./patternparser.o: pattern.h
|
||||
./patternparser.o: patternparser.h
|
||||
# DO NOT DELETE
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
o = item.o pattern.o stringconv.o utf8.o
|
||||
117
src/blocks.cpp
Normal file
117
src/blocks.cpp
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* This file is a part of EZC -- Easy templating in C++ library
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "blocks.h"
|
||||
|
||||
|
||||
namespace Ezc
|
||||
{
|
||||
|
||||
|
||||
void Blocks::Insert(const std::wstring & name, const Item & item)
|
||||
{
|
||||
blocks_tab[name] = item;
|
||||
}
|
||||
|
||||
|
||||
Blocks::Iterator Blocks::Find(const std::wstring & name)
|
||||
{
|
||||
return blocks_tab.find(name);
|
||||
}
|
||||
|
||||
|
||||
Blocks::Iterator Blocks::Begin()
|
||||
{
|
||||
return blocks_tab.begin();
|
||||
}
|
||||
|
||||
|
||||
Blocks::Iterator Blocks::End()
|
||||
{
|
||||
return blocks_tab.end();
|
||||
}
|
||||
|
||||
|
||||
size_t Blocks::Size() const
|
||||
{
|
||||
return blocks_tab.size();
|
||||
}
|
||||
|
||||
|
||||
void Blocks::Clear()
|
||||
{
|
||||
blocks_tab.clear();
|
||||
}
|
||||
|
||||
|
||||
void Blocks::ClearCache()
|
||||
{
|
||||
BlocksTable::iterator i = blocks_tab.begin();
|
||||
|
||||
for( ; i != blocks_tab.end() ; ++i)
|
||||
i->second.ClearCache();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Blocks::CacheObjects(Objects & obj)
|
||||
{
|
||||
BlocksTable::iterator i = blocks_tab.begin();
|
||||
|
||||
for( ; i != blocks_tab.end() ; ++i)
|
||||
Cache(obj, i->second);
|
||||
}
|
||||
|
||||
|
||||
void Blocks::CacheFunctions(Functions & fun)
|
||||
{
|
||||
BlocksTable::iterator i = blocks_tab.begin();
|
||||
|
||||
for( ; i != blocks_tab.end() ; ++i)
|
||||
Cache(fun, i->second);
|
||||
}
|
||||
|
||||
|
||||
void Blocks::CacheBlocks(Blocks & blocks)
|
||||
{
|
||||
BlocksTable::iterator i = blocks_tab.begin();
|
||||
|
||||
for( ; i != blocks_tab.end() ; ++i)
|
||||
Cache(blocks, i->second);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
81
src/blocks.h
Normal file
81
src/blocks.h
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* This file is a part of EZC -- Easy templating in C++ library
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_ezc_blocks
|
||||
#define headerfile_ezc_blocks
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "item.h"
|
||||
#include "cache.h"
|
||||
|
||||
|
||||
namespace Ezc
|
||||
{
|
||||
|
||||
|
||||
|
||||
class Blocks
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::map<std::wstring, Item> BlocksTable;
|
||||
typedef BlocksTable::iterator Iterator;
|
||||
|
||||
void Insert(const std::wstring & name, const Item & item);
|
||||
|
||||
Iterator Find(const std::wstring & name);
|
||||
|
||||
Iterator Begin();
|
||||
Iterator End();
|
||||
size_t Size() const;
|
||||
void Clear();
|
||||
|
||||
void CacheObjects(Objects & obj);
|
||||
void CacheFunctions(Functions & fun);
|
||||
|
||||
void CacheBlocks(Blocks & blocks);
|
||||
void ClearCache();
|
||||
|
||||
private:
|
||||
|
||||
BlocksTable blocks_tab;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
||||
131
src/cache.cpp
Normal file
131
src/cache.cpp
Normal file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* This file is a part of EZC -- Easy templating in C++ library
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014-2015, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "cache.h"
|
||||
#include "blocks.h"
|
||||
|
||||
|
||||
|
||||
namespace Ezc
|
||||
{
|
||||
|
||||
|
||||
void Cache(Blocks & blocks, Item::Function & function)
|
||||
{
|
||||
function.item_block = 0;
|
||||
|
||||
if( !function.name.empty() && function.arg < 0 )
|
||||
{
|
||||
Blocks::Iterator i = blocks.Find(function.name);
|
||||
|
||||
if( i != blocks.End() )
|
||||
function.item_block = &i->second;
|
||||
}
|
||||
|
||||
for(size_t i=0 ; i < function.parameters.size() ; ++i)
|
||||
Cache(blocks, *function.parameters[i]);
|
||||
}
|
||||
|
||||
|
||||
void Cache(Functions & fun, Item::Function & function)
|
||||
{
|
||||
function.fun_cache = 0;
|
||||
|
||||
if( !function.name.empty() && function.arg < 0 )
|
||||
{
|
||||
typename Functions::Iterator i = fun.Find(function.name);
|
||||
|
||||
if( i != fun.End() )
|
||||
function.fun_cache = &i->second;
|
||||
}
|
||||
|
||||
for(size_t i=0 ; i < function.parameters.size() ; ++i)
|
||||
Cache(fun, *function.parameters[i]);
|
||||
}
|
||||
|
||||
|
||||
void Cache(Functions & fun, Item & item)
|
||||
{
|
||||
Cache(fun, item.function);
|
||||
|
||||
for(size_t i=0; i < item.item_tab.size() ; ++i)
|
||||
Cache(fun, *item.item_tab[i]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Cache(Blocks & blocks, Item & item)
|
||||
{
|
||||
Cache(blocks, item.function);
|
||||
|
||||
for(size_t i=0; i < item.item_tab.size() ; ++i)
|
||||
Cache(blocks, *item.item_tab[i]);
|
||||
}
|
||||
|
||||
|
||||
void Cache(Objects & objects, Item::Function & function)
|
||||
{
|
||||
function.base_obj = 0;
|
||||
function.method_index = -1;
|
||||
|
||||
if( !function.name.empty() && function.arg < 0 )
|
||||
{
|
||||
typename Objects::Iterator i = objects.Find(function.name, function.method_index);
|
||||
|
||||
if( i != objects.End() )
|
||||
function.base_obj = *i;
|
||||
}
|
||||
|
||||
for(size_t i=0 ; i < function.parameters.size() ; ++i)
|
||||
Cache(objects, *function.parameters[i]);
|
||||
}
|
||||
|
||||
|
||||
void Cache(Objects & objects, Item & item)
|
||||
{
|
||||
Cache(objects, item.function);
|
||||
|
||||
for(size_t i=0; i < item.item_tab.size() ; ++i)
|
||||
Cache(objects, *item.item_tab[i]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Ezc
|
||||
|
||||
|
||||
62
src/cache.h
Normal file
62
src/cache.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* This file is a part of EZC -- Easy templating in C++ library
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef headerfile_ezc_cache
|
||||
#define headerfile_ezc_cache
|
||||
|
||||
#include "item.h"
|
||||
#include "functions.h"
|
||||
#include "objects.h"
|
||||
|
||||
|
||||
|
||||
|
||||
namespace Ezc
|
||||
{
|
||||
|
||||
class Blocks;
|
||||
|
||||
void Cache(Functions & fun, Item::Function & function);
|
||||
void Cache(Functions & fun, Item & item);
|
||||
void Cache(Blocks & blocks, Item & item);
|
||||
void Cache(Objects & objects, Item::Function & function);
|
||||
void Cache(Objects & objects, Item & item);
|
||||
|
||||
|
||||
} // namespace Ezc
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
304
src/env.h
Normal file
304
src/env.h
Normal file
@@ -0,0 +1,304 @@
|
||||
/*
|
||||
* This file is a part of EZC -- Easy templating in C++ library
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef headerfile_ezc_env
|
||||
#define headerfile_ezc_env
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "item.h"
|
||||
#include "textstream/stream.h"
|
||||
|
||||
|
||||
|
||||
namespace Ezc
|
||||
{
|
||||
|
||||
/*
|
||||
a variable
|
||||
*/
|
||||
struct Var
|
||||
{
|
||||
/*
|
||||
* if true then means 'str' is a function name and should be called (res is ignored)
|
||||
*
|
||||
* if false then means 'str' is a string value and res is a boolean value
|
||||
*/
|
||||
bool is_function;
|
||||
|
||||
std::wstring str; // a string value
|
||||
bool res; // a boolean value
|
||||
|
||||
Var()
|
||||
{
|
||||
res = false;
|
||||
is_function = false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
typedef std::map<std::wstring, Var> Vars;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
a base class for your own function data class
|
||||
*/
|
||||
struct FunData
|
||||
{
|
||||
FunData()
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~FunData()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
a generator's stack item
|
||||
each statement ([if ...] [for ...] [normal_funcion]) have its own stack item
|
||||
iter - is used only in [for...] - it is the current iteration (start from zero)
|
||||
for other statements it is always zero
|
||||
fun_data - by default this is null pointer, you can set it to a pointer
|
||||
to an object derived from FunData
|
||||
(this have sense only in [for...] statement because in other statements
|
||||
this object would be immediately removed)
|
||||
auto_remove - when true it means that object pointing by fun_data and for_name should be automatically
|
||||
removed -- (by using delete fun_data and delete for_name)
|
||||
is_for - true if the item is from [for] statement
|
||||
currently used only in [if-index]
|
||||
(it has to look for the last [for] item)
|
||||
*/
|
||||
struct Stack
|
||||
{
|
||||
size_t iter;
|
||||
FunData * fun_data;
|
||||
bool auto_remove;
|
||||
bool is_for;
|
||||
const Item * item;
|
||||
|
||||
|
||||
Stack()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
~Stack()
|
||||
{
|
||||
if( auto_remove )
|
||||
{
|
||||
if( fun_data )
|
||||
{
|
||||
delete fun_data;
|
||||
fun_data = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
iter = 0;
|
||||
fun_data = 0;
|
||||
auto_remove = true;
|
||||
is_for = false;
|
||||
item = 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// !! IMPROVE ME
|
||||
// the name is bad
|
||||
// may it should be called Env (environment) or FunEnv
|
||||
struct Env
|
||||
{
|
||||
// a result consists of a string and a boolean value
|
||||
// output stream
|
||||
pt::Stream & out;
|
||||
// return value from a user's function (default false if not set directly by the function)
|
||||
bool res;
|
||||
|
||||
// table of parameters
|
||||
// the table can be empty
|
||||
std::vector<Var> & params;
|
||||
|
||||
// the first parameter
|
||||
// you can always use it even if there are not any parameters (params is empty)
|
||||
// in such a way the reference points to an empty string
|
||||
const std::wstring & par;
|
||||
|
||||
// an input stream used in [filter] statement
|
||||
// if there is other statement than [filter] then this is an empty stream
|
||||
const pt::Stream & in;
|
||||
|
||||
// indicates that this function is from [for ...] statement
|
||||
bool is_for;
|
||||
|
||||
// indicates that this function is from [if ...] statement
|
||||
bool is_if;
|
||||
|
||||
// indicates that this function is from [if-def ...] statement
|
||||
bool is_if_def;
|
||||
|
||||
// indicates that this function is from [if-not-def ...] statement
|
||||
bool is_if_not_def;
|
||||
|
||||
// indicates that this funcion is a normal statement e.g.: [funcion_name]
|
||||
bool is_normal;
|
||||
|
||||
// indicates that this function is from a filter statement [filter ...]
|
||||
bool is_filter;
|
||||
|
||||
// a pointer to the stack
|
||||
Stack * stack_tab;
|
||||
|
||||
// current stack item
|
||||
size_t stack_index;
|
||||
|
||||
// a stack's item from generator's stack
|
||||
// each function has a new stack item
|
||||
// on this stack you have iter (description below) and fun_data pointer
|
||||
// you can assign to it your own object derived from FunData
|
||||
// 'stack' is a reference to stack_tab[stack_index]
|
||||
Stack & stack;
|
||||
|
||||
// the same as stack.iter (this is mainly for backward compatibility)
|
||||
// it indicates the number of a current iteration for the [for] statement (the first iteration is 0)
|
||||
// for other statements than [for] this is always zero
|
||||
size_t iter;
|
||||
|
||||
// an item from the tree
|
||||
const Item & item;
|
||||
|
||||
|
||||
|
||||
// arguments: output_stream, table_of_parameters, the_first_parameter
|
||||
Env(pt::Stream & o,
|
||||
std::vector<Var> & pars,
|
||||
const std::wstring & first_par,
|
||||
const pt::Stream & input_stream,
|
||||
Stack & s,
|
||||
const Item & item_) : out(o), params(pars), par(first_par), in(input_stream), stack(s), item(item_)
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
void Clear()
|
||||
{
|
||||
res = false; // result is false by default
|
||||
is_for = false;
|
||||
is_if = false;
|
||||
is_if_def = false;
|
||||
is_if_not_def = false;
|
||||
is_normal = false;
|
||||
is_filter = false;
|
||||
iter = 0;
|
||||
stack_tab = 0;
|
||||
stack_index = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* CHECK ME can it be done only for [for] statements?
|
||||
*
|
||||
* can return a null pointer if there is no such an item on the stack
|
||||
*
|
||||
* add a function with const wchar_t *
|
||||
*/
|
||||
Stack * FindLastFor(const std::wstring & name)
|
||||
{
|
||||
for(size_t i = stack_index ; i > 0 ; --i)
|
||||
{
|
||||
if( stack_tab[i-1].is_for && stack_tab[i-1].item->has_function )
|
||||
{
|
||||
if( stack_tab[i-1].item->function.name == name )
|
||||
{
|
||||
return &stack_tab[i-1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Stack * FindLastFor(const std::wstring & name, const std::wstring & postfix)
|
||||
{
|
||||
for(size_t i = stack_index ; i > 0 ; --i)
|
||||
{
|
||||
if( stack_tab[i-1].is_for && stack_tab[i-1].item->has_function )
|
||||
{
|
||||
if( stack_tab[i-1].item->function.name == name && stack_tab[i-1].item->function.postfix == postfix )
|
||||
{
|
||||
return &stack_tab[i-1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
template<class FunUserObject>
|
||||
FunUserObject * FindUserObject(const std::wstring & function_name, Stack ** ezc_stack = 0)
|
||||
{
|
||||
Stack * stack;
|
||||
|
||||
if( item.has_function && item.function.is_function )
|
||||
stack = FindLastFor(function_name, item.function.postfix);
|
||||
else
|
||||
stack = FindLastFor(function_name);
|
||||
|
||||
if( ezc_stack )
|
||||
*ezc_stack = stack;
|
||||
|
||||
if( stack && stack->fun_data )
|
||||
return dynamic_cast<FunUserObject*>(stack->fun_data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Ezc
|
||||
|
||||
|
||||
#endif
|
||||
66
src/expressionparser.h
Normal file
66
src/expressionparser.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* This file is a part of EZC -- Easy templating in C++ library
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2018, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef headerfile_ezc_expressionparser
|
||||
#define headerfile_ezc_expressionparser
|
||||
|
||||
|
||||
namespace Ezc
|
||||
{
|
||||
|
||||
|
||||
|
||||
class ExpressionParser
|
||||
{
|
||||
public:
|
||||
|
||||
ExpressionParser() {};
|
||||
virtual ~ExpressionParser() {};
|
||||
|
||||
// temporarily
|
||||
|
||||
|
||||
virtual bool Parse(const std::wstring & str) = 0;
|
||||
virtual bool LastResultToBool() = 0;
|
||||
virtual std::wstring LastResult() = 0;
|
||||
virtual int LastError() = 0;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
36
src/ezc.h
36
src/ezc.h
@@ -1,47 +1,43 @@
|
||||
/*
|
||||
* This file is a part of EZC -- Easy templating in C++
|
||||
* and is distributed under the (new) BSD licence.
|
||||
* This file is a part of EZC -- Easy templating in C++ library
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007-2010, Tomasz Sowa
|
||||
* Copyright (c) 2007-2022, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name Tomasz Sowa nor the names of contributors to this
|
||||
* project may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef headerfile_ezc_ezc
|
||||
#define headerfile_ezc_ezc
|
||||
|
||||
|
||||
#include "utf8.h"
|
||||
#include "version.h"
|
||||
#include "generator.h"
|
||||
|
||||
#include "patternparser.h"
|
||||
|
||||
#endif
|
||||
|
||||
109
src/functions.cpp
Normal file
109
src/functions.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* This file is a part of EZC -- Easy templating in C++ library
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "functions.h"
|
||||
|
||||
|
||||
namespace Ezc
|
||||
{
|
||||
|
||||
|
||||
void Functions::Insert(const char * key, UserFunction ufunction)
|
||||
{
|
||||
pt::utf8_to_wide(key, temp_key);
|
||||
functions_tab[temp_key] = ufunction;
|
||||
temp_key.clear();
|
||||
}
|
||||
|
||||
|
||||
void Functions::Insert(const std::string & key, UserFunction ufunction)
|
||||
{
|
||||
Insert(key.c_str(), ufunction);
|
||||
}
|
||||
|
||||
|
||||
void Functions::Insert(const wchar_t * key, UserFunction ufunction)
|
||||
{
|
||||
temp_key = key;
|
||||
functions_tab[temp_key] = ufunction;
|
||||
temp_key.clear();
|
||||
}
|
||||
|
||||
|
||||
void Functions::Insert(const std::wstring & key, UserFunction ufunction)
|
||||
{
|
||||
functions_tab[key] = ufunction;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typename Functions::Iterator Functions::Find(const std::wstring & key)
|
||||
{
|
||||
return functions_tab.find(key);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Functions::Clear()
|
||||
{
|
||||
functions_tab.clear();
|
||||
}
|
||||
|
||||
|
||||
typename Functions::Iterator Functions::Begin()
|
||||
{
|
||||
return functions_tab.begin();
|
||||
}
|
||||
|
||||
|
||||
typename Functions::Iterator Functions::End()
|
||||
{
|
||||
return functions_tab.end();
|
||||
}
|
||||
|
||||
|
||||
size_t Functions::Size() const
|
||||
{
|
||||
return functions_tab.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Ezc
|
||||
|
||||
241
src/functions.h
Executable file → Normal file
241
src/functions.h
Executable file → Normal file
@@ -1,46 +1,44 @@
|
||||
/*
|
||||
* This file is a part of EZC -- Easy templating in C++
|
||||
* and is distributed under the (new) BSD licence.
|
||||
* This file is a part of EZC -- Easy templating in C++ library
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007-2012, Tomasz Sowa
|
||||
/*
|
||||
* Copyright (c) 2007-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name Tomasz Sowa nor the names of contributors to this
|
||||
* project may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_ezc_functions
|
||||
#define headerfile_ezc_functions
|
||||
|
||||
#include <map>
|
||||
#include "funinfo.h"
|
||||
#include "stringconv.h"
|
||||
#include "utf8/utf8.h"
|
||||
#include "env.h"
|
||||
|
||||
|
||||
|
||||
namespace Ezc
|
||||
@@ -48,217 +46,38 @@ namespace Ezc
|
||||
|
||||
|
||||
|
||||
|
||||
// functions or variables
|
||||
template<class StreamType>
|
||||
class Functions
|
||||
{
|
||||
public:
|
||||
|
||||
typedef void (*UserFunction)(FunInfo<StreamType> &);
|
||||
enum Type { function, variable };
|
||||
|
||||
struct Function
|
||||
{
|
||||
Function();
|
||||
|
||||
Type type;
|
||||
UserFunction user_function; // used when type is 'function'
|
||||
std::wstring variable; // used when type is 'variable'
|
||||
};
|
||||
|
||||
typedef std::map<std::wstring, Function> FunctionsTable;
|
||||
typedef void (*UserFunction)(Env &);
|
||||
typedef std::map<std::wstring, UserFunction> FunctionsTable;
|
||||
typedef typename FunctionsTable::iterator Iterator;
|
||||
|
||||
|
||||
void Insert(const char * key, UserFunction ufunction); // inserting a function
|
||||
void Insert(const char * key, const char * var); // inserting a variable
|
||||
void Insert(const char * key, const std::string & var); // inserting a variable
|
||||
void Insert(const std::string & key, UserFunction ufunction); // inserting a function
|
||||
void Insert(const std::string & key, const char * var); // inserting a variable
|
||||
void Insert(const std::string & key, const std::string & var); // inserting a variable
|
||||
void Insert(const char * key, UserFunction ufunction);
|
||||
void Insert(const std::string & key, UserFunction ufunction);
|
||||
void Insert(const wchar_t * key, UserFunction ufunction);
|
||||
void Insert(const std::wstring & key, UserFunction ufunction);
|
||||
void Insert(const std::wstring & key, const wchar_t * var);
|
||||
void Insert(const std::wstring & key, const std::wstring & var);
|
||||
|
||||
bool Find(const std::string & key, Function ** fun);
|
||||
bool Find(const std::wstring & key, Function ** fun);
|
||||
Iterator Find(const std::wstring & key);
|
||||
|
||||
Iterator Begin();
|
||||
Iterator End();
|
||||
size_t Size() const;
|
||||
void Clear();
|
||||
size_t Size() const;
|
||||
void Clear();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
FunctionsTable functions_tab;
|
||||
std::wstring temp_key;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
Functions<StreamType>::Function::Function()
|
||||
{
|
||||
type = Functions::variable;
|
||||
user_function = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
void Functions<StreamType>::Insert(const char * key, UserFunction ufunction)
|
||||
{
|
||||
Function f;
|
||||
f.type = function;
|
||||
f.user_function = ufunction;
|
||||
|
||||
AssignString(key, temp_key);
|
||||
functions_tab[temp_key] = f;
|
||||
}
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
void Functions<StreamType>::Insert(const char * key, const char * var)
|
||||
{
|
||||
Function f;
|
||||
f.type = variable;
|
||||
AssignString(var, f.variable);
|
||||
|
||||
AssignString(key, temp_key);
|
||||
functions_tab[temp_key] = f;
|
||||
}
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
void Functions<StreamType>::Insert(const char * key, const std::string & var)
|
||||
{
|
||||
Function f;
|
||||
f.type = variable;
|
||||
AssignString(var, f.variable);
|
||||
|
||||
AssignString(key, temp_key);
|
||||
functions_tab[temp_key] = f;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
void Functions<StreamType>::Insert(const std::string & key, UserFunction ufunction)
|
||||
{
|
||||
Insert(key.c_str(), ufunction);
|
||||
}
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
void Functions<StreamType>::Insert(const std::string & key, const char * var)
|
||||
{
|
||||
Insert(key.c_str(), var);
|
||||
}
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
void Functions<StreamType>::Insert(const std::string & key, const std::string & var)
|
||||
{
|
||||
Insert(key.c_str(), var);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
void Functions<StreamType>::Insert(const std::wstring & key, UserFunction ufunction)
|
||||
{
|
||||
Function f;
|
||||
f.type = function;
|
||||
f.user_function = ufunction;
|
||||
|
||||
functions_tab[key] = f;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
void Functions<StreamType>::Insert(const std::wstring & key, const wchar_t * var)
|
||||
{
|
||||
Function f;
|
||||
f.type = variable;
|
||||
f.variable = var;
|
||||
|
||||
functions_tab[key] = f;
|
||||
}
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
void Functions<StreamType>::Insert(const std::wstring & key, const std::wstring & var)
|
||||
{
|
||||
Function f;
|
||||
f.type = variable;
|
||||
f.variable = var;
|
||||
|
||||
functions_tab[key] = f;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
bool Functions<StreamType>::Find(const std::string & key, Function ** fun)
|
||||
{
|
||||
AssignString(key, temp_key);
|
||||
return Find(temp_key, fun);
|
||||
}
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
bool Functions<StreamType>::Find(const std::wstring & key, Function ** fun)
|
||||
{
|
||||
typename FunctionsTable::iterator i = functions_tab.find( key );
|
||||
|
||||
if( i == functions_tab.end() )
|
||||
return false;
|
||||
|
||||
*fun = &(i->second);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
void Functions<StreamType>::Clear()
|
||||
{
|
||||
functions_tab.clear();
|
||||
}
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
typename Functions<StreamType>::Iterator Functions<StreamType>::Begin()
|
||||
{
|
||||
return functions_tab.begin();
|
||||
}
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
typename Functions<StreamType>::Iterator Functions<StreamType>::End()
|
||||
{
|
||||
return functions_tab.end();
|
||||
}
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
size_t Functions<StreamType>::Size() const
|
||||
{
|
||||
return functions_tab.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Ezc
|
||||
|
||||
|
||||
|
||||
107
src/funinfo.h
107
src/funinfo.h
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* This file is a part of EZC -- Easy templating in C++
|
||||
* and is distributed under the (new) BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007-2011, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name Tomasz Sowa nor the names of contributors to this
|
||||
* project may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef headerfile_ezc_funinfo
|
||||
#define headerfile_ezc_funinfo
|
||||
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
|
||||
namespace Ezc
|
||||
{
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
struct FunInfo
|
||||
{
|
||||
// output stream
|
||||
StreamType & out;
|
||||
|
||||
// the out stream is treated in case sensitive
|
||||
// used only in [is...] statements
|
||||
// default: true
|
||||
bool case_sensitive;
|
||||
|
||||
// table of parameters
|
||||
// the table can be empty
|
||||
std::vector<std::wstring> & params;
|
||||
|
||||
// the first parameter
|
||||
// you can always use it even if there is not any parameters (params is empty)
|
||||
// in such a way the reference points to an empty string
|
||||
const std::wstring & par;
|
||||
|
||||
// an input stream used in [filter] statement
|
||||
// if there is other statement than [filter] then this is an empty stream
|
||||
const StreamType & in;
|
||||
|
||||
// this is set by Generator
|
||||
// it indicates the number of a current iteration in the last [for] statement (the first is 0)
|
||||
// if there was not any [for] before the value is zero
|
||||
int iter;
|
||||
|
||||
// return value from a user function (default false if not set directly by the user function)
|
||||
// for a variable it is set to true if the variable is not empty
|
||||
bool res;
|
||||
|
||||
// arguments: output_stream, table_of_parameters, the_first_parameter
|
||||
FunInfo(StreamType & o,
|
||||
std::vector<std::wstring> & pars,
|
||||
const std::wstring & first_par,
|
||||
const StreamType & i) : out(o), params(pars), par(first_par), in(i)
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
res = false; // false by default
|
||||
iter = 0;
|
||||
case_sensitive = true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Ezc
|
||||
|
||||
|
||||
#endif
|
||||
3098
src/generator.h
Executable file → Normal file
3098
src/generator.h
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
69
src/item.cpp
Executable file → Normal file
69
src/item.cpp
Executable file → Normal file
@@ -1,38 +1,35 @@
|
||||
/*
|
||||
* This file is a part of EZC -- Easy templating in C++
|
||||
* and is distributed under the (new) BSD licence.
|
||||
* This file is a part of EZC -- Easy templating in C++ library
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007-2011, Tomasz Sowa
|
||||
* Copyright (c) 2007-2018, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name Tomasz Sowa nor the names of contributors to this
|
||||
* project may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
@@ -86,10 +83,12 @@ void Item::ClearItems()
|
||||
void Item::Clear()
|
||||
{
|
||||
ClearItems();
|
||||
type = item_none;
|
||||
|
||||
text.clear();
|
||||
file_name.clear();
|
||||
functions.clear();
|
||||
has_function = false;
|
||||
function.Clear();
|
||||
type = item_none;
|
||||
}
|
||||
|
||||
|
||||
@@ -118,12 +117,15 @@ void Item::DeleteLastItem()
|
||||
Item::Item()
|
||||
{
|
||||
type = item_none;
|
||||
has_function = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Item::Item(const Item & i) : type(i.type), text(i.text), file_name(i.file_name), functions(i.functions)
|
||||
Item::Item(const Item & i) : text(i.text), file_name(i.file_name), function(i.function)
|
||||
{
|
||||
type = i.type;
|
||||
has_function = i.has_function;
|
||||
CopyItemTable(i);
|
||||
}
|
||||
|
||||
@@ -133,8 +135,9 @@ Item & Item::operator=(const Item & i)
|
||||
{
|
||||
type = i.type;
|
||||
text = i.text;
|
||||
file_name = i.file_name;
|
||||
functions = i.functions;
|
||||
file_name = i.file_name;
|
||||
has_function = i.has_function;
|
||||
function = i.function;
|
||||
|
||||
ClearItems();
|
||||
CopyItemTable(i);
|
||||
@@ -160,6 +163,28 @@ Item::~Item()
|
||||
}
|
||||
|
||||
|
||||
void Item::ClearCache(Item::Function & function)
|
||||
{
|
||||
function.base_obj = 0;
|
||||
function.method_index = -1;
|
||||
function.fun_cache = 0;
|
||||
function.item_block = 0;
|
||||
|
||||
for(size_t i=0 ; i<function.parameters.size() ; ++i)
|
||||
ClearCache(*function.parameters[i]);
|
||||
}
|
||||
|
||||
|
||||
void Item::ClearCache()
|
||||
{
|
||||
ClearCache(function);
|
||||
|
||||
for(size_t i = 0; i < item_tab.size() ; ++i)
|
||||
item_tab[i]->ClearCache();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Ezc
|
||||
|
||||
|
||||
132
src/item.h
Executable file → Normal file
132
src/item.h
Executable file → Normal file
@@ -1,38 +1,35 @@
|
||||
/*
|
||||
* This file is a part of EZC -- Easy templating in C++
|
||||
* and is distributed under the (new) BSD licence.
|
||||
* This file is a part of EZC -- Easy templating in C++ library
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007-2011, Tomasz Sowa
|
||||
* Copyright (c) 2007-2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name Tomasz Sowa nor the names of contributors to this
|
||||
* project may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
@@ -41,7 +38,7 @@
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "funinfo.h"
|
||||
|
||||
|
||||
|
||||
namespace Ezc
|
||||
@@ -53,28 +50,101 @@ struct Item
|
||||
{
|
||||
enum Type
|
||||
{
|
||||
item_none, item_container, item_text, item_normal, item_is, item_isno,
|
||||
item_if, item_ifno, item_ifany, item_ifone, item_ifanyno, item_ifoneno, item_ifindex,
|
||||
item_for, item_else, item_end, item_err, item_include, item_comment, item_def, item_filter
|
||||
item_none, item_container, item_text, item_function, item_if, item_if_def, item_if_not_def,
|
||||
item_for, item_else, item_end, item_err, item_include, item_comment,
|
||||
item_def, item_def_if_not_set, item_let, item_let_if_not_set,
|
||||
item_filter, item_ezc, item_block, item_return
|
||||
};
|
||||
|
||||
|
||||
struct Function
|
||||
{
|
||||
std::wstring name; // function name
|
||||
std::vector<std::wstring> params; // function parameters
|
||||
void * fun_cache;
|
||||
bool is_function; // if true then we have a function parameter, if false then we have a string parameter
|
||||
std::wstring name; // a function or parameter name
|
||||
std::vector<std::wstring> fields; // any number of additional fields after a dot e.g. [name.field1.field2]
|
||||
std::wstring postfix; // a function can have an additional postfix in its name
|
||||
// e.g. [my_function:my_postfix]
|
||||
std::vector<Function*> parameters; // if is_function is true then it is a function and can have 'parameters'
|
||||
// if is_function is empty then 'parameters' is empty too
|
||||
void * fun_cache; // only valid if is_function is true
|
||||
Item * item_block;
|
||||
void * base_obj;
|
||||
int method_index;
|
||||
int arg; // used if name is numeric (if no then is equal -1)
|
||||
|
||||
|
||||
Function()
|
||||
{
|
||||
fun_cache = 0;
|
||||
is_function = false;
|
||||
fun_cache = 0;
|
||||
item_block = 0;
|
||||
base_obj = 0;
|
||||
method_index = -1;
|
||||
arg = -1;
|
||||
}
|
||||
|
||||
~Function()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
Function(const Function & f)
|
||||
{
|
||||
operator=(f);
|
||||
}
|
||||
|
||||
Function & operator=(const Function & f)
|
||||
{
|
||||
is_function = f.is_function;
|
||||
name = f.name;
|
||||
fields = f.fields;
|
||||
postfix = f.postfix;
|
||||
fun_cache = f.fun_cache;
|
||||
item_block = f.item_block;
|
||||
base_obj = f.base_obj;
|
||||
method_index = f.method_index;
|
||||
arg = f.arg;
|
||||
|
||||
for(size_t i=0 ; i<f.parameters.size() ; ++i)
|
||||
parameters.push_back(new Function(*f.parameters[i]));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Function & AddNewParam()
|
||||
{
|
||||
parameters.push_back(new Function());
|
||||
|
||||
return *parameters.back();
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
for(size_t i=0 ; i<parameters.size() ; ++i)
|
||||
delete parameters[i];
|
||||
|
||||
fields.clear();
|
||||
parameters.clear();
|
||||
name.clear();
|
||||
postfix.clear();
|
||||
fun_cache = 0;
|
||||
item_block = 0;
|
||||
base_obj = 0;
|
||||
method_index = -1;
|
||||
arg = -1;
|
||||
is_function = false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
Type type;
|
||||
std::wstring text; // used in: item_text
|
||||
std::wstring file_name; // used in: item_include (as a file name)
|
||||
std::vector<Item*> item_tab; // childs
|
||||
std::vector<Function> functions;
|
||||
std::vector<Item*> item_tab; // childs
|
||||
bool has_function; // the [return] statement can be without a function
|
||||
Function function;
|
||||
|
||||
Item();
|
||||
Item(const Item & i);
|
||||
@@ -88,10 +158,18 @@ struct Item
|
||||
Type LastItemType();
|
||||
void DeleteLastItem();
|
||||
void Clear();
|
||||
void ClearCache();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void ClearCache(Item::Function & function);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Ezc
|
||||
|
||||
|
||||
|
||||
136
src/models.cpp
Normal file
136
src/models.cpp
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* This file is a part of EZC -- Easy templating in C++ library
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "models.h"
|
||||
|
||||
|
||||
#ifdef EZC_HAS_MORM_LIBRARY
|
||||
|
||||
|
||||
|
||||
namespace Ezc
|
||||
{
|
||||
|
||||
|
||||
Models::Models()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Models::~Models()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
void Models::Clear()
|
||||
{
|
||||
models_map.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Models::Add(const std::wstring & name, morm::Model & model)
|
||||
{
|
||||
morm::Wrapper wrapper;
|
||||
wrapper.model = &model;
|
||||
models_map[name] = wrapper;
|
||||
}
|
||||
|
||||
|
||||
void Models::Add(const std::wstring & name, morm::Model * model)
|
||||
{
|
||||
morm::Wrapper wrapper;
|
||||
wrapper.model = model;
|
||||
models_map[name] = wrapper;
|
||||
}
|
||||
|
||||
|
||||
void Models::Add(const std::wstring & name, pt::Space & space)
|
||||
{
|
||||
morm::Wrapper wrapper;
|
||||
wrapper.space_wrapper = new morm::SpaceWrapper(&space);
|
||||
models_map[name] = wrapper;
|
||||
}
|
||||
|
||||
|
||||
void Models::Add(const std::wstring & name, pt::Space * space)
|
||||
{
|
||||
morm::Wrapper wrapper;
|
||||
wrapper.space_wrapper = new morm::SpaceWrapper(space);
|
||||
models_map[name] = wrapper;
|
||||
}
|
||||
|
||||
|
||||
void Models::Add(const std::wstring & name, pt::Date & date)
|
||||
{
|
||||
morm::Wrapper wrapper;
|
||||
wrapper.date = &date;
|
||||
models_map[name] = wrapper;
|
||||
}
|
||||
|
||||
|
||||
void Models::Add(const std::wstring & name, pt::Date * date)
|
||||
{
|
||||
morm::Wrapper wrapper;
|
||||
wrapper.date = date;
|
||||
models_map[name] = wrapper;
|
||||
}
|
||||
|
||||
|
||||
morm::Wrapper * Models::Find(const std::wstring & name)
|
||||
{
|
||||
auto iterator = models_map.find(name);
|
||||
|
||||
if( iterator != models_map.end() )
|
||||
{
|
||||
return &iterator->second;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
Models::ModelsMap & Models::GetMap()
|
||||
{
|
||||
return models_map;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
148
src/models.h
Normal file
148
src/models.h
Normal file
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* This file is a part of EZC -- Easy templating in C++ library
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2021-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_ezc_models
|
||||
#define headerfile_ezc_models
|
||||
|
||||
#ifdef EZC_HAS_MORM_LIBRARY
|
||||
|
||||
#include "wrapper.h"
|
||||
#include "env.h"
|
||||
#include "space/space.h"
|
||||
|
||||
|
||||
namespace Ezc
|
||||
{
|
||||
|
||||
|
||||
class Models
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::map<std::wstring, morm::Wrapper> ModelsMap;
|
||||
|
||||
Models();
|
||||
~Models();
|
||||
|
||||
void Add(const std::wstring & name, morm::Model & model);
|
||||
void Add(const std::wstring & name, morm::Model * model);
|
||||
|
||||
void Add(const std::wstring & name, pt::Space & space);
|
||||
void Add(const std::wstring & name, pt::Space * space);
|
||||
|
||||
void Add(const std::wstring & name, pt::Date & space);
|
||||
void Add(const std::wstring & name, pt::Date * space);
|
||||
|
||||
template<typename VectorType>
|
||||
void Add(const std::wstring & name, std::vector<VectorType> & container)
|
||||
{
|
||||
morm::Wrapper wrapper;
|
||||
wrapper.model_container_wrapper = new morm::ModelWrapperVector<VectorType>(&container);
|
||||
models_map[name] = wrapper;
|
||||
}
|
||||
|
||||
template<typename VectorType>
|
||||
void Add(const std::wstring & name, std::vector<VectorType> * container)
|
||||
{
|
||||
morm::Wrapper wrapper;
|
||||
wrapper.model_container_wrapper = new morm::ModelWrapperVector<VectorType>(container);
|
||||
models_map[name] = wrapper;
|
||||
}
|
||||
|
||||
template<typename VectorType>
|
||||
void Add(const std::wstring & name, std::vector<VectorType*> & container)
|
||||
{
|
||||
morm::Wrapper wrapper;
|
||||
wrapper.model_container_wrapper = new morm::ModelWrapperVectorPointer<VectorType>(&container);
|
||||
models_map[name] = wrapper;
|
||||
}
|
||||
|
||||
template<typename VectorType>
|
||||
void Add(const std::wstring & name, std::vector<VectorType*> * container)
|
||||
{
|
||||
morm::Wrapper wrapper;
|
||||
wrapper.model_container_wrapper = new morm::ModelWrapperVectorPointer<VectorType>(container);
|
||||
models_map[name] = wrapper;
|
||||
}
|
||||
|
||||
template<typename ListType>
|
||||
void Add(const std::wstring & name, std::list<ListType> & container)
|
||||
{
|
||||
morm::Wrapper wrapper;
|
||||
wrapper.model_container_wrapper = new morm::ModelWrapperList<ListType>(&container);
|
||||
models_map[name] = wrapper;
|
||||
}
|
||||
|
||||
template<typename ListType>
|
||||
void Add(const std::wstring & name, std::list<ListType> * container)
|
||||
{
|
||||
morm::Wrapper wrapper;
|
||||
wrapper.model_container_wrapper = new morm::ModelWrapperList<ListType>(container);
|
||||
models_map[name] = wrapper;
|
||||
}
|
||||
|
||||
template<typename ListType>
|
||||
void Add(const std::wstring & name, std::list<ListType*> & container)
|
||||
{
|
||||
morm::Wrapper wrapper;
|
||||
wrapper.model_container_wrapper = new morm::ModelWrapperListPointer<ListType>(&container);
|
||||
models_map[name] = wrapper;
|
||||
}
|
||||
|
||||
template<typename ListType>
|
||||
void Add(const std::wstring & name, std::list<ListType*> * container)
|
||||
{
|
||||
morm::Wrapper wrapper;
|
||||
wrapper.model_container_wrapper = new morm::ModelWrapperListPointer<ListType>(container);
|
||||
models_map[name] = wrapper;
|
||||
}
|
||||
|
||||
morm::Wrapper * Find(const std::wstring & name);
|
||||
ModelsMap & GetMap();
|
||||
void Clear();
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
ModelsMap models_map;
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
104
src/objects.cpp
Normal file
104
src/objects.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* This file is a part of EZC -- Easy templating in C++ library
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "objects.h"
|
||||
|
||||
|
||||
namespace Ezc
|
||||
{
|
||||
|
||||
|
||||
typename Objects::Iterator Objects::Find(const std::wstring & key, int & method_index)
|
||||
{
|
||||
Iterator i = obj_tab.begin();
|
||||
method_index = -1;
|
||||
|
||||
for( ; i != obj_tab.end() ; ++i)
|
||||
{
|
||||
int index = (*i)->FindFun(key);
|
||||
|
||||
if( index != -1 )
|
||||
{
|
||||
method_index = index;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return obj_tab.end();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Objects::Insert(BaseObj * base_fun)
|
||||
{
|
||||
obj_tab.push_back(base_fun);
|
||||
}
|
||||
|
||||
|
||||
void Objects::Insert(BaseObj & base_fun)
|
||||
{
|
||||
obj_tab.push_back(&base_fun);
|
||||
}
|
||||
|
||||
|
||||
|
||||
typename Objects::Iterator Objects::Begin()
|
||||
{
|
||||
return obj_tab.begin();
|
||||
}
|
||||
|
||||
|
||||
typename Objects::Iterator Objects::End()
|
||||
{
|
||||
return obj_tab.end();
|
||||
}
|
||||
|
||||
|
||||
size_t Objects::Size() const
|
||||
{
|
||||
return obj_tab.size();
|
||||
}
|
||||
|
||||
|
||||
void Objects::Clear()
|
||||
{
|
||||
obj_tab.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Ezc
|
||||
|
||||
235
src/objects.h
Normal file
235
src/objects.h
Normal file
@@ -0,0 +1,235 @@
|
||||
/*
|
||||
* This file is a part of EZC -- Easy templating in C++ library
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2015-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_ezc_objects
|
||||
#define headerfile_ezc_objects
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "utf8/utf8.h"
|
||||
#include "env.h"
|
||||
|
||||
|
||||
|
||||
|
||||
namespace Ezc
|
||||
{
|
||||
|
||||
|
||||
class BaseObj
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~BaseObj() {}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
virtual std::wstring & GetObjectName() = 0;
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
virtual int FindFun(const std::wstring & fun_name) = 0;
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
virtual void CallFun(int fun_index, Env &) = 0;
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
virtual void ClearFunctions() = 0;
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
virtual size_t FunctionsSize() = 0;
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
virtual void AddFunctions() {};
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define EZC_DEFINE_OBJECT_METHODS(classname) \
|
||||
\
|
||||
\
|
||||
protected: \
|
||||
\
|
||||
struct EzcTemplateMethod \
|
||||
{ \
|
||||
std::wstring fun_name; \
|
||||
void (classname::*fun)(Info &); \
|
||||
}; \
|
||||
\
|
||||
public: \
|
||||
\
|
||||
virtual std::wstring & GetObjectName() \
|
||||
{ \
|
||||
return ezc_object_name; \
|
||||
} \
|
||||
\
|
||||
virtual void CallFun(int fun_index, Info & info) \
|
||||
{ \
|
||||
if( fun_index >=0 && (size_t)fun_index < ezc_template_method_tab.size() ) \
|
||||
{ \
|
||||
(this->*(ezc_template_method_tab[fun_index].fun))(info); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
virtual int FindFun(const std::wstring & fun_name) \
|
||||
{ \
|
||||
for(size_t i=0 ; i<ezc_template_method_tab.size() ; ++i) \
|
||||
{ \
|
||||
if( ezc_template_method_tab[i].fun_name == fun_name ) \
|
||||
{ \
|
||||
return (int)i; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
return -1; \
|
||||
} \
|
||||
\
|
||||
\
|
||||
protected: \
|
||||
\
|
||||
virtual void ClearFunctions() \
|
||||
{ \
|
||||
ezc_template_method_tab.clear(); \
|
||||
} \
|
||||
\
|
||||
virtual size_t FunctionsSize() \
|
||||
{ \
|
||||
return ezc_template_method_tab.size(); \
|
||||
} \
|
||||
\
|
||||
void Insert(const char * name, void (classname::*fun)(Info &)) \
|
||||
{ \
|
||||
EzcTemplateMethod item; \
|
||||
\
|
||||
pt::utf8_to_wide(name, item.fun_name); \
|
||||
item.fun = fun; \
|
||||
\
|
||||
ezc_template_method_tab.push_back(item); \
|
||||
} \
|
||||
\
|
||||
void Insert(const std::string & name, void (classname::*fun)(Info &)) \
|
||||
{ \
|
||||
EzcTemplateMethod item; \
|
||||
\
|
||||
pt::utf8_to_wide(name, item.fun_name); \
|
||||
item.fun = fun; \
|
||||
\
|
||||
ezc_template_method_tab.push_back(item); \
|
||||
} \
|
||||
\
|
||||
void Insert(const wchar_t * name, void (classname::*fun)(Info &)) \
|
||||
{ \
|
||||
EzcTemplateMethod item; \
|
||||
\
|
||||
item.fun_name = name; \
|
||||
item.fun = fun; \
|
||||
\
|
||||
ezc_template_method_tab.push_back(item); \
|
||||
} \
|
||||
\
|
||||
void Insert(const std::wstring & name, void (classname::*fun)(Info &)) \
|
||||
{ \
|
||||
EzcTemplateMethod item; \
|
||||
\
|
||||
item.fun_name = name; \
|
||||
item.fun = fun; \
|
||||
\
|
||||
ezc_template_method_tab.push_back(item); \
|
||||
} \
|
||||
\
|
||||
std::vector<EzcTemplateMethod> ezc_template_method_tab; \
|
||||
std::wstring ezc_object_name; \
|
||||
\
|
||||
private:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Objects
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::vector<BaseObj*> ObjectsTable;
|
||||
typedef typename ObjectsTable::iterator Iterator;
|
||||
|
||||
void Insert(BaseObj * base_fun);
|
||||
void Insert(BaseObj & base_fun);
|
||||
|
||||
Iterator Begin();
|
||||
Iterator End();
|
||||
size_t Size() const;
|
||||
void Clear();
|
||||
|
||||
Iterator Find(const std::wstring & key, int & method_index);
|
||||
|
||||
private:
|
||||
|
||||
ObjectsTable obj_tab;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Ezc
|
||||
|
||||
|
||||
#endif
|
||||
163
src/outstreams.h
Normal file
163
src/outstreams.h
Normal file
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* This file is a part of EZC -- Easy templating in C++ library
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2015-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_ezc_outstreams
|
||||
#define headerfile_ezc_outstreams
|
||||
|
||||
#include "textstream/stream.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace Ezc
|
||||
{
|
||||
|
||||
|
||||
class OutStreams
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::map<std::wstring, pt::Stream*> StreamsMap;
|
||||
typedef std::vector<pt::Stream*> StreamsTab;
|
||||
|
||||
StreamsMap streams_map;
|
||||
StreamsTab streams_tab;
|
||||
|
||||
void ResizeTab(pt::Stream & stream_type, size_t len);
|
||||
|
||||
void ClearMap();
|
||||
void ClearTab();
|
||||
|
||||
~OutStreams();
|
||||
OutStreams();
|
||||
OutStreams(const OutStreams & o);
|
||||
OutStreams & operator=(const OutStreams & o);
|
||||
|
||||
};
|
||||
|
||||
|
||||
OutStreams::~OutStreams()
|
||||
{
|
||||
ClearTab();
|
||||
}
|
||||
|
||||
OutStreams::OutStreams()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
OutStreams::OutStreams(const OutStreams & o)
|
||||
{
|
||||
// we do not copy streams but creating new ones
|
||||
//ResizeTab(o.streams_tab.size());
|
||||
}
|
||||
|
||||
|
||||
OutStreams & OutStreams::operator=(const OutStreams & o)
|
||||
{
|
||||
// we do not copy streams but creating new ones
|
||||
streams_map.clear();
|
||||
//ResizeTab(o.streams_tab.size());
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void OutStreams::ClearTab()
|
||||
{
|
||||
for(size_t i=0 ; i<streams_tab.size() ; ++i)
|
||||
delete streams_tab[i];
|
||||
|
||||
streams_tab.clear();
|
||||
streams_map.clear();
|
||||
}
|
||||
|
||||
|
||||
void OutStreams::ResizeTab(pt::Stream & stream_type, size_t len)
|
||||
{
|
||||
if( streams_tab.size() != len )
|
||||
{
|
||||
if( streams_tab.size() < len )
|
||||
{
|
||||
size_t i = streams_tab.size();
|
||||
streams_tab.resize(len);
|
||||
|
||||
for( ; i<streams_tab.size() ; ++i)
|
||||
streams_tab[i] = stream_type.new_empty();
|
||||
}
|
||||
else
|
||||
{
|
||||
streams_map.clear();
|
||||
|
||||
for(size_t i=len ; i<streams_tab.size() ; ++i)
|
||||
delete streams_tab[i];
|
||||
|
||||
streams_tab.resize(len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OutStreams::ClearMap()
|
||||
{
|
||||
typename StreamsMap::iterator i;
|
||||
|
||||
for(i=streams_map.begin() ; i != streams_map.end() ; ++i)
|
||||
{
|
||||
pt::Stream & str = *(i->second);
|
||||
str.clear();
|
||||
|
||||
// if constexpr(is_pikotools_stream)
|
||||
// {
|
||||
// str.clear();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// str.str(L"");
|
||||
// }
|
||||
}
|
||||
|
||||
streams_map.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
||||
1015
src/pattern.cpp
Executable file → Normal file
1015
src/pattern.cpp
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
232
src/pattern.h
Executable file → Normal file
232
src/pattern.h
Executable file → Normal file
@@ -1,38 +1,35 @@
|
||||
/*
|
||||
* This file is a part of EZC -- Easy templating in C++
|
||||
* and is distributed under the (new) BSD licence.
|
||||
* This file is a part of EZC -- Easy templating in C++ library
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007-2011, Tomasz Sowa
|
||||
/*
|
||||
* Copyright (c) 2007-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name Tomasz Sowa nor the names of contributors to this
|
||||
* project may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
@@ -41,13 +38,10 @@
|
||||
|
||||
#include <string>
|
||||
#include "item.h"
|
||||
#include "cache.h"
|
||||
#include "blocks.h"
|
||||
#include "functions.h"
|
||||
#include "stringconv.h"
|
||||
#include "utf8.h"
|
||||
|
||||
#ifdef EZC_USE_WINIX_LOGGER
|
||||
#include "core/log.h"
|
||||
#endif
|
||||
#include "objects.h"
|
||||
|
||||
|
||||
namespace Ezc
|
||||
@@ -60,197 +54,31 @@ public:
|
||||
|
||||
Pattern();
|
||||
|
||||
/*!
|
||||
clearing only the tree
|
||||
*/
|
||||
void Clear();
|
||||
|
||||
void CacheFunctions(Functions & fun);
|
||||
void CacheBlocks(Blocks & blocks);
|
||||
void CacheObjects(Objects & obj);
|
||||
void ClearCache();
|
||||
|
||||
// first we're trying to read a file from directory dir
|
||||
// if there is no such a file there then we try read from dir2
|
||||
// (the second dir2 can be empty - it will not be used)
|
||||
void Directory(const char * dir, const char * dir2 = 0);
|
||||
void Directory(const std::string & dir);
|
||||
void Directory(const std::string & dir, const std::string & dir2);
|
||||
|
||||
void Directory(const wchar_t * dir, const wchar_t * dir2 = 0);
|
||||
void Directory(const std::wstring & dir);
|
||||
void Directory(const std::wstring & dir, const std::wstring & dir2);
|
||||
|
||||
void ParseFile(const char * file_name);
|
||||
void ParseFile(const std::string & file_name);
|
||||
|
||||
void ParseFile(const wchar_t * file_name);
|
||||
void ParseFile(const std::wstring & file_name);
|
||||
|
||||
|
||||
void ParseString(const char * str);
|
||||
void ParseString(const std::string & str);
|
||||
void ParseString(const wchar_t * str);
|
||||
void ParseString(const std::wstring & str);
|
||||
|
||||
void AllowInclude(bool allow);
|
||||
void DeleteWhiteTextItems(bool del);
|
||||
void SetIncludeMax(int include_max);
|
||||
|
||||
// files and strings (only char* and std::string) are treated
|
||||
// as UTF-8
|
||||
void UTF8(bool utf8);
|
||||
|
||||
void SetCommentary(const char * com_start, const char * com_stop);
|
||||
void SetCommentary(const std::string & com_start, const std::string & com_stop);
|
||||
void SetCommentary(const wchar_t * com_start, const wchar_t * com_stop);
|
||||
void SetCommentary(const std::wstring & com_start, const std::wstring & com_stop);
|
||||
|
||||
void CreateMsg(std::wstring & out, const wchar_t * type, const wchar_t * arg = 0);
|
||||
static bool IsWhite(wchar_t c);
|
||||
|
||||
Item item_root;
|
||||
|
||||
template<class StreamType>
|
||||
void CacheFunctions(Functions<StreamType> & fun)
|
||||
{
|
||||
CacheFunctions(item_root, fun);
|
||||
}
|
||||
|
||||
void ClearCache();
|
||||
|
||||
private:
|
||||
|
||||
// the main pointer to the parsed text
|
||||
const wchar_t * itext;
|
||||
|
||||
|
||||
// allowing include tag
|
||||
// default: true
|
||||
bool allow_include;
|
||||
|
||||
// if true all text-items which have only white characters (with new lines as well)
|
||||
// will be deleted - useful in *.txt templates
|
||||
// this not actually delete the whole item but only the string
|
||||
// the item will be present with an empty string
|
||||
// default: false
|
||||
bool delete_white_text_items;
|
||||
|
||||
// first we're trying to read a file from 'directory'
|
||||
// if there is no such a file there then we try read from 'directory2'
|
||||
// we read from these directories only if they are not empty
|
||||
std::wstring directory, directory2;
|
||||
|
||||
|
||||
bool input_as_utf8;
|
||||
|
||||
int include_level, include_level_max;
|
||||
|
||||
|
||||
|
||||
std::wstring commentary_start, commentary_stop;
|
||||
|
||||
|
||||
// temporary content for ParseString(const char*) method
|
||||
std::wstring string_content;
|
||||
|
||||
// temporary object for a file name
|
||||
std::wstring file_name;
|
||||
|
||||
// temporary object for a file name
|
||||
std::string afile_name;
|
||||
|
||||
// temporary object for a EZC function's parameter
|
||||
std::wstring temp_param;
|
||||
|
||||
// temporary object for a EZC function
|
||||
Item::Function temp_function;
|
||||
|
||||
|
||||
|
||||
void ReadFile(const std::wstring & name, std::wstring & result);
|
||||
void ReadFile(const wchar_t * name, std::wstring & result);
|
||||
bool HasFileAtBeginning(const wchar_t * path, const wchar_t * file);
|
||||
bool IsFileCorrect(const wchar_t * name);
|
||||
bool ReadFileFromDir(const std::wstring & dir, const wchar_t * name, std::wstring & result);
|
||||
void ReadFile(std::ifstream & file, std::wstring & result);
|
||||
void ReadFileContent(std::ifstream & file, std::wstring & result);
|
||||
|
||||
int ReadCharInText();
|
||||
void SkipWhite();
|
||||
void CheckWhiteAndDelete(std::wstring & s);
|
||||
|
||||
bool IsNameChar(wchar_t c);
|
||||
bool IsDigit(wchar_t c);
|
||||
bool IsPositiveNumber(const std::wstring & str);
|
||||
|
||||
bool ReadName(std::wstring & name);
|
||||
bool ReadString(std::wstring & str);
|
||||
bool ReadParams(Item::Function & function);
|
||||
bool ReadFunction(Item::Function & function);
|
||||
bool ReadFunctions(Item & item);
|
||||
|
||||
void ReadDirectiveIf(Item & item);
|
||||
void ReadDirectiveIfno(Item & item);
|
||||
void ReadDirectiveIfany(Item & item);
|
||||
void ReadDirectiveIfone(Item & item);
|
||||
void ReadDirectiveIfanyno(Item & item);
|
||||
void ReadDirectiveIfoneno(Item & item);
|
||||
void ReadDirectiveIs(Item & item);
|
||||
void ReadDirectiveIsno(Item & item);
|
||||
void ReadDirectiveIfindex(Item & item);
|
||||
void ReadDirectiveFor(Item & item);
|
||||
void ReadDirectiveComment(Item & item);
|
||||
void ReadDirectiveInclude(Item & item);
|
||||
void ReadDirectiveDef(Item & item);
|
||||
void ReadDirectiveFilter(Item & item);
|
||||
void ReadDirectiveNormal(const std::wstring & name, Item & item);
|
||||
|
||||
void CreateTreeReadItemDirectiveCheckEnding(Item & item);
|
||||
void CreateTreeReadItemDirective(Item & item);
|
||||
void CreateTreeReadItemText(Item & item);
|
||||
bool CreateTreeReadItem(Item & item);
|
||||
void CreateTreeReadIf(Item & item);
|
||||
void CreateTreeReadFor(Item & item);
|
||||
void CreateTree(Item & item);
|
||||
void CreateTreeReadInclude(Item & item);
|
||||
void CreateTreeReadIncludeSkipAllowFlag(Item & item);
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
void CacheFunctions(Item & item, Functions<StreamType> & fun)
|
||||
{
|
||||
typename Functions<StreamType>::Function * ezc_fun;
|
||||
|
||||
// one exception (if_index is putting its argument on the functions stack)
|
||||
if( item.type != Item::item_ifindex )
|
||||
{
|
||||
for(size_t f=0; f < item.functions.size() ; ++f)
|
||||
{
|
||||
if( fun.Find(item.functions[f].name, &ezc_fun) )
|
||||
{
|
||||
item.functions[f].fun_cache = ezc_fun;
|
||||
}
|
||||
else
|
||||
{
|
||||
item.functions[f].fun_cache = 0;
|
||||
|
||||
#ifdef EZC_USE_WINIX_LOGGER
|
||||
log << log1 << "Ezc: unknown function: " << item.functions[f].name << logend;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(size_t i=0; i < item.item_tab.size() ; ++i)
|
||||
CacheFunctions(*item.item_tab[i], fun);
|
||||
}
|
||||
|
||||
|
||||
void ClearCache(Item & item);
|
||||
|
||||
}; // class Pattern
|
||||
|
||||
|
||||
|
||||
void Pattern::CacheFunctions(Functions & fun)
|
||||
{
|
||||
Cache(fun, item_root);
|
||||
}
|
||||
|
||||
|
||||
void Pattern::CacheObjects(Objects & obj)
|
||||
{
|
||||
Cache(obj, item_root);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
1399
src/patternparser.cpp
Normal file
1399
src/patternparser.cpp
Normal file
File diff suppressed because it is too large
Load Diff
227
src/patternparser.h
Normal file
227
src/patternparser.h
Normal file
@@ -0,0 +1,227 @@
|
||||
/*
|
||||
* This file is a part of EZC -- Easy templating in C++ library
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007-2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef headerfile_ezc_patternparser
|
||||
#define headerfile_ezc_patternparser
|
||||
|
||||
#include "blocks.h"
|
||||
#include "pattern.h"
|
||||
#include "utf8/utf8.h"
|
||||
#include "log/log.h"
|
||||
|
||||
|
||||
namespace Ezc
|
||||
{
|
||||
|
||||
|
||||
class PatternParser
|
||||
{
|
||||
public:
|
||||
|
||||
PatternParser();
|
||||
|
||||
// first we're trying to read a file from directory dir
|
||||
// if there is no such a file there then we try read from dir2
|
||||
// (the second dir2 can be empty - it will not be used)
|
||||
void Directory(const char * dir, const char * dir2 = 0);
|
||||
void Directory(const std::string & dir);
|
||||
void Directory(const std::string & dir, const std::string & dir2);
|
||||
|
||||
void Directory(const wchar_t * dir, const wchar_t * dir2 = 0);
|
||||
void Directory(const std::wstring & dir);
|
||||
void Directory(const std::wstring & dir, const std::wstring & dir2);
|
||||
|
||||
void ParseFile(const char * file_name, Pattern & pattern);
|
||||
void ParseFile(const std::string & file_name, Pattern & pattern);
|
||||
void ParseFile(const wchar_t * file_name, Pattern & pattern);
|
||||
void ParseFile(const std::wstring & file_name, Pattern & pattern);
|
||||
|
||||
void ParseString(const char * str, Pattern & pattern);
|
||||
void ParseString(const std::string & str, Pattern & pattern);
|
||||
void ParseString(const wchar_t * str, Pattern & pattern);
|
||||
void ParseString(const std::wstring & str, Pattern & pattern);
|
||||
|
||||
void AllowInclude(bool allow);
|
||||
void DeleteWhiteTextItems(bool del);
|
||||
void SetIncludeMax(int include_max);
|
||||
void SetBlocks(Blocks & blocks);
|
||||
void SetProgramMode(bool program_mode);
|
||||
void SetLogger(pt::Log * log);
|
||||
|
||||
private:
|
||||
|
||||
struct Env
|
||||
{
|
||||
bool clear_all_white_nodes;
|
||||
bool trim_text_nodes;
|
||||
|
||||
Env()
|
||||
{
|
||||
clear_all_white_nodes = false;
|
||||
trim_text_nodes = false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
std::vector<Env> env_tab;
|
||||
|
||||
// the output object
|
||||
Pattern * pat;
|
||||
|
||||
// the main pointer to the parsed text
|
||||
const wchar_t * itext;
|
||||
|
||||
|
||||
// allowing include tag
|
||||
// default: true
|
||||
bool allow_include;
|
||||
|
||||
// if true all text-items which have only white characters (with new lines as well)
|
||||
// will be deleted - useful in *.txt templates
|
||||
// this not actually delete the whole item but only the string
|
||||
// the item will be present with an empty string
|
||||
// default: false
|
||||
bool delete_white_text_items;
|
||||
|
||||
// first we're trying to read a file from 'directory'
|
||||
// if there is no such a file there then we try read from 'directory2'
|
||||
// we read from these directories only if they are not empty
|
||||
std::wstring directory, directory2;
|
||||
|
||||
|
||||
int include_level, include_level_max;
|
||||
|
||||
|
||||
// temporary content for ParseString(const char*) method
|
||||
std::wstring string_content;
|
||||
|
||||
// temporary object for a file name
|
||||
std::wstring file_name;
|
||||
|
||||
// temporary object for a file name
|
||||
std::string afile_name;
|
||||
|
||||
// temporary object for a EZC function
|
||||
Item::Function temp_function;
|
||||
|
||||
Blocks * pblocks;
|
||||
|
||||
bool program_mode;
|
||||
|
||||
pt::Log * log;
|
||||
|
||||
void InitializeEnvTab();
|
||||
void IncreaseEnvTab();
|
||||
|
||||
void ReadFile(const std::wstring & name, std::wstring & result);
|
||||
void ReadFile(const wchar_t * name, std::wstring & result);
|
||||
bool HasFileAtBeginning(const wchar_t * path, const wchar_t * file);
|
||||
bool IsFileCorrect(const wchar_t * name);
|
||||
bool ReadFileFromDir(const std::wstring & dir, const wchar_t * name, std::wstring & result);
|
||||
void ReadFile(std::ifstream & file, std::wstring & result);
|
||||
|
||||
int ReadCharInText();
|
||||
bool IsWhite(wchar_t c);
|
||||
void SkipWhite();
|
||||
void SkipOneStatement();
|
||||
void CheckWhiteAndDelete(std::wstring & s);
|
||||
void CheckFunctionIsNumber(Item::Function & function);
|
||||
|
||||
bool IsNameChar(wchar_t c);
|
||||
bool IsDigit(wchar_t c);
|
||||
bool IsPositiveNumber(const std::wstring & str);
|
||||
|
||||
bool ReadName(std::wstring & name);
|
||||
bool ReadFunctionName(std::wstring & name, std::wstring & postfix);
|
||||
bool ReadString(std::wstring & str);
|
||||
bool ReadParamString(Item::Function & function);
|
||||
bool ReadParams(Item::Function & function);
|
||||
void ReadFunctionFields(Item::Function & function);
|
||||
bool ReadFunction(Item::Function & function, bool with_params);
|
||||
bool ReadFunction(Item & item);
|
||||
|
||||
void ReadDirectiveIf(Item & item);
|
||||
void ReadDirectiveIfDef(Item & item);
|
||||
void ReadDirectiveIfNotDef(Item & item);
|
||||
void ReadDirectiveEnd(Item & item);
|
||||
void ReadDirectiveElse(Item & item);
|
||||
void ReadDirectiveFor(Item & item);
|
||||
void ReadDirectiveComment(Item & item);
|
||||
void ReadDirectiveInclude(Item & item);
|
||||
void ReadDirectiveDef(Item & item);
|
||||
void ReadDirectiveDefIfNotSet(Item & item);
|
||||
void ReadDirectiveLet(Item & item);
|
||||
void ReadDirectiveLetIfNotSet(Item & item);
|
||||
void ReadDirectiveFilter(Item & item);
|
||||
void ReadDirectiveEzc(Item & item);
|
||||
void ReadDirectiveFrame(Item & item);
|
||||
void ReadDirectiveBlock(Item & item);
|
||||
void ReadDirectiveReturn(Item & item);
|
||||
void ReadNormalStatement(Item & item);
|
||||
|
||||
bool CheckEnv(Item & item);
|
||||
bool CheckEnvIsYesParameter(Item & item);
|
||||
|
||||
void CreateTreeReadDirectiveExpression(Item & item, bool is_statement);
|
||||
bool CreateTreeCheckProgramDirective(Item & item);
|
||||
bool CreateTreeReadExpression(Item & item);
|
||||
|
||||
void CreateTreeReadItemDirectiveCheckEnding(Item & item);
|
||||
void CreateTreeReadItemDirective(Item & item);
|
||||
void CreateTreeReadItemText(Item & item);
|
||||
bool CreateTreeReadItem(Item & item);
|
||||
void CreateTreeReadIf(Item & item);
|
||||
void CreateTreeReadBlock(Item & item);
|
||||
void CreateTreeReadOneChild(Item & item);
|
||||
bool CreateTree(Item & item);
|
||||
void CreateTreeContainer(Item & item);
|
||||
void CreateTreeReadInclude(Item & item);
|
||||
void CreateTreeReadIncludeSkipAllowFlag(Item & item);
|
||||
|
||||
|
||||
}; // class PatternParser
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Ezc
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,108 +0,0 @@
|
||||
/*
|
||||
* This file is a part of EZC -- Easy templating in C++
|
||||
* and is distributed under the (new) BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007-2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name Tomasz Sowa nor the names of contributors to this
|
||||
* project may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "stringconv.h"
|
||||
|
||||
|
||||
|
||||
|
||||
namespace Ezc
|
||||
{
|
||||
|
||||
void AssignString(const char * src, std::wstring & dst, bool clear)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
if( clear )
|
||||
dst.clear();
|
||||
|
||||
for(len=0 ; src[len] ; ++len){}
|
||||
|
||||
if( dst.capacity() < dst.size() + len )
|
||||
dst.reserve(dst.size() + len + 128);
|
||||
|
||||
for( ; *src ; ++src )
|
||||
dst += static_cast<unsigned char>(*src);
|
||||
}
|
||||
|
||||
|
||||
void AssignString(const std::string & src, std::wstring & dst, bool clear)
|
||||
{
|
||||
if( clear )
|
||||
dst.clear();
|
||||
|
||||
if( dst.capacity() < dst.size() + src.size() )
|
||||
dst.reserve(dst.size() + src.size() + 128);
|
||||
|
||||
for(size_t i=0 ; i<src.size() ; ++i )
|
||||
dst += static_cast<unsigned char>(src[i]);
|
||||
}
|
||||
|
||||
|
||||
void AssignString(const wchar_t * src, std::string & dst, bool clear)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
if( clear )
|
||||
dst.clear();
|
||||
|
||||
for(len=0 ; src[len] ; ++len){}
|
||||
|
||||
if( dst.capacity() < dst.size() + len )
|
||||
dst.reserve(dst.size() + len + 128);
|
||||
|
||||
for( ; *src ; ++src )
|
||||
dst += static_cast<char>(*src);
|
||||
}
|
||||
|
||||
|
||||
void AssignString(const std::wstring & src, std::string & dst, bool clear)
|
||||
{
|
||||
if( clear )
|
||||
dst.clear();
|
||||
|
||||
if( dst.capacity() < dst.size() + src.size() )
|
||||
dst.reserve(dst.size() + src.size() + 128);
|
||||
|
||||
for(size_t i=0 ; i<src.size() ; ++i )
|
||||
dst += static_cast<char>(src[i]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Ezc
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* This file is a part of EZC -- Easy templating in C++
|
||||
* and is distributed under the (new) BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007-2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name Tomasz Sowa nor the names of contributors to this
|
||||
* project may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef headerfile_ezc_stringconv
|
||||
#define headerfile_ezc_stringconv
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
|
||||
namespace Ezc
|
||||
{
|
||||
|
||||
|
||||
void AssignString(const char * src, std::wstring & dst, bool clear = true);
|
||||
void AssignString(const std::string & src, std::wstring & dst, bool clear = true);
|
||||
void AssignString(const wchar_t * src, std::string & dst, bool clear = true);
|
||||
void AssignString(const std::wstring & src, std::string & dst, bool clear = true);
|
||||
|
||||
|
||||
|
||||
} // namespace Ezc
|
||||
|
||||
|
||||
#endif
|
||||
896
src/utf8.cpp
896
src/utf8.cpp
@@ -1,896 +0,0 @@
|
||||
/*
|
||||
* This file is a part of EZC -- Easy templating in C++
|
||||
* and is distributed under the (new) BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2011, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name Tomasz Sowa nor the names of contributors to this
|
||||
* project may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "utf8.h"
|
||||
|
||||
|
||||
namespace Ezc
|
||||
{
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
an auxiliary function for converting from UTF-8 string
|
||||
*/
|
||||
static bool UTF8ToInt_FirstOctet(unsigned char uz, size_t & len, int & res)
|
||||
{
|
||||
for(len=0 ; (uz & 0x80) != 0 ; ++len)
|
||||
uz <<= 1;
|
||||
|
||||
if( len == 1 )
|
||||
return false;
|
||||
|
||||
res = uz;
|
||||
|
||||
if( len > 0 )
|
||||
res >>= len;
|
||||
|
||||
if( res == 0 )
|
||||
return false;
|
||||
|
||||
if( len == 0 )
|
||||
len = 1;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
an auxiliary function for converting from UTF-8 string
|
||||
*/
|
||||
static bool UTF8ToInt_AddNextOctet(unsigned char uz, int & res)
|
||||
{
|
||||
if( (uz & 0xc0) != 0x80 )
|
||||
return false;
|
||||
|
||||
res <<= 6;
|
||||
res |= (uz & 0x3F);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
returns true if 'c' is a correct unicode character
|
||||
*/
|
||||
bool UTF8_CheckRange(int c)
|
||||
{
|
||||
return c>=0 && c<=0x10FFFF && !(c>=0xD800 && c<=0xDFFF);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
this function converts one UTF-8 character into one wide-character
|
||||
|
||||
input:
|
||||
utf8 - an input UTF-8 string
|
||||
utf8_len - size of the input string,
|
||||
the string should be at least 4 bytes length for correctly
|
||||
recognized the utf-8 sequence
|
||||
|
||||
output:
|
||||
res - an output character
|
||||
correct - true if it is a correct character
|
||||
|
||||
the function returns how many characters have been used from the input string
|
||||
(returns zero only if utf8_len is zero)
|
||||
even if there are errors the functions returns a different from zero value
|
||||
*/
|
||||
size_t UTF8ToInt(const char * utf8, size_t utf8_len, int & res, bool & correct)
|
||||
{
|
||||
size_t i, len;
|
||||
|
||||
res = 0;
|
||||
correct = false;
|
||||
|
||||
if( utf8_len == 0 )
|
||||
return 0;
|
||||
|
||||
if( !UTF8ToInt_FirstOctet(utf8[0], len, res) )
|
||||
return 1;
|
||||
|
||||
if( utf8_len < len )
|
||||
return utf8_len;
|
||||
|
||||
for(i=1 ; i<len ; ++i)
|
||||
if( !UTF8ToInt_AddNextOctet(utf8[i], res) )
|
||||
return i;
|
||||
|
||||
if( UTF8_CheckRange(res) )
|
||||
correct = true;
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
this function converts one UTF-8 character into one wide-character
|
||||
|
||||
input:
|
||||
utf8 - an input UTF-8 string (null terminated)
|
||||
|
||||
output:
|
||||
res - an output character
|
||||
correct - true if it is a correct character
|
||||
|
||||
the function returns how many characters have been used from the input string
|
||||
(returns zero only if the string has '\0' at the first character)
|
||||
even if there are errors the functions returns a different from zero value
|
||||
*/
|
||||
size_t UTF8ToInt(const char * utf8, int & res, bool & correct)
|
||||
{
|
||||
size_t i, len;
|
||||
|
||||
res = 0;
|
||||
correct = false;
|
||||
|
||||
if( *utf8 == 0 )
|
||||
return 0;
|
||||
|
||||
if( !UTF8ToInt_FirstOctet(utf8[0], len, res) )
|
||||
return 1;
|
||||
|
||||
for(i=1 ; i<len ; ++i)
|
||||
{
|
||||
if( utf8[i] == 0 )
|
||||
return i;
|
||||
|
||||
if( !UTF8ToInt_AddNextOctet(utf8[i], res) )
|
||||
return i;
|
||||
}
|
||||
|
||||
if( UTF8_CheckRange(res) )
|
||||
correct = true;
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
this function converts one UTF-8 character into one wide-character
|
||||
|
||||
input:
|
||||
utf8 - an input UTF-8 string
|
||||
|
||||
output:
|
||||
res - an output character
|
||||
correct - true if it is a correct character
|
||||
|
||||
the function returns how many characters have been used from the input string
|
||||
(returns zero only if utf8 is empty)
|
||||
even if there are errors the functions returns a different from zero value
|
||||
*/
|
||||
size_t UTF8ToInt(const std::string & utf8, int & res, bool & correct)
|
||||
{
|
||||
return UTF8ToInt(utf8.c_str(), utf8.size(), res, correct);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
this function converts one UTF-8 character into one wide-character
|
||||
|
||||
input:
|
||||
utf8 - an input UTF-8 stream
|
||||
|
||||
output:
|
||||
res - an output character
|
||||
correct - true if it is a correct character
|
||||
|
||||
the function returns how many characters have been used from the input stream
|
||||
*/
|
||||
size_t UTF8ToInt(std::istream & utf8, int & res, bool & correct)
|
||||
{
|
||||
size_t i, len;
|
||||
unsigned char uz;
|
||||
|
||||
res = 0;
|
||||
correct = false;
|
||||
|
||||
uz = utf8.get();
|
||||
|
||||
if( !utf8 )
|
||||
return 0;
|
||||
|
||||
if( !UTF8ToInt_FirstOctet(uz, len, res) )
|
||||
return 1;
|
||||
|
||||
for(i=1 ; i<len ; ++i)
|
||||
{
|
||||
uz = utf8.get();
|
||||
|
||||
if( !utf8 )
|
||||
return i;
|
||||
|
||||
if( !UTF8ToInt_AddNextOctet(uz, res) )
|
||||
return i;
|
||||
}
|
||||
|
||||
if( UTF8_CheckRange(res) )
|
||||
correct = true;
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
*/
|
||||
static void IntToWide(int c, std::wstring & res)
|
||||
{
|
||||
if( sizeof(wchar_t)==2 && c>0xffff )
|
||||
{
|
||||
c -= 0x10000;
|
||||
res += static_cast<wchar_t>(((c >> 10) & 0x3FF) + 0xD800);
|
||||
res += static_cast<wchar_t>((c & 0x3FF) + 0xDC00);
|
||||
}
|
||||
else
|
||||
{
|
||||
res += static_cast<wchar_t>(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
this function converts an utf8 string into wide string (std::wstring)
|
||||
|
||||
input:
|
||||
utf8 - an input utf8 string
|
||||
utf8_len - size of the input string
|
||||
mode - what to do with errors when converting
|
||||
0: skip an invalid character
|
||||
1: put U+FFFD "replacement character" istead of the invalid character (default)
|
||||
|
||||
output:
|
||||
res - an output wide string
|
||||
|
||||
the function returns false if there were some errors when converting
|
||||
*/
|
||||
bool UTF8ToWide(const char * utf8, size_t utf8_len, std::wstring & res, bool clear, int mode)
|
||||
{
|
||||
int z;
|
||||
size_t len;
|
||||
bool correct, was_error = false;
|
||||
|
||||
if( clear )
|
||||
res.clear();
|
||||
|
||||
while( utf8_len > 0 )
|
||||
{
|
||||
if( (unsigned char)*utf8 <= 0x7f )
|
||||
{
|
||||
// small optimization
|
||||
len = 1;
|
||||
correct = true;
|
||||
z = static_cast<unsigned char>(*utf8);
|
||||
}
|
||||
else
|
||||
{
|
||||
len = UTF8ToInt(utf8, utf8_len, z, correct); // the len will be different from zero
|
||||
}
|
||||
|
||||
if( !correct )
|
||||
{
|
||||
if( mode == 1 )
|
||||
res += 0xFFFD; // U+FFFD "replacement character"
|
||||
|
||||
was_error = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
IntToWide(z, res);
|
||||
}
|
||||
|
||||
utf8 += len;
|
||||
utf8_len -= len;
|
||||
}
|
||||
|
||||
return !was_error;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
this function converts an utf8 string into wide string (std::wstring)
|
||||
|
||||
input:
|
||||
utf8 - an input utf8 null terminated string
|
||||
mode - what to do with errors when converting
|
||||
0: skip an invalid character
|
||||
1: put U+FFFD "replacement character" istead of the invalid character (default)
|
||||
|
||||
output:
|
||||
res - an output wide string
|
||||
|
||||
the function returns false if there were some errors when converting
|
||||
*/
|
||||
bool UTF8ToWide(const char * utf8, std::wstring & res, bool clear, int mode)
|
||||
{
|
||||
size_t utf8_len = 0;
|
||||
|
||||
while( utf8[utf8_len] != 0 )
|
||||
utf8_len += 1;
|
||||
|
||||
return UTF8ToWide(utf8, utf8_len, res, clear, mode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
this function converts an utf8 string into wide string (std::wstring)
|
||||
|
||||
input:
|
||||
utf8 - an input utf8 string
|
||||
mode - what to do with errors when converting
|
||||
0: skip an invalid character
|
||||
1: put U+FFFD "replacement character" istead of the invalid character (default)
|
||||
|
||||
output:
|
||||
res - an output wide string
|
||||
|
||||
the function returns false if there were some errors when converting
|
||||
*/
|
||||
bool UTF8ToWide(const std::string & utf8, std::wstring & res, bool clear, int mode)
|
||||
{
|
||||
return UTF8ToWide(utf8.c_str(), utf8.size(), res, clear, mode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
this function converts an utf8 stream into wide string (std::wstring)
|
||||
|
||||
input:
|
||||
utf8 - an input utf8 stream
|
||||
mode - what to do with errors when converting
|
||||
0: skip an invalid character
|
||||
1: put U+FFFD "replacement character" istead of the invalid character (default)
|
||||
|
||||
output:
|
||||
res - an output wide string
|
||||
|
||||
the function returns false if there were some errors when converting
|
||||
*/
|
||||
bool UTF8ToWide(std::istream & utf8, std::wstring & res, bool clear, int mode)
|
||||
{
|
||||
int z;
|
||||
bool correct, was_error = false;
|
||||
|
||||
if( clear )
|
||||
res.clear();
|
||||
|
||||
while( UTF8ToInt(utf8, z, correct) > 0 )
|
||||
{
|
||||
if( !correct )
|
||||
{
|
||||
if( mode == 1 )
|
||||
res += 0xFFFD; // U+FFFD "replacement character"
|
||||
|
||||
was_error = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
IntToWide(z, res);
|
||||
}
|
||||
}
|
||||
|
||||
return !was_error;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
this function converts one wide character into UTF-8 sequence
|
||||
|
||||
input:
|
||||
z - wide character
|
||||
|
||||
output:
|
||||
utf8 - a buffer for the output sequence
|
||||
utf8_len - the size of the buffer
|
||||
|
||||
the function returns how many characters have been written to the utf8,
|
||||
zero means the utf8 buffer is too small or 'z' is an incorrect unicode character
|
||||
*/
|
||||
size_t IntToUTF8(int z, char * utf8, size_t utf8_max_len)
|
||||
{
|
||||
char buf[10];
|
||||
int i = 0;
|
||||
int mask = 0x3f; // 6 first bits set
|
||||
|
||||
if( utf8_max_len==0 || !UTF8_CheckRange(z) )
|
||||
return 0;
|
||||
|
||||
if( z <= 0x7f )
|
||||
{
|
||||
utf8[0] = static_cast<char>(z);
|
||||
return 1;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
buf[i] = 0x80 | (z & 0x3f);
|
||||
i += 1;
|
||||
z >>= 6;
|
||||
mask >>= 1;
|
||||
}
|
||||
while( (z & (~mask)) != 0 );
|
||||
|
||||
unsigned int first = -1;
|
||||
first <<= (7 - i);
|
||||
first |= (z & mask);
|
||||
|
||||
if( size_t(i+1) > utf8_max_len )
|
||||
return 0;
|
||||
|
||||
utf8[0] = static_cast<char>(first);
|
||||
|
||||
int a = 1;
|
||||
for(--i; i>=0 ; --i, ++a)
|
||||
utf8[a] = buf[i];
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
this function converts one wide character into UTF-8 string
|
||||
|
||||
input:
|
||||
z - wide character
|
||||
|
||||
output:
|
||||
utf8 - a UTF-8 string for the output sequence (the string is not cleared)
|
||||
|
||||
the function returns how many characters have been written to the utf8 string,
|
||||
zero means that 'z' is an incorrect unicode character
|
||||
*/
|
||||
size_t IntToUTF8(int z, std::string & utf8, bool clear)
|
||||
{
|
||||
char buf[10];
|
||||
|
||||
if( clear )
|
||||
utf8.clear();
|
||||
|
||||
size_t len = IntToUTF8(z, buf, sizeof(buf)/sizeof(char));
|
||||
size_t i;
|
||||
|
||||
for(i=0 ; i<len ; ++i)
|
||||
utf8 += buf[i];
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
this function converts one wide character into UTF-8 stream
|
||||
|
||||
input:
|
||||
z - wide character
|
||||
|
||||
output:
|
||||
utf8 - a UTF-8 stream for the output sequence
|
||||
|
||||
the function returns how many characters have been written to the utf8 stream,
|
||||
zero means that 'z' is an incorrect unicode character
|
||||
*/
|
||||
size_t IntToUTF8(int z, std::ostream & utf8)
|
||||
{
|
||||
char buf[10];
|
||||
|
||||
size_t len = IntToUTF8(z, buf, sizeof(buf)/sizeof(char));
|
||||
size_t i;
|
||||
|
||||
for(i=0 ; i<len ; ++i)
|
||||
utf8 << buf[i];
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
an auxiliary function for converting from wide characters to UTF-8
|
||||
converting a wide character into one int
|
||||
|
||||
returns how many wide characters were used
|
||||
if string_len is greater than 0 then the return value is always greater than zero too
|
||||
*/
|
||||
static size_t WideToInt(const wchar_t * wide_string, size_t string_len, int & z, bool & correct)
|
||||
{
|
||||
if( string_len == 0 )
|
||||
{
|
||||
z = 0;
|
||||
correct = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
z = static_cast<int>(*wide_string);
|
||||
correct = true;
|
||||
|
||||
if( sizeof(wchar_t) == 2 && (z>=0xD800 && z<=0xDFFF) )
|
||||
{
|
||||
if( z>=0xD800 && z<=0xDBFF && string_len>1 )
|
||||
{
|
||||
int z2 = *(wide_string+1);
|
||||
|
||||
if( z2>=0xDC00 && z2<=0xDFFF )
|
||||
{
|
||||
z = 0x10000 + (((z & 0x3FF) << 10) | (z2 & 0x3FF));
|
||||
return 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
correct = false;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
correct = false;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
an auxiliary function for converting from wide characters to UTF-8
|
||||
converting a wide character into one int
|
||||
|
||||
returns how many wide characters were used
|
||||
if wide_string has at least one character then the return value is always greater than zero too
|
||||
*/
|
||||
static size_t WideToInt(const wchar_t * wide_string, int & z, bool & correct)
|
||||
{
|
||||
size_t min_str_len = 1;
|
||||
|
||||
if( *wide_string == 0 )
|
||||
{
|
||||
z = 0;
|
||||
correct = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( *(wide_string+1) != 0 )
|
||||
min_str_len = 2;
|
||||
|
||||
return WideToInt(wide_string, min_str_len, z, correct);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
an auxiliary function for converting from wide characters to UTF-8
|
||||
|
||||
returns how many wide characters were used
|
||||
if string_len is greater than 0 then the return value is always greater than zero too
|
||||
*/
|
||||
static size_t WideOneToUTF8(const wchar_t * wide_string, size_t string_len, std::string & utf8, bool & was_error, int mode)
|
||||
{
|
||||
int z;
|
||||
bool correct;
|
||||
size_t chars;
|
||||
|
||||
chars = WideToInt(wide_string, string_len, z, correct);
|
||||
|
||||
if( correct )
|
||||
correct = IntToUTF8(z, utf8, false) != 0;
|
||||
|
||||
if( !correct )
|
||||
{
|
||||
if( mode == 1 )
|
||||
IntToUTF8(0xFFFD, utf8, false); // U+FFFD "replacement character"
|
||||
|
||||
was_error = true;
|
||||
}
|
||||
|
||||
return chars;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
an auxiliary function for converting from wide characters to UTF-8
|
||||
|
||||
returns how many wide characters were used
|
||||
if wide_string has at least one character then the return value is always greater than zero too
|
||||
*/
|
||||
static size_t WideOneToUTF8(const wchar_t * wide_string, std::string & utf8, bool & was_error, int mode)
|
||||
{
|
||||
int z;
|
||||
bool correct;
|
||||
size_t chars;
|
||||
|
||||
chars = WideToInt(wide_string, z, correct);
|
||||
|
||||
if( correct )
|
||||
correct = IntToUTF8(z, utf8, false) != 0;
|
||||
|
||||
if( !correct )
|
||||
{
|
||||
if( mode == 1 )
|
||||
IntToUTF8(0xFFFD, utf8, false); // U+FFFD "replacement character"
|
||||
|
||||
was_error = true;
|
||||
}
|
||||
|
||||
return chars;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
an auxiliary function for converting from wide characters to UTF-8
|
||||
|
||||
returns how many wide characters were used
|
||||
if string_len is greater than 0 then the return value is always greater than zero too
|
||||
*/
|
||||
static size_t WideOneToUTF8(const wchar_t * wide_string, size_t string_len, std::ostream & utf8, bool & was_error, int mode)
|
||||
{
|
||||
int z;
|
||||
bool correct;
|
||||
size_t chars;
|
||||
|
||||
chars = WideToInt(wide_string, string_len, z, correct);
|
||||
|
||||
if( correct )
|
||||
correct = IntToUTF8(z, utf8) != 0;
|
||||
|
||||
if( !correct )
|
||||
{
|
||||
if( mode == 1 )
|
||||
IntToUTF8(0xFFFD, utf8); // U+FFFD "replacement character"
|
||||
|
||||
was_error = true;
|
||||
}
|
||||
|
||||
return chars;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
an auxiliary function for converting from wide characters to UTF-8
|
||||
*/
|
||||
static size_t WideOneToUTF8(const wchar_t * wide_string, std::ostream & utf8, bool & was_error, int mode)
|
||||
{
|
||||
size_t min_str_len = 1;
|
||||
|
||||
if( *wide_string == 0 )
|
||||
return 0;
|
||||
|
||||
if( *(wide_string+1) != 0 )
|
||||
min_str_len = 2;
|
||||
|
||||
return WideOneToUTF8(wide_string, min_str_len, utf8, was_error, mode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
this function converts a wide string into UTF-8 string
|
||||
|
||||
input:
|
||||
wide_string - a wide string for converting
|
||||
string_len - the size of the string
|
||||
mode - what to do with errors when converting
|
||||
0: skip an invalid character
|
||||
1: put U+FFFD "replacement character" istead of the invalid character (default)
|
||||
|
||||
output:
|
||||
utf8 - a UTF-8 string for the output sequence (the string is not cleared)
|
||||
|
||||
this function returns false if there were some errors when converting
|
||||
*/
|
||||
bool WideToUTF8(const wchar_t * wide_string, size_t string_len, std::string & utf8, bool clear, int mode)
|
||||
{
|
||||
bool was_error = false;
|
||||
size_t chars;
|
||||
|
||||
if( clear )
|
||||
utf8.clear();
|
||||
|
||||
while( string_len > 0 )
|
||||
{
|
||||
chars = WideOneToUTF8(wide_string, string_len, utf8, was_error, mode);
|
||||
wide_string += chars;
|
||||
string_len -= chars;
|
||||
}
|
||||
|
||||
return !was_error;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
this function converts a wide string into UTF-8 string
|
||||
|
||||
input:
|
||||
wide_string - a null terminated wide string for converting
|
||||
mode - what to do with errors when converting
|
||||
0: skip an invalid character
|
||||
1: put U+FFFD "replacement character" istead of the invalid character (default)
|
||||
|
||||
output:
|
||||
utf8 - a UTF-8 string for the output sequence (the string is not cleared)
|
||||
|
||||
this function returns false if there were some errors when converting
|
||||
*/
|
||||
bool WideToUTF8(const wchar_t * wide_string, std::string & utf8, bool clear, int mode)
|
||||
{
|
||||
bool was_error = false;
|
||||
|
||||
if( clear )
|
||||
utf8.clear();
|
||||
|
||||
while( *wide_string )
|
||||
wide_string += WideOneToUTF8(wide_string, utf8, was_error, mode);
|
||||
|
||||
return !was_error;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
this function converts a wide string (std::wstring) into UTF-8 string
|
||||
|
||||
input:
|
||||
wide_string - a wide string for converting
|
||||
mode - what to do with errors when converting
|
||||
0: skip an invalid character
|
||||
1: put U+FFFD "replacement character" istead of the invalid character (default)
|
||||
|
||||
output:
|
||||
utf8 - a UTF-8 string for the output sequence (the string is not cleared)
|
||||
|
||||
this function returns false if there were some errors when converting
|
||||
*/
|
||||
bool WideToUTF8(const std::wstring & wide_string, std::string & utf8, bool clear, int mode)
|
||||
{
|
||||
return WideToUTF8(wide_string.c_str(), wide_string.size(), utf8, clear, mode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
this function converts a wide string into UTF-8 stream
|
||||
|
||||
input:
|
||||
wide_string - a wide string for converting
|
||||
string_len - size of the string
|
||||
mode - what to do with errors when converting
|
||||
0: skip an invalid character
|
||||
1: put U+FFFD "replacement character" istead of the invalid character (default)
|
||||
|
||||
output:
|
||||
utf8 - a UTF-8 stream for the output sequence
|
||||
|
||||
this function returns false if there were some errors when converting
|
||||
*/
|
||||
bool WideToUTF8(const wchar_t * wide_string, size_t string_len, std::ostream & utf8, int mode)
|
||||
{
|
||||
bool was_error = false;
|
||||
size_t chars;
|
||||
|
||||
while( string_len > 0 )
|
||||
{
|
||||
chars = WideOneToUTF8(wide_string, string_len, utf8, was_error, mode);
|
||||
wide_string += chars;
|
||||
string_len -= chars;
|
||||
}
|
||||
|
||||
return !was_error;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
this function converts a wide string into UTF-8 stream
|
||||
|
||||
input:
|
||||
wide_string - a null terminated wide string for converting
|
||||
mode - what to do with errors when converting
|
||||
0: skip an invalid character
|
||||
1: put U+FFFD "replacement character" istead of the invalid character (default)
|
||||
|
||||
output:
|
||||
utf8 - a UTF-8 stream for the output sequence
|
||||
|
||||
this function returns false if there were some errors when converting
|
||||
*/
|
||||
bool WideToUTF8(const wchar_t * wide_string, std::ostream & utf8, int mode)
|
||||
{
|
||||
bool was_error = false;
|
||||
|
||||
while( *wide_string )
|
||||
wide_string += WideOneToUTF8(wide_string, utf8, was_error, mode);
|
||||
|
||||
return !was_error;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
this function converts a wide string (std::wstring) into UTF-8 stream
|
||||
|
||||
input:
|
||||
wide_string - a wide string for converting
|
||||
mode - what to do with errors when converting
|
||||
0: skip an invalid character
|
||||
1: put U+FFFD "replacement character" istead of the invalid character (default)
|
||||
|
||||
output:
|
||||
utf8 - a UTF-8 stream for the output sequence
|
||||
|
||||
this function returns false if there were some errors when converting
|
||||
*/
|
||||
bool WideToUTF8(const std::wstring & wide_string, std::ostream & utf8, int mode)
|
||||
{
|
||||
return WideToUTF8(wide_string.c_str(), wide_string.size(), utf8, mode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Ezc
|
||||
|
||||
|
||||
|
||||
111
src/utf8.h
111
src/utf8.h
@@ -1,111 +0,0 @@
|
||||
/*
|
||||
* This file is a part of EZC -- Easy templating in C++
|
||||
* and is distributed under the (new) BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2011, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name Tomasz Sowa nor the names of contributors to this
|
||||
* project may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef headerfile_ezc_utf8
|
||||
#define headerfile_ezc_utf8
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace Ezc
|
||||
{
|
||||
|
||||
/*!
|
||||
UTF-8, a transformation format of ISO 10646
|
||||
http://tools.ietf.org/html/rfc3629
|
||||
|
||||
when wchar_t is 4 bytes length we use UTF-32
|
||||
when wchar_t is 2 bytes length we use UTF-16 (with surrogate pairs)
|
||||
|
||||
UTF-16
|
||||
http://www.ietf.org/rfc/rfc2781.txt
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
returns true if 'c' is a correct unicode character
|
||||
*/
|
||||
bool UTF8_CheckRange(int c);
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
converting one character from UTF-8 to an int
|
||||
*/
|
||||
size_t UTF8ToInt(const char * utf8, size_t utf8_len, int & res, bool & correct);
|
||||
size_t UTF8ToInt(const char * utf8, int & res, bool & correct);
|
||||
size_t UTF8ToInt(const std::string & utf8, int & res, bool & correct);
|
||||
size_t UTF8ToInt(std::istream & utf8, int & res, bool & correct);
|
||||
|
||||
|
||||
/*!
|
||||
converting UTF-8 string to a wide string
|
||||
*/
|
||||
bool UTF8ToWide(const char * utf8, size_t utf8_len, std::wstring & res, bool clear = true, int mode = 1);
|
||||
bool UTF8ToWide(const char * utf8, std::wstring & res, bool clear = true, int mode = 1);
|
||||
bool UTF8ToWide(const std::string & utf8, std::wstring & res, bool clear = true, int mode = 1);
|
||||
bool UTF8ToWide(std::istream & utf8, std::wstring & res, bool clear = true, int mode = 1);
|
||||
|
||||
|
||||
/*!
|
||||
converting one int character to UTF-8
|
||||
*/
|
||||
size_t IntToUTF8(int z, char * utf8, size_t utf8_max_len);
|
||||
size_t IntToUTF8(int z, std::string & utf8, bool clear = true );
|
||||
size_t IntToUTF8(int z, std::ostream & utf8);
|
||||
|
||||
|
||||
/*!
|
||||
converting a wide string to UTF-8 string
|
||||
*/
|
||||
bool WideToUTF8(const wchar_t * wide_string, size_t string_len, std::string & utf8, bool clear = true, int mode = 1);
|
||||
bool WideToUTF8(const wchar_t * wide_string, std::string & utf8, bool clear = true, int mode = 1);
|
||||
bool WideToUTF8(const std::wstring & wide_string, std::string & utf8, bool clear = true, int mode = 1);
|
||||
bool WideToUTF8(const wchar_t * wide_string, size_t string_len, std::ostream & utf8, int mode = 1);
|
||||
bool WideToUTF8(const wchar_t * wide_string, std::ostream & utf8, int mode = 1);
|
||||
bool WideToUTF8(const std::wstring & wide_string, std::ostream & utf8, int mode = 1);
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Ezc
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
44
src/version.h
Normal file
44
src/version.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* This file is a part of EZC -- Easy templating in C++ library
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2022, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_ezc_version
|
||||
#define headerfile_ezc_version
|
||||
|
||||
|
||||
#define EZC_VERSION_MAJOR 0
|
||||
#define EZC_VERSION_MINOR 9
|
||||
#define EZC_VERSION_PATCH 5
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user