├── HISTORY.md ├── JSPT ├── bin │ ├── .ignore │ ├── genguid │ ├── install.dir │ │ └── jecho │ ├── install.li32 │ ├── install.li64 │ ├── jecho │ ├── json2prj │ │ ├── Makefile.php │ │ ├── include │ │ │ ├── guid.class.php │ │ │ └── print.php │ │ ├── make.php │ │ └── vcproj.php │ ├── jspt │ ├── li32 │ │ └── prj2json │ ├── prj2make │ ├── prj2vcproj │ ├── prjconv │ └── win32 │ │ └── prj2json.exe └── prj2json │ ├── ProjectJson.cpp │ └── build │ ├── Makefile.li32 │ ├── Makefile.li64 │ ├── build │ ├── build.prj │ ├── vc8-win32.vcproj │ └── vc8-win64.vcproj ├── README.md ├── examples ├── boost-lambda │ ├── calc │ │ ├── Calc.cpp │ │ ├── Makefile │ │ ├── build │ │ └── calc.prj │ └── print │ │ ├── Makefile │ │ ├── Simplest.cpp │ │ ├── build │ │ └── print.prj ├── boost-phoenix │ ├── calc │ │ ├── Calc.cpp │ │ ├── Makefile │ │ ├── build │ │ └── calc.prj │ └── print │ │ ├── Makefile │ │ ├── Simplest.cpp │ │ ├── build │ │ └── print.prj ├── calculator │ ├── Calc.cpp │ ├── Makefile │ ├── build │ ├── calculator(vc9).vcproj │ ├── calculator.prj │ ├── calculator.vcproj │ └── readme.txt ├── circuit │ ├── Circuit.cpp │ ├── Makefile │ ├── build │ └── circuit.prj ├── emulator │ ├── Emulator.cpp │ ├── Emulator.vcproj │ ├── Makefile │ ├── build │ └── emulator.prj ├── grammar │ ├── Makefile │ ├── SimpleGrammar.cpp │ ├── build │ └── grammar.prj ├── grammar2 │ ├── Makefile │ ├── SimpleGrammar.cpp │ ├── build │ └── grammar2.prj ├── htmltext │ ├── HtmlText.cpp │ ├── Makefile │ ├── build │ └── htmltext.prj ├── includefiles │ ├── IncludeFiles.cpp │ ├── Makefile │ ├── build │ └── includefiles.prj ├── json-print │ ├── Makefile │ ├── Simplest.cpp │ ├── build │ └── json-print.prj ├── json-print2 │ ├── Makefile │ ├── Simplest.cpp │ ├── build │ └── json-print2.prj ├── lang │ ├── Lang.cpp │ ├── Makefile │ ├── build │ ├── input.lang │ ├── lang.prj │ └── readme.txt ├── projects.plf ├── removecomments │ ├── Makefile │ ├── RemoveCppComments.cpp │ ├── build │ └── removecomments.prj ├── removecomments2 │ ├── Makefile │ ├── RemoveCppComments.cpp │ ├── build │ └── removecomments2.prj ├── simplest │ ├── Makefile │ ├── Simplest.cpp │ ├── build │ ├── simplest.prj │ └── simplest.vcproj ├── simplest2 │ ├── Makefile │ ├── Simplest.cpp │ ├── build │ ├── simplest.vcproj │ └── simplest2.prj ├── token │ ├── Main.cpp │ └── token.vcproj ├── urlparams │ ├── Makefile │ ├── ParseUrlParams.cpp │ ├── build │ └── urlparams.prj ├── validation │ ├── Makefile.li32 │ ├── Makefile.li64 │ ├── Simplest.cpp │ ├── build │ └── validation.prj └── variant │ ├── Makefile │ ├── Variant.cpp │ ├── Variant.h │ ├── build │ └── variant.prj ├── include └── tpl │ ├── Basic.h │ ├── BinRegExp.h │ ├── Emulator.h │ ├── RegExp.h │ ├── binary │ ├── Assignment.h │ ├── Basic.h │ ├── ComPtr.h │ ├── Composition.h │ ├── Customization.h │ ├── MatchResult.h │ ├── Operator.h │ ├── Ref.h │ ├── Storage.h │ └── Terminal.h │ ├── boost │ ├── Lambda.h │ └── Phoenix.h │ ├── c │ ├── Comment.h │ └── Lex.h │ ├── emu │ ├── CPU.h │ ├── Code.h │ ├── Function.h │ ├── Instruction.h │ ├── Label.h │ ├── Var.h │ └── _OldVar.h │ ├── ext │ └── Calculator.h │ ├── html │ ├── Lex.h │ └── entity │ │ ├── Latin-1.h │ │ └── Symbol.h │ └── regex │ ├── Action.h │ ├── Append.h │ ├── Assign.h │ ├── Basic.h │ ├── Case.h │ ├── Composition.h │ ├── Concretion.h │ ├── Condition.h │ ├── Customization.h │ ├── DOM.h │ ├── Find.h │ ├── Match.h │ ├── Operator.h │ ├── Predicate.h │ ├── Ref.h │ ├── RuleTraits.h │ ├── Terminal.h │ ├── Token.h │ ├── Transformation.h │ ├── UComposition.h │ ├── detail │ ├── STLHeaders.h │ └── TypeTraits.h │ ├── grammar │ ├── Action.h │ ├── Concretion.h │ ├── Condition.h │ └── Operator.h │ └── result │ ├── Context.h │ ├── Document.h │ └── Mark.h └── test └── testtpl ├── Demo.cpp ├── Makefile ├── SimpleBinary.cpp ├── StdAfx.cpp ├── TestTpl.cpp ├── TestTpl.vcproj ├── Transformation.cpp ├── WordText.cpp ├── XmlProcess.cpp ├── stdafx.h └── testtpl.prj.li /HISTORY.md: -------------------------------------------------------------------------------- 1 | My C/C++ Open Source Projects 2 | ===== 3 | 4 | ## winx - A C++ GUI Library for Windows 5 | 6 | It was open sourced on [Sourceforge](https://sourceforge.net/projects/winx/) on 2006-08-14. 7 | 8 | * https://sourceforge.net/projects/winx/ 9 | * https://code.google.com/archive/p/winx/ 10 | * https://github.com/xushiwei/winx 11 | 12 | ## stdext - A C++ STL Extensions Libary 13 | 14 | It was originally part of `winx` and became an independent open source project on 2008-01-23. 15 | 16 | * https://code.google.com/archive/p/stdext/ 17 | * https://github.com/xushiwei/stdext 18 | 19 | ## memory - C++ Memory Management Innovation: GC Allocator 20 | 21 | It was originally part of `stdext` and became an independent open source project on 2008-04-28. 22 | 23 | Most of the C++ programmers do not benefit from Garbage Collection technique (GC). Here is a new memory management technique named GC Allocator (Note it is not GC). 24 | 25 | * https://www.codeproject.com/KB/cpp/gc-allocator.aspx 26 | * http://svn.boost.org/svn/boost/sandbox/memory/ (not available) 27 | * https://github.com/xushiwei/memory 28 | 29 | ## tpl - Text Processing Language 30 | 31 | TPL is a Text Processing Library/Language. 32 | 33 | It was open sourced on [Google Code](https://code.google.com/archive/p/libtpl/) on 2008-06-21. 34 | 35 | * https://code.google.com/archive/p/libtpl/ 36 | * https://github.com/xushiwei/tpl 37 | -------------------------------------------------------------------------------- /JSPT/bin/.ignore: -------------------------------------------------------------------------------- 1 | prj2json.exe 2 | jspt.bat 3 | 4 | -------------------------------------------------------------------------------- /JSPT/bin/genguid: -------------------------------------------------------------------------------- 1 | #!/usr/bin/php 2 | 6 | 7 | -------------------------------------------------------------------------------- /JSPT/bin/install.dir/jecho: -------------------------------------------------------------------------------- 1 | ~/bin/jspt.dir/jecho $* 2 | 3 | -------------------------------------------------------------------------------- /JSPT/bin/install.li32: -------------------------------------------------------------------------------- 1 | if [ -z $PLATFORM ]; then 2 | PLATFORM=li32 3 | fi 4 | 5 | AppPath0=`dirname $0` 6 | AppPath=`cd $AppPath0; pwd` 7 | 8 | if [ -z $1 ]; then 9 | TargetDir=~/bin 10 | else 11 | TargetDir=$1 12 | fi 13 | 14 | echo "$AppPath/prjconv \$*" > $TargetDir/prjconv 15 | chmod +x $TargetDir/prjconv 16 | 17 | rm -f $AppPath/prj2json.exe 18 | 19 | sed -i -e "s|PLATFORM=.*|PLATFORM=$PLATFORM|" $AppPath/prj2make 20 | 21 | for File in $AppPath/prj2* ; do 22 | cp $File $TargetDir/ 23 | done 24 | 25 | cd $AppPath 26 | ln -s -f $PLATFORM/prj2json prj2json.exe 27 | cp -f jspt jspt.bat 28 | 29 | mkdir -p ~/bin 30 | ln -s -f $AppPath ~/bin/jspt.dir 31 | cp $AppPath/install.dir/* ~/bin 32 | 33 | -------------------------------------------------------------------------------- /JSPT/bin/install.li64: -------------------------------------------------------------------------------- 1 | PLATFORM=li64 2 | 3 | AppPath=`dirname $0` 4 | $AppPath/install.li32 5 | 6 | -------------------------------------------------------------------------------- /JSPT/bin/jecho: -------------------------------------------------------------------------------- 1 | AppPath=`dirname $0` 2 | $AppPath/jspt $AppPath/json2prj/include/print.php $* 3 | 4 | -------------------------------------------------------------------------------- /JSPT/bin/json2prj/Makefile.php: -------------------------------------------------------------------------------- 1 | link make.php -------------------------------------------------------------------------------- /JSPT/bin/json2prj/include/guid.class.php: -------------------------------------------------------------------------------- 1 | Name = $_ENV["COMPUTERNAME"]; 20 | $address->IP = $_SERVER["SERVER_ADDR"]; 21 | return $address; 22 | } 23 | 24 | function toString() 25 | { 26 | return strtolower($this->Name.'/'.$this->IP); 27 | } 28 | } 29 | 30 | class Random 31 | { 32 | function nextLong() 33 | { 34 | $tmp = rand(0,1)?'-':''; 35 | return $tmp.rand(1000, 9999).rand(1000, 9999).rand(1000, 9999).rand(100, 999).rand(100, 999); 36 | } 37 | } 38 | 39 | // 三段 40 | // 一段是微秒 一段是地址 一段是随机数 41 | class Guid 42 | { 43 | var $valueBeforeMD5; 44 | var $valueAfterMD5; 45 | 46 | function Guid() 47 | { 48 | $this->getGuid(); 49 | } 50 | 51 | function getGuid() 52 | { 53 | $address = NetAddress::getLocalHost(); 54 | $this->valueBeforeMD5 = $address->toString().':'.System::currentTimeMillis().':'.Random::nextLong(); 55 | $this->valueAfterMD5 = md5($this->valueBeforeMD5); 56 | } 57 | 58 | function newGuid() 59 | { 60 | $Guid = new Guid(); 61 | return $Guid; 62 | } 63 | 64 | function toString() 65 | { 66 | $raw = strtoupper($this->valueAfterMD5); 67 | return substr($raw,0,8).'-'.substr($raw,8,4).'-'.substr($raw,12,4).'-'.substr($raw,16,4).'-'.substr($raw,20); 68 | } 69 | } 70 | 71 | function createGuid() 72 | { 73 | $guid = new Guid(); 74 | return $guid->toString(); 75 | } 76 | ?> 77 | -------------------------------------------------------------------------------- /JSPT/bin/json2prj/include/print.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /JSPT/bin/jspt: -------------------------------------------------------------------------------- 1 | #!/usr/bin/php 2 | output\n\n"; 6 | return; 7 | } 8 | 9 | $argv = $_SERVER["argv"]; 10 | if ($argc == 2) 11 | $doc = json_decode(stream_get_contents(STDIN)); 12 | else 13 | $doc = json_decode(file_get_contents($argv[2])); 14 | require($argv[1]); 15 | ?> 16 | -------------------------------------------------------------------------------- /JSPT/bin/li32/prj2json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xushiwei/tpl/c0c5f86e99b072345418b812412894d2b25a4296/JSPT/bin/li32/prj2json -------------------------------------------------------------------------------- /JSPT/bin/prj2make: -------------------------------------------------------------------------------- 1 | if [ -z $1 ]; then 2 | PLATFORM=li32 3 | export PRJCONV_OS=linux 4 | export PRJCONV_BITS=32 5 | export PRJCONV_OUTFILE=Makefile.li32 6 | prjconv make 7 | export PRJCONV_BITS=64 8 | export PRJCONV_OUTFILE=Makefile.li64 9 | prjconv make 10 | ln -s -f Makefile.$PLATFORM Makefile 11 | else 12 | export PRJCONV_BITS=independent 13 | export PRJCONV_OUTFILE=Makefile 14 | prjconv make 15 | fi 16 | 17 | -------------------------------------------------------------------------------- /JSPT/bin/prj2vcproj: -------------------------------------------------------------------------------- 1 | export PRJCONV_BITS=32 2 | export PRJCONV_OUTFILE=vc8-win32.vcproj 3 | prjconv vcproj $* 4 | export PRJCONV_BITS=64 5 | export PRJCONV_OUTFILE=vc8-win64.vcproj 6 | prjconv vcproj $* 7 | 8 | -------------------------------------------------------------------------------- /JSPT/bin/prjconv: -------------------------------------------------------------------------------- 1 | #!/usr/bin/php 2 | [.prj]\n"; 8 | echo "Here can be:\n"; 9 | chdir($AppPath . "/json2prj"); 10 | foreach (glob("*.php") as $File) { 11 | echo "\t" . pathinfo($File, PATHINFO_FILENAME) . "\n"; 12 | } 13 | return -1; 14 | } 15 | 16 | $PhpFile = $AppPath . "/json2prj/" . $argv[1] . ".php"; 17 | if (!file_exists($PhpFile)) { 18 | echo "ERROR: $PhpFile doesn't exists!\n\n"; 19 | return -2; 20 | } 21 | 22 | if ($argc < 3) { 23 | $PrjFile = pathinfo(getcwd(), PATHINFO_BASENAME) . ".prj"; 24 | } 25 | else { 26 | $PrjFile = $argv[2]; 27 | } 28 | if (!file_exists($PrjFile)) { 29 | echo "ERROR: $PrjFile doesn't exists!\n\n"; 30 | return -3; 31 | } 32 | 33 | $Cmd = $AppPath . "/prj2json.exe " . $PrjFile . " | " . $AppPath . "/jspt.bat " . $PhpFile; 34 | $PRJCONV_OUTFILE = getenv("PRJCONV_OUTFILE"); 35 | if ($PRJCONV_OUTFILE) { 36 | $Cmd .= " > " . $PRJCONV_OUTFILE; 37 | } 38 | system($Cmd); 39 | ?> 40 | -------------------------------------------------------------------------------- /JSPT/bin/win32/prj2json.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xushiwei/tpl/c0c5f86e99b072345418b812412894d2b25a4296/JSPT/bin/win32/prj2json.exe -------------------------------------------------------------------------------- /JSPT/prj2json/ProjectJson.cpp: -------------------------------------------------------------------------------- 1 | #define TPL_USE_AUTO_ALLOC 2 | #include 3 | #include 4 | 5 | using namespace tpl; 6 | 7 | // ------------------------------------------------------------------------- 8 | 9 | #define PRJ_PATH token<'\r', '\n', '['>() 10 | #define PRJ_ITEM token<';', '\r', '\n'>() 11 | 12 | int main(int argc, const char* argv[]) 13 | { 14 | const bool array = true; 15 | 16 | NS_STDEXT::ErrorLog err; 17 | if (argc < 2) { 18 | err.print("Usage: prj2json \n"); 19 | return -1; 20 | } 21 | 22 | NS_STDEXT::FileBuf file(argv[1]); 23 | if (!file.good()) { 24 | err.print(">>> ERROR: open input file failed!\n"); 25 | return -2; 26 | } 27 | 28 | typedef DOM<> dom; 29 | 30 | dom::Mark tagInclude("include", array); 31 | dom::NodeMark tagCfg("config", array); 32 | dom::Mark tagName("name"); 33 | dom::NodeMark tagProduct("product"); 34 | dom::Mark tagType("type"); 35 | dom::Mark tagPath("path"); 36 | dom::Mark tagOption("option", array); 37 | dom::Mark tagDefine("define", array); 38 | dom::Mark tagObjDir("objdir"); 39 | dom::Mark tagLibDir("libdir", array); 40 | dom::Mark tagLib("lib", array); 41 | dom::Mark tagSrc("src", array); 42 | 43 | dom::Allocator alloc; 44 | dom::Document doc(alloc); 45 | 46 | dom::NodeMark tagPlatform("platform"); 47 | dom::Mark tagCPU("cpu"); 48 | dom::Mark tagByteSwap("byteswap"); 49 | dom::Mark tagBits("bits"); 50 | dom::Mark tagOS("os"); 51 | 52 | dom::Node* plat = doc.insertNode(alloc, tagPlatform); 53 | 54 | #define PRJ_INSERT_LEAF(tag, data) \ 55 | plat->insertLeaf(alloc, tag, NS_STDEXT::TempString(data)) 56 | 57 | #if defined(__INTEL__) 58 | PRJ_INSERT_LEAF(tagCPU, "intel"); 59 | #elif defined(__SPARC__) 60 | PRJ_INSERT_LEAF(tagCPU, "sparc"); 61 | #endif 62 | 63 | #if defined(__BYTESWAP__) || defined(BYTESWAP) 64 | PRJ_INSERT_LEAF(tagByteSwap, "true"); 65 | #else 66 | PRJ_INSERT_LEAF(tagByteSwap, "false"); 67 | #endif 68 | 69 | #if defined(__32BIT__) || defined(_WIN32) 70 | PRJ_INSERT_LEAF(tagBits, "32"); 71 | #elif defined(__64BIT__) || defined(_WIN64) 72 | PRJ_INSERT_LEAF(tagBits, "64"); 73 | #endif 74 | 75 | #if defined(__LINUX__) || defined(LINUX) 76 | PRJ_INSERT_LEAF(tagOS, "linux"); 77 | #elif defined(_WIN32) || defined(_WIN64) || defined(X_OS_WINDOWS) 78 | PRJ_INSERT_LEAF(tagOS, "windows"); 79 | #endif 80 | 81 | if (file >> (skipws() % ("//" + find_eol())) 82 | [ 83 | !( 84 | gr(icase["[include]"]) + *gr(PRJ_PATH/tagInclude) 85 | ) + 86 | +( 87 | ( 88 | gr(icase["[config"] + ws() + find(']')/tagName + ']') + 89 | +gr( 90 | c_symbol() 91 | [ 92 | case_(eqICase("product")) 93 | [ 94 | skip_non_eol_ws_ 95 | [ 96 | gr(c_symbol()/tagType) + gr(PRJ_PATH/tagPath) 97 | ]/tagProduct 98 | ], 99 | case_(eqICase("options")) 100 | [ 101 | !( 102 | skip_non_eol_ws_ 103 | [ 104 | gr(PRJ_ITEM/tagOption) % ';' 105 | ] 106 | ) 107 | ], 108 | case_(eqICase("defines")) 109 | [ 110 | !( 111 | skip_non_eol_ws_ 112 | [ 113 | gr(PRJ_ITEM/tagDefine) % ';' 114 | ] 115 | ) 116 | ], 117 | case_(eqICase("objdir")) 118 | [ 119 | !( 120 | skip_non_eol_ws_ 121 | [ 122 | gr(PRJ_PATH/tagObjDir) 123 | ] 124 | ) 125 | ], 126 | case_(eqICase("libdir")) 127 | [ 128 | !( 129 | skip_non_eol_ws_ 130 | [ 131 | gr(PRJ_ITEM/tagLibDir) % ';' 132 | ] 133 | ) 134 | ], 135 | case_(eqICase("libraries")) 136 | [ 137 | !( 138 | skip_non_eol_ws_ 139 | [ 140 | gr(PRJ_ITEM/tagLib) % ';' 141 | ] 142 | ) 143 | ] 144 | ] 145 | ) 146 | )/tagCfg 147 | ) + 148 | ( 149 | gr(icase["[source]"]) + +gr(PRJ_PATH/tagSrc) 150 | ) 151 | ]/doc) 152 | { 153 | NS_STDEXT::OutputLog log; 154 | json_print(alloc, log, doc); 155 | return 0; 156 | } 157 | 158 | err.print("Invalid project format!!!\n"); 159 | return -3; 160 | } 161 | 162 | // ------------------------------------------------------------------------- 163 | 164 | -------------------------------------------------------------------------------- /JSPT/prj2json/build/Makefile.li32: -------------------------------------------------------------------------------- 1 | OSAbbr = li 2 | Bits = 32 3 | Platform = li32 4 | 5 | # 6 | # Configuration Default 7 | # 8 | ifeq ($(CFG),) 9 | CFG = Debug 10 | endif 11 | 12 | IncludeDir = -I../../../../tpl/include -I../../../../stdext/include 13 | 14 | # 15 | # Configuration Release 16 | # 17 | ifeq ($(CFG), Release) 18 | ProductDir = ../../bin/$(Platform) 19 | ObjectDir = Release 20 | Product = ../../bin/$(Platform)/prj2json 21 | CFlags = $(Defines) -fPIC -D__32BIT__ -D__INTEL__ -D__LINUX__ -DLINUX -DNDEBUG -O2 -D_MT -fexceptions -Wall 22 | CXXFlags = $(CFlags) -fno-rtti 23 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 24 | CompileCXX = @g++ -c $(IncludeDir) $(CXXFlags) -o $@ $< 25 | Link = @g++ $(LibDir) -o $(Product) 26 | CheckLink = @ldd -u -r $(Product); echo 27 | LD_LIBRARY_PATH += :$(ProductDir) 28 | endif 29 | 30 | # 31 | # Configuration Debug 32 | # 33 | ifeq ($(CFG), Debug) 34 | ProductDir = Debug 35 | ObjectDir = Debug 36 | Product = Debug/prj2json 37 | CFlags = $(Defines) -fPIC -D__32BIT__ -D__INTEL__ -D__LINUX__ -DLINUX -D_DEBUG -g3 -D_MT -fexceptions -Wall 38 | CXXFlags = $(CFlags) -fno-rtti 39 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 40 | CompileCXX = @g++ -c $(IncludeDir) $(CXXFlags) -o $@ $< 41 | Link = @g++ $(LibDir) -o $(Product) 42 | CheckLink = @ldd -u -r $(Product); echo 43 | LD_LIBRARY_PATH += :$(ProductDir) 44 | endif 45 | 46 | # 47 | # Making... 48 | # 49 | all : $(ProductDir) $(ObjectDir) StartMake $(Product) EndMake 50 | 51 | $(ProductDir) : 52 | @mkdir -p $(ProductDir) 53 | 54 | ifneq ($(ProductDir),$(ObjectDir)) 55 | $(ObjectDir) : 56 | @mkdir -p $(ObjectDir) 57 | endif 58 | 59 | clean : 60 | @rm -f $(ObjectDir)/*.o 61 | @rm -f $(Product) 62 | 63 | StartMake : 64 | @echo "-------------- Configuration:" $(PROJ) $(CFG) "--------------" 65 | ifeq ($(ForceLink),1) 66 | @rm -f $(Product) 67 | endif 68 | 69 | EndMake : 70 | @echo ">>> Success <<<" 71 | 72 | # 73 | # Source Files, Objects & Product 74 | # 75 | $(ObjectDir)/ProjectJson.o : \ 76 | ../ProjectJson.cpp 77 | @echo "---> Compiling" $< "..." 78 | $(CompileCXX) 79 | 80 | Objects = $(ObjectDir)/ProjectJson.o 81 | 82 | $(Product) : $(Objects) 83 | @echo "---> Creating" $@ "..." 84 | @rm -f $@ 85 | $(Link) $(Objects) $(Libraries) 86 | $(CheckLink) 87 | 88 | -------------------------------------------------------------------------------- /JSPT/prj2json/build/Makefile.li64: -------------------------------------------------------------------------------- 1 | OSAbbr = li 2 | Bits = 64 3 | Platform = li64 4 | 5 | # 6 | # Configuration Default 7 | # 8 | ifeq ($(CFG),) 9 | CFG = Debug 10 | endif 11 | 12 | IncludeDir = -I../../../../tpl/include -I../../../../stdext/include 13 | 14 | # 15 | # Configuration Release 16 | # 17 | ifeq ($(CFG), Release) 18 | ProductDir = ../../bin/$(Platform) 19 | ObjectDir = Release 20 | Product = ../../bin/$(Platform)/prj2json 21 | CFlags = $(Defines) -fPIC -D__64BIT__ -D__INTEL__ -D__LINUX__ -DLINUX -DNDEBUG -O2 -D_MT -fexceptions -Wall 22 | CXXFlags = $(CFlags) -fno-rtti 23 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 24 | CompileCXX = @g++ -c $(IncludeDir) $(CXXFlags) -o $@ $< 25 | Link = @g++ $(LibDir) -o $(Product) 26 | CheckLink = @ldd -u -r $(Product); echo 27 | LD_LIBRARY_PATH += :$(ProductDir) 28 | endif 29 | 30 | # 31 | # Configuration Debug 32 | # 33 | ifeq ($(CFG), Debug) 34 | ProductDir = Debug 35 | ObjectDir = Debug 36 | Product = Debug/prj2json 37 | CFlags = $(Defines) -fPIC -D__64BIT__ -D__INTEL__ -D__LINUX__ -DLINUX -D_DEBUG -g3 -D_MT -fexceptions -Wall 38 | CXXFlags = $(CFlags) -fno-rtti 39 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 40 | CompileCXX = @g++ -c $(IncludeDir) $(CXXFlags) -o $@ $< 41 | Link = @g++ $(LibDir) -o $(Product) 42 | CheckLink = @ldd -u -r $(Product); echo 43 | LD_LIBRARY_PATH += :$(ProductDir) 44 | endif 45 | 46 | # 47 | # Making... 48 | # 49 | all : $(ProductDir) $(ObjectDir) StartMake $(Product) EndMake 50 | 51 | $(ProductDir) : 52 | @mkdir -p $(ProductDir) 53 | 54 | ifneq ($(ProductDir),$(ObjectDir)) 55 | $(ObjectDir) : 56 | @mkdir -p $(ObjectDir) 57 | endif 58 | 59 | clean : 60 | @rm -f $(ObjectDir)/*.o 61 | @rm -f $(Product) 62 | 63 | StartMake : 64 | @echo "-------------- Configuration:" $(PROJ) $(CFG) "--------------" 65 | ifeq ($(ForceLink),1) 66 | @rm -f $(Product) 67 | endif 68 | 69 | EndMake : 70 | @echo ">>> Success <<<" 71 | 72 | # 73 | # Source Files, Objects & Product 74 | # 75 | $(ObjectDir)/ProjectJson.o : \ 76 | ../ProjectJson.cpp 77 | @echo "---> Compiling" $< "..." 78 | $(CompileCXX) 79 | 80 | Objects = $(ObjectDir)/ProjectJson.o 81 | 82 | $(Product) : $(Objects) 83 | @echo "---> Creating" $@ "..." 84 | @rm -f $@ 85 | $(Link) $(Objects) $(Libraries) 86 | $(CheckLink) 87 | 88 | -------------------------------------------------------------------------------- /JSPT/prj2json/build/build: -------------------------------------------------------------------------------- 1 | make CFG=Release 2 | 3 | -------------------------------------------------------------------------------- /JSPT/prj2json/build/build.prj: -------------------------------------------------------------------------------- 1 | [Include] 2 | ../../../../tpl/include 3 | ../../../../stdext/include 4 | 5 | [Config Release] 6 | Product Exe ../../bin/$(Platform)/prj2json 7 | Options Release; MultiThread; AnsiChar; NoRtti; Exception; WarningAll; MiniDepency 8 | ObjDir Release 9 | LibDir 10 | Libraries 11 | 12 | [Config Debug] 13 | Product Exe Debug/prj2json 14 | Options Debug; MultiThread; AnsiChar; NoRtti; Exception; WarningAll 15 | ObjDir Debug 16 | LibDir 17 | Libraries 18 | 19 | [Source] 20 | ../*.cpp 21 | 22 | -------------------------------------------------------------------------------- /examples/boost-lambda/calc/Calc.cpp: -------------------------------------------------------------------------------- 1 | #define TPL_USE_AUTO_ALLOC 2 | #include // std::cout 3 | #include 4 | #include 5 | 6 | using namespace tpl; 7 | using namespace boost::lambda; 8 | 9 | int main() 10 | { 11 | typedef SimpleImplementation impl; 12 | 13 | // ---- define rules ---- 14 | 15 | impl::Allocator alloc; 16 | 17 | Lambda exec; 18 | 19 | TPL_LAMBDA_LOCAL(double, term); 20 | TPL_LAMBDA_LOCAL(double, factor); 21 | 22 | impl::Rule rTerm( alloc, 23 | real()/assign(factor) + *( 24 | '*' + real()/exec[factor *= _1] | 25 | '/' + real()/exec[factor /= _1] ) 26 | ); 27 | 28 | impl::Rule rExpr( alloc, 29 | rTerm/exec[term = factor] + *( 30 | '+' + rTerm/exec[term += factor] | 31 | '-' + rTerm/exec[term -= factor] ) 32 | ); 33 | 34 | // ---- do match ---- 35 | 36 | for (;;) 37 | { 38 | std::string strExp; 39 | std::cout << "input an expression (q to quit): "; 40 | std::getline(std::cin, strExp); 41 | 42 | if (strExp == "q") 43 | break; 44 | 45 | if (!impl::match(strExp.c_str(), rExpr + eos())) 46 | std::cout << "invalid expression!\n"; 47 | else 48 | std::cout << term() << "\n"; 49 | } 50 | } 51 | 52 | -------------------------------------------------------------------------------- /examples/boost-lambda/calc/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Configuration Default 3 | # 4 | ifeq ($(CFG),) 5 | CFG = Debug 6 | endif 7 | 8 | IncludeDir = -I../../../../tpl/include -I../../../../boost -I../../../../boostmm 9 | 10 | # 11 | # Configuration Release 12 | # 13 | ifeq ($(CFG), Release) 14 | ProductDir = Release 15 | ObjectDir = Release 16 | MocFile = $(ObjectDir)/temp.moc.cpp 17 | Product = Release/calc 18 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__32BIT__ -D__LINUX__ -DLINUX -DNDEBUG -O2 -D_MT -fexceptions 19 | CXXFlags = $(CFlags) -fno-rtti 20 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 21 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 22 | CompileCXX = @$(CXX) $< 23 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 24 | Link = @g++ $(LibDir) -o $(Product) 25 | CheckLink = @ldd -u -r $(Product); echo 26 | 27 | LD_LIBRARY_PATH += :$(ProductDir) 28 | endif 29 | 30 | # 31 | # Configuration Debug 32 | # 33 | ifeq ($(CFG), Debug) 34 | ProductDir = Debug 35 | ObjectDir = Debug 36 | MocFile = $(ObjectDir)/temp.moc.cpp 37 | Product = Debug/calc 38 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__32BIT__ -D__LINUX__ -DLINUX -D_DEBUG -g3 -D_MT -fexceptions 39 | CXXFlags = $(CFlags) -fno-rtti 40 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 41 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 42 | CompileCXX = @$(CXX) $< 43 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 44 | Link = @g++ $(LibDir) -o $(Product) 45 | CheckLink = @ldd -u -r $(Product); echo 46 | 47 | LD_LIBRARY_PATH += :$(ProductDir) 48 | endif 49 | 50 | # 51 | # Making... 52 | # 53 | all : $(ProductDir) $(ObjectDir) StartMake $(Product) EndMake 54 | 55 | $(ProductDir) : 56 | @mkdir -p $(ProductDir) 57 | 58 | ifneq ($(ProductDir),$(ObjectDir)) 59 | $(ObjectDir) : 60 | @mkdir -p $(ObjectDir) 61 | endif 62 | 63 | clean : 64 | @rm -f $(ObjectDir)/*.o 65 | @rm -f $(Product) 66 | 67 | StartMake : 68 | @echo "-------------- Configuration:" $(PROJ) $(CFG) "--------------" 69 | ifeq ($(ForceLink),1) 70 | @rm -f $(Product) 71 | endif 72 | 73 | EndMake : 74 | @echo ">>> Success <<<" 75 | 76 | # 77 | # Source Files, Objects & Product 78 | # 79 | $(ObjectDir)/Calc.o : \ 80 | Calc.cpp 81 | @echo "---> Compiling" $< "..." 82 | $(CompileCXX) 83 | 84 | 85 | Objects = \ 86 | $(ObjectDir)/Calc.o 87 | 88 | $(Product) : $(Objects) $(Libs) 89 | @echo "---> Creating" $@ "..." 90 | @rm -f $@ 91 | $(Link) $(Objects) $(Libraries) 92 | $(CheckLink) 93 | 94 | -------------------------------------------------------------------------------- /examples/boost-lambda/calc/build: -------------------------------------------------------------------------------- 1 | make CFG=Release 2 | 3 | -------------------------------------------------------------------------------- /examples/boost-lambda/calc/calc.prj: -------------------------------------------------------------------------------- 1 | [Include] 2 | ../../../../tpl/include 3 | ../../../../boost 4 | ../../../../boostmm 5 | 6 | [Config Release] 7 | Product Exe Release/calc 8 | Options Release; MultiThread; AnsiChar; NoRtti; Exception 9 | ObjDir Release 10 | LibDir 11 | Libraries 12 | 13 | [Config Debug] 14 | Product Exe Debug/calc 15 | Options Debug; MultiThread; AnsiChar; NoRtti; Exception 16 | ObjDir Debug 17 | LibDir 18 | Libraries 19 | 20 | [Source] 21 | Calc.cpp 22 | 23 | -------------------------------------------------------------------------------- /examples/boost-lambda/print/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Configuration Default 3 | # 4 | ifeq ($(CFG),) 5 | CFG = Debug 6 | endif 7 | 8 | IncludeDir = -I../../../../tpl/include -I../../../../boost -I../../../../boostmm 9 | 10 | # 11 | # Configuration Release 12 | # 13 | ifeq ($(CFG), Release) 14 | ProductDir = Release 15 | ObjectDir = Release 16 | MocFile = $(ObjectDir)/temp.moc.cpp 17 | Product = Release/test 18 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__32BIT__ -D__LINUX__ -DLINUX -DNDEBUG -O2 -D_MT -fexceptions 19 | CXXFlags = $(CFlags) -fno-rtti 20 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 21 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 22 | CompileCXX = @$(CXX) $< 23 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 24 | Link = @g++ $(LibDir) -o $(Product) 25 | CheckLink = @ldd -u -r $(Product); echo 26 | 27 | LD_LIBRARY_PATH += :$(ProductDir) 28 | endif 29 | 30 | # 31 | # Configuration Debug 32 | # 33 | ifeq ($(CFG), Debug) 34 | ProductDir = Debug 35 | ObjectDir = Debug 36 | MocFile = $(ObjectDir)/temp.moc.cpp 37 | Product = Debug/test 38 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__32BIT__ -D__LINUX__ -DLINUX -D_DEBUG -g3 -D_MT -fexceptions 39 | CXXFlags = $(CFlags) -fno-rtti 40 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 41 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 42 | CompileCXX = @$(CXX) $< 43 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 44 | Link = @g++ $(LibDir) -o $(Product) 45 | CheckLink = @ldd -u -r $(Product); echo 46 | 47 | LD_LIBRARY_PATH += :$(ProductDir) 48 | endif 49 | 50 | # 51 | # Making... 52 | # 53 | all : $(ProductDir) $(ObjectDir) StartMake $(Product) EndMake 54 | 55 | $(ProductDir) : 56 | @mkdir -p $(ProductDir) 57 | 58 | ifneq ($(ProductDir),$(ObjectDir)) 59 | $(ObjectDir) : 60 | @mkdir -p $(ObjectDir) 61 | endif 62 | 63 | clean : 64 | @rm -f $(ObjectDir)/*.o 65 | @rm -f $(Product) 66 | 67 | StartMake : 68 | @echo "-------------- Configuration:" $(PROJ) $(CFG) "--------------" 69 | ifeq ($(ForceLink),1) 70 | @rm -f $(Product) 71 | endif 72 | 73 | EndMake : 74 | @echo ">>> Success <<<" 75 | 76 | # 77 | # Source Files, Objects & Product 78 | # 79 | $(ObjectDir)/Simplest.o : \ 80 | ./Simplest.cpp 81 | @echo "---> Compiling" $< "..." 82 | $(CompileCXX) 83 | 84 | 85 | Objects = \ 86 | $(ObjectDir)/Simplest.o 87 | 88 | $(Product) : $(Objects) $(Libs) 89 | @echo "---> Creating" $@ "..." 90 | @rm -f $@ 91 | $(Link) $(Objects) $(Libraries) 92 | $(CheckLink) 93 | 94 | -------------------------------------------------------------------------------- /examples/boost-lambda/print/Simplest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace tpl; 6 | using namespace boost::lambda; 7 | 8 | int main() 9 | { 10 | Lambda exec; 11 | "-.1 -0.1 +32. -22323.2e+12" >> real()/exec[std::cout << _1 << constant('\n')] % ws(); 12 | return 0; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /examples/boost-lambda/print/build: -------------------------------------------------------------------------------- 1 | make CFG=Release 2 | 3 | -------------------------------------------------------------------------------- /examples/boost-lambda/print/print.prj: -------------------------------------------------------------------------------- 1 | [Include] 2 | ../../../../tpl/include 3 | ../../../../boost 4 | ../../../../boostmm 5 | 6 | [Config Release] 7 | Product Exe Release/test 8 | Options Release; MultiThread; AnsiChar; NoRtti; Exception 9 | ObjDir Release 10 | LibDir 11 | Libraries 12 | 13 | [Config Debug] 14 | Product Exe Debug/test 15 | Options Debug; MultiThread; AnsiChar; NoRtti; Exception 16 | ObjDir Debug 17 | LibDir 18 | Libraries 19 | 20 | [Source] 21 | *.cpp 22 | 23 | -------------------------------------------------------------------------------- /examples/boost-phoenix/calc/Calc.cpp: -------------------------------------------------------------------------------- 1 | #define TPL_USE_AUTO_ALLOC 2 | #include // std::cout 3 | #include 4 | #include 5 | 6 | using namespace tpl; 7 | using namespace phoenix; 8 | 9 | int main() 10 | { 11 | typedef SimpleImplementation impl; 12 | 13 | // ---- define rules ---- 14 | 15 | impl::Allocator alloc; 16 | 17 | Phoenix calc; 18 | Phoenix<> exec; 19 | 20 | TPL_PHOENIX_LOCAL(double, term); 21 | TPL_PHOENIX_LOCAL(double, factor); 22 | 23 | impl::Rule rTerm( alloc, 24 | real()/assign(factor) + *( 25 | '*' + real()/calc[factor *= arg1] | 26 | '/' + real()/calc[factor /= arg1] ) 27 | ); 28 | 29 | impl::Rule rExpr( alloc, 30 | rTerm/exec[term = factor] + *( 31 | '+' + rTerm/exec[term += factor] | 32 | '-' + rTerm/exec[term -= factor] ) 33 | ); 34 | 35 | // ---- do match ---- 36 | 37 | for (;;) 38 | { 39 | std::string strExp; 40 | std::cout << "input an expression (q to quit): "; 41 | std::getline(std::cin, strExp); 42 | 43 | if (strExp == "q") 44 | break; 45 | 46 | if (!impl::match(strExp.c_str(), rExpr + eos())) 47 | std::cout << "invalid expression!\n"; 48 | else 49 | std::cout << term() << "\n"; 50 | } 51 | } 52 | 53 | -------------------------------------------------------------------------------- /examples/boost-phoenix/calc/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Configuration Default 3 | # 4 | ifeq ($(CFG),) 5 | CFG = Debug 6 | endif 7 | 8 | IncludeDir = -I../../../../tpl/include -I../../../../boost -I../../../../boostmm 9 | 10 | # 11 | # Configuration Release 12 | # 13 | ifeq ($(CFG), Release) 14 | ProductDir = Release 15 | ObjectDir = Release 16 | MocFile = $(ObjectDir)/temp.moc.cpp 17 | Product = Release/calc 18 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__32BIT__ -D__LINUX__ -DLINUX -DNDEBUG -O2 -D_MT -fexceptions 19 | CXXFlags = $(CFlags) -fno-rtti -Wall 20 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 21 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 22 | CompileCXX = @$(CXX) $< 23 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 24 | Link = @g++ $(LibDir) -o $(Product) 25 | CheckLink = @ldd -u -r $(Product); echo 26 | 27 | LD_LIBRARY_PATH += :$(ProductDir) 28 | endif 29 | 30 | # 31 | # Configuration Debug 32 | # 33 | ifeq ($(CFG), Debug) 34 | ProductDir = Debug 35 | ObjectDir = Debug 36 | MocFile = $(ObjectDir)/temp.moc.cpp 37 | Product = Debug/calc 38 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__32BIT__ -D__LINUX__ -DLINUX -D_DEBUG -g3 -D_MT -fexceptions 39 | CXXFlags = $(CFlags) -fno-rtti -Wall 40 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 41 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 42 | CompileCXX = @$(CXX) $< 43 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 44 | Link = @g++ $(LibDir) -o $(Product) 45 | CheckLink = @ldd -u -r $(Product); echo 46 | 47 | LD_LIBRARY_PATH += :$(ProductDir) 48 | endif 49 | 50 | # 51 | # Making... 52 | # 53 | all : $(ProductDir) $(ObjectDir) StartMake $(Product) EndMake 54 | 55 | $(ProductDir) : 56 | @mkdir -p $(ProductDir) 57 | 58 | ifneq ($(ProductDir),$(ObjectDir)) 59 | $(ObjectDir) : 60 | @mkdir -p $(ObjectDir) 61 | endif 62 | 63 | clean : 64 | @rm -f $(ObjectDir)/*.o 65 | @rm -f $(Product) 66 | 67 | StartMake : 68 | @echo "-------------- Configuration:" $(PROJ) $(CFG) "--------------" 69 | ifeq ($(ForceLink),1) 70 | @rm -f $(Product) 71 | endif 72 | 73 | EndMake : 74 | @echo ">>> Success <<<" 75 | 76 | # 77 | # Source Files, Objects & Product 78 | # 79 | $(ObjectDir)/Calc.o : \ 80 | Calc.cpp 81 | @echo "---> Compiling" $< "..." 82 | $(CompileCXX) 83 | 84 | 85 | Objects = \ 86 | $(ObjectDir)/Calc.o 87 | 88 | $(Product) : $(Objects) $(Libs) 89 | @echo "---> Creating" $@ "..." 90 | @rm -f $@ 91 | $(Link) $(Objects) $(Libraries) 92 | $(CheckLink) 93 | 94 | -------------------------------------------------------------------------------- /examples/boost-phoenix/calc/build: -------------------------------------------------------------------------------- 1 | make CFG=Release 2 | 3 | -------------------------------------------------------------------------------- /examples/boost-phoenix/calc/calc.prj: -------------------------------------------------------------------------------- 1 | [Include] 2 | ../../../../tpl/include 3 | ../../../../boost 4 | ../../../../boostmm 5 | 6 | [Config Release] 7 | Product Exe Release/calc 8 | Options Release; MultiThread; AnsiChar; NoRtti; Exception; WarningAll 9 | ObjDir Release 10 | LibDir 11 | Libraries 12 | 13 | [Config Debug] 14 | Product Exe Debug/calc 15 | Options Debug; MultiThread; AnsiChar; NoRtti; Exception; WarningAll 16 | ObjDir Debug 17 | LibDir 18 | Libraries 19 | 20 | [Source] 21 | Calc.cpp 22 | 23 | -------------------------------------------------------------------------------- /examples/boost-phoenix/print/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Configuration Default 3 | # 4 | ifeq ($(CFG),) 5 | CFG = Debug 6 | endif 7 | 8 | IncludeDir = -I../../../../tpl/include -I../../../../boost -I../../../../boostmm 9 | 10 | # 11 | # Configuration Release 12 | # 13 | ifeq ($(CFG), Release) 14 | ProductDir = Release 15 | ObjectDir = Release 16 | MocFile = $(ObjectDir)/temp.moc.cpp 17 | Product = Release/test 18 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__32BIT__ -D__LINUX__ -DLINUX -DNDEBUG -O2 -D_MT -fexceptions 19 | CXXFlags = $(CFlags) -fno-rtti 20 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 21 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 22 | CompileCXX = @$(CXX) $< 23 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 24 | Link = @g++ $(LibDir) -o $(Product) 25 | CheckLink = @ldd -u -r $(Product); echo 26 | 27 | LD_LIBRARY_PATH += :$(ProductDir) 28 | endif 29 | 30 | # 31 | # Configuration Debug 32 | # 33 | ifeq ($(CFG), Debug) 34 | ProductDir = Debug 35 | ObjectDir = Debug 36 | MocFile = $(ObjectDir)/temp.moc.cpp 37 | Product = Debug/test 38 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__32BIT__ -D__LINUX__ -DLINUX -D_DEBUG -g3 -D_MT -fexceptions 39 | CXXFlags = $(CFlags) -fno-rtti 40 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 41 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 42 | CompileCXX = @$(CXX) $< 43 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 44 | Link = @g++ $(LibDir) -o $(Product) 45 | CheckLink = @ldd -u -r $(Product); echo 46 | 47 | LD_LIBRARY_PATH += :$(ProductDir) 48 | endif 49 | 50 | # 51 | # Making... 52 | # 53 | all : $(ProductDir) $(ObjectDir) StartMake $(Product) EndMake 54 | 55 | $(ProductDir) : 56 | @mkdir -p $(ProductDir) 57 | 58 | ifneq ($(ProductDir),$(ObjectDir)) 59 | $(ObjectDir) : 60 | @mkdir -p $(ObjectDir) 61 | endif 62 | 63 | clean : 64 | @rm -f $(ObjectDir)/*.o 65 | @rm -f $(Product) 66 | 67 | StartMake : 68 | @echo "-------------- Configuration:" $(PROJ) $(CFG) "--------------" 69 | ifeq ($(ForceLink),1) 70 | @rm -f $(Product) 71 | endif 72 | 73 | EndMake : 74 | @echo ">>> Success <<<" 75 | 76 | # 77 | # Source Files, Objects & Product 78 | # 79 | $(ObjectDir)/Simplest.o : \ 80 | ./Simplest.cpp 81 | @echo "---> Compiling" $< "..." 82 | $(CompileCXX) 83 | 84 | 85 | Objects = \ 86 | $(ObjectDir)/Simplest.o 87 | 88 | $(Product) : $(Objects) $(Libs) 89 | @echo "---> Creating" $@ "..." 90 | @rm -f $@ 91 | $(Link) $(Objects) $(Libraries) 92 | $(CheckLink) 93 | 94 | -------------------------------------------------------------------------------- /examples/boost-phoenix/print/Simplest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace tpl; 6 | using namespace phoenix; 7 | 8 | int main() 9 | { 10 | Phoenix exec; 11 | "-.1 -0.1 +32. -22323.2e+12" >> real()/exec[std::cout << arg1 << const_('\n')] % ws(); 12 | return 0; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /examples/boost-phoenix/print/build: -------------------------------------------------------------------------------- 1 | make CFG=Release 2 | 3 | -------------------------------------------------------------------------------- /examples/boost-phoenix/print/print.prj: -------------------------------------------------------------------------------- 1 | [Include] 2 | ../../../../tpl/include 3 | ../../../../boost 4 | ../../../../boostmm 5 | 6 | [Config Release] 7 | Product Exe Release/test 8 | Options Release; MultiThread; AnsiChar; NoRtti; Exception 9 | ObjDir Release 10 | LibDir 11 | Libraries 12 | 13 | [Config Debug] 14 | Product Exe Debug/test 15 | Options Debug; MultiThread; AnsiChar; NoRtti; Exception 16 | ObjDir Debug 17 | LibDir 18 | Libraries 19 | 20 | [Source] 21 | *.cpp 22 | 23 | -------------------------------------------------------------------------------- /examples/calculator/Calc.cpp: -------------------------------------------------------------------------------- 1 | #define TPL_USE_AUTO_ALLOC 2 | #include // sin, cos, pow 3 | #include // std::deque 4 | #include // std::cout 5 | #include // std::plus, std::minus, etc 6 | #include // std::max_element 7 | #include 8 | 9 | using namespace tpl; 10 | 11 | double max_value(const double x[], int count) 12 | { 13 | return *std::max_element(x, x+count); 14 | } 15 | 16 | void calculator(const char* szExpr) 17 | { 18 | typedef SimpleImplementation impl; 19 | 20 | // ---- define rules ---- 21 | 22 | std::deque stk; 23 | 24 | impl::Grammar::Var rFactor; 25 | 26 | impl::Grammar rTerm = 27 | rFactor + *( 28 | '*' + rFactor/calc(stk) | 29 | '/' + rFactor/calc(stk) ); 30 | 31 | impl::Grammar rExpr = 32 | rTerm + *( 33 | '+' + rTerm/calc(stk) | 34 | '-' + rTerm/calc(stk) ); 35 | 36 | int arity; 37 | impl::Rule rFun = 38 | "sin"/calc(stk, sin, arity) | "cos"/calc(stk, cos, arity) | 39 | "pow"/calc(stk, pow, arity) | "max"/calc(stk, max_value, arity); 40 | 41 | rFactor = 42 | real()/append(stk) | 43 | '-' + rFactor/calc(stk) | 44 | '(' + rExpr + ')' | 45 | (gr(c_symbol()) + '(' + rExpr % ','/assign(arity) + ')')/(gr(rFun) + '(') | 46 | '+' + rFactor; 47 | 48 | // ---- do match ---- 49 | 50 | try { 51 | if ( szExpr != skipws_[rExpr] ) 52 | std::cerr << ">>> ERROR: invalid expression!\n"; 53 | else 54 | std::cout << stk.back() << '\n'; 55 | } 56 | catch (const std::logic_error& e) { 57 | std::cerr << ">>> ERROR: " << e.what() << '\n'; 58 | } 59 | } 60 | 61 | int main(int argc, const char* argv[]) 62 | { 63 | if (argc == 2) { 64 | calculator(argv[1]); 65 | return 0; 66 | } 67 | else { 68 | for (;;) 69 | { 70 | std::string strExp; 71 | std::cout << "input an expression (q to quit): "; 72 | if (!std::getline(std::cin, strExp) || strExp == "q") { 73 | std::cout << '\n'; 74 | return 0; 75 | } 76 | calculator(strExp.c_str()); 77 | } 78 | } 79 | } 80 | 81 | -------------------------------------------------------------------------------- /examples/calculator/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Configuration Default 3 | # 4 | ifeq ($(CFG),) 5 | CFG = Debug 6 | endif 7 | 8 | IncludeDir = -I../../../tpl/include -I../../../boost 9 | 10 | # 11 | # Configuration Release 12 | # 13 | ifeq ($(CFG), Release) 14 | ProductDir = Release 15 | ObjectDir = Release 16 | MocFile = $(ObjectDir)/temp.moc.cpp 17 | Product = Release/calc 18 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -DNDEBUG -O2 -D_MT -fexceptions 19 | CXXFlags = $(CFlags) -fno-rtti 20 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 21 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 22 | CompileCXX = @$(CXX) $< 23 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 24 | Link = @g++ $(LibDir) -ldl -o $(Product) 25 | LD_LIBRARY_PATH += :$(ProductDir) 26 | endif 27 | 28 | # 29 | # Configuration Debug 30 | # 31 | ifeq ($(CFG), Debug) 32 | ProductDir = Debug 33 | ObjectDir = Debug 34 | MocFile = $(ObjectDir)/temp.moc.cpp 35 | Product = Debug/calc 36 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -D_DEBUG -g3 -D_MT -fexceptions 37 | CXXFlags = $(CFlags) -fno-rtti 38 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 39 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 40 | CompileCXX = @$(CXX) $< 41 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 42 | Link = @g++ $(LibDir) -ldl -o $(Product) 43 | LD_LIBRARY_PATH += :$(ProductDir) 44 | endif 45 | 46 | # 47 | # Making... 48 | # 49 | all : $(ProductDir) $(ObjectDir) StartMake $(Product) EndMake 50 | 51 | $(ProductDir) : 52 | @mkdir -p $(ProductDir) 53 | 54 | ifneq ($(ProductDir),$(ObjectDir)) 55 | $(ObjectDir) : 56 | @mkdir -p $(ObjectDir) 57 | endif 58 | 59 | clean : 60 | @rm -f $(ObjectDir)/*.o 61 | @rm -f $(Product) 62 | 63 | StartMake : 64 | @echo "-------------- Configuration:" $(PROJ) $(CFG) "--------------" 65 | ifeq ($(ForceLink),1) 66 | @rm -f $(Product) 67 | endif 68 | 69 | EndMake : 70 | @echo ">>> Success <<<" 71 | 72 | # 73 | # Source Files, Objects & Product 74 | # 75 | $(ObjectDir)/Calc.o : \ 76 | Calc.cpp 77 | @echo "---> Compiling" $< "..." 78 | $(CompileCXX) 79 | 80 | 81 | Objects = \ 82 | $(ObjectDir)/Calc.o 83 | 84 | $(Product) : $(Objects) $(Libs) 85 | @echo "---> Creating" $@ "..." 86 | @rm -f $@ 87 | $(Link) $(Objects) $(Libraries) 88 | $(CheckLink) 89 | 90 | -------------------------------------------------------------------------------- /examples/calculator/build: -------------------------------------------------------------------------------- 1 | make CFG=Release 2 | 3 | -------------------------------------------------------------------------------- /examples/calculator/calculator.prj: -------------------------------------------------------------------------------- 1 | [Include] 2 | ../../../tpl/include 3 | ../../../boost 4 | ../../../boostmm 5 | 6 | [Config Release] 7 | Product Exe Release/exp 8 | Options Release; MultiThread; AnsiChar; NoRtti; Exception 9 | ObjDir Release 10 | LibDir 11 | Libraries 12 | 13 | [Config Debug] 14 | Product Exe Debug/exp 15 | Options Debug; MultiThread; AnsiChar; NoRtti; Exception 16 | ObjDir Debug 17 | LibDir 18 | Libraries 19 | 20 | [Source] 21 | Calc.cpp 22 | 23 | -------------------------------------------------------------------------------- /examples/calculator/readme.txt: -------------------------------------------------------------------------------- 1 | + Introduction 2 | 3 | This application is a simple calculator. It supports: 4 | 5 | ++ REAL REAL 6 | 7 | Here can be: operator+, operator-, operator*, operator/. 8 | And here REAL can be any expression that return a real number. 9 | 10 | ++ REAL 11 | 12 | Here can be unary operator+, unary operator-. 13 | 14 | ++ (REAL) 15 | 16 | Yes, the calculator supports (). 17 | 18 | ++ sin(REAL), cos(REAL), pow(REAL, REAL), max(REAL, ...) 19 | 20 | The calculator support sin, cos, pow, max functions. 21 | Note that max function has variable arity. 22 | 23 | + Examples 24 | 25 | Exp: 4 * -(3 + 2) 26 | Result: -20 27 | 28 | Exp: max(1, 2, pow(3,2), pow(2,3)) 29 | Result: 9 30 | 31 | -------------------------------------------------------------------------------- /examples/circuit/Circuit.cpp: -------------------------------------------------------------------------------- 1 | #define TPL_USE_AUTO_ALLOC 2 | #include // std::cout 3 | #include 4 | 5 | using namespace tpl; 6 | 7 | // ------------------------------------------------------------------------- 8 | // circuit 9 | 10 | // Note: 11 | // if two rules A, B circularly refer to each other (or a rule A refer to itself), 12 | // we need use Rule::Var to break the circuit. 13 | 14 | int main() 15 | { 16 | typedef simple impl; 17 | 18 | // ---- define rules ---- 19 | 20 | impl::Allocator alloc; 21 | 22 | std::vector values; 23 | 24 | impl::Rule::Var rDoc; 25 | rDoc.assign( alloc, integer()/append(values) + !(',' + rDoc) ); 26 | 27 | // This is only an example. A better way to do the same thing is: 28 | // rDoc.assign( alloc, integer()/append(values) % ',' ); 29 | 30 | // ---- do match ---- 31 | 32 | if ("10,97,37" >> rDoc) { 33 | for (std::vector::const_iterator it = values.begin(); it != values.end(); ++it) { 34 | std::cout << *it << "\n"; 35 | } 36 | } 37 | return 0; 38 | } 39 | 40 | // ------------------------------------------------------------------------- 41 | 42 | -------------------------------------------------------------------------------- /examples/circuit/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Configuration Default 3 | # 4 | ifeq ($(CFG),) 5 | CFG = Debug 6 | endif 7 | 8 | IncludeDir = -I../../../tpl/include -I../../../boost -I../../../boostmm 9 | 10 | # 11 | # Configuration Release 12 | # 13 | ifeq ($(CFG), Release) 14 | ProductDir = Release 15 | ObjectDir = Release 16 | MocFile = $(ObjectDir)/temp.moc.cpp 17 | Product = Release/circuit 18 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__32BIT__ -D__LINUX__ -DLINUX -DNDEBUG -O2 -D_MT -fexceptions 19 | CXXFlags = $(CFlags) -fno-rtti 20 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 21 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 22 | CompileCXX = @$(CXX) $< 23 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 24 | Link = @g++ $(LibDir) -ldl -o $(Product) 25 | LD_LIBRARY_PATH += :$(ProductDir) 26 | endif 27 | 28 | # 29 | # Configuration Debug 30 | # 31 | ifeq ($(CFG), Debug) 32 | ProductDir = Debug 33 | ObjectDir = Debug 34 | MocFile = $(ObjectDir)/temp.moc.cpp 35 | Product = Debug/circuit 36 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__32BIT__ -D__LINUX__ -DLINUX -D_DEBUG -g3 -D_MT -fexceptions 37 | CXXFlags = $(CFlags) -frtti 38 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 39 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 40 | CompileCXX = @$(CXX) $< 41 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 42 | Link = @g++ $(LibDir) -ldl -o $(Product) 43 | LD_LIBRARY_PATH += :$(ProductDir) 44 | endif 45 | 46 | # 47 | # Making... 48 | # 49 | all : $(ProductDir) $(ObjectDir) StartMake $(Product) EndMake 50 | 51 | $(ProductDir) : 52 | @mkdir -p $(ProductDir) 53 | 54 | ifneq ($(ProductDir),$(ObjectDir)) 55 | $(ObjectDir) : 56 | @mkdir -p $(ObjectDir) 57 | endif 58 | 59 | clean : 60 | @rm -f $(ObjectDir)/*.o 61 | @rm -f $(Product) 62 | 63 | StartMake : 64 | @echo "-------------- Configuration:" $(PROJ) $(CFG) "--------------" 65 | ifeq ($(ForceLink),1) 66 | @rm -f $(Product) 67 | endif 68 | 69 | EndMake : 70 | @echo ">>> Success <<<" 71 | 72 | # 73 | # Source Files, Objects & Product 74 | # 75 | $(ObjectDir)/Circuit.o : \ 76 | Circuit.cpp 77 | @echo "---> Compiling" $< "..." 78 | $(CompileCXX) 79 | 80 | 81 | Objects = \ 82 | $(ObjectDir)/Circuit.o 83 | 84 | $(Product) : $(Objects) $(Libs) 85 | @echo "---> Creating" $@ "..." 86 | @rm -f $@ 87 | $(Link) $(Objects) $(Libraries) 88 | $(CheckLink) 89 | 90 | -------------------------------------------------------------------------------- /examples/circuit/build: -------------------------------------------------------------------------------- 1 | make CFG=Release 2 | 3 | -------------------------------------------------------------------------------- /examples/circuit/circuit.prj: -------------------------------------------------------------------------------- 1 | [Include] 2 | ../../../tpl/include 3 | ../../../boost 4 | ../../../boostmm 5 | 6 | [Config Release] 7 | Product Exe Release/circuit 8 | Options Release; MultiThread; AnsiChar; NoRtti; Exception 9 | ObjDir Release 10 | LibDir 11 | Libraries 12 | 13 | [Config Debug] 14 | Product Exe Debug/circuit 15 | Options Debug; MultiThread; AnsiChar; Rtti; Exception 16 | ObjDir Debug 17 | LibDir 18 | Libraries 19 | 20 | [Source] 21 | Circuit.cpp 22 | 23 | -------------------------------------------------------------------------------- /examples/emulator/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Configuration Default 3 | # 4 | ifeq ($(CFG),) 5 | CFG = Debug 6 | endif 7 | 8 | IncludeDir = -I../../../tpl/include -I../../../boost 9 | 10 | # 11 | # Configuration Release 12 | # 13 | ifeq ($(CFG), Release) 14 | ProductDir = Release 15 | ObjectDir = Release 16 | MocFile = $(ObjectDir)/temp.moc.cpp 17 | Product = Release/emu 18 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -DNDEBUG -O2 -D_MT -fexceptions 19 | CXXFlags = $(CFlags) -fno-rtti 20 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 21 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 22 | CompileCXX = @$(CXX) $< 23 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 24 | Link = @g++ $(LibDir) -ldl -o $(Product) 25 | LD_LIBRARY_PATH += :$(ProductDir) 26 | endif 27 | 28 | # 29 | # Configuration Debug 30 | # 31 | ifeq ($(CFG), Debug) 32 | ProductDir = Debug 33 | ObjectDir = Debug 34 | MocFile = $(ObjectDir)/temp.moc.cpp 35 | Product = Debug/emu 36 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -D_DEBUG -g3 -D_MT -fexceptions 37 | CXXFlags = $(CFlags) -fno-rtti 38 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 39 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 40 | CompileCXX = @$(CXX) $< 41 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 42 | Link = @g++ $(LibDir) -ldl -o $(Product) 43 | LD_LIBRARY_PATH += :$(ProductDir) 44 | endif 45 | 46 | # 47 | # Making... 48 | # 49 | all : $(ProductDir) $(ObjectDir) StartMake $(Product) EndMake 50 | 51 | $(ProductDir) : 52 | @mkdir -p $(ProductDir) 53 | 54 | ifneq ($(ProductDir),$(ObjectDir)) 55 | $(ObjectDir) : 56 | @mkdir -p $(ObjectDir) 57 | endif 58 | 59 | clean : 60 | @rm -f $(ObjectDir)/*.o 61 | @rm -f $(Product) 62 | 63 | StartMake : 64 | @echo "-------------- Configuration:" $(PROJ) $(CFG) "--------------" 65 | ifeq ($(ForceLink),1) 66 | @rm -f $(Product) 67 | endif 68 | 69 | EndMake : 70 | @echo ">>> Success <<<" 71 | 72 | # 73 | # Source Files, Objects & Product 74 | # 75 | $(ObjectDir)/Emulator.o : \ 76 | Emulator.cpp 77 | @echo "---> Compiling" $< "..." 78 | $(CompileCXX) 79 | 80 | 81 | Objects = \ 82 | $(ObjectDir)/Emulator.o 83 | 84 | $(Product) : $(Objects) $(Libs) 85 | @echo "---> Creating" $@ "..." 86 | @rm -f $@ 87 | $(Link) $(Objects) $(Libraries) 88 | $(CheckLink) 89 | 90 | -------------------------------------------------------------------------------- /examples/emulator/build: -------------------------------------------------------------------------------- 1 | make CFG=Release 2 | 3 | -------------------------------------------------------------------------------- /examples/emulator/emulator.prj: -------------------------------------------------------------------------------- 1 | [Include] 2 | ../../../tpl/include 3 | ../../../boost 4 | ../../../boostmm 5 | 6 | [Config Release] 7 | Product Exe Release/emu 8 | Options Release; MultiThread; AnsiChar; NoRtti; Exception 9 | ObjDir Release 10 | LibDir 11 | Libraries 12 | 13 | [Config Debug] 14 | Product Exe Debug/emu 15 | Options Debug; MultiThread; AnsiChar; Rtti; Exception 16 | ObjDir Debug 17 | LibDir 18 | Libraries 19 | 20 | [Source] 21 | Emulator.cpp 22 | 23 | -------------------------------------------------------------------------------- /examples/grammar/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Configuration Default 3 | # 4 | ifeq ($(CFG),) 5 | CFG = Debug 6 | endif 7 | 8 | IncludeDir = -I../../../tpl/include 9 | 10 | # 11 | # Configuration Release 12 | # 13 | ifeq ($(CFG), Release) 14 | ProductDir = Release 15 | ObjectDir = Release 16 | MocFile = $(ObjectDir)/temp.moc.cpp 17 | Product = Release/grammar 18 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -DNDEBUG -O2 -D_MT -fexceptions 19 | CXXFlags = $(CFlags) -fno-rtti 20 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 21 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 22 | CompileCXX = @$(CXX) $< 23 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 24 | Link = @g++ $(LibDir) -ldl -o $(Product) 25 | LD_LIBRARY_PATH += :$(ProductDir) 26 | endif 27 | 28 | # 29 | # Configuration Debug 30 | # 31 | ifeq ($(CFG), Debug) 32 | ProductDir = Debug 33 | ObjectDir = Debug 34 | MocFile = $(ObjectDir)/temp.moc.cpp 35 | Product = Debug/grammar 36 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -D_DEBUG -g3 -D_MT -fexceptions 37 | CXXFlags = $(CFlags) -fno-rtti 38 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 39 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 40 | CompileCXX = @$(CXX) $< 41 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 42 | Link = @g++ $(LibDir) -ldl -o $(Product) 43 | LD_LIBRARY_PATH += :$(ProductDir) 44 | endif 45 | 46 | # 47 | # Making... 48 | # 49 | all : $(ProductDir) $(ObjectDir) StartMake $(Product) EndMake 50 | 51 | $(ProductDir) : 52 | @mkdir -p $(ProductDir) 53 | 54 | ifneq ($(ProductDir),$(ObjectDir)) 55 | $(ObjectDir) : 56 | @mkdir -p $(ObjectDir) 57 | endif 58 | 59 | clean : 60 | @rm -f $(ObjectDir)/*.o 61 | @rm -f $(Product) 62 | 63 | StartMake : 64 | @echo "-------------- Configuration:" $(PROJ) $(CFG) "--------------" 65 | ifeq ($(ForceLink),1) 66 | @rm -f $(Product) 67 | endif 68 | 69 | EndMake : 70 | @echo ">>> Success <<<" 71 | 72 | # 73 | # Source Files, Objects & Product 74 | # 75 | $(ObjectDir)/SimpleGrammar.o : \ 76 | SimpleGrammar.cpp 77 | @echo "---> Compiling" $< "..." 78 | $(CompileCXX) 79 | 80 | 81 | Objects = \ 82 | $(ObjectDir)/SimpleGrammar.o 83 | 84 | $(Product) : $(Objects) $(Libs) 85 | @echo "---> Creating" $@ "..." 86 | @rm -f $@ 87 | $(Link) $(Objects) $(Libraries) 88 | $(CheckLink) 89 | 90 | -------------------------------------------------------------------------------- /examples/grammar/SimpleGrammar.cpp: -------------------------------------------------------------------------------- 1 | #include // std::vector 2 | #include // std::cout 3 | #include 4 | 5 | using namespace tpl; 6 | 7 | // ------------------------------------------------------------------------- 8 | // simple_grammar 9 | 10 | // A simple grammar example. 11 | 12 | // What we use: 13 | // * Rules: /append(), %, real(), gr(','), skipws() 14 | // * Matching: tpl::simple::match() 15 | 16 | int main() 17 | { 18 | std::vector values; // you can change vector to other stl containers. 19 | 20 | if ( simple::match(" -.1 , -0.1 , +32. , -22323.2e+12 ", real()/append(values) % gr(','), skipws()) ) 21 | { 22 | for (std::vector::iterator it = values.begin(); it != values.end(); ++it) 23 | { 24 | std::cout << *it << "\n"; 25 | } 26 | } 27 | return 0; 28 | } 29 | 30 | // ------------------------------------------------------------------------- 31 | 32 | -------------------------------------------------------------------------------- /examples/grammar/build: -------------------------------------------------------------------------------- 1 | make CFG=Release 2 | 3 | -------------------------------------------------------------------------------- /examples/grammar/grammar.prj: -------------------------------------------------------------------------------- 1 | [Include] 2 | ../../../tpl/include 3 | 4 | [Config Release] 5 | Product Exe Release/grammar 6 | Options Release; MultiThread; AnsiChar; NoRtti; Exception 7 | ObjDir Release 8 | LibDir 9 | Libraries 10 | 11 | [Config Debug] 12 | Product Exe Debug/grammar 13 | Options Debug; MultiThread; AnsiChar; NoRtti; Exception 14 | ObjDir Debug 15 | LibDir 16 | Libraries 17 | 18 | [Source] 19 | SimpleGrammar.cpp 20 | 21 | -------------------------------------------------------------------------------- /examples/grammar2/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Configuration Default 3 | # 4 | ifeq ($(CFG),) 5 | CFG = Debug 6 | endif 7 | 8 | IncludeDir = -I../../../tpl/include 9 | 10 | # 11 | # Configuration Release 12 | # 13 | ifeq ($(CFG), Release) 14 | ProductDir = Release 15 | ObjectDir = Release 16 | MocFile = $(ObjectDir)/temp.moc.cpp 17 | Product = Release/grammar 18 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -DNDEBUG -O2 -D_MT -fexceptions 19 | CXXFlags = $(CFlags) -fno-rtti 20 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 21 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 22 | CompileCXX = @$(CXX) $< 23 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 24 | Link = @g++ $(LibDir) -ldl -o $(Product) 25 | LD_LIBRARY_PATH += :$(ProductDir) 26 | endif 27 | 28 | # 29 | # Configuration Debug 30 | # 31 | ifeq ($(CFG), Debug) 32 | ProductDir = Debug 33 | ObjectDir = Debug 34 | MocFile = $(ObjectDir)/temp.moc.cpp 35 | Product = Debug/grammar 36 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -D_DEBUG -g3 -D_MT -fexceptions 37 | CXXFlags = $(CFlags) -fno-rtti 38 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 39 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 40 | CompileCXX = @$(CXX) $< 41 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 42 | Link = @g++ $(LibDir) -ldl -o $(Product) 43 | LD_LIBRARY_PATH += :$(ProductDir) 44 | endif 45 | 46 | # 47 | # Making... 48 | # 49 | all : $(ProductDir) $(ObjectDir) StartMake $(Product) EndMake 50 | 51 | $(ProductDir) : 52 | @mkdir -p $(ProductDir) 53 | 54 | ifneq ($(ProductDir),$(ObjectDir)) 55 | $(ObjectDir) : 56 | @mkdir -p $(ObjectDir) 57 | endif 58 | 59 | clean : 60 | @rm -f $(ObjectDir)/*.o 61 | @rm -f $(Product) 62 | 63 | StartMake : 64 | @echo "-------------- Configuration:" $(PROJ) $(CFG) "--------------" 65 | ifeq ($(ForceLink),1) 66 | @rm -f $(Product) 67 | endif 68 | 69 | EndMake : 70 | @echo ">>> Success <<<" 71 | 72 | # 73 | # Source Files, Objects & Product 74 | # 75 | $(ObjectDir)/SimpleGrammar.o : \ 76 | SimpleGrammar.cpp 77 | @echo "---> Compiling" $< "..." 78 | $(CompileCXX) 79 | 80 | 81 | Objects = \ 82 | $(ObjectDir)/SimpleGrammar.o 83 | 84 | $(Product) : $(Objects) $(Libs) 85 | @echo "---> Creating" $@ "..." 86 | @rm -f $@ 87 | $(Link) $(Objects) $(Libraries) 88 | $(CheckLink) 89 | 90 | -------------------------------------------------------------------------------- /examples/grammar2/SimpleGrammar.cpp: -------------------------------------------------------------------------------- 1 | #include // std::vector 2 | #include // std::cout 3 | #include 4 | 5 | using namespace tpl; 6 | 7 | // ------------------------------------------------------------------------- 8 | // simple_grammar 9 | 10 | // A simple grammar example. 11 | 12 | // What we use: 13 | // * Rules: /append(), %, real(), gr(','), skipws() 14 | // * Matching: operator>> 15 | 16 | int main() 17 | { 18 | std::vector values; // you can change vector to other stl containers. 19 | 20 | if ( " -.1 , -0.1 , +32. , -22323.2e+12 " >> skipws_[real()/append(values) % gr(',')] ) 21 | { 22 | for (std::vector::iterator it = values.begin(); it != values.end(); ++it) 23 | { 24 | std::cout << *it << "\n"; 25 | } 26 | } 27 | return 0; 28 | } 29 | 30 | // ------------------------------------------------------------------------- 31 | 32 | -------------------------------------------------------------------------------- /examples/grammar2/build: -------------------------------------------------------------------------------- 1 | make CFG=Release 2 | 3 | -------------------------------------------------------------------------------- /examples/grammar2/grammar2.prj: -------------------------------------------------------------------------------- 1 | [Include] 2 | ../../../tpl/include 3 | 4 | [Config Release] 5 | Product Exe Release/grammar 6 | Options Release; MultiThread; AnsiChar; NoRtti; Exception 7 | ObjDir Release 8 | LibDir 9 | Libraries 10 | 11 | [Config Debug] 12 | Product Exe Debug/grammar 13 | Options Debug; MultiThread; AnsiChar; NoRtti; Exception 14 | ObjDir Debug 15 | LibDir 16 | Libraries 17 | 18 | [Source] 19 | SimpleGrammar.cpp 20 | 21 | -------------------------------------------------------------------------------- /examples/htmltext/HtmlText.cpp: -------------------------------------------------------------------------------- 1 | #include // std::vector 2 | #include // std::cout 3 | #include 4 | #include 5 | 6 | using namespace tpl; 7 | 8 | // ------------------------------------------------------------------------- 9 | // htmltext 10 | 11 | int main() 12 | { 13 | int nPre = 0; 14 | std::vector text; 15 | 16 | const char html[] = " \tHello,\t\t
 world!\t\t!
abc !!"; 17 | 18 | html >> *( 19 | '<' + 20 | ( 21 | html_symbol() // $tag-start$ 22 | [ 23 | case_(eqICase("pre"))/inc(nPre), 24 | true 25 | ] + find('>') | 26 | ( 27 | '/' + 28 | html_symbol() // $tag-end$ 29 | [ 30 | case_(eqICase("pre"))/dec(nPre), 31 | true 32 | ] + 33 | '>' 34 | ) | 35 | done() // invalid grammar! 36 | ) | 37 | switch_(nPre) // $text$ 38 | [ 39 | case_(0) // nPre == 0 40 | [ 41 | html_skipws() + 42 | find('<' | html_space())/append(text) + 43 | !( html_ws()/append(text, " ") ) 44 | ], 45 | default_() // nPre != 0 46 | [ 47 | find('<')/append(text) 48 | ] 49 | ] ); 50 | 51 | for (std::vector::iterator it = text.begin(); it != text.end(); ++it) { 52 | std::cout << *it; 53 | } 54 | std::cout << '\n'; 55 | return 0; 56 | } 57 | 58 | // ------------------------------------------------------------------------- 59 | 60 | -------------------------------------------------------------------------------- /examples/htmltext/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Configuration Default 3 | # 4 | ifeq ($(CFG),) 5 | CFG = Debug 6 | endif 7 | 8 | IncludeDir = -I../../../tpl/include 9 | 10 | # 11 | # Configuration Release 12 | # 13 | ifeq ($(CFG), Release) 14 | ProductDir = Release 15 | ObjectDir = Release 16 | MocFile = $(ObjectDir)/temp.moc.cpp 17 | Product = Release/htmltext 18 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__32BIT__ -D__LINUX__ -DLINUX -DNDEBUG -O2 -D_MT -fexceptions 19 | CXXFlags = $(CFlags) -fno-rtti 20 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 21 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 22 | CompileCXX = @$(CXX) $< 23 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 24 | Link = @g++ $(LibDir) -o $(Product) 25 | CheckLink = @ldd -u -r $(Product); echo 26 | 27 | LD_LIBRARY_PATH += :$(ProductDir) 28 | endif 29 | 30 | # 31 | # Configuration Debug 32 | # 33 | ifeq ($(CFG), Debug) 34 | ProductDir = Debug 35 | ObjectDir = Debug 36 | MocFile = $(ObjectDir)/temp.moc.cpp 37 | Product = Debug/htmltext 38 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__32BIT__ -D__LINUX__ -DLINUX -D_DEBUG -g3 -D_MT -fexceptions 39 | CXXFlags = $(CFlags) -fno-rtti 40 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 41 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 42 | CompileCXX = @$(CXX) $< 43 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 44 | Link = @g++ $(LibDir) -o $(Product) 45 | CheckLink = @ldd -u -r $(Product); echo 46 | 47 | LD_LIBRARY_PATH += :$(ProductDir) 48 | endif 49 | 50 | # 51 | # Making... 52 | # 53 | all : $(ProductDir) $(ObjectDir) StartMake $(Product) EndMake 54 | 55 | $(ProductDir) : 56 | @mkdir -p $(ProductDir) 57 | 58 | ifneq ($(ProductDir),$(ObjectDir)) 59 | $(ObjectDir) : 60 | @mkdir -p $(ObjectDir) 61 | endif 62 | 63 | clean : 64 | @rm -f $(ObjectDir)/*.o 65 | @rm -f $(Product) 66 | 67 | StartMake : 68 | @echo "-------------- Configuration:" $(PROJ) $(CFG) "--------------" 69 | ifeq ($(ForceLink),1) 70 | @rm -f $(Product) 71 | endif 72 | 73 | EndMake : 74 | @echo ">>> Success <<<" 75 | 76 | # 77 | # Source Files, Objects & Product 78 | # 79 | $(ObjectDir)/HtmlText.o : \ 80 | HtmlText.cpp 81 | @echo "---> Compiling" $< "..." 82 | $(CompileCXX) 83 | 84 | 85 | Objects = \ 86 | $(ObjectDir)/HtmlText.o 87 | 88 | $(Product) : $(Objects) $(Libs) 89 | @echo "---> Creating" $@ "..." 90 | @rm -f $@ 91 | $(Link) $(Objects) $(Libraries) 92 | $(CheckLink) 93 | 94 | -------------------------------------------------------------------------------- /examples/htmltext/build: -------------------------------------------------------------------------------- 1 | make CFG=Release 2 | 3 | -------------------------------------------------------------------------------- /examples/htmltext/htmltext.prj: -------------------------------------------------------------------------------- 1 | [Include] 2 | ../../../tpl/include 3 | ../../../boostmm 4 | 5 | [Config Release] 6 | Product Exe Release/htmltext 7 | Options Release; MultiThread; AnsiChar; NoRtti; Exception 8 | ObjDir Release 9 | LibDir 10 | Libraries 11 | 12 | [Config Debug] 13 | Product Exe Debug/htmltext 14 | Options Debug; MultiThread; AnsiChar; NoRtti; Exception 15 | ObjDir Debug 16 | LibDir 17 | Libraries 18 | 19 | [Source] 20 | HtmlText.cpp 21 | 22 | -------------------------------------------------------------------------------- /examples/includefiles/IncludeFiles.cpp: -------------------------------------------------------------------------------- 1 | #include // std::vector 2 | #include // std::cout 3 | #include 4 | #include 5 | /* is */ # /* this */ include /* supported? *//* 6 | no problem! */ "stdext/FileBuf.h" 7 | 8 | using namespace tpl; 9 | 10 | // ------------------------------------------------------------------------- 11 | // list include files 12 | 13 | #define LIST_INC_STDFILE \ 14 | ('<' + find('>')/append(result) + '>') 15 | 16 | #define LIST_INC_FILE \ 17 | ('\"' + find('\"')/append(result) + '\"') 18 | 19 | #define LIST_INC \ 20 | gr(LIST_INC_STDFILE | LIST_INC_FILE) 21 | 22 | #define LIST_GRAMMAR \ 23 | *(!(gr('#') + "include" + LIST_INC) + find_strict_eol()) 24 | 25 | int main() 26 | { 27 | std::vector result; 28 | 29 | const std::FileBuf file(__FILE__); 30 | file >> c_skip_non_eol_[LIST_GRAMMAR]; 31 | 32 | for (std::vector::iterator it = result.begin(); it != result.end(); ++it) 33 | std::cout << *it << '\n'; 34 | return 0; 35 | } 36 | 37 | // ------------------------------------------------------------------------- 38 | 39 | -------------------------------------------------------------------------------- /examples/includefiles/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Configuration Default 3 | # 4 | ifeq ($(CFG),) 5 | CFG = Debug 6 | endif 7 | 8 | IncludeDir = -I../../../tpl/include -I../../../stdext/include 9 | 10 | # 11 | # Configuration Release 12 | # 13 | ifeq ($(CFG), Release) 14 | ProductDir = Release 15 | ObjectDir = Release 16 | MocFile = $(ObjectDir)/temp.moc.cpp 17 | Product = Release/includefiles 18 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -DNDEBUG -O2 -D_MT -fexceptions 19 | CXXFlags = $(CFlags) -fno-rtti 20 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 21 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 22 | CompileCXX = @$(CXX) $< 23 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 24 | Link = @g++ $(LibDir) -ldl -o $(Product) 25 | LD_LIBRARY_PATH += :$(ProductDir) 26 | endif 27 | 28 | # 29 | # Configuration Debug 30 | # 31 | ifeq ($(CFG), Debug) 32 | ProductDir = Debug 33 | ObjectDir = Debug 34 | MocFile = $(ObjectDir)/temp.moc.cpp 35 | Product = Debug/includefiles 36 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -D_DEBUG -g3 -D_MT -fexceptions 37 | CXXFlags = $(CFlags) -fno-rtti 38 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 39 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 40 | CompileCXX = @$(CXX) $< 41 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 42 | Link = @g++ $(LibDir) -ldl -o $(Product) 43 | LD_LIBRARY_PATH += :$(ProductDir) 44 | endif 45 | 46 | # 47 | # Making... 48 | # 49 | all : $(ProductDir) $(ObjectDir) StartMake $(Product) EndMake 50 | 51 | $(ProductDir) : 52 | @mkdir -p $(ProductDir) 53 | 54 | ifneq ($(ProductDir),$(ObjectDir)) 55 | $(ObjectDir) : 56 | @mkdir -p $(ObjectDir) 57 | endif 58 | 59 | clean : 60 | @rm -f $(ObjectDir)/*.o 61 | @rm -f $(Product) 62 | 63 | StartMake : 64 | @echo "-------------- Configuration:" $(PROJ) $(CFG) "--------------" 65 | ifeq ($(ForceLink),1) 66 | @rm -f $(Product) 67 | endif 68 | 69 | EndMake : 70 | @echo ">>> Success <<<" 71 | 72 | # 73 | # Source Files, Objects & Product 74 | # 75 | $(ObjectDir)/IncludeFiles.o : \ 76 | IncludeFiles.cpp 77 | @echo "---> Compiling" $< "..." 78 | $(CompileCXX) 79 | 80 | 81 | Objects = \ 82 | $(ObjectDir)/IncludeFiles.o 83 | 84 | $(Product) : $(Objects) $(Libs) 85 | @echo "---> Creating" $@ "..." 86 | @rm -f $@ 87 | $(Link) $(Objects) $(Libraries) 88 | $(CheckLink) 89 | 90 | -------------------------------------------------------------------------------- /examples/includefiles/build: -------------------------------------------------------------------------------- 1 | make CFG=Release 2 | 3 | -------------------------------------------------------------------------------- /examples/includefiles/includefiles.prj: -------------------------------------------------------------------------------- 1 | [Include] 2 | ../../../tpl/include 3 | ../../../stdext/include 4 | ../../../boostmm 5 | 6 | [Config Release] 7 | Product Exe Release/includefiles 8 | Options Release; MultiThread; AnsiChar; NoRtti; Exception 9 | ObjDir Release 10 | LibDir 11 | Libraries 12 | 13 | [Config Debug] 14 | Product Exe Debug/includefiles 15 | Options Debug; MultiThread; AnsiChar; NoRtti; Exception 16 | ObjDir Debug 17 | LibDir 18 | Libraries 19 | 20 | [Source] 21 | IncludeFiles.cpp 22 | 23 | -------------------------------------------------------------------------------- /examples/json-print/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Configuration Default 3 | # 4 | ifeq ($(CFG),) 5 | CFG = Debug 6 | endif 7 | 8 | IncludeDir = -I../../../tpl/include 9 | 10 | # 11 | # Configuration Release 12 | # 13 | ifeq ($(CFG), Release) 14 | ProductDir = Release 15 | ObjectDir = Release 16 | MocFile = $(ObjectDir)/temp.moc.cpp 17 | Product = Release/simplest 18 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -DNDEBUG -O2 -D_MT -fexceptions 19 | CXXFlags = $(CFlags) -fno-rtti 20 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 21 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 22 | CompileCXX = @$(CXX) $< 23 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 24 | Link = @g++ $(LibDir) -ldl -o $(Product) 25 | LD_LIBRARY_PATH += :$(ProductDir) 26 | endif 27 | 28 | # 29 | # Configuration Debug 30 | # 31 | ifeq ($(CFG), Debug) 32 | ProductDir = Debug 33 | ObjectDir = Debug 34 | MocFile = $(ObjectDir)/temp.moc.cpp 35 | Product = Debug/simplest 36 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -D_DEBUG -g3 -D_MT -fexceptions 37 | CXXFlags = $(CFlags) -fno-rtti 38 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 39 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 40 | CompileCXX = @$(CXX) $< 41 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 42 | Link = @g++ $(LibDir) -ldl -o $(Product) 43 | LD_LIBRARY_PATH += :$(ProductDir) 44 | endif 45 | 46 | # 47 | # Making... 48 | # 49 | all : $(ProductDir) $(ObjectDir) StartMake $(Product) EndMake 50 | 51 | $(ProductDir) : 52 | @mkdir -p $(ProductDir) 53 | 54 | ifneq ($(ProductDir),$(ObjectDir)) 55 | $(ObjectDir) : 56 | @mkdir -p $(ObjectDir) 57 | endif 58 | 59 | clean : 60 | @rm -f $(ObjectDir)/*.o 61 | @rm -f $(Product) 62 | 63 | StartMake : 64 | @echo "-------------- Configuration:" $(PROJ) $(CFG) "--------------" 65 | ifeq ($(ForceLink),1) 66 | @rm -f $(Product) 67 | endif 68 | 69 | EndMake : 70 | @echo ">>> Success <<<" 71 | 72 | # 73 | # Source Files, Objects & Product 74 | # 75 | $(ObjectDir)/Simplest.o : \ 76 | Simplest.cpp 77 | @echo "---> Compiling" $< "..." 78 | $(CompileCXX) 79 | 80 | 81 | Objects = \ 82 | $(ObjectDir)/Simplest.o 83 | 84 | $(Product) : $(Objects) $(Libs) 85 | @echo "---> Creating" $@ "..." 86 | @rm -f $@ 87 | $(Link) $(Objects) $(Libraries) 88 | $(CheckLink) 89 | 90 | -------------------------------------------------------------------------------- /examples/json-print/Simplest.cpp: -------------------------------------------------------------------------------- 1 | #define TPL_USE_AUTO_ALLOC 2 | #include 3 | #include 4 | 5 | using namespace tpl; 6 | 7 | // ------------------------------------------------------------------------- 8 | // json print 9 | 10 | // A json print example. 11 | 12 | int main() 13 | { 14 | typedef DOM<> dom; 15 | 16 | const char source[] = "class Foo : public Base1, Base2 {};"; 17 | 18 | dom::Mark tagName("name"); 19 | dom::NodeMark tagBase("base", true); 20 | dom::Mark tagAccess("access"); 21 | //dom::Mark tagName("name"); 22 | 23 | dom::Allocator alloc; 24 | dom::Document doc(alloc); 25 | 26 | if ( 27 | source >> cpp_skip_ 28 | [ 29 | gr(c_symbol()/eq("class")) + c_symbol()/tagName + ':' + 30 | ( 31 | !gr(c_symbol()/(eq("public")||eq("private"))/tagAccess) + c_symbol()/tagName 32 | )/tagBase % ',' + 33 | '{' + '}' + ';' 34 | ]/doc 35 | ) 36 | { 37 | std::OutputLog log; 38 | json_print(alloc, log, doc); 39 | } 40 | return 0; 41 | } 42 | 43 | // ------------------------------------------------------------------------- 44 | 45 | -------------------------------------------------------------------------------- /examples/json-print/build: -------------------------------------------------------------------------------- 1 | make CFG=Release 2 | 3 | -------------------------------------------------------------------------------- /examples/json-print/json-print.prj: -------------------------------------------------------------------------------- 1 | [Include] 2 | ../../../tpl/include 3 | 4 | [Config Release] 5 | Product Exe Release/simplest 6 | Options Release; MultiThread; AnsiChar; NoRtti; Exception 7 | ObjDir Release 8 | LibDir 9 | Libraries 10 | 11 | [Config Debug] 12 | Product Exe Debug/simplest 13 | Options Debug; MultiThread; AnsiChar; NoRtti; Exception 14 | ObjDir Debug 15 | LibDir 16 | Libraries 17 | 18 | [Source] 19 | Simplest.cpp 20 | 21 | -------------------------------------------------------------------------------- /examples/json-print2/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Configuration Default 3 | # 4 | ifeq ($(CFG),) 5 | CFG = Debug 6 | endif 7 | 8 | IncludeDir = -I../../../tpl/include 9 | 10 | # 11 | # Configuration Release 12 | # 13 | ifeq ($(CFG), Release) 14 | ProductDir = Release 15 | ObjectDir = Release 16 | MocFile = $(ObjectDir)/temp.moc.cpp 17 | Product = Release/simplest 18 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -DNDEBUG -O2 -D_MT -fexceptions 19 | CXXFlags = $(CFlags) -fno-rtti 20 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 21 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 22 | CompileCXX = @$(CXX) $< 23 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 24 | Link = @g++ $(LibDir) -ldl -o $(Product) 25 | LD_LIBRARY_PATH += :$(ProductDir) 26 | endif 27 | 28 | # 29 | # Configuration Debug 30 | # 31 | ifeq ($(CFG), Debug) 32 | ProductDir = Debug 33 | ObjectDir = Debug 34 | MocFile = $(ObjectDir)/temp.moc.cpp 35 | Product = Debug/simplest 36 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -D_DEBUG -g3 -D_MT -fexceptions 37 | CXXFlags = $(CFlags) -fno-rtti 38 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 39 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 40 | CompileCXX = @$(CXX) $< 41 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 42 | Link = @g++ $(LibDir) -ldl -o $(Product) 43 | LD_LIBRARY_PATH += :$(ProductDir) 44 | endif 45 | 46 | # 47 | # Making... 48 | # 49 | all : $(ProductDir) $(ObjectDir) StartMake $(Product) EndMake 50 | 51 | $(ProductDir) : 52 | @mkdir -p $(ProductDir) 53 | 54 | ifneq ($(ProductDir),$(ObjectDir)) 55 | $(ObjectDir) : 56 | @mkdir -p $(ObjectDir) 57 | endif 58 | 59 | clean : 60 | @rm -f $(ObjectDir)/*.o 61 | @rm -f $(Product) 62 | 63 | StartMake : 64 | @echo "-------------- Configuration:" $(PROJ) $(CFG) "--------------" 65 | ifeq ($(ForceLink),1) 66 | @rm -f $(Product) 67 | endif 68 | 69 | EndMake : 70 | @echo ">>> Success <<<" 71 | 72 | # 73 | # Source Files, Objects & Product 74 | # 75 | $(ObjectDir)/Simplest.o : \ 76 | Simplest.cpp 77 | @echo "---> Compiling" $< "..." 78 | $(CompileCXX) 79 | 80 | 81 | Objects = \ 82 | $(ObjectDir)/Simplest.o 83 | 84 | $(Product) : $(Objects) $(Libs) 85 | @echo "---> Creating" $@ "..." 86 | @rm -f $@ 87 | $(Link) $(Objects) $(Libraries) 88 | $(CheckLink) 89 | 90 | -------------------------------------------------------------------------------- /examples/json-print2/Simplest.cpp: -------------------------------------------------------------------------------- 1 | #define TPL_USE_AUTO_ALLOC 2 | #include 3 | #include 4 | 5 | using namespace tpl; 6 | 7 | // ------------------------------------------------------------------------- 8 | // json print 9 | 10 | // A json print example. 11 | 12 | int main() 13 | { 14 | typedef DOM<> dom; 15 | 16 | const char source[] = "\ 17 | class Foo // Foo comment\n\ 18 | : public Base1, Base2\n\ 19 | {};\ 20 | "; 21 | 22 | dom::Mark tagName("name"); 23 | dom::NodeMark tagBase("base", true); 24 | dom::Mark tagAccess("access"); 25 | //dom::Mark tagName("name"); 26 | 27 | dom::Allocator alloc; 28 | dom::Document doc(alloc); 29 | 30 | source >> cpp_skip_ 31 | [ 32 | gr(c_symbol()/eq("class")) + c_symbol()/tagName + 33 | !(':' + 34 | ( 35 | !gr(c_symbol()/eq("public")/tagAccess) + 36 | c_symbol()/tagName 37 | )/tagBase % ',' 38 | ) + 39 | '{' + '}' + ';' 40 | ]/doc; 41 | 42 | std::OutputLog log; 43 | json_print(alloc, log, doc); 44 | return 0; 45 | } 46 | 47 | // ------------------------------------------------------------------------- 48 | 49 | -------------------------------------------------------------------------------- /examples/json-print2/build: -------------------------------------------------------------------------------- 1 | make CFG=Release 2 | 3 | -------------------------------------------------------------------------------- /examples/json-print2/json-print2.prj: -------------------------------------------------------------------------------- 1 | [Include] 2 | ../../../tpl/include 3 | 4 | [Config Release] 5 | Product Exe Release/simplest 6 | Options Release; MultiThread; AnsiChar; NoRtti; Exception 7 | ObjDir Release 8 | LibDir 9 | Libraries 10 | 11 | [Config Debug] 12 | Product Exe Debug/simplest 13 | Options Debug; MultiThread; AnsiChar; NoRtti; Exception 14 | ObjDir Debug 15 | LibDir 16 | Libraries 17 | 18 | [Source] 19 | Simplest.cpp 20 | 21 | -------------------------------------------------------------------------------- /examples/lang/Lang.cpp: -------------------------------------------------------------------------------- 1 | #define TPL_USE_AUTO_ALLOC 2 | #include 3 | #include // std::cout 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace tpl; 9 | 10 | template 11 | class IsNotKeywords 12 | { 13 | private: 14 | typedef std::basic_string key_t; 15 | typedef std::set set_t; 16 | 17 | set_t m_set; 18 | 19 | public: 20 | IsNotKeywords(const CharT* keywords[], size_t n) { 21 | while (n--) { 22 | m_set.insert(keywords[n]); 23 | } 24 | } 25 | 26 | typedef key_t value_type; 27 | 28 | template 29 | bool TPL_CALL operator()(const ValueT& val) const { 30 | key_t k(val.begin(), val.end()); 31 | return m_set.find(k) == m_set.end(); 32 | } 33 | }; 34 | 35 | int main(int argc, const char* argv[]) 36 | { 37 | if (argc < 2) { 38 | std::cout << "Usage: " << argv[0] << " LangFile\n"; 39 | return -1; 40 | } 41 | 42 | typedef SimpleImplementation impl; 43 | 44 | const char* keywords[] = { 45 | "if", "elif", "else", 46 | "case", "of", "default", 47 | }; 48 | IsNotKeywords not_keywords(keywords, countof(keywords)); 49 | 50 | impl::Allocator alloc; 51 | 52 | impl::Grammar::Var rFactor; 53 | 54 | // ::= ('*' | '/' )* 55 | impl::Grammar rTerm2( alloc, 56 | rFactor + *( 57 | '*' + rFactor | 58 | '/' + rFactor) 59 | ); 60 | 61 | // ::= ('+' | '-' )* 62 | impl::Grammar rTerm( alloc, 63 | rTerm2 + *( 64 | '+' + rTerm2 | 65 | '-' + rTerm2) 66 | ); 67 | 68 | // ::= '<=' | '<' | '>=' | '>' | '==' | '!=' 69 | impl::Grammar rCompare( alloc, 70 | "<=" + rTerm | 71 | '<' + rTerm | 72 | ">=" + rTerm | 73 | '>' + rTerm | 74 | "==" + rTerm | 75 | "!=" + rTerm 76 | ); 77 | 78 | // ::= * ('&&' *)* 79 | impl::Grammar rAndExpr( alloc, 80 | rTerm + *rCompare + *( 81 | "&&" + rTerm + *rCompare) 82 | ); 83 | 84 | // ::= ('||' )* 85 | impl::Grammar rExpr( alloc, 86 | rAndExpr + *( 87 | "||" + rAndExpr) 88 | ); 89 | 90 | // ::= 91 | // c_symbol() ( 92 | // '=' | 93 | // '(' c_symbol() % ',' ')' '=' ) | 94 | // 95 | impl::Grammar::Var rAssignment; 96 | rAssignment.assign( alloc, 97 | c_symbol() + ( 98 | '=' + rAssignment | 99 | '(' + c_symbol() % gr(',') + ')' + '=' + rAssignment) | 100 | rExpr 101 | ); 102 | 103 | // ::= ( ';')* 104 | impl::Grammar rLang( alloc, 105 | *(rAssignment + ';') 106 | ); 107 | 108 | // ::= 109 | // real() | 110 | // c_string() | 111 | // '(' % ',' ')' | 112 | // '-' | 113 | // '+' | 114 | // 'if' '(' ')' ('elif' '(' ')' )* 'else' | 115 | // 'case' 'of' 116 | // (( | ) ':' )* 117 | // 'default' ':' | 118 | // c_symbol() ('(' % ',' ')')? 119 | rFactor.assign( alloc, 120 | real() | 121 | c_string() | 122 | '-' + rFactor | 123 | '+' + rFactor | 124 | '(' + rAssignment % ',' + ')' | 125 | c_symbol() 126 | [ 127 | case_(not_keywords) 128 | [ 129 | !('(' + rAssignment % ',' + ')') 130 | ], 131 | case_("if") 132 | [ 133 | '(' + rExpr + ')' + rAssignment + 134 | *(gr("elif") + '(' + rExpr + ')' + rAssignment) + 135 | c_symbol()/eq("else") + rAssignment 136 | ], 137 | case_("case") 138 | [ 139 | rExpr + "of" + 140 | *((rCompare | rExpr) + ':' + rAssignment + ',') + 141 | gr("default") + ':' + rAssignment 142 | ] 143 | ]); 144 | 145 | // ---- do match ---- 146 | 147 | std::FileBuf file(argv[1]); 148 | if (!file.good()) { 149 | std::cout << ">>> ERROR: open file failed!\n"; 150 | return -2; 151 | } 152 | try { 153 | if ( !impl::match(file.begin(), file.end(), rLang + eos(), skipws() % ("//" + find_eol())) ) 154 | std::cout << ">>> ERROR: invalid grammar!\n"; 155 | else 156 | std::cout << "passed!" << '\n'; 157 | } 158 | catch (const std::logic_error& e) { 159 | std::cout << ">>> ERROR: " << e.what() << '\n'; 160 | } 161 | } 162 | 163 | // ------------------------------------------------------------------------- 164 | 165 | -------------------------------------------------------------------------------- /examples/lang/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Configuration Default 3 | # 4 | ifeq ($(CFG),) 5 | CFG = Debug 6 | endif 7 | 8 | IncludeDir = -I../../../tpl/include -I../../../stdext/include -I../../../boost 9 | 10 | # 11 | # Configuration Release 12 | # 13 | ifeq ($(CFG), Release) 14 | ProductDir = Release 15 | ObjectDir = Release 16 | Product = Release/lang 17 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -DNDEBUG -O2 -D_MT -fexceptions 18 | CXXFlags = $(CFlags) -fno-rtti 19 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 20 | CompileCXX = @g++ -c $(IncludeDir) $(CXXFlags) -o $@ $< 21 | Link = @g++ $(LibDir) -o $(Product) 22 | CheckLink = @ldd -u -r $(Product); echo 23 | LD_LIBRARY_PATH += :$(ProductDir) 24 | endif 25 | 26 | # 27 | # Configuration Debug 28 | # 29 | ifeq ($(CFG), Debug) 30 | ProductDir = Debug 31 | ObjectDir = Debug 32 | Product = Debug/lang 33 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -D_DEBUG -g3 -D_MT -fexceptions 34 | CXXFlags = $(CFlags) -fno-rtti 35 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 36 | CompileCXX = @g++ -c $(IncludeDir) $(CXXFlags) -o $@ $< 37 | Link = @g++ $(LibDir) -o $(Product) 38 | CheckLink = @ldd -u -r $(Product); echo 39 | LD_LIBRARY_PATH += :$(ProductDir) 40 | endif 41 | 42 | # 43 | # Making... 44 | # 45 | all : $(ProductDir) $(ObjectDir) StartMake $(Product) EndMake 46 | 47 | $(ProductDir) : 48 | @mkdir -p $(ProductDir) 49 | 50 | ifneq ($(ProductDir),$(ObjectDir)) 51 | $(ObjectDir) : 52 | @mkdir -p $(ObjectDir) 53 | endif 54 | 55 | clean : 56 | @rm -f $(ObjectDir)/*.o 57 | @rm -f $(Product) 58 | 59 | StartMake : 60 | @echo "-------------- Configuration:" $(PROJ) $(CFG) "--------------" 61 | ifeq ($(ForceLink),1) 62 | @rm -f $(Product) 63 | endif 64 | 65 | EndMake : 66 | @echo ">>> Success <<<" 67 | 68 | # 69 | # Source Files, Objects & Product 70 | # 71 | $(ObjectDir)/Lang.o : \ 72 | Lang.cpp 73 | @echo "---> Compiling" $< "..." 74 | $(CompileCXX) 75 | 76 | Objects = $(ObjectDir)/Lang.o 77 | 78 | $(Product) : $(Objects) 79 | @echo "---> Creating" $@ "..." 80 | @rm -f $@ 81 | $(Link) $(Objects) $(Libraries) 82 | $(CheckLink) 83 | 84 | -------------------------------------------------------------------------------- /examples/lang/build: -------------------------------------------------------------------------------- 1 | make CFG=Release 2 | 3 | -------------------------------------------------------------------------------- /examples/lang/input.lang: -------------------------------------------------------------------------------- 1 | weekday(n) = 2 | case n of 3 | 1: "Mon", 4 | 2: "Tue", 5 | 3: "Wed", 6 | 4: "Thu", 7 | 5: "Fri", 8 | 6: "Sat", 9 | 7: "Sun", 10 | default: "Error"; 11 | 12 | println("weekday(3) = ", weekday(3)); 13 | 14 | abs(x) = if (x < 0) -x else x; 15 | 16 | abs2(x) = 17 | case x of 18 | < 0: -x, 19 | default: x; 20 | 21 | println("abs(-3) = ", abs(x), " = ", abs2(x)); 22 | 23 | factal(n) = if (n <= 1) 1 else n * factal(n-1); 24 | 25 | println("10! = ", factal(10)); 26 | 27 | pi = 3.1415926; 28 | 29 | x = abs(sin(-pi/4)); 30 | 31 | println("x = ", x); 32 | 33 | times1(n) = 34 | ( 35 | fun(y) = 36 | ( 37 | val = n * y, 38 | val 39 | ), 40 | fun 41 | ); 42 | 43 | times2(n) = 44 | fun(y) = 45 | ( 46 | val = n * y, 47 | val 48 | ); 49 | 50 | times(n) = 51 | fun(y) = n * y; 52 | 53 | twice = times(2); 54 | 55 | y = twice(3); // y = 6 56 | 57 | println("twice(3) = ", y); 58 | 59 | -------------------------------------------------------------------------------- /examples/lang/lang.prj: -------------------------------------------------------------------------------- 1 | [Include] 2 | ../../../tpl/include 3 | ../../../stdext/include 4 | ../../../boost 5 | 6 | [Config Release] 7 | Product Exe Release/lang 8 | Options Release; MultiThread; AnsiChar; NoRtti; Exception 9 | ObjDir Release 10 | LibDir 11 | Libraries 12 | 13 | [Config Debug] 14 | Product Exe Debug/lang 15 | Options Debug; MultiThread; AnsiChar; NoRtti; Exception 16 | ObjDir Debug 17 | LibDir 18 | Libraries 19 | 20 | [Source] 21 | Lang.cpp 22 | 23 | -------------------------------------------------------------------------------- /examples/lang/readme.txt: -------------------------------------------------------------------------------- 1 | + Introduction 2 | 3 | This application is a simple language interreptor. 4 | 5 | + Language Definition 6 | 7 | ::= ( ';')* 8 | 9 | ::= 10 | c_symbol() ( 11 | '=' | 12 | '(' c_symbol() % ',' ')' '=' ) | 13 | 14 | 15 | ::= ('||' )* 16 | 17 | ::= ('&&' )* 18 | 19 | ::= '<=' | '<' | '>=' | '>' | '==' | '!=' 20 | 21 | ::= ('+' | '-' )* 22 | 23 | ::= ('*' | '/' )* 24 | 25 | ::= 26 | real() | 27 | c_string() | 28 | '-' | 29 | '+' | 30 | '(' % ',' ')' | 31 | c_symbol() ('(' % ',' ')')? | 32 | 'if' '(' ')' ('elif' '(' ')' )* 'else' | 33 | 'case' 'of' 34 | (( | ) ':' )* 35 | 'default' ':' 36 | 37 | ::= 38 | skipws() % ('//' find_eol()) 39 | 40 | + Example 41 | 42 | weekday(n) = 43 | case n of 44 | 1: "Mon", 45 | 2: "Tue", 46 | 3: "Wed", 47 | 4: "Thu", 48 | 5: "Fri", 49 | 6: "Sat", 50 | 7: "Sun", 51 | default: "Error"; 52 | 53 | abs(x) = 54 | case x of 55 | < 0: -x, 56 | default: x; 57 | 58 | abs(x) = if (x < 0) -x else x; 59 | 60 | factal(n) = if (n <= 1) 1 else n * factal(n-1); 61 | 62 | pi = 3.1415926; 63 | 64 | x = abs(sin(-pi/4)); 65 | 66 | print("x=", x); 67 | 68 | times(n) = 69 | ( 70 | fun(y) = 71 | ( 72 | val = n * y, 73 | val 74 | ), 75 | fun 76 | ); 77 | 78 | times(n) = 79 | fun(y) = 80 | ( 81 | val = n * y, 82 | val 83 | ); 84 | 85 | times(n) = 86 | fun(y) = n * y; 87 | 88 | twice = times(2); 89 | 90 | y = twice(3); // y = 6 91 | 92 | print("y=", y); 93 | 94 | -------------------------------------------------------------------------------- /examples/projects.plf: -------------------------------------------------------------------------------- 1 | simplest/simplest 2 | simplest2/simplest2 3 | grammar/grammar 4 | grammar2/grammar2 5 | urlparams/urlparams 6 | boost-lambda/print/print 7 | boost-lambda/calc/calc 8 | boost-phoenix/print/print 9 | boost-phoenix/calc/calc 10 | circuit/circuit 11 | calculator/calculator 12 | removecomments/removecomments 13 | removecomments2/removecomments2 14 | includefiles/includefiles 15 | htmltext/htmltext 16 | json-print/json-print 17 | json-print2/json-print2 18 | emulator/emulator 19 | variant/variant 20 | lang/lang 21 | 22 | -------------------------------------------------------------------------------- /examples/removecomments/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Configuration Default 3 | # 4 | ifeq ($(CFG),) 5 | CFG = Debug 6 | endif 7 | 8 | IncludeDir = -I../../../tpl/include -I../../../stdext/include 9 | 10 | # 11 | # Configuration Release 12 | # 13 | ifeq ($(CFG), Release) 14 | ProductDir = Release 15 | ObjectDir = Release 16 | MocFile = $(ObjectDir)/temp.moc.cpp 17 | Product = Release/removecomments 18 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -DNDEBUG -O2 -D_MT -fexceptions 19 | CXXFlags = $(CFlags) -fno-rtti 20 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 21 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 22 | CompileCXX = @$(CXX) $< 23 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 24 | Link = @g++ $(LibDir) -ldl -o $(Product) 25 | LD_LIBRARY_PATH += :$(ProductDir) 26 | endif 27 | 28 | # 29 | # Configuration Debug 30 | # 31 | ifeq ($(CFG), Debug) 32 | ProductDir = Debug 33 | ObjectDir = Debug 34 | MocFile = $(ObjectDir)/temp.moc.cpp 35 | Product = Debug/removecomments 36 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -D_DEBUG -g3 -D_MT -fexceptions 37 | CXXFlags = $(CFlags) -fno-rtti 38 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 39 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 40 | CompileCXX = @$(CXX) $< 41 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 42 | Link = @g++ $(LibDir) -ldl -o $(Product) 43 | LD_LIBRARY_PATH += :$(ProductDir) 44 | endif 45 | 46 | # 47 | # Making... 48 | # 49 | all : $(ProductDir) $(ObjectDir) StartMake $(Product) EndMake 50 | 51 | $(ProductDir) : 52 | @mkdir -p $(ProductDir) 53 | 54 | ifneq ($(ProductDir),$(ObjectDir)) 55 | $(ObjectDir) : 56 | @mkdir -p $(ObjectDir) 57 | endif 58 | 59 | clean : 60 | @rm -f $(ObjectDir)/*.o 61 | @rm -f $(Product) 62 | 63 | StartMake : 64 | @echo "-------------- Configuration:" $(PROJ) $(CFG) "--------------" 65 | ifeq ($(ForceLink),1) 66 | @rm -f $(Product) 67 | endif 68 | 69 | EndMake : 70 | @echo ">>> Success <<<" 71 | 72 | # 73 | # Source Files, Objects & Product 74 | # 75 | $(ObjectDir)/RemoveCppComments.o : \ 76 | RemoveCppComments.cpp 77 | @echo "---> Compiling" $< "..." 78 | $(CompileCXX) 79 | 80 | 81 | Objects = \ 82 | $(ObjectDir)/RemoveCppComments.o 83 | 84 | $(Product) : $(Objects) $(Libs) 85 | @echo "---> Creating" $@ "..." 86 | @rm -f $@ 87 | $(Link) $(Objects) $(Libraries) 88 | $(CheckLink) 89 | 90 | -------------------------------------------------------------------------------- /examples/removecomments/RemoveCppComments.cpp: -------------------------------------------------------------------------------- 1 | #define TPL_USE_AUTO_ALLOC 2 | #include // std::vector 3 | #include // std::cout 4 | #include 5 | #include 6 | #pragma warning(disable:4010) 7 | 8 | using namespace tpl; 9 | 10 | // ------------------------------------------------------------------------- 11 | // remove_cpp_comments() 12 | 13 | int main() 14 | { 15 | typedef SimpleImplementation impl; 16 | 17 | // ---- define rules ---- 18 | 19 | std::vector result; 20 | 21 | impl::Allocator alloc; 22 | 23 | impl::Rule::Var rCppEol; 24 | 25 | rCppEol.assign( alloc, 26 | find_set<'\r', '\n', '\\'>() + 27 | ( 28 | '\\' + !eol() + rCppEol | eol()/append(result) 29 | )); 30 | 31 | Var delim; 32 | impl::Rule rString( alloc, ch('\'', '\"')/assign(delim) + *('\\' + ch_any() | ~delim) + delim ); 33 | 34 | impl::Rule rItem( alloc, 35 | find_set<'/', '\'', '\"'>()/append(result) + 36 | ( 37 | "/*" + find("*/") | /* I will be removed haha~ */ 38 | "//" + rCppEol | // Multiline \ 39 | comments are also allowed. haha~ 40 | ('/' | rString)/append(result) 41 | )); 42 | 43 | impl::Rule rDoc( alloc, *rItem + done()/append(result) ); 44 | 45 | // ---- do match ---- 46 | 47 | const std::FileBuf file(__FILE__); 48 | impl::match(file, rDoc); 49 | 50 | for (std::vector::iterator it = result.begin(); it != result.end(); ++it) 51 | std::cout << *it; 52 | 53 | return 0; 54 | } 55 | 56 | -------------------------------------------------------------------------------- /examples/removecomments/build: -------------------------------------------------------------------------------- 1 | make CFG=Release 2 | 3 | -------------------------------------------------------------------------------- /examples/removecomments/removecomments.prj: -------------------------------------------------------------------------------- 1 | [Include] 2 | ../../../tpl/include 3 | ../../../stdext/include 4 | 5 | [Config Release] 6 | Product Exe Release/removecomments 7 | Options Release; MultiThread; AnsiChar; NoRtti; Exception 8 | ObjDir Release 9 | LibDir 10 | Libraries 11 | 12 | [Config Debug] 13 | Product Exe Debug/removecomments 14 | Options Debug; MultiThread; AnsiChar; NoRtti; Exception 15 | ObjDir Debug 16 | LibDir 17 | Libraries 18 | 19 | [Source] 20 | RemoveCppComments.cpp 21 | 22 | -------------------------------------------------------------------------------- /examples/removecomments2/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Configuration Default 3 | # 4 | ifeq ($(CFG),) 5 | CFG = Debug 6 | endif 7 | 8 | IncludeDir = -I../../../tpl/include -I../../../stdext/include 9 | 10 | # 11 | # Configuration Release 12 | # 13 | ifeq ($(CFG), Release) 14 | ProductDir = Release 15 | ObjectDir = Release 16 | MocFile = $(ObjectDir)/temp.moc.cpp 17 | Product = Release/removecomments 18 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -DNDEBUG -O2 -D_MT -fexceptions 19 | CXXFlags = $(CFlags) -fno-rtti 20 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 21 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 22 | CompileCXX = @$(CXX) $< 23 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 24 | Link = @g++ $(LibDir) -ldl -o $(Product) 25 | LD_LIBRARY_PATH += :$(ProductDir) 26 | endif 27 | 28 | # 29 | # Configuration Debug 30 | # 31 | ifeq ($(CFG), Debug) 32 | ProductDir = Debug 33 | ObjectDir = Debug 34 | MocFile = $(ObjectDir)/temp.moc.cpp 35 | Product = Debug/removecomments 36 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -D_DEBUG -g3 -D_MT -fexceptions 37 | CXXFlags = $(CFlags) -fno-rtti 38 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 39 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 40 | CompileCXX = @$(CXX) $< 41 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 42 | Link = @g++ $(LibDir) -ldl -o $(Product) 43 | LD_LIBRARY_PATH += :$(ProductDir) 44 | endif 45 | 46 | # 47 | # Making... 48 | # 49 | all : $(ProductDir) $(ObjectDir) StartMake $(Product) EndMake 50 | 51 | $(ProductDir) : 52 | @mkdir -p $(ProductDir) 53 | 54 | ifneq ($(ProductDir),$(ObjectDir)) 55 | $(ObjectDir) : 56 | @mkdir -p $(ObjectDir) 57 | endif 58 | 59 | clean : 60 | @rm -f $(ObjectDir)/*.o 61 | @rm -f $(Product) 62 | 63 | StartMake : 64 | @echo "-------------- Configuration:" $(PROJ) $(CFG) "--------------" 65 | ifeq ($(ForceLink),1) 66 | @rm -f $(Product) 67 | endif 68 | 69 | EndMake : 70 | @echo ">>> Success <<<" 71 | 72 | # 73 | # Source Files, Objects & Product 74 | # 75 | $(ObjectDir)/RemoveCppComments.o : \ 76 | RemoveCppComments.cpp 77 | @echo "---> Compiling" $< "..." 78 | $(CompileCXX) 79 | 80 | 81 | Objects = \ 82 | $(ObjectDir)/RemoveCppComments.o 83 | 84 | $(Product) : $(Objects) $(Libs) 85 | @echo "---> Creating" $@ "..." 86 | @rm -f $@ 87 | $(Link) $(Objects) $(Libraries) 88 | $(CheckLink) 89 | 90 | -------------------------------------------------------------------------------- /examples/removecomments2/RemoveCppComments.cpp: -------------------------------------------------------------------------------- 1 | #define TPL_USE_AUTO_ALLOC 2 | #include // std::vector 3 | #include // std::cout 4 | #include // cpp_comment() 5 | #include 6 | #include 7 | #pragma warning(disable:4010) 8 | 9 | using namespace tpl; 10 | 11 | // ------------------------------------------------------------------------- 12 | // remove_cpp_comments() 13 | 14 | int main() 15 | { 16 | typedef SimpleImplementation impl; 17 | 18 | // ---- define rules ---- 19 | 20 | std::vector result; 21 | 22 | impl::Allocator alloc; 23 | 24 | impl::Rule rItem( alloc, 25 | find_set<'/', '\'', '\"'>()/append(result) + 26 | ( 27 | cpp_comment() | /* I will be removed haha~ */ 28 | // Multiline \ 29 | comments are also allowed. haha~ 30 | ('/' | c_string_or_char())/append(result) 31 | )); 32 | 33 | // ---- do match ---- 34 | 35 | const std::FileBuf file(__FILE__); 36 | file >> *rItem + done()/append(result); 37 | 38 | for (std::vector::iterator it = result.begin(); it != result.end(); ++it) 39 | std::cout << *it; 40 | 41 | return 0; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /examples/removecomments2/build: -------------------------------------------------------------------------------- 1 | make CFG=Release 2 | 3 | -------------------------------------------------------------------------------- /examples/removecomments2/removecomments2.prj: -------------------------------------------------------------------------------- 1 | [Include] 2 | ../../../tpl/include 3 | ../../../stdext/include 4 | 5 | [Config Release] 6 | Product Exe Release/removecomments 7 | Options Release; MultiThread; AnsiChar; NoRtti; Exception 8 | ObjDir Release 9 | LibDir 10 | Libraries 11 | 12 | [Config Debug] 13 | Product Exe Debug/removecomments 14 | Options Debug; MultiThread; AnsiChar; NoRtti; Exception 15 | ObjDir Debug 16 | LibDir 17 | Libraries 18 | 19 | [Source] 20 | RemoveCppComments.cpp 21 | 22 | -------------------------------------------------------------------------------- /examples/simplest/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Configuration Default 3 | # 4 | ifeq ($(CFG),) 5 | CFG = Debug 6 | endif 7 | 8 | IncludeDir = -I../../../tpl/include 9 | 10 | # 11 | # Configuration Release 12 | # 13 | ifeq ($(CFG), Release) 14 | ProductDir = Release 15 | ObjectDir = Release 16 | MocFile = $(ObjectDir)/temp.moc.cpp 17 | Product = Release/simplest 18 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -DNDEBUG -O2 -D_MT -fexceptions 19 | CXXFlags = $(CFlags) -fno-rtti 20 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 21 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 22 | CompileCXX = @$(CXX) $< 23 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 24 | Link = @g++ $(LibDir) -ldl -o $(Product) 25 | LD_LIBRARY_PATH += :$(ProductDir) 26 | endif 27 | 28 | # 29 | # Configuration Debug 30 | # 31 | ifeq ($(CFG), Debug) 32 | ProductDir = Debug 33 | ObjectDir = Debug 34 | MocFile = $(ObjectDir)/temp.moc.cpp 35 | Product = Debug/simplest 36 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -D_DEBUG -g3 -D_MT -fexceptions 37 | CXXFlags = $(CFlags) -fno-rtti 38 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 39 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 40 | CompileCXX = @$(CXX) $< 41 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 42 | Link = @g++ $(LibDir) -ldl -o $(Product) 43 | LD_LIBRARY_PATH += :$(ProductDir) 44 | endif 45 | 46 | # 47 | # Making... 48 | # 49 | all : $(ProductDir) $(ObjectDir) StartMake $(Product) EndMake 50 | 51 | $(ProductDir) : 52 | @mkdir -p $(ProductDir) 53 | 54 | ifneq ($(ProductDir),$(ObjectDir)) 55 | $(ObjectDir) : 56 | @mkdir -p $(ObjectDir) 57 | endif 58 | 59 | clean : 60 | @rm -f $(ObjectDir)/*.o 61 | @rm -f $(Product) 62 | 63 | StartMake : 64 | @echo "-------------- Configuration:" $(PROJ) $(CFG) "--------------" 65 | ifeq ($(ForceLink),1) 66 | @rm -f $(Product) 67 | endif 68 | 69 | EndMake : 70 | @echo ">>> Success <<<" 71 | 72 | # 73 | # Source Files, Objects & Product 74 | # 75 | $(ObjectDir)/Simplest.o : \ 76 | Simplest.cpp 77 | @echo "---> Compiling" $< "..." 78 | $(CompileCXX) 79 | 80 | 81 | Objects = \ 82 | $(ObjectDir)/Simplest.o 83 | 84 | $(Product) : $(Objects) $(Libs) 85 | @echo "---> Creating" $@ "..." 86 | @rm -f $@ 87 | $(Link) $(Objects) $(Libraries) 88 | $(CheckLink) 89 | 90 | -------------------------------------------------------------------------------- /examples/simplest/Simplest.cpp: -------------------------------------------------------------------------------- 1 | #include // std::vector 2 | #include // std::cout 3 | #include 4 | 5 | using namespace tpl; 6 | 7 | // ------------------------------------------------------------------------- 8 | // simplest 9 | 10 | // A simplest example. 11 | 12 | // What we use: 13 | // * Rules: /append(), %, real(), ws() 14 | // * Matching: tpl::simple::match() 15 | 16 | int main() 17 | { 18 | std::vector values; // you can change vector to other stl containers. 19 | 20 | if ( simple::match("-.1 -0.1 +32. -22323.2e+12", real()/append(values) % ws()) ) 21 | { 22 | for (std::vector::iterator it = values.begin(); it != values.end(); ++it) 23 | { 24 | std::cout << *it << "\n"; 25 | } 26 | } 27 | return 0; 28 | } 29 | 30 | // ------------------------------------------------------------------------- 31 | 32 | -------------------------------------------------------------------------------- /examples/simplest/build: -------------------------------------------------------------------------------- 1 | make CFG=Release 2 | 3 | -------------------------------------------------------------------------------- /examples/simplest/simplest.prj: -------------------------------------------------------------------------------- 1 | [Include] 2 | ../../../tpl/include 3 | 4 | [Config Release] 5 | Product Exe Release/simplest 6 | Options Release; MultiThread; AnsiChar; NoRtti; Exception; WarningAll 7 | ObjDir Release 8 | LibDir 9 | Libraries 10 | 11 | [Config Debug] 12 | Product Exe Debug/simplest 13 | Options Debug; MultiThread; AnsiChar; NoRtti; Exception; WarningAll 14 | ObjDir Debug 15 | LibDir 16 | Libraries 17 | 18 | [Source] 19 | Simplest.cpp 20 | 21 | -------------------------------------------------------------------------------- /examples/simplest2/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Configuration Default 3 | # 4 | ifeq ($(CFG),) 5 | CFG = Debug 6 | endif 7 | 8 | IncludeDir = -I../../../tpl/include 9 | 10 | # 11 | # Configuration Release 12 | # 13 | ifeq ($(CFG), Release) 14 | ProductDir = Release 15 | ObjectDir = Release 16 | MocFile = $(ObjectDir)/temp.moc.cpp 17 | Product = Release/simplest 18 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -DNDEBUG -O2 -D_MT -fexceptions 19 | CXXFlags = $(CFlags) -fno-rtti 20 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 21 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 22 | CompileCXX = @$(CXX) $< 23 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 24 | Link = @g++ $(LibDir) -ldl -o $(Product) 25 | LD_LIBRARY_PATH += :$(ProductDir) 26 | endif 27 | 28 | # 29 | # Configuration Debug 30 | # 31 | ifeq ($(CFG), Debug) 32 | ProductDir = Debug 33 | ObjectDir = Debug 34 | MocFile = $(ObjectDir)/temp.moc.cpp 35 | Product = Debug/simplest 36 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -D_DEBUG -g3 -D_MT -fexceptions 37 | CXXFlags = $(CFlags) -fno-rtti 38 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 39 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 40 | CompileCXX = @$(CXX) $< 41 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 42 | Link = @g++ $(LibDir) -ldl -o $(Product) 43 | LD_LIBRARY_PATH += :$(ProductDir) 44 | endif 45 | 46 | # 47 | # Making... 48 | # 49 | all : $(ProductDir) $(ObjectDir) StartMake $(Product) EndMake 50 | 51 | $(ProductDir) : 52 | @mkdir -p $(ProductDir) 53 | 54 | ifneq ($(ProductDir),$(ObjectDir)) 55 | $(ObjectDir) : 56 | @mkdir -p $(ObjectDir) 57 | endif 58 | 59 | clean : 60 | @rm -f $(ObjectDir)/*.o 61 | @rm -f $(Product) 62 | 63 | StartMake : 64 | @echo "-------------- Configuration:" $(PROJ) $(CFG) "--------------" 65 | ifeq ($(ForceLink),1) 66 | @rm -f $(Product) 67 | endif 68 | 69 | EndMake : 70 | @echo ">>> Success <<<" 71 | 72 | # 73 | # Source Files, Objects & Product 74 | # 75 | $(ObjectDir)/Simplest.o : \ 76 | Simplest.cpp 77 | @echo "---> Compiling" $< "..." 78 | $(CompileCXX) 79 | 80 | 81 | Objects = \ 82 | $(ObjectDir)/Simplest.o 83 | 84 | $(Product) : $(Objects) $(Libs) 85 | @echo "---> Creating" $@ "..." 86 | @rm -f $@ 87 | $(Link) $(Objects) $(Libraries) 88 | $(CheckLink) 89 | 90 | -------------------------------------------------------------------------------- /examples/simplest2/Simplest.cpp: -------------------------------------------------------------------------------- 1 | #include // std::vector 2 | #include // std::cout 3 | #include // minimization of including tpl 4 | 5 | using namespace tpl; 6 | 7 | // ------------------------------------------------------------------------- 8 | // simplest 9 | 10 | // A simplest example. 11 | 12 | // What we use: 13 | // * Rules: /append(), %, real(), ws() 14 | // * Matching: operator>> 15 | 16 | int main() 17 | { 18 | std::vector values; // you can change vector to other stl containers. 19 | 20 | if ( "-.1 -0.1 +32. -22323.2e+12" >> real()/append(values) % ws() ) 21 | { 22 | for (std::vector::iterator it = values.begin(); it != values.end(); ++it) 23 | { 24 | std::cout << *it << "\n"; 25 | } 26 | } 27 | return 0; 28 | } 29 | 30 | // ------------------------------------------------------------------------- 31 | 32 | -------------------------------------------------------------------------------- /examples/simplest2/build: -------------------------------------------------------------------------------- 1 | make CFG=Release 2 | 3 | -------------------------------------------------------------------------------- /examples/simplest2/simplest2.prj: -------------------------------------------------------------------------------- 1 | [Include] 2 | ../../../tpl/include 3 | 4 | [Config Release] 5 | Product Exe Release/simplest 6 | Options Release; MultiThread; AnsiChar; NoRtti; Exception 7 | ObjDir Release 8 | LibDir 9 | Libraries 10 | 11 | [Config Debug] 12 | Product Exe Debug/simplest 13 | Options Debug; MultiThread; AnsiChar; NoRtti; Exception 14 | ObjDir Debug 15 | LibDir 16 | Libraries 17 | 18 | [Source] 19 | Simplest.cpp 20 | 21 | -------------------------------------------------------------------------------- /examples/token/Main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace tpl; 4 | 5 | // ------------------------------------------------------------------------- 6 | 7 | int main() 8 | { 9 | const char source[] = "\ 10 | class Foo // Foo comment\n\ 11 | : public Base1, Base2\n\ 12 | {};\ 13 | "; 14 | 15 | source >> cpp_skip_[ 16 | *gr(c_token()/TPL_INFO("TOKEN")) 17 | ]; 18 | } 19 | 20 | // ------------------------------------------------------------------------- 21 | -------------------------------------------------------------------------------- /examples/urlparams/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Configuration Default 3 | # 4 | ifeq ($(CFG),) 5 | CFG = Debug 6 | endif 7 | 8 | IncludeDir = -I../../../tpl/include 9 | 10 | # 11 | # Configuration Release 12 | # 13 | ifeq ($(CFG), Release) 14 | ProductDir = Release 15 | ObjectDir = Release 16 | MocFile = $(ObjectDir)/temp.moc.cpp 17 | Product = Release/urlparams 18 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -DNDEBUG -O2 -D_MT -fexceptions 19 | CXXFlags = $(CFlags) -fno-rtti 20 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 21 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 22 | CompileCXX = @$(CXX) $< 23 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 24 | Link = @g++ $(LibDir) -ldl -o $(Product) 25 | LD_LIBRARY_PATH += :$(ProductDir) 26 | endif 27 | 28 | # 29 | # Configuration Debug 30 | # 31 | ifeq ($(CFG), Debug) 32 | ProductDir = Debug 33 | ObjectDir = Debug 34 | MocFile = $(ObjectDir)/temp.moc.cpp 35 | Product = Debug/urlparams 36 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -D_DEBUG -g3 -D_MT -fexceptions 37 | CXXFlags = $(CFlags) -fno-rtti 38 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 39 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 40 | CompileCXX = @$(CXX) $< 41 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 42 | Link = @g++ $(LibDir) -ldl -o $(Product) 43 | LD_LIBRARY_PATH += :$(ProductDir) 44 | endif 45 | 46 | # 47 | # Making... 48 | # 49 | all : $(ProductDir) $(ObjectDir) StartMake $(Product) EndMake 50 | 51 | $(ProductDir) : 52 | @mkdir -p $(ProductDir) 53 | 54 | ifneq ($(ProductDir),$(ObjectDir)) 55 | $(ObjectDir) : 56 | @mkdir -p $(ObjectDir) 57 | endif 58 | 59 | clean : 60 | @rm -f $(ObjectDir)/*.o 61 | @rm -f $(Product) 62 | 63 | StartMake : 64 | @echo "-------------- Configuration:" $(PROJ) $(CFG) "--------------" 65 | ifeq ($(ForceLink),1) 66 | @rm -f $(Product) 67 | endif 68 | 69 | EndMake : 70 | @echo ">>> Success <<<" 71 | 72 | # 73 | # Source Files, Objects & Product 74 | # 75 | $(ObjectDir)/ParseUrlParams.o : \ 76 | ParseUrlParams.cpp 77 | @echo "---> Compiling" $< "..." 78 | $(CompileCXX) 79 | 80 | 81 | Objects = \ 82 | $(ObjectDir)/ParseUrlParams.o 83 | 84 | $(Product) : $(Objects) $(Libs) 85 | @echo "---> Creating" $@ "..." 86 | @rm -f $@ 87 | $(Link) $(Objects) $(Libraries) 88 | $(CheckLink) 89 | 90 | -------------------------------------------------------------------------------- /examples/urlparams/ParseUrlParams.cpp: -------------------------------------------------------------------------------- 1 | #include // std::map/multimap 2 | #include // std::cout 3 | #include 4 | 5 | using namespace tpl; 6 | 7 | // ------------------------------------------------------------------------- 8 | // parse_url_params 9 | 10 | #define MAP map // can be map or multimap 11 | #define OVERWRITE true // can be true or false 12 | #define RULE *( \ 13 | *ch('&') + find('=')/assign(key) + '=' + find_set<'&', EOF>()/insert(values, key) ) 14 | 15 | int main() 16 | { 17 | std::string key; 18 | std::MAP values; 19 | 20 | if ( simple::match("&page=1&x=2&&lang=en&x=3", RULE) ) 21 | { 22 | for (std::MAP::iterator it = values.begin(); it != values.end(); ++it) 23 | { 24 | std::cout << it->first << " = " << it->second << "\n"; 25 | } 26 | } 27 | return 0; 28 | } 29 | 30 | // ------------------------------------------------------------------------- 31 | 32 | -------------------------------------------------------------------------------- /examples/urlparams/build: -------------------------------------------------------------------------------- 1 | make CFG=Release 2 | 3 | -------------------------------------------------------------------------------- /examples/urlparams/urlparams.prj: -------------------------------------------------------------------------------- 1 | [Include] 2 | ../../../tpl/include 3 | 4 | [Config Release] 5 | Product Exe Release/urlparams 6 | Options Release; MultiThread; AnsiChar; NoRtti; Exception 7 | ObjDir Release 8 | LibDir 9 | Libraries 10 | 11 | [Config Debug] 12 | Product Exe Debug/urlparams 13 | Options Debug; MultiThread; AnsiChar; NoRtti; Exception 14 | ObjDir Debug 15 | LibDir 16 | Libraries 17 | 18 | [Source] 19 | ParseUrlParams.cpp 20 | 21 | -------------------------------------------------------------------------------- /examples/validation/Makefile.li32: -------------------------------------------------------------------------------- 1 | OSAbbr = li 2 | Bits = 32 3 | Platform = li32 4 | 5 | # 6 | # Configuration Default 7 | # 8 | ifeq ($(CFG),) 9 | CFG = Debug 10 | endif 11 | 12 | IncludeDir = -I../../../tpl/include -I../../../boost 13 | 14 | # 15 | # Configuration Release 16 | # 17 | ifeq ($(CFG), Release) 18 | ProductDir = Release 19 | ObjectDir = Release 20 | Product = Release/simplest 21 | CFlags = $(Defines) -fPIC -D__32BIT__ -D__INTEL__ -D__LINUX__ -DLINUX -DNDEBUG -O2 -D_MT -fexceptions 22 | CXXFlags = $(CFlags) -fno-rtti 23 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 24 | CompileCXX = @g++ -c $(IncludeDir) $(CXXFlags) -o $@ $< 25 | Link = @g++ $(LibDir) -o $(Product) 26 | CheckLink = @ldd -u -r $(Product); echo 27 | LD_LIBRARY_PATH += :$(ProductDir) 28 | endif 29 | 30 | # 31 | # Configuration Debug 32 | # 33 | ifeq ($(CFG), Debug) 34 | ProductDir = Debug 35 | ObjectDir = Debug 36 | Product = Debug/simplest 37 | CFlags = $(Defines) -fPIC -D__32BIT__ -D__INTEL__ -D__LINUX__ -DLINUX -D_DEBUG -g3 -D_MT -fexceptions 38 | CXXFlags = $(CFlags) -fno-rtti 39 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 40 | CompileCXX = @g++ -c $(IncludeDir) $(CXXFlags) -o $@ $< 41 | Link = @g++ $(LibDir) -o $(Product) 42 | CheckLink = @ldd -u -r $(Product); echo 43 | LD_LIBRARY_PATH += :$(ProductDir) 44 | endif 45 | 46 | # 47 | # Making... 48 | # 49 | all : $(ProductDir) $(ObjectDir) StartMake $(Product) EndMake 50 | 51 | $(ProductDir) : 52 | @mkdir -p $(ProductDir) 53 | 54 | ifneq ($(ProductDir),$(ObjectDir)) 55 | $(ObjectDir) : 56 | @mkdir -p $(ObjectDir) 57 | endif 58 | 59 | clean : 60 | @rm -f $(ObjectDir)/*.o 61 | @rm -f $(Product) 62 | 63 | StartMake : 64 | @echo "-------------- Configuration:" $(PROJ) $(CFG) "--------------" 65 | ifeq ($(ForceLink),1) 66 | @rm -f $(Product) 67 | endif 68 | 69 | EndMake : 70 | @echo ">>> Success <<<" 71 | 72 | # 73 | # Source Files, Objects & Product 74 | # 75 | $(ObjectDir)/Simplest.o : \ 76 | Simplest.cpp 77 | @echo "---> Compiling" $< "..." 78 | $(CompileCXX) 79 | 80 | Objects = $(ObjectDir)/Simplest.o 81 | 82 | $(Product) : $(Objects) 83 | @echo "---> Creating" $@ "..." 84 | @rm -f $@ 85 | $(Link) $(Objects) $(Libraries) 86 | $(CheckLink) 87 | 88 | -------------------------------------------------------------------------------- /examples/validation/Makefile.li64: -------------------------------------------------------------------------------- 1 | OSAbbr = li 2 | Bits = 64 3 | Platform = li64 4 | 5 | # 6 | # Configuration Default 7 | # 8 | ifeq ($(CFG),) 9 | CFG = Debug 10 | endif 11 | 12 | IncludeDir = -I../../../tpl/include -I../../../boost 13 | 14 | # 15 | # Configuration Release 16 | # 17 | ifeq ($(CFG), Release) 18 | ProductDir = Release 19 | ObjectDir = Release 20 | Product = Release/simplest 21 | CFlags = $(Defines) -fPIC -D__64BIT__ -D__INTEL__ -D__LINUX__ -DLINUX -DNDEBUG -O2 -D_MT -fexceptions 22 | CXXFlags = $(CFlags) -fno-rtti 23 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 24 | CompileCXX = @g++ -c $(IncludeDir) $(CXXFlags) -o $@ $< 25 | Link = @g++ $(LibDir) -o $(Product) 26 | CheckLink = @ldd -u -r $(Product); echo 27 | LD_LIBRARY_PATH += :$(ProductDir) 28 | endif 29 | 30 | # 31 | # Configuration Debug 32 | # 33 | ifeq ($(CFG), Debug) 34 | ProductDir = Debug 35 | ObjectDir = Debug 36 | Product = Debug/simplest 37 | CFlags = $(Defines) -fPIC -D__64BIT__ -D__INTEL__ -D__LINUX__ -DLINUX -D_DEBUG -g3 -D_MT -fexceptions 38 | CXXFlags = $(CFlags) -fno-rtti 39 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 40 | CompileCXX = @g++ -c $(IncludeDir) $(CXXFlags) -o $@ $< 41 | Link = @g++ $(LibDir) -o $(Product) 42 | CheckLink = @ldd -u -r $(Product); echo 43 | LD_LIBRARY_PATH += :$(ProductDir) 44 | endif 45 | 46 | # 47 | # Making... 48 | # 49 | all : $(ProductDir) $(ObjectDir) StartMake $(Product) EndMake 50 | 51 | $(ProductDir) : 52 | @mkdir -p $(ProductDir) 53 | 54 | ifneq ($(ProductDir),$(ObjectDir)) 55 | $(ObjectDir) : 56 | @mkdir -p $(ObjectDir) 57 | endif 58 | 59 | clean : 60 | @rm -f $(ObjectDir)/*.o 61 | @rm -f $(Product) 62 | 63 | StartMake : 64 | @echo "-------------- Configuration:" $(PROJ) $(CFG) "--------------" 65 | ifeq ($(ForceLink),1) 66 | @rm -f $(Product) 67 | endif 68 | 69 | EndMake : 70 | @echo ">>> Success <<<" 71 | 72 | # 73 | # Source Files, Objects & Product 74 | # 75 | $(ObjectDir)/Simplest.o : \ 76 | Simplest.cpp 77 | @echo "---> Compiling" $< "..." 78 | $(CompileCXX) 79 | 80 | Objects = $(ObjectDir)/Simplest.o 81 | 82 | $(Product) : $(Objects) 83 | @echo "---> Creating" $@ "..." 84 | @rm -f $@ 85 | $(Link) $(Objects) $(Libraries) 86 | $(CheckLink) 87 | 88 | -------------------------------------------------------------------------------- /examples/validation/Simplest.cpp: -------------------------------------------------------------------------------- 1 | #include // std::cout 2 | #include // minimization of including tpl 3 | 4 | using namespace tpl; 5 | 6 | // ------------------------------------------------------------------------- 7 | 8 | void validation_example_1(const char* str) 9 | { 10 | if (str == integer()) 11 | std::cout << " " << str << " is an integer value.\n"; 12 | else if (str == real()) 13 | std::cout << " " << str << " is a real value.\n"; 14 | else 15 | std::cout << " " << str << " isn't a numeric value.\n"; 16 | } 17 | 18 | // ------------------------------------------------------------------------- 19 | 20 | void validation_example_2(const char* str) 21 | { 22 | int val; 23 | if (str == integer()/assign(val) && val >= 1 && val <= 12) 24 | std::cout << " " << str << " is an integer value between 1 to 12.\n"; 25 | else 26 | std::cout << " " << str << " is not valid data.\n"; 27 | } 28 | 29 | // ------------------------------------------------------------------------- 30 | 31 | #include 32 | 33 | using namespace phoenix; 34 | 35 | void validation_example_3(const char* str) 36 | { 37 | if (str == integer()/meet(arg1 >= 1 && arg1 <= 12)) 38 | std::cout << " " << str << " is an integer value between 1 to 12.\n"; 39 | else 40 | std::cout << " " << str << " is not valid data.\n"; 41 | } 42 | 43 | // ------------------------------------------------------------------------- 44 | 45 | void validation_example_4(const char* str) 46 | { 47 | if (str == integer()/(ge(1) && le(12))) 48 | std::cout << " " << str << " is an integer value between 1 to 12.\n"; 49 | else 50 | std::cout << " " << str << " is not valid data.\n"; 51 | } 52 | 53 | // ------------------------------------------------------------------------- 54 | 55 | int main() 56 | { 57 | validation_example_1("-135"); 58 | validation_example_1("+.23e-23"); 59 | validation_example_1("-.1.e23"); 60 | std::cout << "\n"; 61 | 62 | validation_example_2("3"); 63 | validation_example_2("13"); 64 | validation_example_2("-135"); 65 | validation_example_2("+.23e-23"); 66 | std::cout << "\n"; 67 | 68 | validation_example_3("3"); 69 | validation_example_3("13"); 70 | validation_example_3("-135"); 71 | validation_example_3("+.23e-23"); 72 | std::cout << "\n"; 73 | 74 | validation_example_4("3"); 75 | validation_example_4("13"); 76 | validation_example_4("-135"); 77 | validation_example_4("+.23e-23"); 78 | std::cout << "\n"; 79 | return 0; 80 | } 81 | 82 | // ------------------------------------------------------------------------- 83 | 84 | -------------------------------------------------------------------------------- /examples/validation/build: -------------------------------------------------------------------------------- 1 | make CFG=Release 2 | 3 | -------------------------------------------------------------------------------- /examples/validation/validation.prj: -------------------------------------------------------------------------------- 1 | [Include] 2 | ../../../tpl/include 3 | ../../../boost 4 | 5 | [Config Release] 6 | Product Exe Release/simplest 7 | Options Release; MultiThread; AnsiChar; NoRtti; Exception 8 | ObjDir Release 9 | LibDir 10 | Libraries 11 | 12 | [Config Debug] 13 | Product Exe Debug/simplest 14 | Options Debug; MultiThread; AnsiChar; NoRtti; Exception 15 | ObjDir Debug 16 | LibDir 17 | Libraries 18 | 19 | [Source] 20 | Simplest.cpp 21 | 22 | -------------------------------------------------------------------------------- /examples/variant/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Configuration Default 3 | # 4 | ifeq ($(CFG),) 5 | CFG = Debug 6 | endif 7 | 8 | IncludeDir = -I../../../tpl/include -I../../../stdext/include -I../../../boost 9 | 10 | # 11 | # Configuration Release 12 | # 13 | ifeq ($(CFG), Release) 14 | ProductDir = Release 15 | ObjectDir = Release 16 | MocFile = $(ObjectDir)/temp.moc.cpp 17 | Product = Release/emu 18 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -DNDEBUG -O2 -D_MT -fexceptions 19 | CXXFlags = $(CFlags) -fno-rtti 20 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 21 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 22 | CompileCXX = @$(CXX) $< 23 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 24 | Link = @g++ $(LibDir) -ldl -o $(Product) 25 | LD_LIBRARY_PATH += :$(ProductDir) 26 | endif 27 | 28 | # 29 | # Configuration Debug 30 | # 31 | ifeq ($(CFG), Debug) 32 | ProductDir = Debug 33 | ObjectDir = Debug 34 | MocFile = $(ObjectDir)/temp.moc.cpp 35 | Product = Debug/emu 36 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -D_DEBUG -g3 -D_MT -fexceptions 37 | CXXFlags = $(CFlags) -frtti 38 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 39 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 40 | CompileCXX = @$(CXX) $< 41 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 42 | Link = @g++ $(LibDir) -ldl -o $(Product) 43 | LD_LIBRARY_PATH += :$(ProductDir) 44 | endif 45 | 46 | # 47 | # Making... 48 | # 49 | all : $(ProductDir) $(ObjectDir) StartMake $(Product) EndMake 50 | 51 | $(ProductDir) : 52 | @mkdir -p $(ProductDir) 53 | 54 | ifneq ($(ProductDir),$(ObjectDir)) 55 | $(ObjectDir) : 56 | @mkdir -p $(ObjectDir) 57 | endif 58 | 59 | clean : 60 | @rm -f $(ObjectDir)/*.o 61 | @rm -f $(Product) 62 | 63 | StartMake : 64 | @echo "-------------- Configuration:" $(PROJ) $(CFG) "--------------" 65 | ifeq ($(ForceLink),1) 66 | @rm -f $(Product) 67 | endif 68 | 69 | EndMake : 70 | @echo ">>> Success <<<" 71 | 72 | # 73 | # Source Files, Objects & Product 74 | # 75 | $(ObjectDir)/Variant.o : \ 76 | Variant.cpp 77 | @echo "---> Compiling" $< "..." 78 | $(CompileCXX) 79 | 80 | 81 | Objects = \ 82 | $(ObjectDir)/Variant.o 83 | 84 | $(Product) : $(Objects) $(Libs) 85 | @echo "---> Creating" $@ "..." 86 | @rm -f $@ 87 | $(Link) $(Objects) $(Libraries) 88 | $(CheckLink) 89 | 90 | -------------------------------------------------------------------------------- /examples/variant/Variant.cpp: -------------------------------------------------------------------------------- 1 | #define TPL_USE_AUTO_ALLOC 2 | #include // sin, cos, pow 3 | #include // std::cout 4 | #include 5 | #include "Variant.h" 6 | 7 | // class TestEmulator 8 | 9 | class TestEmulator 10 | { 11 | public: 12 | typedef tpl::emu::ExtCPU cpu; 13 | 14 | void simplest() 15 | { 16 | cpu::alloc_type alloc; 17 | cpu::code_type code(alloc); 18 | 19 | // 3 / 2 20 | code << 21 | cpu::push(3), 22 | cpu::push(2), 23 | cpu::div(); 24 | 25 | cpu::stack_type stk; 26 | code.exec(alloc, 0, code.size(), stk); 27 | 28 | std::cout << stk.top() << "\n\n"; 29 | } 30 | 31 | void local_var() 32 | { 33 | cpu::alloc_type alloc; 34 | cpu::code_type code(alloc); 35 | cpu::var_type x, y; 36 | 37 | // x = 2 38 | // y = 3.0 39 | // x * y 40 | code << 41 | cpu::var(x, y), 42 | 43 | cpu::lea(x), 44 | cpu::push(2), 45 | cpu::assign(), 46 | cpu::pop(), 47 | 48 | cpu::lea(y), 49 | cpu::push(3.0), 50 | cpu::assign(), 51 | cpu::pop(), 52 | 53 | cpu::push(x), 54 | cpu::push(y), 55 | cpu::mul(); 56 | 57 | cpu::stack_type stk; 58 | code.exec(alloc, 0, code.size(), stk); 59 | 60 | std::cout << stk.top() << "\n\n"; 61 | } 62 | 63 | void local_var_optimization() 64 | { 65 | cpu::alloc_type alloc; 66 | cpu::code_type code(alloc); 67 | cpu::var_type x, y; 68 | 69 | // x = 2.0 70 | // y = 3.0 71 | // x * y 72 | code << 73 | cpu::push(2.0), 74 | cpu::var_init(x), 75 | cpu::push(3.0), 76 | cpu::var_init(y), 77 | 78 | cpu::push(x), 79 | cpu::push(y), 80 | cpu::mul(); 81 | 82 | cpu::stack_type stk; 83 | code.exec(alloc, 0, code.size(), stk); 84 | 85 | std::cout << stk.top() << "\n\n"; 86 | } 87 | 88 | static Variant my_sin(cpu::alloc_type& alloc, const Variant& x) 89 | { 90 | return Variant(alloc, sin(to_double(x))); 91 | } 92 | 93 | static Variant max_value(const Variant x[], int count) 94 | { 95 | return *std::max_element(x, x+count); 96 | } 97 | 98 | void vargs() 99 | { 100 | cpu::alloc_type alloc; 101 | cpu::code_type code(alloc); 102 | 103 | // max(2.0, 3.0, sin(4.0)) 104 | code << 105 | cpu::push(2.0), 106 | cpu::push(3.0), 107 | cpu::push(4.0), 108 | cpu::func(my_sin), 109 | cpu::arity(3), 110 | cpu::func(max_value); 111 | 112 | cpu::stack_type stk; 113 | code.exec(alloc, 0, code.size(), stk); 114 | 115 | std::cout << stk.top() << "\n\n"; 116 | } 117 | 118 | void call_proc() 119 | { 120 | cpu::alloc_type alloc; 121 | cpu::code_type code(alloc); 122 | 123 | cpu::proc_type<> my_div; 124 | cpu::label_type<> my_label; 125 | cpu::var_type x, y; 126 | 127 | code << 128 | cpu::jmp(my_label), 129 | 130 | cpu::proc(my_div), 131 | cpu::arg(x), 132 | cpu::arg(y), 133 | cpu::end_arglist(), 134 | cpu::push(x), 135 | cpu::push(y), 136 | cpu::div(), 137 | cpu::ret(2), 138 | 139 | cpu::label(my_label), 140 | cpu::push(3), 141 | cpu::push(2), 142 | cpu::call(my_div); 143 | 144 | cpu::stack_type stk; 145 | code.exec(alloc, 0, code.size(), stk); 146 | 147 | std::cout << stk.top() << "\n\n"; 148 | } 149 | 150 | void call_proc2() 151 | { 152 | cpu::alloc_type alloc; 153 | cpu::code_type code(alloc); 154 | 155 | cpu::proc_type<0> my_div; 156 | cpu::label_type<0> my_label; 157 | cpu::var_type x, y; 158 | 159 | code << 160 | cpu::proc(my_div, x, y), 161 | cpu::push(x), 162 | cpu::push(y), 163 | cpu::div(), 164 | cpu::ret(2), 165 | 166 | cpu::label(my_label), 167 | cpu::push(3), 168 | cpu::push(2.0), 169 | cpu::call(my_div); 170 | 171 | cpu::stack_type stk; 172 | code.exec(alloc, my_label, code.size(), stk); 173 | 174 | std::cout << stk.top() << "\n\n"; 175 | } 176 | }; 177 | 178 | int main() 179 | { 180 | TestEmulator test; 181 | test.simplest(); 182 | test.local_var(); 183 | test.local_var_optimization(); 184 | test.vargs(); 185 | test.call_proc(); 186 | test.call_proc2(); 187 | } 188 | 189 | // ------------------------------------------------------------------------- 190 | 191 | -------------------------------------------------------------------------------- /examples/variant/Variant.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include // std::String 3 | 4 | class Procedure 5 | { 6 | private: 7 | size_t m_proc; 8 | }; 9 | 10 | // class test::Variant 11 | 12 | enum TypeList { 13 | vtNone = 0, // void 14 | vtInt = 0x0001, // int 15 | vtDouble = 0x0002, // Double 16 | vtBool = 0x0004, // bool 17 | vtString = 0x0008, // std::String 18 | vtProc = 0x0010, // Procedure 19 | }; 20 | 21 | WINX_VARIANT_TYPES_BEGIN(test, TypeList, vtNone) 22 | WINX_VARIANT_TYPE(int, vtInt) 23 | WINX_VARIANT_TYPE(double, vtDouble) 24 | WINX_VARIANT_TYPES_END() 25 | 26 | typedef test::Variant Variant; 27 | 28 | inline double TPL_CALL to_double(const Variant& a) 29 | { 30 | switch (a.type()) 31 | { 32 | case vtDouble: return a.get(); 33 | case vtInt: return a.get(); 34 | default: throw std::bad_cast(); 35 | } 36 | return 0; 37 | } 38 | 39 | namespace std { 40 | 41 | template 42 | inline OStreamT& TPL_CALL operator<<(OStreamT& os, const test::Variant& a) 43 | { 44 | switch (a.type()) 45 | { 46 | case vtDouble: return os << a.get(); 47 | case vtInt: return os << a.get(); 48 | default: return os << "(unassigned)"; 49 | } 50 | } 51 | 52 | inline bool operator<(const test::Variant& a, const test::Variant& b) 53 | { 54 | return to_double(a) < to_double(b); 55 | } 56 | 57 | } 58 | 59 | template 60 | inline Variant TPL_CALL ext_multiplies( 61 | AllocT& alloc, const Variant& a, const Variant& b) 62 | { 63 | if (a.type() == vtInt && b.type() == vtInt) { 64 | return Variant(alloc, a.get() * b.get()); 65 | } 66 | else 67 | return Variant(alloc, to_double(a) * to_double(b)); 68 | } 69 | 70 | template 71 | inline Variant TPL_CALL ext_divides( 72 | AllocT& alloc, const Variant& a, const Variant& b) 73 | { 74 | if (a.type() == vtInt && b.type() == vtInt) 75 | return Variant(alloc, a.get() / b.get()); 76 | else 77 | return Variant(alloc, to_double(a) / to_double(b)); 78 | } 79 | 80 | template 81 | inline Variant TPL_CALL ext_assign( 82 | AllocT& alloc, Variant& a, const Variant& b) 83 | { 84 | if (a.type() != vtNone) 85 | throw std::logic_error("variable is already assigned!"); 86 | return a = b; 87 | } 88 | 89 | -------------------------------------------------------------------------------- /examples/variant/build: -------------------------------------------------------------------------------- 1 | make CFG=Release 2 | 3 | -------------------------------------------------------------------------------- /examples/variant/variant.prj: -------------------------------------------------------------------------------- 1 | [Include] 2 | ../../../tpl/include 3 | ../../../stdext/include 4 | ../../../boost 5 | ../../../boostmm 6 | 7 | [Config Release] 8 | Product Exe Release/emu 9 | Options Release; MultiThread; AnsiChar; NoRtti; Exception 10 | ObjDir Release 11 | LibDir 12 | Libraries 13 | 14 | [Config Debug] 15 | Product Exe Debug/emu 16 | Options Debug; MultiThread; AnsiChar; Rtti; Exception 17 | ObjDir Debug 18 | LibDir 19 | Libraries 20 | 21 | [Source] 22 | Variant.cpp 23 | 24 | -------------------------------------------------------------------------------- /include/tpl/BinRegExp.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | // WINX: a C++ template GUI library - MOST SIMPLE BUT EFFECTIVE 3 | // 4 | // This file is a part of the WINX Library. 5 | // The use and distribution terms for this software are covered by the 6 | // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) 7 | // which can be found in the file CPL.txt at this distribution. By using 8 | // this software in any fashion, you are agreeing to be bound by the terms 9 | // of this license. You must not remove this notice, or any other, from 10 | // this software. 11 | // 12 | // Module: tpl/BinRegExp.h 13 | // Creator: xushiwei 14 | // Email: xushiweizh@gmail.com 15 | // Date: 2006-8-13 9:41:58 16 | // 17 | // $Id: BinRegExp.h 625 2008-06-10 14:16:54Z xushiweizh $ 18 | // -----------------------------------------------------------------------*/ 19 | #ifndef TPL_BINREGEXP_H 20 | #define TPL_BINREGEXP_H 21 | 22 | #ifndef TPL_REGEXP_H 23 | #include "RegExp.h" 24 | #endif 25 | 26 | #ifndef TPL_BINARY_BASIC_H 27 | #include "binary/Basic.h" 28 | #endif 29 | 30 | #ifndef TPL_BINARY_OPERATOR_H 31 | #include "binary/Operator.h" 32 | #endif 33 | 34 | #ifndef TPL_BINARY_STORAGE_H 35 | #include "binary/Storage.h" 36 | #endif 37 | 38 | #ifndef TPL_BINARY_MATCHRESULT_H 39 | #include "binary/MatchResult.h" 40 | #endif 41 | 42 | #ifndef TPL_BINARY_TERMINAL_H 43 | #include "binary/Terminal.h" 44 | #endif 45 | 46 | #ifndef TPL_BINARY_CUSTOMIZATION_H 47 | #include "binary/Customization.h" 48 | #endif 49 | 50 | // ------------------------------------------------------------------------- 51 | // $Log: $ 52 | 53 | #endif /* TPL_BINREGEXP_H */ 54 | -------------------------------------------------------------------------------- /include/tpl/Emulator.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | // WINX: a C++ template GUI library - MOST SIMPLE BUT EFFECTIVE 3 | // 4 | // This file is a part of the WINX Library. 5 | // The use and distribution terms for this software are covered by the 6 | // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) 7 | // which can be found in the file CPL.txt at this distribution. By using 8 | // this software in any fashion, you are agreeing to be bound by the terms 9 | // of this license. You must not remove this notice, or any other, from 10 | // this software. 11 | // 12 | // Module: tpl/Enulator.h 13 | // Creator: xushiwei 14 | // Email: xushiweizh@gmail.com 15 | // Date: 2006-8-13 9:41:58 16 | // 17 | // $Id: Enulator.h 588 2008-05-28 07:22:04Z xushiweizh $ 18 | // -----------------------------------------------------------------------*/ 19 | #ifndef TPL_EMULATOR_H 20 | #define TPL_EMULATOR_H 21 | 22 | // ========================================================================= 23 | 24 | #ifndef TPL_EMU_FUNCTION_H 25 | #include "emu/Function.h" 26 | #endif 27 | 28 | #ifndef TPL_EMU_INSTRUCTION_H 29 | #include "emu/Instruction.h" 30 | #endif 31 | 32 | #ifndef TPL_EMU_LABEL_H 33 | #include "emu/Label.h" 34 | #endif 35 | 36 | #ifndef TPL_EMU_VAR_H 37 | #include "emu/Var.h" 38 | #endif 39 | 40 | #ifndef TPL_EMU_CODE_H 41 | #include "emu/Code.h" 42 | #endif 43 | 44 | #ifndef TPL_EMU_CPU_H 45 | #include "emu/CPU.h" 46 | #endif 47 | 48 | // ========================================================================= 49 | // $Log: $ 50 | 51 | #endif /* TPL_EMULATOR_H */ 52 | 53 | -------------------------------------------------------------------------------- /include/tpl/RegExp.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | // WINX: a C++ template GUI library - MOST SIMPLE BUT EFFECTIVE 3 | // 4 | // This file is a part of the WINX Library. 5 | // The use and distribution terms for this software are covered by the 6 | // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) 7 | // which can be found in the file CPL.txt at this distribution. By using 8 | // this software in any fashion, you are agreeing to be bound by the terms 9 | // of this license. You must not remove this notice, or any other, from 10 | // this software. 11 | // 12 | // Module: tpl/RegExp.h 13 | // Creator: xushiwei 14 | // Email: xushiweizh@gmail.com 15 | // Date: 2006-8-13 9:41:58 16 | // 17 | // $Id: RegExp.h 985 2009-03-28 15:30:51Z xushiweizh $ 18 | // -----------------------------------------------------------------------*/ 19 | #ifndef TPL_REGEXP_H 20 | #define TPL_REGEXP_H 21 | 22 | // ------------------------------------------------------------------------- 23 | 24 | #ifndef TPL_REGEX_BASIC_H 25 | #include "regex/Basic.h" 26 | #endif 27 | 28 | #ifndef TPL_REGEX_TERMINAL_H 29 | #include "regex/Terminal.h" 30 | #endif 31 | 32 | #ifndef TPL_REGEX_COMPOSITION_H 33 | #include "regex/Composition.h" 34 | #endif 35 | 36 | #ifndef TPL_REGEX_UCOMPOSITION_H 37 | #include "regex/UComposition.h" 38 | #endif 39 | 40 | #ifndef TPL_REGEX_OPERATOR_H 41 | #include "regex/Operator.h" 42 | #endif 43 | 44 | #ifndef TPL_REGEX_TOKEN_H 45 | #include "regex/Token.h" 46 | #endif 47 | 48 | #ifndef TPL_REGEX_ACTION_H 49 | #include "regex/Action.h" 50 | #endif 51 | 52 | #ifndef TPL_REGEX_ASSIGN_H 53 | #include "regex/Assign.h" 54 | #endif 55 | 56 | #ifndef TPL_REGEX_APPEND_H 57 | #include "regex/Append.h" 58 | #endif 59 | 60 | #ifndef TPL_REGEX_REF_H 61 | #include "regex/Ref.h" 62 | #endif 63 | 64 | #ifndef TPL_REGEX_FIND_H 65 | #include "regex/Find.h" 66 | #endif 67 | 68 | #ifndef TPL_REGEX_CONDITION_H 69 | #include "regex/Condition.h" 70 | #endif 71 | 72 | #ifndef TPL_REGEX_CASE_H 73 | #include "regex/Case.h" 74 | #endif 75 | 76 | #ifndef TPL_REGEX_TRANSFORMATION_H 77 | #include "regex/Transformation.h" 78 | #endif 79 | 80 | #ifndef TPL_REGEX_MATCH_H 81 | #include "regex/Match.h" 82 | #endif 83 | 84 | // ------------------------------------------------------------------------- 85 | 86 | #ifndef TPL_REGEX_GRAMMAR_OPERATOR_H 87 | #include "regex/grammar/Operator.h" 88 | #endif 89 | 90 | #ifndef TPL_REGEX_GRAMMAR_ACTION_H 91 | #include "regex/grammar/Action.h" 92 | #endif 93 | 94 | #ifndef TPL_REGEX_GRAMMAR_CONDITION_H 95 | #include "regex/grammar/Condition.h" 96 | #endif 97 | 98 | // ------------------------------------------------------------------------- 99 | 100 | #ifndef TPL_REGEX_CONCRETION_H 101 | #include "regex/Concretion.h" 102 | #endif 103 | 104 | #ifndef TPL_REGEX_GRAMMAR_CONCRETION_H 105 | #include "regex/grammar/Concretion.h" 106 | #endif 107 | 108 | // ------------------------------------------------------------------------- 109 | 110 | #ifndef TPL_REGEX_RESULT_MARK_H 111 | #include "regex/result/Mark.h" 112 | #endif 113 | 114 | #ifndef TPL_REGEX_RESULT_DOCUMENT_H 115 | #include "regex/result/Document.h" 116 | #endif 117 | 118 | #ifndef TPL_REGEX_RESULT_CONTEXT_H 119 | #include "regex/result/Context.h" 120 | #endif 121 | 122 | #ifndef TPL_REGEX_DOM_H 123 | #include "regex/DOM.h" 124 | #endif 125 | 126 | // ------------------------------------------------------------------------- 127 | 128 | #ifndef TPL_REGEX_CUSTOMIZATION_H 129 | #include "regex/Customization.h" 130 | #endif 131 | 132 | // ------------------------------------------------------------------------- 133 | // $Log: $ 134 | 135 | #endif /* TPL_REGEXP_H */ 136 | 137 | -------------------------------------------------------------------------------- /include/tpl/binary/Assignment.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | // WINX: a C++ template GUI library - MOST SIMPLE BUT EFFECTIVE 3 | // 4 | // This file is a part of the WINX Library. 5 | // The use and distribution terms for this software are covered by the 6 | // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) 7 | // which can be found in the file CPL.txt at this distribution. By using 8 | // this software in any fashion, you are agreeing to be bound by the terms 9 | // of this license. You must not remove this notice, or any other, from 10 | // this software. 11 | // 12 | // Module: tpl/binary/Assignment.h 13 | // Creator: xushiwei 14 | // Email: xushiweizh@gmail.com 15 | // Date: 2006-8-13 9:41:58 16 | // 17 | // $Id: Assignment.h 625 2008-06-10 14:16:54Z xushiweizh $ 18 | // -----------------------------------------------------------------------*/ 19 | #ifndef TPL_BINARY_ASSIGNMENT_H 20 | #define TPL_BINARY_ASSIGNMENT_H 21 | 22 | #ifndef TPL_BINARY_BASIC_H 23 | #include "Basic.h" 24 | #endif 25 | 26 | #ifndef TPL_BINARY_MATCHRESULT_H 27 | #include "MatchResult.h" 28 | #endif 29 | 30 | #ifndef TPL_BINARY_TERMINAL_H 31 | #include "Terminal.h" 32 | #endif 33 | 34 | NS_TPL_BEGIN 35 | 36 | // ========================================================================= 37 | // class AssigCType 38 | 39 | template 40 | class AssigCType 41 | { 42 | public: 43 | template 44 | static TypeT TPL_CALL get(Iterator first, Iterator last, const void* pExtra) 45 | { 46 | typedef ArchiveIteratorTraits Tr_; 47 | typedef typename Tr_::value_type value_type; 48 | TPL_REQUIRE(sizeof(value_type) == 1, CharRequire_); 49 | TPL_REQUIRE_CLASS(TypeT, TypeT2, EqClass_); 50 | return _get_value(first); 51 | } 52 | }; 53 | 54 | template 55 | struct AssigTraits > { 56 | typedef AssigCType assig_type; 57 | }; 58 | 59 | // ========================================================================= 60 | // class AssigCEq 61 | 62 | template 63 | class AssigCEq 64 | { 65 | public: 66 | template 67 | static TypeT TPL_CALL get(Iterator first, Iterator last, const CEq* rule_) 68 | { 69 | return rule_->m_val; 70 | } 71 | }; 72 | 73 | template 74 | struct AssigTraits > { 75 | typedef AssigCEq assig_type; 76 | }; 77 | 78 | // ========================================================================= 79 | // class AssigCArr 80 | 81 | template 82 | class AssigCArr 83 | { 84 | public: 85 | template 86 | static ArrT TPL_CALL get(Iterator first, Iterator last, const CArr* arr) 87 | { 88 | Arr& result 89 | typedef ArchiveIteratorTraits Tr_; 90 | typedef typename Tr_::value_type value_type; 91 | TPL_REQUIRE(sizeof(value_type) == 1, CharRequire_); 92 | TPL_REQUIRE_CLASS(Arr, ArrT, EqClass_); 93 | return ArrT(first, arr->size()); 94 | } 95 | }; 96 | 97 | template 98 | struct AssigTraits > { 99 | typedef AssigCArr assig_type; 100 | }; 101 | 102 | 103 | // ========================================================================= 104 | // function c_type, c_array 105 | 106 | template 107 | __forceinline 108 | Rule, Assign > > 109 | TPL_CALL c_array(VarT& val, const size_t dim_) { 110 | return c_array(dim_) / assign(val); 111 | } 112 | 113 | template 114 | __forceinline 115 | Rule >, Assign > > 116 | TPL_CALL c_array(VarT& val, const Var& dim_) { 117 | return c_array(dim_) / assign(val); 118 | } 119 | 120 | // ========================================================================= 121 | // $Log: $ 122 | 123 | NS_TPL_END 124 | 125 | #endif /* TPL_BINARY_ASSIGNMENT_H */ 126 | -------------------------------------------------------------------------------- /include/tpl/binary/Basic.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | // WINX: a C++ template GUI library - MOST SIMPLE BUT EFFECTIVE 3 | // 4 | // This file is a part of the WINX Library. 5 | // The use and distribution terms for this software are covered by the 6 | // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) 7 | // which can be found in the file CPL.txt at this distribution. By using 8 | // this software in any fashion, you are agreeing to be bound by the terms 9 | // of this license. You must not remove this notice, or any other, from 10 | // this software. 11 | // 12 | // Module: tpl/binary/Basic.h 13 | // Creator: xushiwei 14 | // Email: xushiweizh@gmail.com 15 | // Date: 2006-8-13 9:41:58 16 | // 17 | // $Id: Basic.h 625 2008-06-10 14:16:54Z xushiweizh $ 18 | // -----------------------------------------------------------------------*/ 19 | #ifndef TPL_BINARY_BASIC_H 20 | #define TPL_BINARY_BASIC_H 21 | 22 | #ifndef TPL_REGEX_BASIC_H 23 | #include "../regex/Basic.h" 24 | #endif 25 | 26 | #if defined(WINX_BYTESWAP) || defined(BYTESWAP) || defined(__BYTESWAP__) 27 | #define TPL_BYTESWAP 28 | #endif 29 | 30 | NS_TPL_BEGIN 31 | 32 | // ========================================================================= 33 | // class StgRule 34 | 35 | template 36 | class SubMatch 37 | { 38 | private: 39 | RuleT m_rule; 40 | SubMatchT m_subMatch; 41 | 42 | public: 43 | SubMatch(const RuleT& rule_, const SubMatchT& subMatch_) 44 | : m_rule(rule_), m_subMatch(subMatch_) { 45 | } 46 | 47 | public: 48 | typedef typename SubMatchT::result_type result_type; 49 | 50 | template 51 | bool TPL_CALL match(const SourceT& stg, ContextT& context, result_type& result) { 52 | typedef typename RuleT::result_type ResultT; 53 | ResultT res; 54 | if (m_rule.match(stg, context, res)) 55 | return m_subMatch.match(res, context, result); 56 | return false; 57 | } 58 | }; 59 | 60 | template 61 | class StgRule : public RuleT 62 | { 63 | public: 64 | template 65 | StgRule(const ArgT& x) : RuleT(x) {} 66 | 67 | template 68 | StgRule > TPL_CALL operator[](const StgRule& subMatch_) const { 69 | return StgRule >(*this, subMatch_); 70 | } 71 | }; 72 | 73 | // ========================================================================= 74 | // struct WStringTraits 75 | 76 | template 77 | struct WStringTraits { 78 | }; 79 | 80 | template <> 81 | struct WStringTraits { 82 | LPCWSTR value_type; 83 | }; 84 | 85 | template <> 86 | struct WStringTraits { 87 | LPCWSTR value_type; 88 | }; 89 | 90 | // ========================================================================= 91 | // $Log: $ 92 | 93 | NS_TPL_END 94 | 95 | #endif /* TPL_BINARY_BASIC_H */ 96 | -------------------------------------------------------------------------------- /include/tpl/binary/ComPtr.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | // WINX: a C++ template GUI library - MOST SIMPLE BUT EFFECTIVE 3 | // 4 | // This file is a part of the WINX Library. 5 | // The use and distribution terms for this software are covered by the 6 | // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) 7 | // which can be found in the file CPL.txt at this distribution. By using 8 | // this software in any fashion, you are agreeing to be bound by the terms 9 | // of this license. You must not remove this notice, or any other, from 10 | // this software. 11 | // 12 | // Module: tpl/binary/ComPtr.h 13 | // Creator: xushiwei 14 | // Email: xushiweizh@gmail.com 15 | // Date: 2006-8-13 9:41:58 16 | // 17 | // $Id: ComPtr.h 618 2008-06-01 03:33:32Z xushiweizh $ 18 | // -----------------------------------------------------------------------*/ 19 | #ifndef TPL_BINARY_COMPTR_H 20 | #define TPL_BINARY_COMPTR_H 21 | 22 | #ifndef TPL_BINARY_BASIC_H 23 | #include "Basic.h" // TPL_ASSERT, NS_TPL 24 | #endif 25 | 26 | #if !defined( _OBJBASE_H_ ) 27 | #include 28 | #endif 29 | 30 | NS_TPL_BEGIN 31 | 32 | // ========================================================================= 33 | // class ComPtr 34 | 35 | template 36 | class ComPtr 37 | { 38 | public: 39 | T* p; 40 | 41 | public: 42 | ComPtr() { 43 | p = NULL; 44 | } 45 | ComPtr(T* lp) { 46 | p = lp; 47 | if (p != NULL) 48 | p->AddRef(); 49 | } 50 | ~ComPtr() 51 | { 52 | if (p) 53 | p->Release(); 54 | } 55 | 56 | operator T*() const { 57 | return p; 58 | } 59 | T& TPL_CALL operator*() const { 60 | return *p; 61 | } 62 | T** TPL_CALL operator&() { 63 | //The assert on operator& usually indicates a bug. If this is really 64 | //what is needed, however, take the address of the p member explicitly. 65 | TPL_ASSERT(p==NULL); 66 | return &p; 67 | } 68 | T* TPL_CALL operator->() const { 69 | TPL_ASSERT(p!=NULL); 70 | return p; 71 | } 72 | 73 | bool TPL_CALL operator!() const { 74 | return (p == NULL); 75 | } 76 | bool TPL_CALL operator!=(T* pT) const { 77 | return !operator==(pT); 78 | } 79 | bool TPL_CALL operator==(T* pT) const { 80 | return p == pT; 81 | } 82 | 83 | // Release the interface and set to NULL 84 | void TPL_CALL clear() { 85 | T* pTemp = p; 86 | if (pTemp) 87 | { 88 | p = NULL; 89 | pTemp->Release(); 90 | } 91 | } 92 | // Attach to an existing interface (does not AddRef) 93 | void TPL_CALL attach(T* p2) { 94 | if (p) 95 | p->Release(); 96 | p = p2; 97 | } 98 | // Detach the interface (does not Release) 99 | T* TPL_CALL detach() 100 | { 101 | T* pt = p; 102 | p = NULL; 103 | return pt; 104 | } 105 | 106 | HRESULT create(REFCLSID rclsid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL) 107 | { 108 | TPL_ASSERT(p == NULL); 109 | return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&p); 110 | } 111 | HRESULT create(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL) 112 | { 113 | CLSID clsid; 114 | HRESULT hr = ::CLSIDFromProgID(szProgID, &clsid); 115 | TPL_ASSERT(p == NULL); 116 | if (SUCCEEDED(hr)) 117 | hr = ::CoCreateInstance(clsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&p); 118 | return hr; 119 | } 120 | 121 | template 122 | HRESULT queryInterface(Q** pp) const 123 | { 124 | TPL_ASSERT(pp != NULL); 125 | return p->QueryInterface(__uuidof(Q), (void**)pp); 126 | } 127 | }; 128 | 129 | // ========================================================================= 130 | // $Log: $ 131 | 132 | NS_TPL_END 133 | 134 | #endif /* TPL_BINARY_COMPTR_H */ 135 | -------------------------------------------------------------------------------- /include/tpl/binary/Composition.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | // WINX: a C++ template GUI library - MOST SIMPLE BUT EFFECTIVE 3 | // 4 | // This file is a part of the WINX Library. 5 | // The use and distribution terms for this software are covered by the 6 | // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) 7 | // which can be found in the file CPL.txt at this distribution. By using 8 | // this software in any fashion, you are agreeing to be bound by the terms 9 | // of this license. You must not remove this notice, or any other, from 10 | // this software. 11 | // 12 | // Module: tpl/binary/Composition.h 13 | // Creator: xushiwei 14 | // Email: xushiweizh@gmail.com 15 | // Date: 2006-8-13 9:41:58 16 | // 17 | // $Id: Composition.h 625 2008-06-10 14:16:54Z xushiweizh $ 18 | // -----------------------------------------------------------------------*/ 19 | #ifndef TPL_BINARY_COMPOSITION_H 20 | #define TPL_BINARY_COMPOSITION_H 21 | 22 | #ifndef TPL_BINARY_BASIC_H 23 | #include "Basic.h" 24 | #endif 25 | 26 | #ifndef TPL_BINARY_REF_H 27 | #include "Ref.h" 28 | #endif 29 | 30 | NS_TPL_BEGIN 31 | 32 | // ========================================================================= 33 | // function c_array 34 | 35 | // Usage: c_array(n) 36 | // Examples: 37 | // c_array(10) 38 | // c_array(ref(count)) 39 | 40 | template 41 | class SizeTDim 42 | { 43 | private: 44 | DimT m_count; 45 | 46 | public: 47 | SizeTDim(DimT count_) : m_count(count_) {} 48 | 49 | size_t TPL_CALL calc_size() const { 50 | return m_count; 51 | } 52 | 53 | size_t TPL_CALL size() const { 54 | return m_count; 55 | } 56 | }; 57 | 58 | template > 59 | class CArr : public DimT 60 | { 61 | public: 62 | template 63 | CArr(const T1& count_) : DimT(count_) { 64 | }; 65 | 66 | enum { character = 0 }; 67 | 68 | typedef ExplicitConvertible convertible_type; 69 | typedef CArr assig_tag; 70 | 71 | template 72 | bool TPL_CALL match(SourceT& ar, ContextT& context) const { 73 | TPL_REQUIRE(sizeof(typename SourceT::char_type) == 1, CharRequire_); 74 | return ar.try_skip(sizeof(TypeT) * DimT::calc_size()); 75 | } 76 | }; 77 | 78 | template 79 | __forceinline 80 | Rule > TPL_CALL c_array(const size_t dim_) { 81 | return Rule >(dim_); 82 | } 83 | 84 | template 85 | __forceinline 86 | Rule > > TPL_CALL c_array(const Var& dim_) { 87 | return Rule > >(dim_.val); 88 | } 89 | 90 | // ========================================================================= 91 | // class CArrEq 92 | 93 | // Usage: c_array(const_array_var, array_size) 94 | 95 | class CArrEq // todo 96 | { 97 | }; 98 | 99 | // ========================================================================= 100 | // $Log: $ 101 | 102 | NS_TPL_END 103 | 104 | #endif /* TPL_BINARY_COMPOSITION_H */ 105 | -------------------------------------------------------------------------------- /include/tpl/binary/Customization.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | // WINX: a C++ template GUI library - MOST SIMPLE BUT EFFECTIVE 3 | // 4 | // This file is a part of the WINX Library. 5 | // The use and distribution terms for this software are covered by the 6 | // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) 7 | // which can be found in the file CPL.txt at this distribution. By using 8 | // this software in any fashion, you are agreeing to be bound by the terms 9 | // of this license. You must not remove this notice, or any other, from 10 | // this software. 11 | // 12 | // Module: tpl/binary/Customization.h 13 | // Creator: xushiwei 14 | // Email: xushiweizh@gmail.com 15 | // Date: 2006-8-13 9:41:58 16 | // 17 | // $Id: Customization.h 625 2008-06-10 14:16:54Z xushiweizh $ 18 | // -----------------------------------------------------------------------*/ 19 | #ifndef TPL_BINARY_CUSTOMIZATION_H 20 | #define TPL_BINARY_CUSTOMIZATION_H 21 | 22 | #ifndef TPL_REGEX_CUSTOMIZATION_H 23 | #include "../regex/Customization.h" 24 | #endif 25 | 26 | NS_TPL_BEGIN 27 | 28 | template 29 | class BinaryImpl : public Customization 30 | { 31 | private: 32 | typedef Customization Base; 33 | 34 | public: 35 | typedef typename Base::Iterator Iterator; 36 | 37 | template 38 | class Array : public tpl::Arr 39 | { 40 | public: 41 | Array() {} 42 | Array(Iterator it_, size_t count_) : tpl::Arr(it_, count_) {} 43 | }; 44 | 45 | public: 46 | template 47 | static inline bool TPL_CALL match(Iterator pos, size_t cb, const tpl::Rule& rule_) 48 | { 49 | typedef ArchiveIteratorTraits Tr_; 50 | typedef typename Tr_::value_type ValueT; 51 | TPL_REQUIRE(sizeof(ValueT) == 1, CharRequire_); 52 | 53 | Iterator pos2 = pos; 54 | std::advance(pos2, cb); 55 | Source source(pos, pos2); 56 | Context context; 57 | return rule_.match(source, context); 58 | } 59 | 60 | template 61 | static inline bool TPL_CALL match(const void* pos, size_t cb, const tpl::Rule& rule_) { 62 | return match((const char*)pos, cb, rule_); 63 | } 64 | }; 65 | 66 | // ------------------------------------------------------------------------- 67 | // SimpleBinaryImplementation 68 | 69 | typedef BinaryImpl SimpleBinaryImpl; 70 | typedef SimpleBinaryImpl SimpleBinaryImplementation; 71 | 72 | // ------------------------------------------------------------------------- 73 | // BinaryImplementation 74 | 75 | typedef BinaryImpl<> BinaryImplementation; 76 | 77 | // ------------------------------------------------------------------------- 78 | // $Log: $ 79 | 80 | NS_TPL_END 81 | 82 | #endif /* TPL_BINARY_CUSTOMIZATION_H */ 83 | -------------------------------------------------------------------------------- /include/tpl/binary/MatchResult.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | // WINX: a C++ template GUI library - MOST SIMPLE BUT EFFECTIVE 3 | // 4 | // This file is a part of the WINX Library. 5 | // The use and distribution terms for this software are covered by the 6 | // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) 7 | // which can be found in the file CPL.txt at this distribution. By using 8 | // this software in any fashion, you are agreeing to be bound by the terms 9 | // of this license. You must not remove this notice, or any other, from 10 | // this software. 11 | // 12 | // Module: tpl/binary/MatchResult.h 13 | // Creator: xushiwei 14 | // Email: xushiweizh@gmail.com 15 | // Date: 2006-8-13 9:41:58 16 | // 17 | // $Id: MatchResult.h 625 2008-06-10 14:16:54Z xushiweizh $ 18 | // -----------------------------------------------------------------------*/ 19 | #ifndef TPL_BINARY_MATCHRESULT_H 20 | #define TPL_BINARY_MATCHRESULT_H 21 | 22 | #ifndef TPL_BINARY_BASIC_H 23 | #include "Basic.h" 24 | #endif 25 | 26 | #ifndef TPL_REGEX_STLHEADERS_H 27 | #include "../regex/STLHeaders.h" 28 | #endif 29 | 30 | NS_TPL_BEGIN 31 | 32 | // ========================================================================= 33 | // class Arr 34 | 35 | // function _get_value 36 | 37 | #if defined(TPL_BYTESWAP) 38 | #error "todo" 39 | #else 40 | 41 | template 42 | __forceinline TypeT TPL_CALL _get_value(Iterator it) { 43 | char val[sizeof(TypeT)]; 44 | for (size_t i = 0; i < sizeof(TypeT); ++i) 45 | val[i] = *it++; 46 | return *(const TypeT*)val; 47 | } 48 | 49 | template 50 | __forceinline TypeT TPL_CALL _get_value(const char* it) { 51 | TypeT val; 52 | memcpy(&val, it, sizeof(TypeT)); 53 | return val; 54 | } 55 | 56 | #endif 57 | 58 | // class Arr 59 | 60 | template 61 | class Arr 62 | { 63 | private: 64 | Iterator m_arr; 65 | size_t m_count; 66 | 67 | public: 68 | typedef TypeT value_type; 69 | typedef size_t size_type; 70 | 71 | public: 72 | Arr() : m_count(0) {} 73 | Arr(Iterator arr_, size_t count_) : m_arr(arr_), m_count(count_) {} 74 | 75 | size_type TPL_CALL size() const { 76 | return m_count; 77 | } 78 | 79 | #if defined(TPL_BYTESWAP) 80 | #error "todo" 81 | #else 82 | value_type TPL_CALL operator[](size_type i) const { 83 | Iterator it = m_arr; 84 | std::advance(it, sizeof(TypeT) * i); 85 | return _get_value(it); 86 | } 87 | #endif 88 | }; 89 | 90 | #if defined(TPL_HAS_OSTREAM) 91 | 92 | template 93 | inline std::basic_ostream& 94 | TPL_CALL operator<<(std::basic_ostream& os, const Arr& v) { 95 | for (size_t i = 0; i < v.size(); ++i) 96 | os << v[i] << '\t'; 97 | return os; 98 | } 99 | 100 | #endif 101 | 102 | // ========================================================================= 103 | // $Log: $ 104 | 105 | NS_TPL_END 106 | 107 | #endif /* TPL_BINARY_MATCHRESULT_H */ 108 | -------------------------------------------------------------------------------- /include/tpl/binary/Operator.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | // WINX: a C++ template GUI library - MOST SIMPLE BUT EFFECTIVE 3 | // 4 | // This file is a part of the WINX Library. 5 | // The use and distribution terms for this software are covered by the 6 | // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) 7 | // which can be found in the file CPL.txt at this distribution. By using 8 | // this software in any fashion, you are agreeing to be bound by the terms 9 | // of this license. You must not remove this notice, or any other, from 10 | // this software. 11 | // 12 | // Module: tpl/binary/Operator.h 13 | // Creator: xushiwei 14 | // Email: xushiweizh@gmail.com 15 | // Date: 2006-8-13 9:41:58 16 | // 17 | // $Id: Operator.h 618 2008-06-01 03:33:32Z xushiweizh $ 18 | // -----------------------------------------------------------------------*/ 19 | #ifndef TPL_BINARY_OPERATOR_H 20 | #define TPL_BINARY_OPERATOR_H 21 | 22 | #ifndef TPL_BINARY_BASIC_H 23 | #include "Basic.h" 24 | #endif 25 | 26 | NS_TPL_BEGIN 27 | 28 | // ========================================================================= 29 | // operator, 30 | 31 | template 32 | class MatchLst 33 | { 34 | private: 35 | MatchT1 m_x; 36 | MatchT2 m_y; 37 | 38 | public: 39 | MatchLst(const MatchT1& x, const MatchT2& y) 40 | : m_x(x), m_y(y) {} 41 | 42 | public: 43 | typedef int result_type; 44 | 45 | template 46 | bool TPL_CALL match(const SourceT& stg, ContextT& context, result_type& result) { 47 | typename MatchT1::result_type res1; 48 | if (m_x.match(stg, context, res1)) { 49 | typename MatchT2::result_type res2; 50 | return m_y.match(stg, context, res2); 51 | } 52 | return false; 53 | } 54 | }; 55 | 56 | template 57 | __forceinline 58 | StgRule > 59 | TPL_CALL operator,(const StgRule& x, const StgRule& y) { 60 | return StgRule >(x, y); 61 | } 62 | 63 | // ========================================================================= 64 | // $Log: $ 65 | 66 | NS_TPL_END 67 | 68 | #endif /* TPL_BINARY_OPERATOR_H */ 69 | -------------------------------------------------------------------------------- /include/tpl/binary/Ref.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | // WINX: a C++ template GUI library - MOST SIMPLE BUT EFFECTIVE 3 | // 4 | // This file is a part of the WINX Library. 5 | // The use and distribution terms for this software are covered by the 6 | // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) 7 | // which can be found in the file CPL.txt at this distribution. By using 8 | // this software in any fashion, you are agreeing to be bound by the terms 9 | // of this license. You must not remove this notice, or any other, from 10 | // this software. 11 | // 12 | // Module: tpl/binary/Ref.h 13 | // Creator: xushiwei 14 | // Email: xushiweizh@gmail.com 15 | // Date: 2006-8-13 9:41:58 16 | // 17 | // $Id: Ref.h 625 2008-06-10 14:16:54Z xushiweizh $ 18 | // -----------------------------------------------------------------------*/ 19 | #ifndef TPL_BINARY_REF_H 20 | #define TPL_BINARY_REF_H 21 | 22 | #ifndef TPL_REGEX_REF_H 23 | #include "../regex/Ref.h" 24 | #endif 25 | 26 | #ifndef TPL_BINARY_TERMINAL_H 27 | #include "Terminal.h" 28 | #endif 29 | 30 | NS_TPL_BEGIN 31 | 32 | // ========================================================================= 33 | // ReferenceTratis 34 | 35 | // Usage: Var var; 36 | // Examples: 37 | // Var a; 38 | // Var b; 39 | 40 | template <> 41 | struct ReferenceTratis { 42 | typedef CEq reference_type; 43 | }; 44 | 45 | template <> 46 | struct ReferenceTratis { 47 | typedef CEq reference_type; 48 | }; 49 | 50 | template <> 51 | struct ReferenceTratis { 52 | typedef CEq reference_type; 53 | }; 54 | 55 | template <> 56 | struct ReferenceTratis { 57 | typedef CEq reference_type; 58 | }; 59 | 60 | template <> 61 | struct ReferenceTratis { 62 | typedef CEq reference_type; 63 | }; 64 | 65 | // ========================================================================= 66 | // class Struct 67 | 68 | // Usage: Struct var; 69 | // Examples: 70 | // Struct a; 71 | 72 | template 73 | class Struct : public Rule > > 74 | { 75 | public: 76 | Type val; 77 | 78 | public: 79 | Struct() : Rule > >(val) {} 80 | }; 81 | 82 | template 83 | __forceinline 84 | Rule > TPL_CALL c_eq(const Var& var_) { 85 | return Rule >(var_.val); 86 | } 87 | 88 | template 89 | __forceinline 90 | Rule > TPL_CALL c_eq(const Struct& var_) { 91 | return Rule >(var_.val); 92 | } 93 | 94 | // ========================================================================= 95 | // $Log: $ 96 | 97 | NS_TPL_END 98 | 99 | #endif /* TPL_BINARY_REF_H */ 100 | -------------------------------------------------------------------------------- /include/tpl/binary/Storage.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | // WINX: a C++ template GUI library - MOST SIMPLE BUT EFFECTIVE 3 | // 4 | // This file is a part of the WINX Library. 5 | // The use and distribution terms for this software are covered by the 6 | // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) 7 | // which can be found in the file CPL.txt at this distribution. By using 8 | // this software in any fashion, you are agreeing to be bound by the terms 9 | // of this license. You must not remove this notice, or any other, from 10 | // this software. 11 | // 12 | // Module: tpl/binary/Storage.h 13 | // Creator: xushiwei 14 | // Email: xushiweizh@gmail.com 15 | // Date: 2006-8-13 9:41:58 16 | // 17 | // $Id: Storage.h 618 2008-06-01 03:33:32Z xushiweizh $ 18 | // -----------------------------------------------------------------------*/ 19 | #ifndef TPL_BINARY_STORAGE_H 20 | #define TPL_BINARY_STORAGE_H 21 | 22 | #ifndef TPL_BINARY_BASIC_H 23 | #include "Basic.h" 24 | #endif 25 | 26 | #ifndef TPL_BINARY_COMPTR_H 27 | #include "ComPtr.h" 28 | #endif 29 | 30 | #if !defined( _OBJBASE_H_ ) 31 | #include 32 | #endif 33 | 34 | NS_TPL_BEGIN 35 | 36 | #define TPL_STGM_READONLY (STGM_SHARE_DENY_WRITE | STGM_READ) 37 | 38 | // ========================================================================= 39 | // class Stream 40 | 41 | template 42 | class Stream 43 | { 44 | private: 45 | WStringArgT m_stgName; 46 | 47 | public: 48 | template 49 | Stream(const ArgT& stgName) 50 | : m_stgName(stgName) { 51 | } 52 | 53 | typedef ComPtr result_type; 54 | 55 | template 56 | bool TPL_CALL match(IStorage* stg, ContextT& context, result_type& strm) const { 57 | return S_OK == stg->OpenStream( 58 | m_stgName, NULL, TPL_STGM_READONLY, 0, &strm); 59 | } 60 | }; 61 | 62 | template __forceinline 63 | StgRule::value_type> > 64 | TPL_CALL stream(const ArgT& stgName) { 65 | return StgRule::value_type> >(stgName); 66 | } 67 | 68 | // ========================================================================= 69 | // class Storage 70 | 71 | template 72 | class Storage 73 | { 74 | private: 75 | WStringArgT m_stgName; 76 | 77 | public: 78 | template 79 | Storage(const ArgT& stgName) 80 | : m_stgName(stgName) { 81 | } 82 | 83 | typedef ComPtr result_type; 84 | 85 | template 86 | bool TPL_CALL match(IStorage* stg, ContextT& context, result_type& strm) const { 87 | return S_OK == stg->OpenStorage( 88 | m_stgName, NULL, TPL_STGM_READONLY, 0, 0, &strm); 89 | } 90 | }; 91 | 92 | template __forceinline 93 | StgRule::value_type> > 94 | TPL_CALL storage(const ArgT& stgName) { 95 | return StgRule::value_type> >(stgName); 96 | } 97 | 98 | // ========================================================================= 99 | // $Log: $ 100 | 101 | NS_TPL_END 102 | 103 | #endif /* TPL_BINARY_STORAGE_H */ 104 | -------------------------------------------------------------------------------- /include/tpl/binary/Terminal.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | // WINX: a C++ template GUI library - MOST SIMPLE BUT EFFECTIVE 3 | // 4 | // This file is a part of the WINX Library. 5 | // The use and distribution terms for this software are covered by the 6 | // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) 7 | // which can be found in the file CPL.txt at this distribution. By using 8 | // this software in any fashion, you are agreeing to be bound by the terms 9 | // of this license. You must not remove this notice, or any other, from 10 | // this software. 11 | // 12 | // Module: tpl/binary/Terminal.h 13 | // Creator: xushiwei 14 | // Email: xushiweizh@gmail.com 15 | // Date: 2006-8-13 9:41:58 16 | // 17 | // $Id: Terminal.h 625 2008-06-10 14:16:54Z xushiweizh $ 18 | // -----------------------------------------------------------------------*/ 19 | #ifndef TPL_BINARY_TERMINAL_H 20 | #define TPL_BINARY_TERMINAL_H 21 | 22 | #ifndef TPL_BINARY_BASIC_H 23 | #include "Basic.h" 24 | #endif 25 | 26 | #ifndef TPL_REGEX_REF_H 27 | #include "../regex/Ref.h" 28 | #endif 29 | 30 | NS_TPL_BEGIN 31 | 32 | // ========================================================================= 33 | // class CType 34 | 35 | // Usage: c_type() 36 | // Usage: c_struct() 37 | // Examples: 38 | // c_type() 39 | // c_struct() 40 | 41 | template 42 | class CType 43 | { 44 | public: 45 | enum { character = 0 }; 46 | 47 | typedef ExplicitConvertible convertible_type; 48 | typedef CType assig_tag; 49 | 50 | template 51 | bool TPL_CALL match(SourceT& ar, ContextT& context) const { 52 | TPL_REQUIRE(sizeof(typename SourceT::char_type) == 1, CharRequire_); 53 | return ar.try_skip(sizeof(TypeT)); 54 | } 55 | }; 56 | 57 | template 58 | __forceinline 59 | Rule > TPL_CALL c_type() { 60 | return Rule >(); 61 | } 62 | 63 | template 64 | __forceinline 65 | Rule > TPL_CALL c_struct() { 66 | return Rule >(); 67 | } 68 | 69 | // ========================================================================= 70 | // class CEq 71 | 72 | // Usage: c_type(const_val) 73 | // Usage: c_struct(const_val) 74 | // Usage: c_eq(var) 75 | // Examples: 76 | // c_type(23243) 77 | // c_struct(a_const_struct_val) 78 | // c_eq(a_var) 79 | 80 | template 81 | class AssigCEq; 82 | 83 | template 84 | class CEq 85 | { 86 | private: 87 | TypeT m_val; 88 | 89 | friend class AssigCEq; 90 | 91 | public: 92 | template 93 | CEq(const T1& val) : m_val(val) {} 94 | 95 | public: 96 | enum { character = 0 }; 97 | 98 | typedef ExplicitConvertible convertible_type; 99 | typedef CEq assig_tag; 100 | 101 | template 102 | bool TPL_CALL match(SourceT& ar, ContextT& context) const { 103 | TPL_REQUIRE(sizeof(typename SourceT::char_type) == 1, CharRequire_); 104 | TypeT val; 105 | if (!ar.try_get((char*)&val, sizeof(TypeT))) 106 | return false; 107 | #if defined(TPL_BYTESWAP) 108 | #error "todo" 109 | #endif 110 | return val == m_val; 111 | } 112 | }; 113 | 114 | template 115 | __forceinline 116 | Rule > TPL_CALL c_type(const ValueT& val) { 117 | return Rule >(val); 118 | } 119 | 120 | template 121 | __forceinline 122 | Rule > TPL_CALL c_struct(const ValueT& val) { 123 | return Rule >(val); 124 | } 125 | 126 | // ========================================================================= 127 | // $Log: $ 128 | 129 | NS_TPL_END 130 | 131 | #endif /* TPL_BINARY_TERMINAL_H */ 132 | -------------------------------------------------------------------------------- /include/tpl/boost/Lambda.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | // WINX: a C++ template GUI library - MOST SIMPLE BUT EFFECTIVE 3 | // 4 | // This file is a part of the WINX Library. 5 | // The use and distribution terms for this software are covered by the 6 | // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) 7 | // which can be found in the file CPL.txt at this distribution. By using 8 | // this software in any fashion, you are agreeing to be bound by the terms 9 | // of this license. You must not remove this notice, or any other, from 10 | // this software. 11 | // 12 | // Module: tpl/Lambda.h 13 | // Creator: xushiwei 14 | // Email: xushiweizh@gmail.com 15 | // Date: 2006-8-13 9:41:58 16 | // 17 | // $Id: Lambda.h 554 2008-05-25 07:50:50Z xushiweizh $ 18 | // -----------------------------------------------------------------------*/ 19 | #ifndef TPL_BOOST_LAMBDA_H 20 | #define TPL_BOOST_LAMBDA_H 21 | 22 | #if defined(_MSC_VER) 23 | #pragma warning(disable:4819) 24 | #endif 25 | 26 | #ifndef BOOST_LAMBDA_LAMBDA_HPP 27 | #include 28 | #endif 29 | 30 | #ifndef TPL_REGEX_ASSIGN_H 31 | #include "../regex/Assign.h" 32 | #endif 33 | 34 | NS_TPL_BEGIN 35 | 36 | // ------------------------------------------------------------------------- 37 | // class Lambda 38 | 39 | template ::value > 40 | class LambdaExec_ 41 | { 42 | }; 43 | 44 | template 45 | class LambdaExec_ 46 | { 47 | private: 48 | OperaT m_opera; 49 | 50 | public: 51 | typedef ValueT value_type; 52 | typedef Action action_type; 53 | 54 | public: 55 | LambdaExec_(const OperaT& opera) : m_opera(opera) { 56 | } 57 | 58 | void TPL_CALL operator()(const value_type& val) const { 59 | m_opera(val); 60 | } 61 | }; 62 | 63 | template 64 | class LambdaExec_ 65 | { 66 | private: 67 | OperaT m_opera; 68 | 69 | public: 70 | typedef SimpleAction action_type; 71 | 72 | public: 73 | LambdaExec_(const OperaT& opera) : m_opera(opera) { 74 | } 75 | 76 | void TPL_CALL operator()() const { 77 | m_opera(); 78 | } 79 | }; 80 | 81 | template 82 | class Lambda 83 | { 84 | public: 85 | template 86 | typename LambdaExec_::action_type TPL_CALL operator[](const OperaT& op) const { 87 | return typename LambdaExec_::action_type(op); 88 | } 89 | }; 90 | 91 | // ------------------------------------------------------------------------- 92 | // TPL_LAMBDA_LOCAL 93 | 94 | template 95 | class LambdaLocal_ 96 | { 97 | public: 98 | typedef boost::lambda::lambda_functor > const Ref; 99 | }; 100 | 101 | #define TPL_LAMBDA_LOCAL(ValueT, variable) \ 102 | ValueT _tpl_##variable = ValueT(); \ 103 | tpl::LambdaLocal_::Ref variable = boost::lambda::var(_tpl_##variable) 104 | 105 | template 106 | __forceinline Action > TPL_CALL assign( 107 | const boost::lambda::lambda_functor >& var_) 108 | { 109 | ValueT& result = var_(); 110 | return Action >(result); 111 | } 112 | 113 | template 114 | __forceinline Action > TPL_CALL assign( 115 | boost::lambda::lambda_functor >& var_) 116 | { 117 | ValueT& result = var_(); 118 | return Action >(result); 119 | } 120 | 121 | // ------------------------------------------------------------------------- 122 | // $Log: $ 123 | 124 | NS_TPL_END 125 | 126 | #endif /* TPL_REGEXP_H */ 127 | -------------------------------------------------------------------------------- /include/tpl/boost/Phoenix.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | // WINX: a C++ template GUI library - MOST SIMPLE BUT EFFECTIVE 3 | // 4 | // This file is a part of the WINX Library. 5 | // The use and distribution terms for this software are covered by the 6 | // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) 7 | // which can be found in the file CPL.txt at this distribution. By using 8 | // this software in any fashion, you are agreeing to be bound by the terms 9 | // of this license. You must not remove this notice, or any other, from 10 | // this software. 11 | // 12 | // Module: tpl/Phoenix.h 13 | // Creator: xushiwei 14 | // Email: xushiweizh@gmail.com 15 | // Date: 2006-8-13 9:41:58 16 | // 17 | // $Id: Phoenix.h 554 2008-05-25 07:50:50Z xushiweizh $ 18 | // -----------------------------------------------------------------------*/ 19 | #ifndef TPL_BOOST_PHOENIX_H 20 | #define TPL_BOOST_PHOENIX_H 21 | 22 | #ifndef BOOST_SPIRIT_PHOENIX_HPP 23 | #include 24 | #endif 25 | 26 | #ifndef TPL_REGEX_ASSIGN_H 27 | #include "../regex/Assign.h" 28 | #endif 29 | 30 | NS_TPL_BEGIN 31 | 32 | // ------------------------------------------------------------------------- 33 | // class Exec 34 | 35 | struct TplVoid { 36 | }; 37 | 38 | template 39 | class Exec 40 | { 41 | private: 42 | OperaT m_opera; 43 | 44 | public: 45 | typedef ValueT value_type; 46 | typedef Action action_type; 47 | 48 | public: 49 | Exec(const OperaT& opera) : m_opera(opera) { 50 | } 51 | 52 | void TPL_CALL operator()(const value_type& val) const { 53 | m_opera(val); 54 | } 55 | }; 56 | 57 | template 58 | class Exec 59 | { 60 | private: 61 | OperaT m_opera; 62 | 63 | public: 64 | typedef SimpleAction action_type; 65 | 66 | public: 67 | Exec(const OperaT& opera) : m_opera(opera) { 68 | } 69 | 70 | void TPL_CALL operator()() const { 71 | m_opera(); 72 | } 73 | }; 74 | 75 | // ------------------------------------------------------------------------- 76 | // class Phoenix 77 | 78 | template 79 | class Phoenix 80 | { 81 | public: 82 | template 83 | typename Exec::action_type TPL_CALL operator[](const OperaT& op) const { 84 | return typename Exec::action_type(op); 85 | } 86 | }; 87 | 88 | // ------------------------------------------------------------------------- 89 | // TPL_LAMBDA_LOCAL 90 | 91 | template 92 | class PhoenixLocal_ 93 | { 94 | public: 95 | typedef phoenix::actor > const Ref; 96 | }; 97 | 98 | #define TPL_PHOENIX_LOCAL(ValueT, variable) \ 99 | ValueT _tpl_##variable = ValueT(); \ 100 | tpl::PhoenixLocal_::Ref variable(_tpl_##variable) 101 | 102 | template 103 | __forceinline Action > TPL_CALL assign( 104 | const phoenix::actor >& var_) 105 | { 106 | ValueT& result = var_(); 107 | return Action >(result); 108 | } 109 | 110 | template 111 | __forceinline Action > TPL_CALL assign( 112 | phoenix::actor >& var_) 113 | { 114 | ValueT& result = var_(); 115 | return Action >(result); 116 | } 117 | 118 | // ------------------------------------------------------------------------- 119 | // $Log: $ 120 | 121 | NS_TPL_END 122 | 123 | #endif /* TPL_REGEXP_H */ 124 | -------------------------------------------------------------------------------- /include/tpl/c/Comment.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | // WINX: a C++ template GUI library - MOST SIMPLE BUT EFFECTIVE 3 | // 4 | // This file is a part of the WINX Library. 5 | // The use and distribution terms for this software are covered by the 6 | // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) 7 | // which can be found in the file CPL.txt at this distribution. By using 8 | // this software in any fashion, you are agreeing to be bound by the terms 9 | // of this license. You must not remove this notice, or any other, from 10 | // this software. 11 | // 12 | // Module: tpl/c/Comment.h 13 | // Creator: xushiwei 14 | // Email: xushiweizh@gmail.com 15 | // Date: 2006-8-18 18:08:57 16 | // 17 | // $Id: Comment.h,v 1.6 2007/01/10 09:38:10 xushiwei Exp $ 18 | // -----------------------------------------------------------------------*/ 19 | #ifndef TPL_C_COMMENT_H 20 | #define TPL_C_COMMENT_H 21 | 22 | #ifndef TPL_C_LEX_H 23 | #include "Lex.h" 24 | #endif 25 | 26 | NS_TPL_BEGIN 27 | 28 | // ------------------------------------------------------------------------- 29 | // class FilterCComment 30 | 31 | #define TPL_CSKIP_M1_ ( +ch('*') ) 32 | #define TPL_CSKIP_M2_ ( +ch('-') ) 33 | #define TPL_CSKIP_M3_ ( +ch('=') ) 34 | #define TPL_CSKIP_M4_ ( +ch('/') ) 35 | #define TPL_CSKIP_M5_ ( '!' ) 36 | #define TPL_CSKIP_MX_ ( TPL_CSKIP_M1_ | TPL_CSKIP_M2_ | TPL_CSKIP_M3_ | TPL_CSKIP_M4_ | TPL_CSKIP_M5_ ) 37 | #define TPL_CSKIP_SP_ ( non_eol_space() | peek<0x0a, 0x0d, -1>() ) 38 | #define TPL_CSKIP_M_ ( skipws() + TPL_CSKIP_MX_ + TPL_CSKIP_SP_ ) 39 | 40 | template 41 | class FilterCComment 42 | { 43 | private: 44 | typedef typename ArchiveT::char_type CharT; 45 | 46 | ArchiveT& m_wr; 47 | 48 | public: 49 | explicit FilterCComment(ArchiveT& wr) 50 | : m_wr(wr) { 51 | } 52 | 53 | public: 54 | typedef NS_STDEXT::BasicString value_type; 55 | 56 | void TPL_CALL operator()(const value_type& val) const 57 | { 58 | val >> *( !TPL_CSKIP_M_ + ((paragraph() + eol())/put(m_wr) | strict_eol()) ); 59 | } 60 | }; 61 | 62 | // ------------------------------------------------------------------------- 63 | // class CppCommentContent 64 | 65 | #define TPL_C_COMMENT_CONTENT ( +("/*" + find("*/")/filter + "*/") ) 66 | #define TPL_CPPONLY_COMMENT_CONTENT ( +("//" + find_eol()/filter) ) 67 | #define TPL_CPP_COMMENT_CONTENT ( TPL_CPPONLY_COMMENT_CONTENT | TPL_C_COMMENT_CONTENT ) 68 | 69 | template 70 | class CppCommentContent 71 | { 72 | private: 73 | Rule const m_rule; 74 | AllocT& m_alloc; 75 | 76 | public: 77 | CppCommentContent(AllocT& alloc, const Rule& rule) 78 | : m_rule(rule), m_alloc(alloc) 79 | { 80 | } 81 | 82 | public: 83 | enum { character = RegExT::character }; 84 | 85 | typedef SelfConvertible convertible_type; 86 | typedef TagAssigNone assig_tag; 87 | 88 | template 89 | bool TPL_CALL match(SourceT& ar, ContextT& context) const 90 | { 91 | using namespace NS_STDEXT; 92 | typedef typename SourceT::char_type char_type; 93 | typedef std::vector content_type; 94 | typedef MemWriteArchive content_writer; 95 | content_type text; 96 | content_writer wr(text); 97 | Action > filter(wr); 98 | bool fOk = TPL_CPP_COMMENT_CONTENT.match(ar, context); 99 | if (fOk) 100 | NS_TPL::match(BasicString(m_alloc, text), m_rule, context); 101 | return fOk; 102 | } 103 | 104 | TPL_SIMPLEST_GRAMMAR_(); 105 | }; 106 | 107 | template 108 | inline Rule > const 109 | TPL_CALL cpp_comment_content(AllocT& alloc, const Rule& rule) { 110 | return Rule >(alloc, rule); 111 | } 112 | 113 | // ------------------------------------------------------------------------- 114 | 115 | NS_TPL_END 116 | 117 | #endif /* TPL_C_COMMENT_H */ 118 | -------------------------------------------------------------------------------- /include/tpl/html/entity/Latin-1.h: -------------------------------------------------------------------------------- 1 | { "quot", 34 }, 2 | { "amp", 38 }, 3 | { "lt", 60 }, 4 | { "gt", 62 }, 5 | #if defined(TPL_HTML_NBSP) 6 | { "nbsp", 160 }, 7 | #else 8 | { "nbsp", ' ' }, 9 | #endif 10 | { "iexcl", 161 }, 11 | { "cent", 162 }, 12 | { "pound", 163 }, 13 | { "curren", 164 }, 14 | { "yen", 165 }, 15 | { "brvbar", 166 }, 16 | { "sect", 167 }, 17 | { "uml", 168 }, 18 | { "copy", 169 }, 19 | { "ordf", 170 }, 20 | { "laquo", 171 }, 21 | { "not", 172 }, 22 | { "shy", 173 }, 23 | { "reg", 174 }, 24 | { "macr", 175 }, 25 | { "deg", 176 }, 26 | { "plusmn", 177 }, 27 | { "sup2", 178 }, 28 | { "sup3", 179 }, 29 | { "acute", 180 }, 30 | { "micro", 181 }, 31 | { "para", 182 }, 32 | { "middot", 183 }, 33 | { "cedil", 184 }, 34 | { "sup1", 185 }, 35 | { "ordm", 186 }, 36 | { "raquo", 187 }, 37 | { "frac14", 188 }, 38 | { "frac12", 189 }, 39 | { "frac34", 190 }, 40 | { "iquest", 191 }, 41 | { "times", 215 }, 42 | { "divide", 247 }, 43 | { "Agrave", 192 }, 44 | { "Aacute", 193 }, 45 | { "Acirc", 194 }, 46 | { "Atilde", 195 }, 47 | { "Auml", 196 }, 48 | { "Aring", 197 }, 49 | { "AElig", 198 }, 50 | { "Ccedil", 199 }, 51 | { "Egrave", 200 }, 52 | { "Eacute", 201 }, 53 | { "Ecirc", 202 }, 54 | { "Euml", 203 }, 55 | { "Igrave", 204 }, 56 | { "Iacute", 205 }, 57 | { "Icirc", 206 }, 58 | { "Iuml", 207 }, 59 | { "ETH", 208 }, 60 | { "Ntilde", 209 }, 61 | { "Ograve", 210 }, 62 | { "Oacute", 211 }, 63 | { "Ocirc", 212 }, 64 | { "Otilde", 213 }, 65 | { "Ouml", 214 }, 66 | { "Oslash", 216 }, 67 | { "Ugrave", 217 }, 68 | { "Uacute", 218 }, 69 | { "Ucirc", 219 }, 70 | { "Uuml", 220 }, 71 | { "Yacute", 221 }, 72 | { "THORN", 222 }, 73 | { "szlig", 223 }, 74 | { "agrave", 224 }, 75 | { "aacute", 225 }, 76 | { "acirc", 226 }, 77 | { "atilde", 227 }, 78 | { "auml", 228 }, 79 | { "aring", 229 }, 80 | { "aelig", 230 }, 81 | { "ccedil", 231 }, 82 | { "egrave", 232 }, 83 | { "eacute", 233 }, 84 | { "ecirc", 234 }, 85 | { "euml", 235 }, 86 | { "igrave", 236 }, 87 | { "iacute", 237 }, 88 | { "icirc", 238 }, 89 | { "iuml", 239 }, 90 | { "eth", 240 }, 91 | { "ntilde", 241 }, 92 | { "ograve", 242 }, 93 | { "oacute", 243 }, 94 | { "ocirc", 244 }, 95 | { "otilde", 245 }, 96 | { "ouml", 246 }, 97 | { "oslash", 248 }, 98 | { "ugrave", 249 }, 99 | { "uacute", 250 }, 100 | { "ucirc", 251 }, 101 | { "uuml", 252 }, 102 | { "yacute", 253 }, 103 | { "thorn", 254 }, 104 | { "yuml", 255 }, 105 | -------------------------------------------------------------------------------- /include/tpl/html/entity/Symbol.h: -------------------------------------------------------------------------------- 1 | { "forall", 8704 }, 2 | { "part", 8706 }, 3 | { "exists", 8707 }, 4 | { "empty", 8709 }, 5 | { "nabla", 8711 }, 6 | { "isin", 8712 }, 7 | { "notin", 8713 }, 8 | { "ni", 8715 }, 9 | { "prod", 8719 }, 10 | { "sum", 8721 }, 11 | { "minus", 8722 }, 12 | { "lowast", 8727 }, 13 | { "radic", 8730 }, 14 | { "prop", 8733 }, 15 | { "infin", 8734 }, 16 | { "ang", 8736 }, 17 | { "and", 8743 }, 18 | { "or", 8744 }, 19 | { "cap", 8745 }, 20 | { "cup", 8746 }, 21 | { "int", 8747 }, 22 | { "there4", 8756 }, 23 | { "sim", 8764 }, 24 | { "cong", 8773 }, 25 | { "asymp", 8776 }, 26 | { "ne", 8800 }, 27 | { "equiv", 8801 }, 28 | { "le", 8804 }, 29 | { "ge", 8805 }, 30 | { "sub", 8834 }, 31 | { "sup", 8835 }, 32 | { "nsub", 8836 }, 33 | { "sube", 8838 }, 34 | { "supe", 8839 }, 35 | { "oplus", 8853 }, 36 | { "otimes", 8855 }, 37 | { "perp", 8869 }, 38 | { "sdot", 8901 }, 39 | { "Alpha", 913 }, 40 | { "Beta", 914 }, 41 | { "Gamma", 915 }, 42 | { "Delta", 916 }, 43 | { "Epsilon", 917 }, 44 | { "Zeta", 918 }, 45 | { "Eta", 919 }, 46 | { "Theta", 920 }, 47 | { "Iota", 921 }, 48 | { "Kappa", 922 }, 49 | { "Lambda", 923 }, 50 | { "Mu", 924 }, 51 | { "Nu", 925 }, 52 | { "Xi", 926 }, 53 | { "Omicron", 927 }, 54 | { "Pi", 928 }, 55 | { "Rho", 929 }, 56 | { "Sigma", 931 }, 57 | { "Tau", 932 }, 58 | { "Upsilon", 933 }, 59 | { "Phi", 934 }, 60 | { "Chi", 935 }, 61 | { "Psi", 936 }, 62 | { "Omega", 937 }, 63 | { "alpha", 945 }, 64 | { "beta", 946 }, 65 | { "gamma", 947 }, 66 | { "delta", 948 }, 67 | { "epsilon", 949 }, 68 | { "zeta", 950 }, 69 | { "eta", 951 }, 70 | { "theta", 952 }, 71 | { "iota", 953 }, 72 | { "kappa", 954 }, 73 | { "lambda", 955 }, 74 | { "mu", 956 }, 75 | { "nu", 957 }, 76 | { "xi", 958 }, 77 | { "omicron", 959 }, 78 | { "pi", 960 }, 79 | { "rho", 961 }, 80 | { "sigmaf", 962 }, 81 | { "sigma", 963 }, 82 | { "tau", 964 }, 83 | { "upsilon", 965 }, 84 | { "phi", 966 }, 85 | { "chi", 967 }, 86 | { "psi", 968 }, 87 | { "omega", 969 }, 88 | { "thetasym", 977 }, 89 | { "upsih", 978 }, 90 | { "piv", 982 }, 91 | { "OElig", 338 }, 92 | { "oelig", 339 }, 93 | { "Scaron", 352 }, 94 | { "scaron", 353 }, 95 | { "Yuml", 376 }, 96 | { "fnof", 402 }, 97 | { "circ", 710 }, 98 | { "tilde", 732 }, 99 | { "ensp", 8194 }, 100 | { "emsp", 8195 }, 101 | { "thinsp", 8201 }, 102 | { "zwnj", 8204 }, 103 | { "zwj", 8205 }, 104 | { "lrm", 8206 }, 105 | { "rlm", 8207 }, 106 | { "ndash", 8211 }, 107 | { "mdash", 8212 }, 108 | { "lsquo", 8216 }, 109 | { "rsquo", 8217 }, 110 | { "sbquo", 8218 }, 111 | { "ldquo", 8220 }, 112 | { "rdquo", 8221 }, 113 | { "bdquo", 8222 }, 114 | { "dagger", 8224 }, 115 | { "Dagger", 8225 }, 116 | { "bull", 8226 }, 117 | { "hellip", 8230 }, 118 | { "permil", 8240 }, 119 | { "prime", 8242 }, 120 | { "Prime", 8243 }, 121 | { "lsaquo", 8249 }, 122 | { "rsaquo", 8250 }, 123 | { "oline", 8254 }, 124 | { "euro", 8364 }, 125 | { "trade", 8482 }, 126 | { "larr", 8592 }, 127 | { "uarr", 8593 }, 128 | { "rarr", 8594 }, 129 | { "darr", 8595 }, 130 | { "harr", 8596 }, 131 | { "crarr", 8629 }, 132 | { "lceil", 8968 }, 133 | { "rceil", 8969 }, 134 | { "lfloor", 8970 }, 135 | { "rfloor", 8971 }, 136 | { "loz", 9674 }, 137 | { "spades", 9824 }, 138 | { "clubs", 9827 }, 139 | { "hearts", 9829 }, 140 | { "diams", 9830 }, 141 | -------------------------------------------------------------------------------- /include/tpl/regex/detail/STLHeaders.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | // WINX: a C++ template GUI library - MOST SIMPLE BUT EFFECTIVE 3 | // 4 | // This file is a part of the WINX Library. 5 | // The use and distribution terms for this software are covered by the 6 | // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) 7 | // which can be found in the file CPL.txt at this distribution. By using 8 | // this software in any fashion, you are agreeing to be bound by the terms 9 | // of this license. You must not remove this notice, or any other, from 10 | // this software. 11 | // 12 | // Module: tpl/regex/detail/STLHeaders.h 13 | // Creator: xushiwei 14 | // Email: xushiweizh@gmail.com 15 | // Date: 2006-8-13 9:41:58 16 | // 17 | // $Id: STLHeaders.h 795 2008-07-04 17:14:19Z xushiweizh@gmail.com $ 18 | // -----------------------------------------------------------------------*/ 19 | #ifndef TPL_REGEX_DETAIL_STLHEADERS_H 20 | #define TPL_REGEX_DETAIL_STLHEADERS_H 21 | 22 | // ------------------------------------------------------------------------- 23 | 24 | #if defined(_GLIBCXX_STACK) || defined(_STACK_) || defined(_STACK) 25 | #define TPL_HAS_STACK 26 | #endif 27 | 28 | // ------------------------------------------------------------------------- 29 | // std::queue 30 | 31 | #if defined(_GLIBCXX_QUEUE) || defined(_QUEUE_) || defined(_QUEUE) 32 | #define TPL_HAS_QUEUE 33 | #endif 34 | 35 | // ------------------------------------------------------------------------- 36 | // std::deque 37 | 38 | #if defined(_GLIBCXX_DEQUE) || defined(_DEQUE_) || defined(_DEQUE) 39 | #define TPL_HAS_DEQUE 40 | #endif 41 | 42 | // ------------------------------------------------------------------------- 43 | // std::vector 44 | 45 | #if defined(_GLIBCXX_VECTOR) || defined(_VECTOR_) || defined(_VECTOR) 46 | #define TPL_HAS_VECTOR 47 | #endif 48 | 49 | // ------------------------------------------------------------------------- 50 | // std::list 51 | 52 | #if defined(_GLIBCXX_LIST) || defined(_LIST_) || defined(_LIST) 53 | #define TPL_HAS_LIST 54 | #endif 55 | 56 | // ------------------------------------------------------------------------- 57 | // std::set, std::multiset 58 | 59 | #if defined(_GLIBCXX_SET) || defined(_SET_) || defined(_SET) 60 | #define TPL_HAS_SET 61 | #define TPL_HAS_MULTI_SET 62 | #endif 63 | 64 | // ------------------------------------------------------------------------- 65 | // std::map, std::multimap 66 | 67 | #if defined(_GLIBCXX_MAP) || defined(_MAP_) || defined(_MAP) 68 | #define TPL_HAS_MAP 69 | #define TPL_HAS_MULTI_MAP 70 | #endif 71 | 72 | // ------------------------------------------------------------------------- 73 | // std::basic_ostream 74 | 75 | #if defined(_GLIBCXX_OSTREAM) || defined(_OSTREAM_) || defined(_OSTREAM) 76 | #define TPL_HAS_OSTREAM 77 | #endif 78 | 79 | // ------------------------------------------------------------------------- 80 | // $Log: $ 81 | 82 | #endif /* TPL_REGEX_DETAIL_STLHEADERS_H */ 83 | 84 | -------------------------------------------------------------------------------- /include/tpl/regex/detail/TypeTraits.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | // WINX: a C++ template GUI library - MOST SIMPLE BUT EFFECTIVE 3 | // 4 | // This file is a part of the WINX Library. 5 | // The use and distribution terms for this software are covered by the 6 | // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) 7 | // which can be found in the file CPL.txt at this distribution. By using 8 | // this software in any fashion, you are agreeing to be bound by the terms 9 | // of this license. You must not remove this notice, or any other, from 10 | // this software. 11 | // 12 | // Module: tpl/regex/detail/TypeTraits.h 13 | // Creator: xushiwei 14 | // Email: xushiweizh@gmail.com 15 | // Date: 2006-8-13 9:41:58 16 | // 17 | // $Id: TypeTraits.h 619 2008-06-01 16:00:35Z xushiweizh $ 18 | // -----------------------------------------------------------------------*/ 19 | #ifndef TPL_REGEX_DETAIL_TYPETRAITS_H 20 | #define TPL_REGEX_DETAIL_TYPETRAITS_H 21 | 22 | #ifndef TPL_BASIC_H 23 | #include "../Basic.h" 24 | #endif 25 | 26 | NS_TPL_BEGIN 27 | 28 | // ------------------------------------------------------------------------- 29 | // class ArrayTypeTraits 30 | 31 | template 32 | struct ArrayTypeTraits 33 | { 34 | typedef ValueT type; 35 | typedef ValueT const_type; 36 | typedef ValueT& reference; 37 | typedef const ValueT& const_reference; 38 | }; 39 | 40 | template 41 | struct ArrayTypeTraits 42 | { 43 | typedef ValueT* type; 44 | typedef const ValueT* const_type; 45 | typedef ValueT* reference; 46 | typedef const ValueT* const_reference; 47 | }; 48 | 49 | template 50 | struct ArrayTypeTraits // it seems that this is impossible (tested in g++) 51 | { 52 | typedef const ValueT* type; 53 | typedef const ValueT* const_type; 54 | typedef const ValueT* reference; 55 | typedef const ValueT* const_reference; 56 | }; 57 | 58 | // ------------------------------------------------------------------------- 59 | // class LValueTraits 60 | 61 | template 62 | class Var; 63 | 64 | template 65 | struct LValueTraits { 66 | typedef ValueT type; 67 | typedef ValueT& reference; 68 | }; 69 | 70 | template 71 | struct LValueTraits > { 72 | typedef ValueT type; 73 | typedef ValueT& reference; 74 | }; 75 | 76 | // ------------------------------------------------------------------------- 77 | // class SmartRefTraits 78 | 79 | template 80 | struct SmartRefTraits 81 | { 82 | }; 83 | 84 | template 85 | struct SmartRefTraits&> 86 | { 87 | typedef const ValueT& type; 88 | typedef const ValueT& const_type; 89 | }; 90 | 91 | template 92 | struct SmartRefTraits&> 93 | { 94 | typedef ValueT& type; 95 | typedef const ValueT& const_type; 96 | }; 97 | 98 | template 99 | struct SmartRefTraits 100 | { 101 | typedef ArrayTypeTraits Tr_; 102 | typedef typename Tr_::type type; 103 | typedef typename Tr_::const_type const_type; 104 | }; 105 | 106 | template 107 | struct SmartRefTraits 108 | { 109 | typedef ArrayTypeTraits Tr_; 110 | typedef typename Tr_::reference type; 111 | typedef typename Tr_::const_reference const_type; 112 | }; 113 | 114 | // ------------------------------------------------------------------------- 115 | // $Log: $ 116 | 117 | NS_TPL_END 118 | 119 | #endif /* TPL_REGEX_DETAIL_TYPETRAITS_H */ 120 | 121 | -------------------------------------------------------------------------------- /include/tpl/regex/grammar/Action.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | // WINX: a C++ template GUI library - MOST SIMPLE BUT EFFECTIVE 3 | // 4 | // This file is a part of the WINX Library. 5 | // The use and distribution terms for this software are covered by the 6 | // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) 7 | // which can be found in the file CPL.txt at this distribution. By using 8 | // this software in any fashion, you are agreeing to be bound by the terms 9 | // of this license. You must not remove this notice, or any other, from 10 | // this software. 11 | // 12 | // Module: tpl/regex/grammar/Action.h 13 | // Creator: xushiwei 14 | // Email: xushiweizh@gmail.com 15 | // Date: 2006-8-13 9:41:58 16 | // 17 | // $Id: Action.h 811 2008-07-08 04:51:39Z xushiweizh@gmail.com $ 18 | // -----------------------------------------------------------------------*/ 19 | #ifndef TPL_REGEX_GRAMMAR_ACTION_H 20 | #define TPL_REGEX_GRAMMAR_ACTION_H 21 | 22 | #ifndef TPL_REGEX_BASIC_H 23 | #include "../Basic.h" 24 | #endif 25 | 26 | #ifndef TPL_REGEX_ACTION_H 27 | #include "../Action.h" 28 | #endif 29 | 30 | #ifndef TPL_REGEX_CASE_H 31 | #include "../Case.h" 32 | #endif 33 | 34 | NS_TPL_BEGIN 35 | 36 | // ========================================================================= 37 | // class GAct0 38 | 39 | template 40 | class GAct0 41 | { 42 | public: 43 | const GrammarT m_x; 44 | const ActionT m_action; 45 | 46 | public: 47 | GAct0() : m_x(), m_action() {} 48 | GAct0(const GrammarT& x, const ActionT& act) 49 | : m_x(x), m_action(act) {} 50 | 51 | public: 52 | enum { character = GrammarT::character }; 53 | 54 | template 55 | bool TPL_CALL match(SourceT& ar, ContextT& context, const SkipperT& skipper_) const 56 | { 57 | if (m_x.match(ar, context, skipper_)) { 58 | m_action(); 59 | return true; 60 | } 61 | return false; 62 | } 63 | }; 64 | 65 | // ------------------------------------------------------------------------- 66 | // operator/ 67 | 68 | // Usage: Rule/SimpleAction, Grammar/SimpleAction 69 | // Usage: Case/Action ==> Case[eps()/Action] 70 | 71 | template 72 | struct SimpleActionTraits_ { 73 | typedef typename RuleOrGrCompose2::type type; 74 | }; 75 | 76 | template 77 | struct SimpleActionTraits_, T2> { 78 | typedef Condition > type; 79 | }; 80 | 81 | template 82 | struct SimpleActionTraits_, T2> { 83 | typedef Condition > type; 84 | }; 85 | 86 | template 87 | inline typename SimpleActionTraits_::type const 88 | TPL_CALL operator/(const T1& x, const SimpleAction& y) { 89 | return typename SimpleActionTraits_::type(x, y); 90 | } 91 | 92 | // ========================================================================= 93 | // class GAct 94 | 95 | template 96 | class GAct 97 | { 98 | public: 99 | const GrammarT m_x; 100 | const ActionT m_action; 101 | 102 | public: 103 | GAct() : m_x(), m_action() {} 104 | GAct(const GrammarT& x, const ActionT& act) 105 | : m_x(x), m_action(act) {} 106 | 107 | public: 108 | enum { character = GrammarT::character }; 109 | 110 | typedef typename GrammarT::assig_tag assig_tag; 111 | 112 | template 113 | bool TPL_CALL match(SourceT& ar, ContextT& context, const SkipperT& skipper_) const 114 | { 115 | TPL_ASSIG_PREPARE(assig_tag, typename ActionT::value_type) 116 | 117 | const iterator pos = ar.position(); 118 | if (m_x.match(ar, context, skipper_)) { 119 | const iterator pos2 = ar.position(); 120 | const value_type val(TPL_ASSIG_GET(pos, pos2, &m_x)); 121 | m_action(val); 122 | return true; 123 | } 124 | return false; 125 | } 126 | }; 127 | 128 | // ------------------------------------------------------------------------- 129 | // operator/ 130 | 131 | // Usage: Rule/Action, Grammar/Action 132 | 133 | template 134 | inline typename RuleOrGrCompose2::type const 135 | TPL_CALL operator/(const T1& x, const Action& y) { 136 | return typename RuleOrGrCompose2::type(x, y); 137 | } 138 | 139 | // ========================================================================= 140 | // $Log: $ 141 | 142 | NS_TPL_END 143 | 144 | #endif /* TPL_REGEX_GRAMMAR_ACTION_H */ 145 | 146 | -------------------------------------------------------------------------------- /include/tpl/regex/grammar/Condition.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | // WINX: a C++ template GUI library - MOST SIMPLE BUT EFFECTIVE 3 | // 4 | // This file is a part of the WINX Library. 5 | // The use and distribution terms for this software are covered by the 6 | // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) 7 | // which can be found in the file CPL.txt at this distribution. By using 8 | // this software in any fashion, you are agreeing to be bound by the terms 9 | // of this license. You must not remove this notice, or any other, from 10 | // this software. 11 | // 12 | // Module: tpl/regex/grammar/Condition.h 13 | // Creator: xushiwei 14 | // Email: xushiweizh@gmail.com 15 | // Date: 2006-8-13 9:41:58 16 | // 17 | // $Id: Condition.h 731 2008-06-25 21:47:21Z xushiweizh@gmail.com $ 18 | // -----------------------------------------------------------------------*/ 19 | #ifndef TPL_REGEX_GRAMMAR_CONDITION_H 20 | #define TPL_REGEX_GRAMMAR_CONDITION_H 21 | 22 | #ifndef TPL_REGEX_ACTION_H 23 | #include "../Action.h" 24 | #endif 25 | 26 | NS_TPL_BEGIN 27 | 28 | // ========================================================================= 29 | // class GCond 30 | 31 | template 32 | class GCond 33 | { 34 | public: 35 | const RegExT m_x; 36 | const ConditionT m_y; 37 | 38 | public: 39 | GCond() : m_x(), m_y() {} 40 | GCond(const RegExT& x, const ConditionT& y) : m_x(x), m_y(y) {} 41 | 42 | public: 43 | enum { character = RegExT::character | ConditionT::character }; 44 | 45 | typedef TagAssigNone assig_tag; 46 | 47 | template 48 | bool TPL_CALL match(SourceT& ar, ContextT& context, const SkipperT& skipper_) const 49 | { 50 | TPL_ASSIG_PREPARE1(typename RegExT::assig_tag) 51 | 52 | skipper_.match(ar, context); 53 | typename ContextT::template trans_type trans(ar, context); 54 | const iterator pos = ar.position(); 55 | if (m_x.match(ar, context)) { 56 | const iterator pos2 = ar.position(); 57 | const value_type val(TPL_ASSIG_GET(pos, pos2, &m_x)); 58 | if (m_y.match_if(val, ar, context, skipper_) == matchOk) 59 | return true; 60 | } 61 | trans.rollback(ar); 62 | return false; 63 | } 64 | }; 65 | 66 | template 67 | struct IndexOpTraits, GCondition > 68 | { 69 | typedef Grammar > const result_type; 70 | 71 | static result_type TPL_CALL call(const Rule& rule_, const GCondition& cond_) { 72 | return result_type(rule_, cond_); 73 | } 74 | }; 75 | 76 | // ========================================================================= 77 | // class GCondBind 78 | 79 | template 80 | class GCondBind 81 | { 82 | public: 83 | const PredT m_pred; 84 | const NextT m_next; 85 | 86 | public: 87 | GCondBind() : m_pred(), m_next() {} 88 | GCondBind(const PredT& pred_, const NextT& next_) 89 | : m_pred(pred_), m_next(next_) {} 90 | 91 | public: 92 | enum { character = NextT::character }; 93 | 94 | template 95 | MatchCode TPL_CALL match_if( 96 | const ValueT& val, SourceT& ar, ContextT& context, const SkipperT& skipper_) const 97 | { 98 | if (m_pred(val)) 99 | return m_next.match(ar, context, skipper_) ? matchOk : matchStop; 100 | else 101 | return matchFailed; 102 | } 103 | }; 104 | 105 | // ========================================================================= 106 | // operator, 107 | 108 | template 109 | class GCondOr 110 | { 111 | private: 112 | const CondT1 m_x; 113 | const CondT2 m_y; 114 | 115 | public: 116 | GCondOr(const CondT1& x, const CondT2& y) 117 | : m_x(x), m_y(y) {} 118 | 119 | public: 120 | enum { character = CondT1::character | CondT2::character }; 121 | 122 | template 123 | MatchCode TPL_CALL match_if( 124 | const ValueT& val, SourceT& ar, ContextT& context, const SkipperT& skipper_) const 125 | { 126 | MatchCode result = m_x.match_if(val, ar, context, skipper_); 127 | if (result != matchFailed) 128 | return result; 129 | else 130 | return m_y.match_if(val, ar, context, skipper_); 131 | } 132 | }; 133 | 134 | template 135 | __forceinline 136 | GCondition > const 137 | TPL_CALL operator,(const GCondition& x, const GCondition& y) { 138 | return GCondition >(x, y); 139 | } 140 | 141 | // ========================================================================= 142 | // $Log: $ 143 | 144 | NS_TPL_END 145 | 146 | #endif /* TPL_REGEX_GRAMMAR_CONDITION_H */ 147 | -------------------------------------------------------------------------------- /include/tpl/regex/result/Context.h: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | // WINX: a C++ template GUI library - MOST SIMPLE BUT EFFECTIVE 3 | // 4 | // This file is a part of the WINX Library. 5 | // The use and distribution terms for this software are covered by the 6 | // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) 7 | // which can be found in the file CPL.txt at this distribution. By using 8 | // this software in any fashion, you are agreeing to be bound by the terms 9 | // of this license. You must not remove this notice, or any other, from 10 | // this software. 11 | // 12 | // Module: tpl/regex/result/Context.h 13 | // Creator: xushiwei 14 | // Email: xushiweizh@gmail.com 15 | // Date: 2006-8-13 9:41:58 16 | // 17 | // $Id: Context.h 794 2008-07-04 06:27:26Z xushiweizh@gmail.com $ 18 | // -----------------------------------------------------------------------*/ 19 | #ifndef TPL_REGEX_RESULT_CONTEXT_H 20 | #define TPL_REGEX_RESULT_CONTEXT_H 21 | 22 | #ifndef TPL_REGEX_MATCH_H 23 | #include "../Match.h" 24 | #endif 25 | 26 | #ifndef TPL_REGEX_RESULT_MARK_H 27 | #include "Mark.h" 28 | #endif 29 | 30 | #ifndef TPL_REGEX_RESULT_DOCUMENT_H 31 | #include "Document.h" 32 | #endif 33 | 34 | NS_TPL_BEGIN 35 | 36 | // ------------------------------------------------------------------------- 37 | // class ContextTransaction 38 | 39 | template 40 | class ContextTransaction { 41 | }; 42 | 43 | template 44 | class ContextTransaction<0, Iterator, Scope> 45 | { 46 | private: 47 | Iterator vPos; 48 | 49 | public: 50 | template 51 | ContextTransaction(const SourceT& ar, const ContextT&) { 52 | vPos = ar.position(); 53 | } 54 | 55 | template 56 | void TPL_CALL rollback(SourceT& ar) { 57 | ar.seek(vPos); 58 | } 59 | }; 60 | 61 | template 62 | class ContextTransaction 63 | { 64 | private: 65 | Scope vScope; 66 | Iterator vPos; 67 | 68 | public: 69 | template 70 | ContextTransaction(const SourceT& ar, const ContextT& context) : vScope(context) { 71 | vPos = ar.position(); 72 | } 73 | 74 | template 75 | void TPL_CALL rollback(SourceT& ar) { 76 | ar.seek(vPos); 77 | vScope.rollback(); 78 | } 79 | }; 80 | 81 | // ------------------------------------------------------------------------- 82 | // class Context 83 | 84 | template 85 | class Context 86 | { 87 | private: 88 | typedef Node NodeT; 89 | typedef NS_STDEXT::ConsList StackT; 90 | 91 | AllocT& m_alloc; 92 | StackT m_stk; 93 | 94 | public: 95 | Context(AllocT& alloc, NodeT& doc) 96 | : m_alloc(alloc) 97 | { 98 | m_stk.push_front(alloc, &doc); 99 | } 100 | 101 | private: 102 | typedef Mark LeafMarkT; 103 | typedef Mark NodeMarkT; 104 | 105 | public: 106 | typedef AllocT alloc_type; 107 | 108 | alloc_type& TPL_CALL get_alloc() const { 109 | return m_alloc; 110 | } 111 | 112 | void TPL_CALL insertLeaf(const LeafMarkT& mark, const LeafT& val) { 113 | m_stk.front()->insertLeaf(m_alloc, mark, val); 114 | } 115 | 116 | public: 117 | class ScopeTransaction 118 | { 119 | private: 120 | NodeT* vParent; 121 | NodeT vOld; 122 | 123 | public: 124 | ScopeTransaction(const Context& context) { 125 | StackT stk = context.m_stk; 126 | vParent = stk.front(); 127 | vOld = *vParent; 128 | } 129 | 130 | void TPL_CALL rollback() { 131 | *vParent = vOld; 132 | } 133 | }; 134 | 135 | typedef ScopeTransaction scope_trans_type; 136 | 137 | public: 138 | template 139 | class trans_type : public ContextTransaction 140 | { 141 | private: 142 | typedef ContextTransaction Base; 143 | 144 | public: 145 | template 146 | trans_type(const SourceT& ar, const Context& context) 147 | : Base(ar, context) { 148 | } 149 | }; 150 | 151 | public: 152 | class Scope 153 | { 154 | private: 155 | StackT& m_stk; 156 | 157 | public: 158 | Scope(Context& context, const NodeMarkT& mark) 159 | : m_stk(context.m_stk) 160 | { 161 | NodeT* v = m_stk.front()->insertNode(context.m_alloc, mark); 162 | m_stk.push_front(context.m_alloc, v); 163 | } 164 | ~Scope() { 165 | m_stk.pop_front(); 166 | } 167 | }; 168 | friend class Scope; 169 | 170 | typedef Scope scope_type; 171 | }; 172 | 173 | // ------------------------------------------------------------------------- 174 | // $Log: $ 175 | 176 | NS_TPL_END 177 | 178 | #endif /* TPL_REGEX_RESULT_CONTEXT_H */ 179 | -------------------------------------------------------------------------------- /test/testtpl/Demo.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | // ------------------------------------------------------------------------- 4 | // demo 5 | 6 | // What we use: 7 | // * Rules: Rule, +, /, %, c_symbol(), real(), skipws() 8 | // * Tags: LeafMark, NodeMark, double* 9 | // * Matching: Rule::match() 10 | // * Result Processing: Document::all(), select(), [] 11 | 12 | void demo() 13 | { 14 | using namespace tpl; 15 | 16 | impl::Allocator alloc; 17 | 18 | // ---- define source ---- 19 | 20 | impl::Source source("x1=-.1, x2=+32., x3=-22323.2e+12"); 21 | 22 | // ---- define rules ---- 23 | 24 | double dblValue; 25 | impl::LeafMark tagSym; 26 | impl::LeafMark tagValue; 27 | impl::LeafMark tagPairValue; 28 | impl::NodeMark tagPair; 29 | 30 | impl::MarkedRule rPair( alloc, (c_symbol()/tagSym + '=' + real()/tagValue/assign(dblValue))/tagPair/tagPairValue ); 31 | impl::MarkedRule rDoc( alloc, (skipws() + rPair) % ',' ); 32 | 33 | // ---- do match ---- 34 | 35 | impl::Document doc; 36 | impl::Context context(alloc, doc); 37 | 38 | if (!rDoc.match(source, context)) { 39 | std::cout << "match failed\n"; 40 | return; 41 | } 42 | 43 | // ---- print dblValue ---- 44 | 45 | std::cout << "\nDoubleValue: " << dblValue << "\n"; // guess what it is! 46 | 47 | // ---- print all data ---- 48 | 49 | for (impl::Document::cons it = doc.all(); it; it = it.tl()) 50 | { 51 | impl::Document::value_type item = it.hd(); 52 | if (item.key() == tagPair) { 53 | impl::Document::node_data vPair = item.node(); 54 | impl::Document::leaf_data vSym = vPair[tagSym]; 55 | impl::Document::leaf_data vValue = vPair[tagValue]; 56 | std::cout << vSym.stl_str() << ": " << vValue.stl_str() << "\n"; 57 | } 58 | else { 59 | impl::Document::leaf_data vPair = item.leaf(); 60 | std::cout << "Pair: " << vPair.stl_str() << "\n"; 61 | } 62 | } 63 | 64 | // ---- select what we are interested in and print ---- 65 | 66 | std::cout << "\n"; 67 | impl::Document::leaf_cons it2 = doc.select(alloc, tagPairValue); 68 | for (; it2; it2 = it2.tl()) { 69 | impl::Document::leaf_data vPair = *it2; 70 | std::cout << "Pair: " << vPair.stl_str() << "\n"; 71 | } 72 | } 73 | 74 | // ------------------------------------------------------------------------- 75 | -------------------------------------------------------------------------------- /test/testtpl/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Configuration Default 3 | # 4 | ifeq ($(CFG),) 5 | CFG = Debug 6 | endif 7 | 8 | IncludeDir = -I. -I../../../tpl/include -I../../../stdext/include -I../../../boost 9 | 10 | # 11 | # Configuration Release 12 | # 13 | ifeq ($(CFG), Release) 14 | ProductDir = LRelease 15 | ObjectDir = LRelease 16 | MocFile = $(ObjectDir)/temp.moc.cpp 17 | Product = LRelease/testtpl 18 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -DNDEBUG -O2 -D_MT -fexceptions 19 | CXXFlags = $(CFlags) -fno-rtti 20 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 21 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 22 | CompileCXX = @$(CXX) $< 23 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 24 | Link = @g++ $(LibDir) -ldl -o $(Product) 25 | LD_LIBRARY_PATH += :$(ProductDir) 26 | endif 27 | 28 | # 29 | # Configuration Debug 30 | # 31 | ifeq ($(CFG), Debug) 32 | ProductDir = LDebug 33 | ObjectDir = LDebug 34 | MocFile = $(ObjectDir)/temp.moc.cpp 35 | Product = LDebug/testtpl 36 | CFlags = $(Defines) -fPIC -D__INTEL__ -D__LINUX__ -DLINUX -D_DEBUG -g3 -D_MT -fexceptions 37 | CXXFlags = $(CFlags) -fno-rtti 38 | CXX = g++ -c $(IncludeDir) $(CXXFlags) -o $@ 39 | CompileC = @gcc -c $(IncludeDir) $(CFlags) -o $@ $< 40 | CompileCXX = @$(CXX) $< 41 | CompileMoc = @moc $< -o $(MocFile) && $(CXX) $(MocFile) && rm -f $(MocFile) 42 | Link = @g++ $(LibDir) -ldl -o $(Product) 43 | LD_LIBRARY_PATH += :$(ProductDir) 44 | endif 45 | 46 | # 47 | # Making... 48 | # 49 | all : $(ProductDir) $(ObjectDir) StartMake $(Product) EndMake 50 | 51 | $(ProductDir) : 52 | @mkdir -p $(ProductDir) 53 | 54 | ifneq ($(ProductDir),$(ObjectDir)) 55 | $(ObjectDir) : 56 | @mkdir -p $(ObjectDir) 57 | endif 58 | 59 | clean : 60 | @rm -f $(ObjectDir)/*.o 61 | @rm -f $(Product) 62 | 63 | StartMake : 64 | @echo "-------------- Configuration:" $(PROJ) $(CFG) "--------------" 65 | ifeq ($(ForceLink),1) 66 | @rm -f $(Product) 67 | endif 68 | 69 | EndMake : 70 | @echo ">>> Success <<<" 71 | 72 | # 73 | # Source Files, Objects & Product 74 | # 75 | $(ObjectDir)/Simplest.o : \ 76 | Simplest.cpp 77 | @echo "---> Compiling" $< "..." 78 | $(CompileCXX) 79 | 80 | $(ObjectDir)/ParseClass.o : \ 81 | ParseClass.cpp 82 | @echo "---> Compiling" $< "..." 83 | $(CompileCXX) 84 | 85 | $(ObjectDir)/Calculator.o : \ 86 | Calculator.cpp 87 | @echo "---> Compiling" $< "..." 88 | $(CompileCXX) 89 | 90 | $(ObjectDir)/Calculator2.o : \ 91 | Calculator2.cpp 92 | @echo "---> Compiling" $< "..." 93 | $(CompileCXX) 94 | 95 | $(ObjectDir)/TestTpl.o : \ 96 | TestTpl.cpp 97 | @echo "---> Compiling" $< "..." 98 | $(CompileCXX) 99 | 100 | 101 | Objects = \ 102 | $(ObjectDir)/Simplest.o \ 103 | $(ObjectDir)/ParseClass.o \ 104 | $(ObjectDir)/Calculator.o \ 105 | $(ObjectDir)/Calculator2.o \ 106 | $(ObjectDir)/TestTpl.o 107 | 108 | $(Product) : $(Objects) $(Libs) 109 | @echo "---> Creating" $@ "..." 110 | @rm -f $@ 111 | $(Link) $(Objects) $(Libraries) 112 | $(CheckLink) 113 | 114 | -------------------------------------------------------------------------------- /test/testtpl/SimpleBinary.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include 3 | 4 | using namespace tpl; 5 | 6 | // ------------------------------------------------------------------------- 7 | // simple_binary 8 | 9 | struct SimpleBinary 10 | { 11 | UINT32 tag; 12 | UINT16 cw; 13 | UINT16 cl; 14 | UINT16 w[24]; 15 | UINT32 l[8]; 16 | }; 17 | 18 | void simple_binary() 19 | { 20 | typedef SimpleBinaryImplementation impl; 21 | 22 | SimpleBinary b = { 23 | 123456, 24 | 24, 25 | 8, 26 | { 1, 2, 3, 4, 5, 6, 7, 8 }, 27 | { 9, 10, 11, 12 } 28 | }; 29 | 30 | UINT32 tag; 31 | Var cw; 32 | Var cl; 33 | 34 | impl::Array w; 35 | impl::Array l; 36 | 37 | impl::Allocator alloc; 38 | impl::Rule rDoc( alloc, 39 | c_type(tag) + 40 | c_type(cw) + 41 | c_type(cl) + 42 | c_array(w, cw) + 43 | c_array(l, cl) 44 | ); 45 | 46 | if (impl::match(&b, sizeof(b), rDoc)) { 47 | std::cout << tag << '\n' 48 | << cw.val << '\n' << cl.val << '\n' 49 | << w << '\n' << l << '\n'; 50 | } 51 | } 52 | 53 | // ------------------------------------------------------------------------- 54 | -------------------------------------------------------------------------------- /test/testtpl/StdAfx.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | -------------------------------------------------------------------------------- /test/testtpl/TestTpl.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "stdafx.h" 3 | //#include 4 | 5 | void demo(); 6 | void customize(); 7 | void xml_process(); 8 | void parse_class(); 9 | void html_process(); 10 | void circuit(); 11 | void calculate(); 12 | void word_text(); 13 | 14 | int main() 15 | { 16 | // circuit(); 17 | // customize(); 18 | parse_class(); 19 | // html_process(); 20 | // xml_process(); 21 | // demo(); 22 | // calculate(); 23 | // word_text(); 24 | return 0; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /test/testtpl/Transformation.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | // ------------------------------------------------------------------------- 4 | // html_process 5 | 6 | // What we use: 7 | 8 | void html_process() 9 | { 10 | using namespace tpl; 11 | 12 | typedef SimpleImplementation impl; 13 | 14 | impl::Allocator alloc; 15 | 16 | // ---- define rules ---- 17 | 18 | char delim; 19 | std::string strSourceTag; 20 | std::string strTransformedTag; 21 | std::string strProp; 22 | std::string strValue; 23 | std::string strText; 24 | 25 | impl::Rule rTagName( alloc, (ucase() >> c_symbol()/assign(strTransformedTag))/assign(strSourceTag) ); 26 | impl::Rule rPropVal( alloc, ch('\"', '\'')/assign(delim) + find_ref(delim)/assign(strValue) + ref(delim) ); 27 | impl::Rule rProp( alloc, (ucase() >> c_symbol()/assign(strProp)) + skipws() + '=' + skipws() + rPropVal ); 28 | impl::Rule rTagStart( alloc, '<' + rTagName + !(ws() + rProp % ws()) + skipws() + '>' ); 29 | impl::Rule rText( alloc, find('<')/assign(strText) ); 30 | impl::Rule rTagEnd( alloc, "> c_symbol()/ref(strTransformedTag)) + '>' ); 31 | impl::Rule rHtmlStart(alloc, ucase() >> '<' + c_symbol()/"HTML" + '>' ); 32 | impl::Rule rHtmlEnd(alloc, ucase() >> "' ); 33 | impl::Rule rDoc( alloc, rHtmlStart + rTagStart + rText + rTagEnd + rHtmlEnd ); 34 | 35 | // ---- do match ---- 36 | 37 | if (!impl::match("XUSHIWEI.COM", rDoc)) { 38 | std::cout << "match failed\n"; 39 | return; 40 | } 41 | 42 | // ---- print info ---- 43 | 44 | std::cout << "SourceTag: " << strSourceTag << "\n"; 45 | std::cout << "TransformedTag: " << strTransformedTag << "\n"; 46 | std::cout << "Prop: " << strProp << "\n"; 47 | std::cout << "Value: " << strValue << "\n"; 48 | std::cout << "Text: " << strText << "\n"; 49 | } 50 | -------------------------------------------------------------------------------- /test/testtpl/WordText.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include 3 | 4 | using namespace tpl; 5 | 6 | // ------------------------------------------------------------------------- 7 | // word_text 8 | 9 | struct FIB_HEADER; 10 | 11 | class SelectTableStream 12 | { 13 | private: 14 | const FIB_HEADER& m_fib; 15 | 16 | public: 17 | SelectTableStream(const FIB_HEADER& fib) 18 | : m_fib(fib) {} 19 | 20 | typedef ComPtr result_type; 21 | 22 | template 23 | bool TPL_CALL match(IStorage* stg, ContextT& context, result_type& strm) const { 24 | WCHAR Table[] = { '0', 'T', 'a', 'b', 'l', 'e', '\0' }; 25 | Table[0] += m_fib.fWhichTblStm; 26 | return S_OK == stg->OpenStream(Table, NULL, TPL_STGM_READONLY, 0, &strm); 27 | } 28 | }; 29 | 30 | __forceinline 31 | StgRule TPL_CALL selectTableStream(const FIB_HEADER& fib) { 32 | return StgRule(fib); 33 | } 34 | 35 | void word_text() 36 | { 37 | /* typedef StorageImplementation impl; 38 | 39 | FIB_HEADER fib; 40 | 41 | UINT16 cWordArray; 42 | UINT16 cLongArray; 43 | UINT16 cRestPart; 44 | 45 | c_type()/assign(cWordArray); 46 | c_type(cWordArray); 47 | 48 | stream(L"WordDocument")[ c_struct()/assign(fib) ]; 49 | selectTableStream(fib); 50 | 51 | impl::match_file(L"test.doc", ); 52 | */ 53 | } 54 | 55 | // ------------------------------------------------------------------------- 56 | -------------------------------------------------------------------------------- /test/testtpl/XmlProcess.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | // ------------------------------------------------------------------------- 4 | // xml_process 5 | 6 | // What we use: 7 | // * Rules: Rule, +, /, %, xml_symbol(), c_symbol(), integer(), ws(), skipws() 8 | // * Tags: LeafMark, NodeMark 9 | // * Matching: Rule::match() 10 | // * Result Processing: Document::all(), [] 11 | 12 | void xml_process() 13 | { 14 | using namespace tpl; 15 | 16 | impl::Allocator alloc; 17 | 18 | // ---- define source ---- 19 | 20 | impl::Source source("text"); 21 | 22 | // ---- define rules ---- 23 | 24 | impl::LeafMark tagProp; 25 | impl::LeafMark tagValue; 26 | impl::LeafMark tagText; 27 | impl::NodeMark tagProps; 28 | 29 | impl::MarkedRule rProp( alloc, xml_symbol()/tagProp + skipws() + '=' + skipws() + integer()/tagValue ); 30 | impl::MarkedRule rProps( alloc, rProp % ws() / tagProps ); 31 | impl::MarkedRule rTagStart( alloc, '<' + xml_symbol()/"tag" + ws() + rProps + '>' ); 32 | impl::MarkedRule rDoc( alloc, rTagStart + c_symbol()/tagText + "" ); 33 | 34 | // ---- do match ---- 35 | 36 | impl::Document doc; 37 | impl::Context context(alloc, doc); 38 | 39 | if (!rDoc.match(source, context)) { 40 | std::cout << "match failed\n"; 41 | return; 42 | } 43 | 44 | // ---- print text ---- 45 | 46 | std::cout << "\nText: " << doc[tagText].stl_str() << "\n"; 47 | 48 | // ---- print properties ---- 49 | 50 | impl::Document::node_data vProps = doc[tagProps]; 51 | for (impl::Document::cons it = vProps.all(); it; it = it.tl()) 52 | { 53 | impl::Document::value_type item = it.hd(); 54 | std::cout << (item.key() == tagProp ? "Prop: " : "Value: "); 55 | 56 | impl::Document::leaf_data vData = item.leaf(); 57 | std::cout << vData.stl_str() << "\n"; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /test/testtpl/stdafx.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #define TPL_USE_AUTO_ALLOC 8 | #include 9 | 10 | -------------------------------------------------------------------------------- /test/testtpl/testtpl.prj.li: -------------------------------------------------------------------------------- 1 | [Include] 2 | . 3 | ../../../tpl/include 4 | ../../../stdext/include 5 | ../../../boost 6 | 7 | [Config Release] 8 | Product Exe LRelease/testtpl 9 | Options Release; MultiThread; AnsiChar; NoRtti; Exception 10 | ObjDir LRelease 11 | LibDir 12 | Libraries 13 | 14 | [Config Debug] 15 | Product Exe LDebug/testtpl 16 | Options Debug; MultiThread; AnsiChar; NoRtti; Exception 17 | ObjDir LDebug 18 | LibDir 19 | Libraries 20 | 21 | [Source] 22 | // Transformation.cpp 23 | // ParseClass.cpp 24 | // Calculator.cpp 25 | // TestTpl.cpp 26 | // Customization.cpp 27 | // Circuit.cpp 28 | // Demo.cpp 29 | // XmlProcess.cpp 30 | 31 | --------------------------------------------------------------------------------