Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
62a094f2c6
|
||
|
|
b646287c9b
|
||
|
|
44ea6a162e
|
||
|
|
32d9fdc816 | ||
|
|
1f2b5c8d12
|
||
|
|
37f78ad8e0
|
||
|
|
8819adbb3f
|
||
|
|
19d33139fc
|
||
|
|
ec45ae971e
|
||
|
|
dc2ee61a23
|
||
|
|
345e1870e3
|
||
|
|
6f75664400
|
||
|
|
0ac4df97e9
|
||
|
|
6e2fe34a5c
|
||
|
|
079a62c230
|
||
|
|
5d5d5bcdde
|
||
|
|
e39311c290
|
||
|
|
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 | ||
|
|
c6b4db0aa9 | ||
|
|
b4f7d4b8de | ||
|
|
542587e5e8 | ||
|
|
fb05eb6860 | ||
|
|
8df9aa86a0 | ||
|
|
2d304a9714 | ||
|
|
861269383e | ||
|
|
542e50d757 | ||
|
|
3c85fa1a75 | ||
|
|
fd2194623a | ||
|
|
c4f5f79218 | ||
|
|
0b09b5454f | ||
|
|
5108495540 | ||
|
|
33c86d494b | ||
|
|
8f94937ed1 | ||
|
|
b5ea2514e2 | ||
|
|
376fe414f8 | ||
|
|
7554630395 | ||
|
|
573d241dc1 | ||
|
|
c807d1c9b3 | ||
|
|
b89c6daa7d | ||
|
|
f65178dd0e | ||
|
|
bb00f23f29 | ||
|
|
31156d33f3 | ||
|
|
e71c213ad1 | ||
|
|
b2aacc2da3 | ||
|
|
dbe91a6d91 | ||
|
|
9b4586d7be | ||
|
|
141e1f67b3 | ||
|
|
f8f55eae77 | ||
|
|
0b88257e08 | ||
|
|
0760313ec3 | ||
|
|
54be9c0489 | ||
|
|
bf585d3716 |
@@ -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
|
||||
@@ -0,0 +1,8 @@
|
||||
.cproject
|
||||
.project
|
||||
.settings/
|
||||
*.o
|
||||
*.a
|
||||
/.clangd
|
||||
/.qtcreator/
|
||||
/.qtc_clangd/
|
||||
@@ -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, -DMORM_HAS_EZC_LIBRARY]
|
||||
@@ -0,0 +1 @@
|
||||
-std=c20
|
||||
@@ -0,0 +1 @@
|
||||
#define EZC_HAS_MORM_LIBRARY 1
|
||||
@@ -0,0 +1 @@
|
||||
[General]
|
||||
@@ -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>
|
||||
@@ -0,0 +1 @@
|
||||
-std=c++20
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
Executable
+30
@@ -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
|
||||
|
||||
|
||||
Executable
+99
@@ -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
|
||||
|
||||
|
||||
+10
-14
@@ -1,28 +1,24 @@
|
||||
Copyright (c) 2007, 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.
|
||||
@@ -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:
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
sourcefiles:=$(shell find . -name "*.cpp")
|
||||
objfiles:=$(patsubst %.cpp,%.o,$(sourcefiles))
|
||||
|
||||
|
||||
|
||||
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) -o $@ $<
|
||||
|
||||
|
||||
clean:
|
||||
rm -f $(objfiles)
|
||||
rm -f $(libname)
|
||||
|
||||
|
||||
depend:
|
||||
makedepend -w 10 -Y. -I../../pikotools/src -f- $(sourcefiles) | sort -u > Makefile.dep
|
||||
|
||||
|
||||
-include Makefile.dep
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
|
||||
./blocks.o: ../../pikotools/src/convert/inttostr.h
|
||||
./blocks.o: ../../pikotools/src/convert/misc.h
|
||||
./blocks.o: ../../pikotools/src/date/date.h
|
||||
./blocks.o: ../../pikotools/src/membuffer/membuffer.h
|
||||
./blocks.o: ../../pikotools/src/space/space.h
|
||||
./blocks.o: ../../pikotools/src/textstream/stream_private.h
|
||||
./blocks.o: ../../pikotools/src/textstream/stream.h
|
||||
./blocks.o: ../../pikotools/src/textstream/textstream.h
|
||||
./blocks.o: ../../pikotools/src/textstream/types.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
|
||||
./blocks.o: val.h
|
||||
./cache.o: ../../pikotools/src/convert/inttostr.h
|
||||
./cache.o: ../../pikotools/src/convert/misc.h
|
||||
./cache.o: ../../pikotools/src/date/date.h
|
||||
./cache.o: ../../pikotools/src/membuffer/membuffer.h
|
||||
./cache.o: ../../pikotools/src/space/space.h
|
||||
./cache.o: ../../pikotools/src/textstream/stream_private.h
|
||||
./cache.o: ../../pikotools/src/textstream/stream.h
|
||||
./cache.o: ../../pikotools/src/textstream/textstream.h
|
||||
./cache.o: ../../pikotools/src/textstream/types.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
|
||||
./cache.o: val.h
|
||||
./functions.o: ../../pikotools/src/convert/inttostr.h
|
||||
./functions.o: ../../pikotools/src/convert/misc.h
|
||||
./functions.o: ../../pikotools/src/date/date.h
|
||||
./functions.o: ../../pikotools/src/membuffer/membuffer.h
|
||||
./functions.o: ../../pikotools/src/space/space.h
|
||||
./functions.o: ../../pikotools/src/textstream/stream_private.h
|
||||
./functions.o: ../../pikotools/src/textstream/stream.h
|
||||
./functions.o: ../../pikotools/src/textstream/textstream.h
|
||||
./functions.o: ../../pikotools/src/textstream/types.h
|
||||
./functions.o: ../../pikotools/src/utf8/utf8.h
|
||||
./functions.o: env.h
|
||||
./functions.o: functions.h
|
||||
./functions.o: item.h
|
||||
./functions.o: val.h
|
||||
./item.o: item.h
|
||||
./models.o: models.h
|
||||
./objects.o: ../../pikotools/src/convert/inttostr.h
|
||||
./objects.o: ../../pikotools/src/convert/misc.h
|
||||
./objects.o: ../../pikotools/src/date/date.h
|
||||
./objects.o: ../../pikotools/src/membuffer/membuffer.h
|
||||
./objects.o: ../../pikotools/src/space/space.h
|
||||
./objects.o: ../../pikotools/src/textstream/stream_private.h
|
||||
./objects.o: ../../pikotools/src/textstream/stream.h
|
||||
./objects.o: ../../pikotools/src/textstream/textstream.h
|
||||
./objects.o: ../../pikotools/src/textstream/types.h
|
||||
./objects.o: ../../pikotools/src/utf8/utf8.h
|
||||
./objects.o: env.h
|
||||
./objects.o: item.h
|
||||
./objects.o: objects.h
|
||||
./objects.o: val.h
|
||||
./pattern.o: ../../pikotools/src/convert/inttostr.h
|
||||
./pattern.o: ../../pikotools/src/convert/misc.h
|
||||
./pattern.o: ../../pikotools/src/date/date.h
|
||||
./pattern.o: ../../pikotools/src/membuffer/membuffer.h
|
||||
./pattern.o: ../../pikotools/src/space/space.h
|
||||
./pattern.o: ../../pikotools/src/textstream/stream_private.h
|
||||
./pattern.o: ../../pikotools/src/textstream/stream.h
|
||||
./pattern.o: ../../pikotools/src/textstream/textstream.h
|
||||
./pattern.o: ../../pikotools/src/textstream/types.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
|
||||
./pattern.o: val.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
|
||||
./patternparser.o: val.h
|
||||
./val.o: ../../pikotools/src/convert/inttostr.h
|
||||
./val.o: ../../pikotools/src/convert/misc.h
|
||||
./val.o: ../../pikotools/src/date/date.h
|
||||
./val.o: ../../pikotools/src/membuffer/membuffer.h
|
||||
./val.o: ../../pikotools/src/space/space.h
|
||||
./val.o: ../../pikotools/src/textstream/stream_private.h
|
||||
./val.o: ../../pikotools/src/textstream/stream.h
|
||||
./val.o: ../../pikotools/src/textstream/textstream.h
|
||||
./val.o: ../../pikotools/src/textstream/types.h
|
||||
./val.o: ../../pikotools/src/utf8/utf8.h
|
||||
./val.o: item.h
|
||||
./val.o: val.h
|
||||
./valwrapper.o: ../../pikotools/src/convert/inttostr.h
|
||||
./valwrapper.o: ../../pikotools/src/convert/misc.h
|
||||
./valwrapper.o: ../../pikotools/src/date/date.h
|
||||
./valwrapper.o: ../../pikotools/src/membuffer/membuffer.h
|
||||
./valwrapper.o: ../../pikotools/src/space/space.h
|
||||
./valwrapper.o: ../../pikotools/src/textstream/stream_private.h
|
||||
./valwrapper.o: ../../pikotools/src/textstream/stream.h
|
||||
./valwrapper.o: ../../pikotools/src/textstream/textstream.h
|
||||
./valwrapper.o: ../../pikotools/src/textstream/types.h
|
||||
./valwrapper.o: ../../pikotools/src/utf8/utf8.h
|
||||
./valwrapper.o: item.h
|
||||
./valwrapper.o: val.h
|
||||
./valwrapper.o: valwrapper.h
|
||||
# DO NOT DELETE
|
||||
+117
@@ -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
|
||||
@@ -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
@@ -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
@@ -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
|
||||
@@ -0,0 +1,317 @@
|
||||
/*
|
||||
* 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 "val.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;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct Env
|
||||
{
|
||||
// a result consists of a string and a boolean value
|
||||
// output stream
|
||||
pt::Stream & out; // OLD INTERFACE a reference to res.stream
|
||||
|
||||
// table of parameters
|
||||
// the table can be empty
|
||||
std::vector<Val> & params;
|
||||
|
||||
// output
|
||||
Val & res;
|
||||
|
||||
//
|
||||
// old interface but still available
|
||||
//
|
||||
|
||||
// return value from a user's function (default false if not set directly by the function)
|
||||
//bool res;
|
||||
|
||||
// old interface DEPRECATED
|
||||
|
||||
// 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<Val> & pars,
|
||||
Val & res,
|
||||
const pt::Stream & input_stream,
|
||||
Stack & s,
|
||||
const Item & item_) : out(o), params(pars), res(res), in(input_stream), stack(s), item(item_)
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
void Clear()
|
||||
{
|
||||
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;
|
||||
res.clear();
|
||||
}
|
||||
|
||||
/*
|
||||
* 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
|
||||
@@ -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
|
||||
-982
@@ -1,982 +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@slimaczek.pl>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007, 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 "ezc.h"
|
||||
|
||||
namespace Ezc
|
||||
{
|
||||
|
||||
|
||||
std::string CreateMsg(const char * type, const char * arg)
|
||||
{
|
||||
std::ostringstream buffer;
|
||||
|
||||
buffer << "<!-- ezc: " << type << " ";
|
||||
|
||||
if( arg )
|
||||
buffer << arg << " ";
|
||||
|
||||
buffer << "-->";
|
||||
|
||||
return buffer.str();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
this method splits the input file name into a directory and a file name
|
||||
e.g
|
||||
if 'name' is "/this/is/dummy/file.ezc"
|
||||
the result will be:
|
||||
dir = "/this/is/dummy"
|
||||
file = "file.ezc"
|
||||
*/
|
||||
void SplitUnixDirectory(const char * name, std::string & dir, std::string & file)
|
||||
{
|
||||
dir.clear();
|
||||
file.clear();
|
||||
|
||||
int i;
|
||||
for( i=0 ; name[i] != 0 ; ++i );
|
||||
|
||||
if( i == 0 )
|
||||
return;
|
||||
|
||||
for( --i ; i>=0 && name[i]!='\\' && name[i]!='/' ; --i );
|
||||
|
||||
if( i < 0 )
|
||||
{
|
||||
file.assign(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
if( i == 0 )
|
||||
// we're leaving one '/' in the directory
|
||||
// (we have only the root directory)
|
||||
dir.assign(name, 1);
|
||||
else
|
||||
dir.assign(name, i);
|
||||
|
||||
file.assign(name + i + 1 );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void SplitUnixDirectory(const std::string & name, std::string & dir, std::string & file)
|
||||
{
|
||||
SplitUnixDirectory(name.c_str(), dir, file);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Pattern
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
void Pattern::ParseFile(const std::string & file_name)
|
||||
{
|
||||
ParseFile( file_name.c_str() );
|
||||
}
|
||||
|
||||
void Pattern::ParseFile(const char * file_name)
|
||||
{
|
||||
std::string file;
|
||||
|
||||
if( directory.empty() )
|
||||
SplitUnixDirectory(file_name, directory, file);
|
||||
else
|
||||
file = file_name;
|
||||
|
||||
file.insert(file.begin(), '\"');
|
||||
|
||||
item_root.directives.clear();
|
||||
item_root.directives.push_back( file );
|
||||
|
||||
CreateTreeReadInclude(item_root);
|
||||
}
|
||||
|
||||
|
||||
void Pattern::Directory(const char * d)
|
||||
{
|
||||
directory = d;
|
||||
}
|
||||
|
||||
void Pattern::Directory(const std::string & d)
|
||||
{
|
||||
directory = d;
|
||||
}
|
||||
|
||||
|
||||
bool Pattern::CheckFileName(const char * name)
|
||||
{
|
||||
// very simple testing -- this path 'some..name' is incorrect as well
|
||||
// (in the future it can be changed)
|
||||
|
||||
for( ; *name ; ++name )
|
||||
{
|
||||
if( *name=='.' && *(name+1)=='.' )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
'name' must be a relative path
|
||||
*/
|
||||
std::string Pattern::ReadFile(const char * name)
|
||||
{
|
||||
// for security reason we can't open a file which has two dots
|
||||
// somewhere in its name '..'
|
||||
if( !CheckFileName(name) )
|
||||
return CreateMsg("incorrect file name:", name);
|
||||
|
||||
std::string file_name(directory);
|
||||
|
||||
if( !file_name.empty() )
|
||||
file_name += '/';
|
||||
|
||||
file_name += name;
|
||||
|
||||
std::ifstream file(file_name.c_str());
|
||||
|
||||
if( !file )
|
||||
return CreateMsg("can't open:", name);
|
||||
// or we can give the whole path here (file_name)
|
||||
else
|
||||
{
|
||||
std::string result;
|
||||
std::getline(file, result, '\0');
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int Pattern::ReadCharInText()
|
||||
{
|
||||
if( *itext==0 || *itext=='[' )
|
||||
return -1;
|
||||
|
||||
if( *itext == '\\' )
|
||||
{
|
||||
if( *(itext+1)=='\\' || *(itext+1)=='[' || *(itext+1)==']' )
|
||||
++itext;
|
||||
}
|
||||
|
||||
return *(itext++);
|
||||
}
|
||||
|
||||
|
||||
void Pattern::SkipWhiteCharacters()
|
||||
{
|
||||
while( *itext==' ' || *itext=='\t' )
|
||||
++itext;
|
||||
}
|
||||
|
||||
|
||||
std::string Pattern::ReadDirective()
|
||||
{
|
||||
std::string directive;
|
||||
|
||||
SkipWhiteCharacters();
|
||||
|
||||
while( (*itext>='a' && *itext<='z') ||
|
||||
(*itext>='A' && *itext<='Z') ||
|
||||
(*itext>='0' && *itext<='9') ||
|
||||
*itext=='_' || *itext=='-' || *itext=='.' || *itext=='#' )
|
||||
{
|
||||
directive += *itext;
|
||||
|
||||
++itext;
|
||||
}
|
||||
|
||||
return directive;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string Pattern::ReadString()
|
||||
{
|
||||
std::string directive;
|
||||
|
||||
SkipWhiteCharacters();
|
||||
|
||||
if( *itext != '\"' )
|
||||
return directive;
|
||||
|
||||
// string is signed by its first character equal (")
|
||||
directive += '\"';
|
||||
|
||||
for( ++itext ; *itext && *itext!='\"' && *itext!='\n' ; ++itext )
|
||||
directive += *itext;
|
||||
|
||||
if( *itext != '\"' )
|
||||
// the second quotation mark (") is missing
|
||||
directive.clear();
|
||||
else
|
||||
++itext;
|
||||
|
||||
// the second quotation mark (") we don't add into the 'directive'
|
||||
|
||||
return directive;
|
||||
}
|
||||
|
||||
|
||||
std::string Pattern::ReadDirectiveOrString()
|
||||
{
|
||||
SkipWhiteCharacters();
|
||||
|
||||
if( *itext == '\"' )
|
||||
{
|
||||
// we've got string
|
||||
return ReadString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return ReadDirective();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Pattern::CreateTreeReadItemDirectiveCheckEnding(Item & item)
|
||||
{
|
||||
SkipWhiteCharacters();
|
||||
|
||||
if( *itext != ']' )
|
||||
{
|
||||
item.type = Item::item_err;
|
||||
|
||||
while( *itext!=0 && *itext!=']' )
|
||||
++itext;
|
||||
}
|
||||
|
||||
if( *itext == ']' )
|
||||
++itext;
|
||||
}
|
||||
|
||||
|
||||
void Pattern::ReadDirectiveIfany(Item & item)
|
||||
{
|
||||
item.type = Item::item_ifany;
|
||||
|
||||
while( true )
|
||||
{
|
||||
std::string directive = ReadDirective();
|
||||
|
||||
if( directive.empty() )
|
||||
break;
|
||||
|
||||
item.directives.push_back(directive);
|
||||
}
|
||||
|
||||
if( item.directives.empty() )
|
||||
item.type = Item::item_err;
|
||||
}
|
||||
|
||||
|
||||
void Pattern::ReadDirectiveIfone(Item & item)
|
||||
{
|
||||
ReadDirectiveIfany(item);
|
||||
|
||||
if( item.type == Item::item_ifany )
|
||||
item.type = Item::item_ifone;
|
||||
}
|
||||
|
||||
|
||||
void Pattern::ReadDirectiveIs(Item & item)
|
||||
{
|
||||
item.type = Item::item_is;
|
||||
std::string directive = ReadDirective();
|
||||
|
||||
if( !directive.empty() )
|
||||
{
|
||||
item.directives.push_back(directive);
|
||||
|
||||
directive = ReadDirectiveOrString();
|
||||
|
||||
if( !directive.empty() )
|
||||
item.directives.push_back(directive);
|
||||
}
|
||||
|
||||
if( item.directives.size() != 2 )
|
||||
item.type = Item::item_err;
|
||||
}
|
||||
|
||||
|
||||
void Pattern::ReadDirectiveIfindex(Item & item)
|
||||
{
|
||||
item.type = Item::item_ifindex;
|
||||
std::string directive = ReadDirective();
|
||||
|
||||
if( !directive.empty() )
|
||||
{
|
||||
item.directives.push_back(directive);
|
||||
|
||||
directive = ReadDirective();
|
||||
|
||||
if( !directive.empty() )
|
||||
item.directives.push_back(directive);
|
||||
}
|
||||
|
||||
if( item.directives.size() != 2 )
|
||||
item.type = Item::item_err;
|
||||
}
|
||||
|
||||
|
||||
void Pattern::ReadDirectiveFor(Item & item)
|
||||
{
|
||||
item.type = Item::item_for;
|
||||
std::string directive = ReadDirective();
|
||||
|
||||
if( !directive.empty() )
|
||||
item.directives.push_back(directive);
|
||||
else
|
||||
item.type = Item::item_err;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Pattern::ReadDirectiveComment(Item & item)
|
||||
{
|
||||
item.type = Item::item_comment;
|
||||
|
||||
while( *itext && *itext!=']' && *itext!='\n' )
|
||||
++itext;
|
||||
}
|
||||
|
||||
|
||||
void Pattern::ReadDirectiveInclude(Item & item)
|
||||
{
|
||||
item.type = Item::item_include;
|
||||
std::string directive = ReadString();
|
||||
|
||||
if( !directive.empty() )
|
||||
item.directives.push_back(directive);
|
||||
else
|
||||
item.type = Item::item_err;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Pattern::CreateTreeReadItemDirective(Item & item)
|
||||
{
|
||||
++itext;
|
||||
|
||||
std::string directive = ReadDirective();
|
||||
|
||||
if( directive == "if-any" )
|
||||
ReadDirectiveIfany(item);
|
||||
else
|
||||
if( directive == "if-one" )
|
||||
ReadDirectiveIfone(item);
|
||||
else
|
||||
if( directive == "is" )
|
||||
ReadDirectiveIs(item);
|
||||
else
|
||||
if( directive == "if-index" )
|
||||
ReadDirectiveIfindex(item);
|
||||
else
|
||||
if( directive == "end" )
|
||||
item.type = Item::item_end;
|
||||
else
|
||||
if( directive == "else" )
|
||||
item.type = Item::item_else;
|
||||
else
|
||||
if( directive == "for" )
|
||||
ReadDirectiveFor(item);
|
||||
else
|
||||
if( directive == "include" )
|
||||
ReadDirectiveInclude(item);
|
||||
else
|
||||
if( directive == "#" )
|
||||
ReadDirectiveComment(item);
|
||||
else
|
||||
{
|
||||
// user defined
|
||||
item.directives.push_back(directive);
|
||||
item.type = Item::item_normal;
|
||||
}
|
||||
|
||||
CreateTreeReadItemDirectiveCheckEnding(item);
|
||||
}
|
||||
|
||||
|
||||
void Pattern::CreateTreeReadItemText(Item & item)
|
||||
{
|
||||
int c;
|
||||
|
||||
while( (c = ReadCharInText()) != -1 )
|
||||
item.text += c;
|
||||
|
||||
item.type = Item::item_text;
|
||||
}
|
||||
|
||||
|
||||
bool Pattern::CreateTreeReadItem(Item & item)
|
||||
{
|
||||
item.Clear();
|
||||
|
||||
if( *itext == '[' )
|
||||
{
|
||||
CreateTreeReadItemDirective(item);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
if( *itext )
|
||||
{
|
||||
CreateTreeReadItemText(item);
|
||||
return true;
|
||||
}
|
||||
|
||||
// the end of the string
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Pattern::CreateTreeReadInclude(Item & item)
|
||||
{
|
||||
if( item.directives.empty() || item.directives[0].empty() || item.directives[0][0]!='\"' )
|
||||
return;
|
||||
|
||||
std::string file_text = ReadFile( item.directives[0].c_str()+1 );
|
||||
|
||||
const char * itext_copy = itext;
|
||||
itext = file_text.c_str();
|
||||
CreateTree(item);
|
||||
itext = itext_copy;
|
||||
}
|
||||
|
||||
|
||||
void Pattern::CreateTreeReadIf(Item & item)
|
||||
{
|
||||
Item * pitem = item.AddItem();
|
||||
CreateTree(*pitem);
|
||||
|
||||
if( pitem->LastItemType() == Item::item_else )
|
||||
{
|
||||
pitem->DeleteLastItem();
|
||||
|
||||
pitem = item.AddItem();
|
||||
CreateTree(*pitem);
|
||||
}
|
||||
|
||||
pitem->DeleteLastItem(); // it deletes [end] from the tree
|
||||
}
|
||||
|
||||
|
||||
void Pattern::CreateTreeReadFor(Item & item)
|
||||
{
|
||||
Item * pitem = item.AddItem();
|
||||
CreateTree(*pitem);
|
||||
|
||||
pitem->DeleteLastItem(); // it deletes [end] from the tree
|
||||
}
|
||||
|
||||
|
||||
void Pattern::CreateTree(Item & item)
|
||||
{
|
||||
item.Clear();
|
||||
item.type = Item::item_container;
|
||||
|
||||
Item item_temp;
|
||||
|
||||
while( CreateTreeReadItem(item_temp) )
|
||||
{
|
||||
if( item_temp.type == Item::item_comment )
|
||||
continue;
|
||||
|
||||
Item * pitem = item.AddItem(item_temp);
|
||||
|
||||
if( item_temp.type==Item::item_end || item_temp.type==Item::item_else )
|
||||
return;
|
||||
|
||||
if( pitem->type == Item::item_ifany ||
|
||||
pitem->type == Item::item_ifone ||
|
||||
pitem->type == Item::item_ifindex ||
|
||||
pitem->type == Item::item_is )
|
||||
CreateTreeReadIf(*pitem);
|
||||
|
||||
if( pitem->type == Item::item_for )
|
||||
CreateTreeReadFor(*pitem);
|
||||
|
||||
if( pitem->type == Item::item_include )
|
||||
CreateTreeReadInclude(*pitem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Pattern::Item
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
Pattern::Item * Pattern::Item::AddItem(const Pattern::Item * porg)
|
||||
{
|
||||
Item * pitem;
|
||||
|
||||
if( porg )
|
||||
pitem = new Item(*porg);
|
||||
else
|
||||
pitem = new Item();
|
||||
|
||||
item_table.push_back(pitem);
|
||||
|
||||
return pitem;
|
||||
}
|
||||
|
||||
|
||||
Pattern::Item * Pattern::Item::AddItem(const Pattern::Item & porg)
|
||||
{
|
||||
return AddItem(&porg);
|
||||
}
|
||||
|
||||
void Pattern::Item::ClearItems()
|
||||
{
|
||||
std::vector<Item*>::iterator i = item_table.begin();
|
||||
|
||||
for( ; i != item_table.end() ; ++i )
|
||||
delete *i;
|
||||
|
||||
item_table.clear();
|
||||
}
|
||||
|
||||
void Pattern::Item::Clear()
|
||||
{
|
||||
ClearItems();
|
||||
type = item_none;
|
||||
text.clear();
|
||||
directives.clear();
|
||||
}
|
||||
|
||||
|
||||
Pattern::Item::ItemType Pattern::Item::LastItemType()
|
||||
{
|
||||
if( item_table.empty() )
|
||||
return item_none;
|
||||
|
||||
return item_table.back()->type;
|
||||
}
|
||||
|
||||
void Pattern::Item::DeleteLastItem()
|
||||
{
|
||||
if( item_table.empty() )
|
||||
return;
|
||||
|
||||
delete item_table.back();
|
||||
|
||||
item_table.erase( item_table.end() - 1 );
|
||||
}
|
||||
|
||||
|
||||
Pattern::Item::Item()
|
||||
{
|
||||
type = item_none;
|
||||
}
|
||||
|
||||
|
||||
Pattern::Item::Item(const Pattern::Item & i) : type(i.type), text(i.text), directives(i.directives)
|
||||
{
|
||||
CopyItemTable(i);
|
||||
}
|
||||
|
||||
|
||||
Pattern::Item & Pattern::Item::operator=(const Pattern::Item & i)
|
||||
{
|
||||
type = i.type;
|
||||
text = i.text;
|
||||
directives = i.directives;
|
||||
|
||||
CopyItemTable(i);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void Pattern::Item::CopyItemTable(const Pattern::Item & item)
|
||||
{
|
||||
std::vector<Item*>::const_iterator i = item.item_table.begin();
|
||||
|
||||
for( ; i != item.item_table.end() ; ++i)
|
||||
AddItem( *i );
|
||||
}
|
||||
|
||||
|
||||
Pattern::Item::~Item()
|
||||
{
|
||||
ClearItems();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Info
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
Info::Info()
|
||||
{
|
||||
result = false;
|
||||
iter = 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Generator
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
std::string & Generator::Generate(Pattern & data)
|
||||
{
|
||||
otext.clear();
|
||||
MakeText( data.item_root );
|
||||
|
||||
return otext;
|
||||
}
|
||||
|
||||
std::string & Generator::String()
|
||||
{
|
||||
return otext;
|
||||
}
|
||||
|
||||
void Generator::Insert(const std::string & key, UserFunction ufunction)
|
||||
{
|
||||
UserInfo ui;
|
||||
ui.user_function = ufunction;
|
||||
ui.iter = 0;
|
||||
|
||||
user_info_table.insert( std::make_pair(key, ui) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Generator::MakeTextContainer(Pattern::Item & item)
|
||||
{
|
||||
std::vector<Pattern::Item*>::iterator i = item.item_table.begin();
|
||||
|
||||
for( ; i != item.item_table.end() ; ++i )
|
||||
MakeText(**i);
|
||||
}
|
||||
|
||||
|
||||
bool Generator::Find(const std::string & key, UserInfo ** user_info)
|
||||
{
|
||||
UserInfoTable::iterator i = user_info_table.find( key );
|
||||
|
||||
if( i == user_info_table.end() )
|
||||
{
|
||||
otext += CreateMsg("can't find", key.c_str() );
|
||||
return false;
|
||||
}
|
||||
|
||||
*user_info = &(i->second);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Generator::MakeTextNormal(Pattern::Item & item)
|
||||
{
|
||||
if( item.directives.size() != 1 )
|
||||
return;
|
||||
|
||||
UserInfo * user_info;
|
||||
|
||||
if( Find(item.directives[0], &user_info) )
|
||||
{
|
||||
Info info;
|
||||
(user_info->user_function)(info);
|
||||
|
||||
otext += info.text;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Generator::MakeTextIf_go(Pattern::Item & item, bool result)
|
||||
{
|
||||
if( result )
|
||||
{
|
||||
if( item.item_table.size() > 0 )
|
||||
MakeText( *item.item_table[0] );
|
||||
}
|
||||
else
|
||||
{
|
||||
// second element can be (or not -- it's from [else])
|
||||
if( item.item_table.size() > 1 )
|
||||
MakeText( *item.item_table[1] );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Generator::MakeTextIfany(Pattern::Item & item)
|
||||
{
|
||||
std::vector<std::string>::iterator d = item.directives.begin();
|
||||
unsigned how_many_true = 0;
|
||||
|
||||
for( ; d != item.directives.end() ; ++d )
|
||||
{
|
||||
UserInfo * user_info;
|
||||
|
||||
if( !Find(*d, &user_info) )
|
||||
return;
|
||||
|
||||
|
||||
Info info;
|
||||
(user_info->user_function)(info);
|
||||
|
||||
if( !info.text.empty() || info.result )
|
||||
++how_many_true;
|
||||
|
||||
}
|
||||
|
||||
MakeTextIf_go(item, how_many_true == item.directives.size() );
|
||||
}
|
||||
|
||||
|
||||
void Generator::MakeTextIfone(Pattern::Item & item)
|
||||
{
|
||||
std::vector<std::string>::iterator d = item.directives.begin();
|
||||
int how_many_true = 0;
|
||||
|
||||
for( ; d != item.directives.end() ; ++d )
|
||||
{
|
||||
UserInfo * user_info;
|
||||
|
||||
if( !Find(*d, &user_info) )
|
||||
return;
|
||||
|
||||
Info info;
|
||||
(user_info->user_function)(info);
|
||||
|
||||
if( !info.text.empty() || info.result )
|
||||
++how_many_true;
|
||||
}
|
||||
|
||||
MakeTextIf_go(item, how_many_true > 0 );
|
||||
}
|
||||
|
||||
|
||||
void Generator::MakeTextIs(Pattern::Item & item)
|
||||
{
|
||||
if( item.directives.size() != 2 )
|
||||
return;
|
||||
|
||||
UserInfo * user_info;
|
||||
|
||||
if( !Find(item.directives[0], &user_info) )
|
||||
return;
|
||||
|
||||
bool result = false;
|
||||
Info info1, info2;
|
||||
(user_info->user_function)(info1);
|
||||
|
||||
if( !item.directives[1].empty() && item.directives[1][0]=='\"' )
|
||||
{
|
||||
if( std::strcmp(info1.text.c_str(), item.directives[1].c_str()+1) == 0 )
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( Find(item.directives[1], &user_info) )
|
||||
{
|
||||
(user_info->user_function)(info2);
|
||||
|
||||
if( info1.result==info2.result && info1.text==info2.text )
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
MakeTextIf_go(item, result);
|
||||
}
|
||||
|
||||
|
||||
bool Generator::MakeTextIfindexnumber(Pattern::Item & item, UserInfo * user_info, bool & result)
|
||||
{
|
||||
if( item.directives.size() != 2 )
|
||||
return false;
|
||||
|
||||
const char * number_text = item.directives[1].c_str();
|
||||
char * last_char;
|
||||
|
||||
int number = (int)strtol(number_text, &last_char, 10);
|
||||
|
||||
if( *last_char == '\0' )
|
||||
{
|
||||
if( user_info->iter == number )
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
otext += CreateMsg("if-index: syntax error");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Generator::MakeTextIfindex(Pattern::Item & item)
|
||||
{
|
||||
if( item.directives.size() != 2 )
|
||||
return;
|
||||
|
||||
UserInfo * user_info;
|
||||
bool result = false;
|
||||
|
||||
if( !Find(item.directives[0], &user_info) )
|
||||
return;
|
||||
|
||||
|
||||
if( item.directives[1] == "odd" )
|
||||
{
|
||||
if( ( user_info->iter & 1) == 1 )
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
if( item.directives[1] == "even" )
|
||||
{
|
||||
if( ( user_info->iter & 1) == 0 )
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
if( item.directives[1] == "first" )
|
||||
{
|
||||
if( user_info->iter == 0 )
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !MakeTextIfindexnumber(item, user_info, result) )
|
||||
return;
|
||||
}
|
||||
|
||||
MakeTextIf_go(item, result);
|
||||
}
|
||||
|
||||
|
||||
void Generator::MakeTextFor(Pattern::Item & item)
|
||||
{
|
||||
if( item.directives.size() != 1 )
|
||||
return;
|
||||
|
||||
UserInfo * user_info;
|
||||
|
||||
if( !Find(item.directives[0], &user_info) )
|
||||
return;
|
||||
|
||||
|
||||
Info info;
|
||||
user_info->iter = 0;
|
||||
|
||||
while( true )
|
||||
{
|
||||
(user_info->user_function)(info);
|
||||
|
||||
if( info.text.empty() && !info.result )
|
||||
break;
|
||||
|
||||
if( item.item_table.size() > 0 )
|
||||
MakeText( *item.item_table[0] );
|
||||
|
||||
++info.iter;
|
||||
user_info->iter = info.iter;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Generator::MakeText(Pattern::Item & item)
|
||||
{
|
||||
switch( item.type )
|
||||
{
|
||||
case Pattern::Item::item_text:
|
||||
otext += item.text;
|
||||
break;
|
||||
case Pattern::Item::item_container:
|
||||
MakeTextContainer(item);
|
||||
break;
|
||||
case Pattern::Item::item_normal:
|
||||
MakeTextNormal(item);
|
||||
break;
|
||||
case Pattern::Item::item_ifany:
|
||||
MakeTextIfany(item);
|
||||
break;
|
||||
case Pattern::Item::item_ifone:
|
||||
MakeTextIfone(item);
|
||||
break;
|
||||
case Pattern::Item::item_ifindex:
|
||||
MakeTextIfindex(item);
|
||||
break;
|
||||
case Pattern::Item::item_is:
|
||||
MakeTextIs(item);
|
||||
break;
|
||||
case Pattern::Item::item_for:
|
||||
MakeTextFor(item);
|
||||
break;
|
||||
case Pattern::Item::item_err:
|
||||
otext += CreateMsg("a wrong directive");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Generator::Clear()
|
||||
{
|
||||
user_info_table.clear();
|
||||
otext.clear();
|
||||
}
|
||||
|
||||
|
||||
} // namespace Ezc
|
||||
|
||||
@@ -1,194 +1,43 @@
|
||||
/*
|
||||
* This file is a part of EZC -- Easy templating in C++
|
||||
* and is distributed under the (new) BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@slimaczek.pl>
|
||||
* 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, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* version 0.9.0
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef headerfileezc
|
||||
#define headerfileezc
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
|
||||
namespace Ezc
|
||||
{
|
||||
|
||||
std::string CreateMsg(const char * type, const char * arg = 0);
|
||||
void SplitUnixDirectory(const char * name, std::string & dir, std::string & file);
|
||||
void SplitUnixDirectory(const std::string & name, std::string & dir, std::string & file);
|
||||
|
||||
|
||||
class Pattern
|
||||
{
|
||||
public:
|
||||
void ParseFile(const std::string & file_name);
|
||||
void ParseFile(const char * file_name);
|
||||
void Directory(const char * d);
|
||||
void Directory(const std::string & d);
|
||||
|
||||
struct Item
|
||||
{
|
||||
enum ItemType
|
||||
{
|
||||
item_none, item_container, item_text, item_ifany, item_for,
|
||||
item_else, item_end, item_err, item_normal, item_ifindex,
|
||||
item_include, item_is, item_ifone, item_comment
|
||||
};
|
||||
|
||||
ItemType type;
|
||||
std::string text;
|
||||
std::vector<Item*> item_table;
|
||||
std::vector<std::string> directives;
|
||||
|
||||
Item();
|
||||
Item(const Item & i);
|
||||
Item & operator=(const Item & i);
|
||||
void CopyItemTable(const Item & i);
|
||||
~Item();
|
||||
|
||||
Item * AddItem(const Item * porg = 0);
|
||||
Item * AddItem(const Item & porg);
|
||||
void ClearItems();
|
||||
ItemType LastItemType();
|
||||
void DeleteLastItem();
|
||||
void Clear();
|
||||
};
|
||||
|
||||
Item item_root;
|
||||
|
||||
private:
|
||||
const char * itext;
|
||||
std::string directory;
|
||||
|
||||
|
||||
bool CheckFileName(const char * name);
|
||||
std::string ReadFile(const char * name);
|
||||
|
||||
int ReadCharInText();
|
||||
void SkipWhiteCharacters();
|
||||
|
||||
std::string ReadDirective();
|
||||
std::string ReadString();
|
||||
std::string ReadDirectiveOrString();
|
||||
|
||||
void CreateTreeReadItemDirectiveCheckEnding(Item & item);
|
||||
|
||||
void ReadDirectiveIfany(Item & item);
|
||||
void ReadDirectiveIfone(Item & item);
|
||||
void ReadDirectiveIs(Item & item);
|
||||
void ReadDirectiveIfindex(Item & item);
|
||||
void ReadDirectiveFor(Item & item);
|
||||
void ReadDirectiveComment(Item & item);
|
||||
void ReadDirectiveInclude(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);
|
||||
|
||||
}; // Pattern
|
||||
|
||||
|
||||
struct Info
|
||||
{
|
||||
std::string text;
|
||||
bool result;
|
||||
int iter;
|
||||
|
||||
Info();
|
||||
};
|
||||
|
||||
|
||||
|
||||
class Generator
|
||||
{
|
||||
private:
|
||||
typedef void (*UserFunction)(Info &);
|
||||
|
||||
struct UserInfo
|
||||
{
|
||||
UserFunction user_function;
|
||||
int iter;
|
||||
};
|
||||
|
||||
typedef std::map<std::string, UserInfo> UserInfoTable;
|
||||
|
||||
public:
|
||||
|
||||
void Insert(const std::string & key, UserFunction ufunction);
|
||||
std::string & Generate(Pattern & data);
|
||||
std::string & String();
|
||||
void Clear();
|
||||
|
||||
private:
|
||||
|
||||
UserInfoTable user_info_table;
|
||||
std::string otext;
|
||||
|
||||
bool Find(const std::string & key, UserInfo ** user_info);
|
||||
void MakeTextIf_go(Pattern::Item & item, bool result);
|
||||
bool MakeTextIfindexnumber(Pattern::Item & item, UserInfo * user_info, bool & result);
|
||||
void MakeTextIfany(Pattern::Item & item);
|
||||
void MakeTextIfone(Pattern::Item & item);
|
||||
void MakeTextIfindex(Pattern::Item & item);
|
||||
void MakeTextFor(Pattern::Item & item);
|
||||
void MakeTextContainer(Pattern::Item & item);
|
||||
void MakeTextNormal(Pattern::Item & item);
|
||||
void MakeTextIs(Pattern::Item & item);
|
||||
void MakeText(Pattern::Item & item);
|
||||
|
||||
}; // Generator
|
||||
|
||||
} // namespace Ezc
|
||||
#ifndef headerfile_ezc_ezc
|
||||
#define headerfile_ezc_ezc
|
||||
|
||||
#include "version.h"
|
||||
#include "generator.h"
|
||||
#include "patternparser.h"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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_functions
|
||||
#define headerfile_ezc_functions
|
||||
|
||||
#include <map>
|
||||
#include "utf8/utf8.h"
|
||||
#include "env.h"
|
||||
|
||||
|
||||
|
||||
namespace Ezc
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
// functions or variables
|
||||
/*
|
||||
class Functions
|
||||
{
|
||||
public:
|
||||
|
||||
typedef void (*UserFunction)(Env &);
|
||||
typedef std::map<std::wstring, UserFunction> FunctionsTable;
|
||||
typedef typename FunctionsTable::iterator Iterator;
|
||||
|
||||
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);
|
||||
|
||||
Iterator Find(const std::wstring & key);
|
||||
|
||||
Iterator Begin();
|
||||
Iterator End();
|
||||
size_t Size() const;
|
||||
void Clear();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
FunctionsTable functions_tab;
|
||||
std::wstring temp_key;
|
||||
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
} // namespace Ezc
|
||||
|
||||
|
||||
#endif
|
||||
+3614
File diff suppressed because it is too large
Load Diff
+190
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
* 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-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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "item.h"
|
||||
|
||||
|
||||
|
||||
namespace Ezc
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Item * Item::AddItem(const Item * porg)
|
||||
{
|
||||
Item * pitem;
|
||||
|
||||
if( porg )
|
||||
pitem = new Item(*porg);
|
||||
else
|
||||
pitem = new Item();
|
||||
|
||||
item_tab.push_back(pitem);
|
||||
|
||||
return pitem;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Item * Item::AddItem(const Item & porg)
|
||||
{
|
||||
return AddItem(&porg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Item::ClearItems()
|
||||
{
|
||||
std::vector<Item*>::iterator i = item_tab.begin();
|
||||
|
||||
for( ; i != item_tab.end() ; ++i )
|
||||
delete *i;
|
||||
|
||||
item_tab.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Item::Clear()
|
||||
{
|
||||
ClearItems();
|
||||
|
||||
text.clear();
|
||||
file_name.clear();
|
||||
has_function = false;
|
||||
function.Clear();
|
||||
type = item_none;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Item::Type Item::LastItemType()
|
||||
{
|
||||
if( item_tab.empty() )
|
||||
return item_none;
|
||||
|
||||
return item_tab.back()->type;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Item::DeleteLastItem()
|
||||
{
|
||||
if( item_tab.empty() )
|
||||
return;
|
||||
|
||||
delete item_tab.back();
|
||||
item_tab.pop_back();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Item::Item()
|
||||
{
|
||||
type = item_none;
|
||||
has_function = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Item & Item::operator=(const Item & i)
|
||||
{
|
||||
type = i.type;
|
||||
text = i.text;
|
||||
file_name = i.file_name;
|
||||
has_function = i.has_function;
|
||||
function = i.function;
|
||||
|
||||
ClearItems();
|
||||
CopyItemTable(i);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Item::CopyItemTable(const Item & item)
|
||||
{
|
||||
std::vector<Item*>::const_iterator i = item.item_tab.begin();
|
||||
|
||||
for( ; i != item.item_tab.end() ; ++i)
|
||||
AddItem(*i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Item::~Item()
|
||||
{
|
||||
ClearItems();
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
|
||||
+176
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* 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_item
|
||||
#define headerfile_ezc_item
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
|
||||
|
||||
namespace Ezc
|
||||
{
|
||||
|
||||
|
||||
|
||||
struct Item
|
||||
{
|
||||
enum Type
|
||||
{
|
||||
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
|
||||
{
|
||||
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()
|
||||
{
|
||||
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
|
||||
bool has_function; // the [return] statement can be without a function
|
||||
Function function;
|
||||
|
||||
Item();
|
||||
Item(const Item & i);
|
||||
Item & operator=(const Item & i);
|
||||
void CopyItemTable(const Item & i);
|
||||
~Item();
|
||||
|
||||
Item * AddItem(const Item * porg = 0);
|
||||
Item * AddItem(const Item & porg);
|
||||
void ClearItems();
|
||||
Type LastItemType();
|
||||
void DeleteLastItem();
|
||||
void Clear();
|
||||
void ClearCache();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void ClearCache(Item::Function & function);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Ezc
|
||||
|
||||
|
||||
#endif
|
||||
+164
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* 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-2025, 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)
|
||||
{
|
||||
ValWrapper valcache;
|
||||
valcache.val.set_pointer_to(&model);
|
||||
models_map[name] = valcache;
|
||||
}
|
||||
|
||||
|
||||
void Models::Add(const std::wstring & name, morm::Model * model)
|
||||
{
|
||||
ValWrapper valcache;
|
||||
valcache.val.set_pointer_to(model);
|
||||
models_map[name] = valcache;
|
||||
}
|
||||
|
||||
|
||||
void Models::Add(const std::wstring & name, pt::Space & space)
|
||||
{
|
||||
ValWrapper valcache;
|
||||
valcache.val.set_pointer_to(new morm::SpaceWrapper(&space));
|
||||
models_map[name] = valcache;
|
||||
}
|
||||
|
||||
|
||||
void Models::Add(const std::wstring & name, pt::Space * space)
|
||||
{
|
||||
ValWrapper valcache;
|
||||
valcache.val.set_pointer_to(new morm::SpaceWrapper(space));
|
||||
models_map[name] = valcache;
|
||||
}
|
||||
|
||||
|
||||
void Models::Add(const std::wstring & name, pt::Date & date)
|
||||
{
|
||||
ValWrapper valcache;
|
||||
valcache.val.set_pointer_to(&date);
|
||||
models_map[name] = valcache;
|
||||
}
|
||||
|
||||
|
||||
void Models::Add(const std::wstring & name, pt::Date * date)
|
||||
{
|
||||
ValWrapper valcache;
|
||||
valcache.val.set_pointer_to(date);
|
||||
models_map[name] = valcache;
|
||||
}
|
||||
|
||||
|
||||
void Models::Add(const std::wstring & name, const std::wstring & value)
|
||||
{
|
||||
ValWrapper valcache;
|
||||
valcache.val.set(value);
|
||||
models_map[name] = valcache;
|
||||
}
|
||||
|
||||
|
||||
void Models::Add(const std::wstring & name, Val::UserFunction ufunction)
|
||||
{
|
||||
ValWrapper valcache;
|
||||
valcache.val.set_pointer_to(ufunction);
|
||||
models_map[name] = valcache;
|
||||
}
|
||||
|
||||
|
||||
ValWrapper * Models::Find(const std::wstring & name)
|
||||
{
|
||||
auto iterator = models_map.find(name);
|
||||
|
||||
if( iterator != models_map.end() )
|
||||
{
|
||||
return &iterator->second;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
Val * Models::FindVal(const std::wstring & name)
|
||||
{
|
||||
auto iterator = models_map.find(name);
|
||||
|
||||
if( iterator != models_map.end() )
|
||||
{
|
||||
if( iterator->second.has_evaluated_val )
|
||||
return &iterator->second.evaluated_val;
|
||||
else
|
||||
return &iterator->second.val;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
Models::ModelsMap & Models::GetMap()
|
||||
{
|
||||
return models_map;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* 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-2025, 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 "valwrapper.h"
|
||||
#include "space/space.h"
|
||||
|
||||
|
||||
namespace Ezc
|
||||
{
|
||||
|
||||
|
||||
/*
|
||||
* RENAMEME to a better name
|
||||
* e.g.
|
||||
* Vals, Vars, Variables, Values...
|
||||
*/
|
||||
class Models
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::map<std::wstring, ValWrapper> 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);
|
||||
|
||||
void Add(const std::wstring & name, const std::wstring & value);
|
||||
|
||||
void Add(const std::wstring & name, Val::UserFunction ufunction);
|
||||
|
||||
template<typename VectorType>
|
||||
void Add(const std::wstring & name, std::vector<VectorType> & container)
|
||||
{
|
||||
ValWrapper valcache;
|
||||
valcache.val.set_pointer_to(new morm::ModelWrapperVector<VectorType>(&container));
|
||||
models_map[name] = valcache;
|
||||
}
|
||||
|
||||
template<typename VectorType>
|
||||
void Add(const std::wstring & name, std::vector<VectorType> * container)
|
||||
{
|
||||
ValWrapper valcache;
|
||||
valcache.val.set_pointer_to(new morm::ModelWrapperVector<VectorType>(container));
|
||||
models_map[name] = valcache;
|
||||
}
|
||||
|
||||
template<typename VectorType>
|
||||
void Add(const std::wstring & name, std::vector<VectorType*> & container)
|
||||
{
|
||||
ValWrapper valcache;
|
||||
valcache.val.set_pointer_to(new morm::ModelWrapperVectorPointer<VectorType>(&container));
|
||||
models_map[name] = valcache;
|
||||
}
|
||||
|
||||
template<typename VectorType>
|
||||
void Add(const std::wstring & name, std::vector<VectorType*> * container)
|
||||
{
|
||||
ValWrapper valcache;
|
||||
valcache.val.set_pointer_to(new morm::ModelWrapperVectorPointer<VectorType>(container));
|
||||
models_map[name] = valcache;
|
||||
}
|
||||
|
||||
template<typename ListType>
|
||||
void Add(const std::wstring & name, std::list<ListType> & container)
|
||||
{
|
||||
ValWrapper valcache;
|
||||
valcache.val.set_pointer_to(new morm::ModelWrapperList<ListType>(&container));
|
||||
models_map[name] = valcache;
|
||||
}
|
||||
|
||||
template<typename ListType>
|
||||
void Add(const std::wstring & name, std::list<ListType> * container)
|
||||
{
|
||||
ValWrapper valcache;
|
||||
valcache.val.set_pointer_to(new morm::ModelWrapperList<ListType>(container));
|
||||
models_map[name] = valcache;
|
||||
}
|
||||
|
||||
template<typename ListType>
|
||||
void Add(const std::wstring & name, std::list<ListType*> & container)
|
||||
{
|
||||
ValWrapper valcache;
|
||||
valcache.val.set_pointer_to(new morm::ModelWrapperListPointer<ListType>(&container));
|
||||
models_map[name] = valcache;
|
||||
}
|
||||
|
||||
template<typename ListType>
|
||||
void Add(const std::wstring & name, std::list<ListType*> * container)
|
||||
{
|
||||
ValWrapper valcache;
|
||||
valcache.val.set_pointer_to(new morm::ModelWrapperListPointer<ListType>(container));
|
||||
models_map[name] = valcache;
|
||||
}
|
||||
|
||||
ValWrapper * Find(const std::wstring & name);
|
||||
Val * FindVal(const std::wstring & name);
|
||||
|
||||
|
||||
ModelsMap & GetMap();
|
||||
void Clear();
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
ModelsMap models_map;
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
+104
@@ -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
@@ -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
|
||||
@@ -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
|
||||
@@ -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) 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "pattern.h"
|
||||
|
||||
|
||||
namespace Ezc
|
||||
{
|
||||
|
||||
|
||||
Pattern::Pattern()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
void Pattern::Clear()
|
||||
{
|
||||
item_root.Clear();
|
||||
}
|
||||
|
||||
|
||||
void Pattern::CacheBlocks(Blocks & blocks)
|
||||
{
|
||||
Cache(blocks, item_root);
|
||||
}
|
||||
|
||||
|
||||
void Pattern::ClearCache()
|
||||
{
|
||||
item_root.ClearCache();
|
||||
}
|
||||
|
||||
|
||||
// void Pattern::CacheFunctions(Functions & fun)
|
||||
// {
|
||||
// Cache(fun, item_root);
|
||||
// }
|
||||
|
||||
|
||||
void Pattern::CacheObjects(Objects & obj)
|
||||
{
|
||||
Cache(obj, item_root);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Ezc
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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_pattern
|
||||
#define headerfile_ezc_pattern
|
||||
|
||||
#include "item.h"
|
||||
#include "cache.h"
|
||||
#include "blocks.h"
|
||||
#include "functions.h"
|
||||
#include "objects.h"
|
||||
|
||||
|
||||
namespace Ezc
|
||||
{
|
||||
|
||||
|
||||
class Pattern
|
||||
{
|
||||
public:
|
||||
|
||||
Pattern();
|
||||
|
||||
void Clear();
|
||||
|
||||
//void CacheFunctions(Functions & fun);
|
||||
void CacheBlocks(Blocks & blocks);
|
||||
void CacheObjects(Objects & obj);
|
||||
void ClearCache();
|
||||
|
||||
|
||||
Item item_root;
|
||||
|
||||
|
||||
}; // class Pattern
|
||||
|
||||
|
||||
|
||||
} // namespace Ezc
|
||||
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||
+1366
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,394 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_ezc_val
|
||||
#define headerfile_ezc_val
|
||||
|
||||
#include "spacewrapper.h"
|
||||
#include "date/date.h"
|
||||
#include "item.h"
|
||||
#include "modelcontainerwrapper.h"
|
||||
#include "textstream/textstream.h"
|
||||
|
||||
|
||||
namespace morm
|
||||
{
|
||||
class Model;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
namespace Ezc
|
||||
{
|
||||
|
||||
|
||||
struct Env;
|
||||
|
||||
|
||||
/*
|
||||
|
||||
*/
|
||||
class Val
|
||||
{
|
||||
public:
|
||||
|
||||
using UserFunction = void (*)(Env &);
|
||||
|
||||
#ifdef EZC_HAS_MORM_LIBRARY
|
||||
using ModelMethod1 = void (morm::Model::*)(Env &);
|
||||
using ModelMethod3 = bool (morm::Model::*)();
|
||||
using ModelMethod4 = bool (morm::Model::*)() const;
|
||||
#endif
|
||||
|
||||
|
||||
enum Type
|
||||
{
|
||||
TYPE_VOID,
|
||||
TYPE_SPACE_LOCAL,
|
||||
TYPE_STREAM,
|
||||
TYPE_FUNCTION,
|
||||
TYPE_DATE,
|
||||
#ifdef EZC_HAS_MORM_LIBRARY
|
||||
TYPE_MODEL,
|
||||
TYPE_MODEL_CONTAINER_WRAPPER,
|
||||
TYPE_MODEL_METHOD,
|
||||
#endif
|
||||
TYPE_SPACE,
|
||||
TYPE_ITEM_BLOCK,
|
||||
TYPE_CHAR,
|
||||
TYPE_WCHAR, //
|
||||
TYPE_SHORT,
|
||||
TYPE_INT,
|
||||
TYPE_LONG,
|
||||
TYPE_LONG_LONG,
|
||||
TYPE_UNSIGNED_CHAR,
|
||||
TYPE_UNSIGNED_SHORT,
|
||||
TYPE_UNSIGNED_INT,
|
||||
TYPE_UNSIGNED_LONG,
|
||||
TYPE_UNSIGNED_LONG_LONG,
|
||||
TYPE_FLOAT,
|
||||
TYPE_DOUBLE,
|
||||
TYPE_LONG_DOUBLE,
|
||||
TYPE_STRING,
|
||||
TYPE_WSTRING,
|
||||
};
|
||||
|
||||
|
||||
Val();
|
||||
Val(pt::Stream * output_stream);
|
||||
Val(const Val & val);
|
||||
Val & operator=(const Val & val);
|
||||
~Val();
|
||||
// IMPROVEME add move cctor and operator=
|
||||
|
||||
void set_output_stream(pt::Stream * output_stream);
|
||||
void set_output_stream(pt::Stream & output_stream);
|
||||
|
||||
bool has_object();
|
||||
bool has_function();
|
||||
|
||||
#ifdef EZC_HAS_MORM_LIBRARY
|
||||
bool has_method();
|
||||
bool has_model_object();
|
||||
#endif
|
||||
|
||||
bool has_pod_type();
|
||||
//bool has_space_object();
|
||||
|
||||
void clear();
|
||||
|
||||
|
||||
bool to_bool() const;
|
||||
|
||||
|
||||
void set(const char * str);
|
||||
void set(const wchar_t * str);
|
||||
void set(const std::string & str);
|
||||
void set(const std::wstring & str);
|
||||
|
||||
void set(bool val);
|
||||
void set(short val);
|
||||
void set(int val);
|
||||
void set(long val);
|
||||
void set(long long val);
|
||||
void set(unsigned short val);
|
||||
void set(unsigned int val);
|
||||
void set(unsigned long val);
|
||||
void set(unsigned long long val);
|
||||
|
||||
void set(float val);
|
||||
void set(double val);
|
||||
void set(long double val);
|
||||
|
||||
|
||||
void set_pointer_to(pt::Stream * str);
|
||||
void set_pointer_to(UserFunction user_function);
|
||||
#ifdef EZC_HAS_MORM_LIBRARY
|
||||
void set_pointer_to(morm::Model * model, ModelMethod1 model_method1);
|
||||
void set_pointer_to(morm::Model * model, ModelMethod3 model_method3);
|
||||
void set_pointer_to(morm::Model * model, ModelMethod4 model_method4);
|
||||
#endif
|
||||
void set_pointer_to(pt::Date * date);
|
||||
void set_pointer_to(morm::Model * model);
|
||||
void set_pointer_to(morm::ModelContainerWrapper * model_container_wrapper);
|
||||
|
||||
template<typename ModelType>
|
||||
void set_pointer_to(std::vector<ModelType> * model_container);
|
||||
|
||||
template<typename ModelType>
|
||||
void set_pointer_to(std::list<ModelType> * model_container);
|
||||
|
||||
template<typename ModelType>
|
||||
void set_pointer_to(std::vector<ModelType*> * model_container);
|
||||
|
||||
template<typename ModelType>
|
||||
void set_pointer_to(std::list<ModelType*> * model_container);
|
||||
|
||||
void set_pointer_to(morm::SpaceWrapper * space_wrapper);
|
||||
void set_pointer_to(pt::Space * space, bool create_wrapper = true);
|
||||
|
||||
//void set(Val & val);
|
||||
|
||||
void set_pointer_to(Item * item_block);
|
||||
|
||||
void set_pointer_to(bool * val);
|
||||
void set_pointer_to(char * val);
|
||||
void set_pointer_to(wchar_t * val);
|
||||
void set_pointer_to(short * val);
|
||||
void set_pointer_to(int * val);
|
||||
void set_pointer_to(long * val);
|
||||
void set_pointer_to(long long * val);
|
||||
|
||||
void set_pointer_to(unsigned char * val);
|
||||
void set_pointer_to(unsigned short * val);
|
||||
void set_pointer_to(unsigned int * val);
|
||||
void set_pointer_to(unsigned long * val);
|
||||
void set_pointer_to(unsigned long long * val);
|
||||
|
||||
void set_pointer_to(float * val);
|
||||
void set_pointer_to(double * val);
|
||||
void set_pointer_to(long double * val);
|
||||
|
||||
void set_pointer_to(std::string * val);
|
||||
void set_pointer_to(std::wstring * val);
|
||||
|
||||
|
||||
// bool is_equal(const char * str) const;
|
||||
// bool is_equal(const wchar_t * str) const;
|
||||
|
||||
// bool is_equal(const std::string & str) const;
|
||||
// bool is_equal(const std::wstring & str) const;
|
||||
|
||||
void serialize_to(pt::Stream & str);
|
||||
|
||||
|
||||
Val & operator<<(const char * str);
|
||||
Val & operator<<(const wchar_t * str);
|
||||
Val & operator<<(const std::string & str);
|
||||
Val & operator<<(const std::wstring & str);
|
||||
Val & operator<<(char val);
|
||||
Val & operator<<(unsigned char val);
|
||||
Val & operator<<(wchar_t val);
|
||||
Val & operator<<(bool val);
|
||||
Val & operator<<(short val);
|
||||
Val & operator<<(int val);
|
||||
Val & operator<<(long val);
|
||||
Val & operator<<(long long val);
|
||||
Val & operator<<(unsigned short val);
|
||||
Val & operator<<(unsigned int val);
|
||||
Val & operator<<(unsigned long val);
|
||||
Val & operator<<(unsigned long long val);
|
||||
Val & operator<<(float val);
|
||||
Val & operator<<(double val);
|
||||
Val & operator<<(long double val);
|
||||
Val & operator<<(const pt::Stream & str);
|
||||
|
||||
Val & operator=(bool res);
|
||||
|
||||
|
||||
void put_pod_type_to_stream();
|
||||
|
||||
|
||||
void allow_to_cache(bool allow_to_cache);
|
||||
bool is_allowed_to_cache();
|
||||
|
||||
|
||||
Type type;
|
||||
pt::Space space_local;
|
||||
void * pointer;
|
||||
|
||||
#ifdef EZC_HAS_MORM_LIBRARY
|
||||
ModelMethod1 model_method1;
|
||||
ModelMethod3 model_method3;
|
||||
ModelMethod4 model_method4;
|
||||
#endif
|
||||
|
||||
|
||||
// used when pointer is pointing to a pt::Space
|
||||
// but can be null
|
||||
morm::SpaceWrapper * space_wrapper;
|
||||
size_t space_table_index;
|
||||
|
||||
bool allow_to_cache_value;
|
||||
|
||||
// UserFunction user_function;
|
||||
|
||||
// // Wrapper
|
||||
// morm::Model * model;
|
||||
// morm::ModelContainerWrapper * model_container_wrapper;
|
||||
// pt::Date * date;
|
||||
// morm::SpaceWrapper * space_wrapper;
|
||||
// //
|
||||
|
||||
// pt::Space * space;
|
||||
// pt::Stream * stream;
|
||||
|
||||
// Item * item_block;
|
||||
|
||||
|
||||
|
||||
// output stream
|
||||
pt::Stream * output_stream;
|
||||
|
||||
|
||||
bool is_equal_string(const wchar_t * str) const;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
void initialize_empty();
|
||||
void copy(const Val & val);
|
||||
void increment_model_container_wrapper_ref();
|
||||
void increment_space_wrapper_ref();
|
||||
|
||||
|
||||
void clear_model_container_wrapper();
|
||||
void clear_space_wrapper();
|
||||
|
||||
// bool is_equal_bool(const char * str) const;
|
||||
// bool is_equal_string(const char * str) const;
|
||||
|
||||
// bool is_equal_bool(const wchar_t * str) const;
|
||||
|
||||
bool is_space_equal_string(const pt::Space & space, const wchar_t * str) const;
|
||||
bool is_stream_equal_string(const pt::Stream & stream, const wchar_t * str) const;
|
||||
|
||||
bool to_bool_stream() const;
|
||||
bool to_bool_space() const;
|
||||
bool to_bool_model_container_wrapper() const;
|
||||
|
||||
void serialize_stream_to(pt::Stream & str);
|
||||
void serialize_date_to(pt::Stream & str);
|
||||
void serialize_model_to(pt::Stream & str);
|
||||
void serialize_model_container_wrapper_to(pt::Stream & str);
|
||||
void serialize_space_to(pt::Stream & str);
|
||||
|
||||
template<typename PODType>
|
||||
void serialize_pod_type_to(pt::Stream & str)
|
||||
{
|
||||
PODType * val = reinterpret_cast<PODType*>(pointer);
|
||||
str << *val;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* old
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* 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
|
||||
|
||||
};
|
||||
|
||||
|
||||
template<typename ModelType>
|
||||
void Val::set_pointer_to(std::vector<ModelType> * model_container)
|
||||
{
|
||||
clear();
|
||||
type = TYPE_MODEL_CONTAINER_WRAPPER;
|
||||
this->pointer = new morm::ModelWrapperVector<ModelType>(model_container);
|
||||
this->allow_to_cache_value = true;
|
||||
}
|
||||
|
||||
|
||||
template<typename ModelType>
|
||||
void Val::set_pointer_to(std::list<ModelType> * model_container)
|
||||
{
|
||||
clear();
|
||||
type = TYPE_MODEL_CONTAINER_WRAPPER;
|
||||
this->pointer = new morm::ModelWrapperList<ModelType>(model_container);
|
||||
this->allow_to_cache_value = true;
|
||||
}
|
||||
|
||||
|
||||
template<typename ModelType>
|
||||
void Val::set_pointer_to(std::vector<ModelType*> * model_container)
|
||||
{
|
||||
clear();
|
||||
type = TYPE_MODEL_CONTAINER_WRAPPER;
|
||||
this->pointer = new morm::ModelWrapperVectorPointer<ModelType>(model_container);
|
||||
this->allow_to_cache_value = true;
|
||||
}
|
||||
|
||||
|
||||
template<typename ModelType>
|
||||
void Val::set_pointer_to(std::list<ModelType*> * model_container)
|
||||
{
|
||||
clear();
|
||||
type = TYPE_MODEL_CONTAINER_WRAPPER;
|
||||
this->pointer = new morm::ModelWrapperListPointer<ModelType>(model_container);
|
||||
this->allow_to_cache_value = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
typedef std::map<std::wstring, Val> Vals;
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Ezc
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* 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) 2025, 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 "valwrapper.h"
|
||||
|
||||
|
||||
namespace Ezc
|
||||
{
|
||||
|
||||
|
||||
ValWrapper::ValWrapper()
|
||||
{
|
||||
has_evaluated_val = false;
|
||||
evaluated_str = nullptr;
|
||||
}
|
||||
|
||||
|
||||
ValWrapper::ValWrapper(const ValWrapper & valcache)
|
||||
{
|
||||
operator=(valcache);
|
||||
}
|
||||
|
||||
|
||||
ValWrapper & ValWrapper::operator=(const ValWrapper & valcache)
|
||||
{
|
||||
val = valcache.val;
|
||||
has_evaluated_val = valcache.has_evaluated_val;
|
||||
evaluated_val = valcache.evaluated_val;
|
||||
|
||||
if( valcache.evaluated_str )
|
||||
{
|
||||
evaluated_str = valcache.evaluated_str->new_empty();
|
||||
|
||||
if( !valcache.evaluated_str->empty() )
|
||||
{
|
||||
evaluated_str->escape_input(false);
|
||||
*evaluated_str << *valcache.evaluated_str;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
evaluated_str = nullptr;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void ValWrapper::clear()
|
||||
{
|
||||
val.clear();
|
||||
clear_evaluated_value();
|
||||
clear_childs();
|
||||
}
|
||||
|
||||
|
||||
void ValWrapper::clear_evaluated_value()
|
||||
{
|
||||
has_evaluated_val = false;
|
||||
|
||||
if( evaluated_str )
|
||||
{
|
||||
delete evaluated_str;
|
||||
}
|
||||
|
||||
evaluated_str = nullptr;
|
||||
evaluated_val.clear();
|
||||
}
|
||||
|
||||
|
||||
void ValWrapper::clear_childs()
|
||||
{
|
||||
childs_map.clear();
|
||||
}
|
||||
|
||||
|
||||
ValWrapper * ValWrapper::add_child(const std::wstring & child_name, const ValWrapper & val)
|
||||
{
|
||||
ValWrapper & v = childs_map[child_name];
|
||||
v.clear();
|
||||
v = val;
|
||||
return &v;
|
||||
}
|
||||
|
||||
|
||||
ValWrapper * ValWrapper::add_child(const std::wstring & child_name, const Val & val)
|
||||
{
|
||||
ValWrapper & v = childs_map[child_name];
|
||||
v.clear();
|
||||
v.val = val;
|
||||
return &v;
|
||||
}
|
||||
|
||||
|
||||
ValWrapper * ValWrapper::find_child(const std::wstring & child_name)
|
||||
{
|
||||
auto i = childs_map.find(child_name);
|
||||
|
||||
if( i != childs_map.end() )
|
||||
{
|
||||
return &i->second;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Ezc
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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) 2025, 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_valcache
|
||||
#define headerfile_ezc_valcache
|
||||
|
||||
#include "val.h"
|
||||
|
||||
|
||||
namespace Ezc
|
||||
{
|
||||
|
||||
//ValWrapper
|
||||
|
||||
class ValWrapper
|
||||
{
|
||||
public:
|
||||
|
||||
ValWrapper();
|
||||
ValWrapper(const ValWrapper &);
|
||||
ValWrapper & operator=(const ValWrapper &);
|
||||
|
||||
|
||||
Val val;
|
||||
|
||||
bool has_evaluated_val;
|
||||
Val evaluated_val;
|
||||
pt::Stream * evaluated_str; // can be null
|
||||
|
||||
|
||||
void clear();
|
||||
void clear_evaluated_value();
|
||||
void clear_childs();
|
||||
|
||||
ValWrapper * add_child(const std::wstring & child_name, const ValWrapper & val);
|
||||
ValWrapper * add_child(const std::wstring & child_name, const Val & val);
|
||||
ValWrapper * find_child(const std::wstring & child_name);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
std::map<std::wstring, ValWrapper> childs_map;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace Ezc
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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