clasp-2.1.4/0000755000404600007640000000000012245072215012326 5ustar kaufmanncoolsclasp-2.1.4/COPYING0000644000404600007640000004310311074666157013377 0ustar kaufmanncools GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. clasp-2.1.4/CMakeLists.txt0000644000404600007640000000025512016165013015063 0ustar kaufmanncoolscmake_minimum_required(VERSION 2.6) project(clasp) add_definitions( -DWITH_THREADS=0 ) add_subdirectory(libclasp) add_subdirectory(libprogram_opts) add_subdirectory(app) clasp-2.1.4/build_vc/0000755000404600007640000000000012245072211014111 5ustar kaufmanncoolsclasp-2.1.4/build_vc/vc9/0000755000404600007640000000000012245072211014612 5ustar kaufmanncoolsclasp-2.1.4/build_vc/vc9/clasp/0000755000404600007640000000000012245072211015714 5ustar kaufmanncoolsclasp-2.1.4/build_vc/vc9/clasp/clasp.sln0000644000404600007640000001030412015427045017536 0ustar kaufmanncools Microsoft Visual Studio Solution File, Format Version 10.00 # Visual Studio 2008 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libclasp", "lib\lib.vcproj", "{A95999D0-C3A7-423F-84D1-D620674A136E}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "app", "app\app.vcproj", "{EF6CFDA6-F838-40E9-8688-BEE97EE14265}" ProjectSection(ProjectDependencies) = postProject {A95999D0-C3A7-423F-84D1-D620674A136E} = {A95999D0-C3A7-423F-84D1-D620674A136E} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test", "test\test.vcproj", "{73ACA93A-C49E-4537-BC3A-DCF91E85ED2A}" ProjectSection(ProjectDependencies) = postProject {A95999D0-C3A7-423F-84D1-D620674A136E} = {A95999D0-C3A7-423F-84D1-D620674A136E} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "examples", "examples\examples.vcproj", "{3D533F47-3043-4EAC-9669-06F01CDB75E2}" ProjectSection(ProjectDependencies) = postProject {A95999D0-C3A7-423F-84D1-D620674A136E} = {A95999D0-C3A7-423F-84D1-D620674A136E} EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 Release_MT_Static|Win32 = Release_MT_Static|Win32 Release_Static|Win32 = Release_Static|Win32 Release|Win32 = Release|Win32 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {A95999D0-C3A7-423F-84D1-D620674A136E}.Debug|Win32.ActiveCfg = Debug|Win32 {A95999D0-C3A7-423F-84D1-D620674A136E}.Debug|Win32.Build.0 = Debug|Win32 {A95999D0-C3A7-423F-84D1-D620674A136E}.Release_MT_Static|Win32.ActiveCfg = Release_MT_Static|Win32 {A95999D0-C3A7-423F-84D1-D620674A136E}.Release_MT_Static|Win32.Build.0 = Release_MT_Static|Win32 {A95999D0-C3A7-423F-84D1-D620674A136E}.Release_Static|Win32.ActiveCfg = Release_Static|Win32 {A95999D0-C3A7-423F-84D1-D620674A136E}.Release_Static|Win32.Build.0 = Release_Static|Win32 {A95999D0-C3A7-423F-84D1-D620674A136E}.Release|Win32.ActiveCfg = Release|Win32 {A95999D0-C3A7-423F-84D1-D620674A136E}.Release|Win32.Build.0 = Release|Win32 {EF6CFDA6-F838-40E9-8688-BEE97EE14265}.Debug|Win32.ActiveCfg = Debug|Win32 {EF6CFDA6-F838-40E9-8688-BEE97EE14265}.Debug|Win32.Build.0 = Debug|Win32 {EF6CFDA6-F838-40E9-8688-BEE97EE14265}.Release_MT_Static|Win32.ActiveCfg = Release_MT_Static|Win32 {EF6CFDA6-F838-40E9-8688-BEE97EE14265}.Release_MT_Static|Win32.Build.0 = Release_MT_Static|Win32 {EF6CFDA6-F838-40E9-8688-BEE97EE14265}.Release_Static|Win32.ActiveCfg = Release_Static|Win32 {EF6CFDA6-F838-40E9-8688-BEE97EE14265}.Release_Static|Win32.Build.0 = Release_Static|Win32 {EF6CFDA6-F838-40E9-8688-BEE97EE14265}.Release|Win32.ActiveCfg = Release|Win32 {EF6CFDA6-F838-40E9-8688-BEE97EE14265}.Release|Win32.Build.0 = Release|Win32 {73ACA93A-C49E-4537-BC3A-DCF91E85ED2A}.Debug|Win32.ActiveCfg = Debug|Win32 {73ACA93A-C49E-4537-BC3A-DCF91E85ED2A}.Debug|Win32.Build.0 = Debug|Win32 {73ACA93A-C49E-4537-BC3A-DCF91E85ED2A}.Release_MT_Static|Win32.ActiveCfg = Debug|Win32 {73ACA93A-C49E-4537-BC3A-DCF91E85ED2A}.Release_MT_Static|Win32.Build.0 = Debug|Win32 {73ACA93A-C49E-4537-BC3A-DCF91E85ED2A}.Release_Static|Win32.ActiveCfg = Debug|Win32 {73ACA93A-C49E-4537-BC3A-DCF91E85ED2A}.Release_Static|Win32.Build.0 = Debug|Win32 {73ACA93A-C49E-4537-BC3A-DCF91E85ED2A}.Release|Win32.ActiveCfg = Debug|Win32 {73ACA93A-C49E-4537-BC3A-DCF91E85ED2A}.Release|Win32.Build.0 = Debug|Win32 {3D533F47-3043-4EAC-9669-06F01CDB75E2}.Debug|Win32.ActiveCfg = Debug|Win32 {3D533F47-3043-4EAC-9669-06F01CDB75E2}.Debug|Win32.Build.0 = Debug|Win32 {3D533F47-3043-4EAC-9669-06F01CDB75E2}.Release_MT_Static|Win32.ActiveCfg = Release|Win32 {3D533F47-3043-4EAC-9669-06F01CDB75E2}.Release_MT_Static|Win32.Build.0 = Release|Win32 {3D533F47-3043-4EAC-9669-06F01CDB75E2}.Release_Static|Win32.ActiveCfg = Release|Win32 {3D533F47-3043-4EAC-9669-06F01CDB75E2}.Release_Static|Win32.Build.0 = Release|Win32 {3D533F47-3043-4EAC-9669-06F01CDB75E2}.Release|Win32.ActiveCfg = Release|Win32 {3D533F47-3043-4EAC-9669-06F01CDB75E2}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal clasp-2.1.4/build_vc/vc9/clasp/clasp.vcproj0000644000404600007640000000702411074666157020267 0ustar kaufmanncools clasp-2.1.4/build_vc/vc9/clasp/app/0000755000404600007640000000000012245072211016474 5ustar kaufmanncoolsclasp-2.1.4/build_vc/vc9/clasp/app/app.vcproj0000644000404600007640000002226712016165013020511 0ustar kaufmanncools clasp-2.1.4/build_vc/vc9/clasp/test/0000755000404600007640000000000012245072211016673 5ustar kaufmanncoolsclasp-2.1.4/build_vc/vc9/clasp/test/test.vcproj0000644000404600007640000001253712076220023021105 0ustar kaufmanncools clasp-2.1.4/build_vc/vc9/clasp/lib/0000755000404600007640000000000012245072211016462 5ustar kaufmanncoolsclasp-2.1.4/build_vc/vc9/clasp/lib/lib.vcproj0000644000404600007640000002607112016165013020462 0ustar kaufmanncools clasp-2.1.4/build_vc/vc9/clasp/examples/0000755000404600007640000000000012245072211017532 5ustar kaufmanncoolsclasp-2.1.4/build_vc/vc9/clasp/examples/examples.vcproj0000644000404600007640000001030712016165013022575 0ustar kaufmanncools clasp-2.1.4/configure.sh0000755000404600007640000002071312076032077014655 0ustar kaufmanncools#!/bin/bash # OPTIONS claspre=0 static=0 machine=0 mt=0 rpath=0 PREFIX="/usr/local" BIN_DIR="" CONFIG="" # CONFIGURATION CXXFLAGS="${CXXFLAGS}" LDFLAGS="${LDFLAGS}" LDLIBS="" BUILDPATH="" INSTALLPATH="" CXX="" POST_BUILD="" TBB_INCLUDE="" TBB_LIB="" while [[ $# > 0 ]]; do case $1 in CXXFLAGS=*) CXXFLAGS=`echo "$1"| sed 's/^[A-Z]*=*//'` ;; LDFLAGS=*) LDFLAGS=`echo "$1"| sed 's/^[A-Z]*=*//'` ;; CXX=*) CXX=`echo "$1"| sed 's/^[A-Z]*=*//'` ;; TBB_INCLUDE=*) TBB_INCLUDE=`echo "$1"| sed 's/^[A-Z_]*=*//'` ;; TBB_LIB=*) TBB_LIB=`echo "$1"| sed 's/^[A-Z_]*=*//'` ;; "--strip") POST_BUILD="strip" ;; "--static") static=1 ;; "--with-claspre") claspre=1 ;; "--with-mt") mt=1 ;; "--set-rpath") rpath=1 ;; "--m32") machine=32 ;; "--m64") machine=64 ;; --bindir*|--prefix*|--config*) T=`echo "$1"| sed 's/^--[a-z-]*=*//'` A=$1 if [ -z "$T" ]; then if [ -z "$2" ]; then echo "error: required parameter missing after '$1'" exit 1 fi T=$2 shift fi case $A in --bindir*) BIN_DIR=$T;; --prefix*) PREFIX=$T;; --config*) CONFIG=$T;; esac ;; "--clean") rm -rf build/ exit 0 ;; "--help") echo echo "$0 [options]" echo echo " --help : show this help" echo " --prefix=PREFIX : set install prefix to PREFIX" echo " Default: '/usr/local'" echo " --bindir=PATH : set install path to PATH" echo " Default: '${PREFIX}/bin'" echo echo " --config=NAME : set configuration to NAME" echo " NAME=release : configure for optimized release version" echo " NAME=debug : configure for debug version" echo " NAME=check : configure for release version with assertions enabled" echo " : configure for custom configuration with name " echo echo " --with-mt : enable multi-thread support (see below)" echo " --set-rpath : store path to shared libraries in binary header" echo " --with-claspre : enable claspre features in clasp" echo " --static : link statically (if supported)" echo " --m32 : force 32-bit binary (if supported)" echo " --m64 : force 64-bit binary (if supported)" echo " --strip : discard symbols (calls strip after build)" echo " --clean : remove all generated files" echo echo "Note: Multi-thread support currently requires Intel® Threading Building Blocks >= 3.x." echo " Use option --with-mt and either set TBB30_INSTALL_DIR environment variable or" echo " explicitly set include and/or library path via:" echo " $0 --with-mt TBB_INCLUDE= TBB_LIB=" echo echo "Note: To create a custom configuration call $0 like this: " echo " $0 --config=my_config CXX=my_gcc CXXFLAGS=my_cxxflags LDFLAGS=my_ldflags" echo exit 0 ;; *) echo "*** Error: unknown option $1" echo "type '$0 --help' for an overview of supported options" exit 1 esac shift done if [ -z "$CONFIG" ]; then CONFIG="release" fi case $CONFIG in release) CXXFLAGS="-O3 -DNDEBUG" ;; debug) CXXFLAGS="-g -D_DEBUG -DDEBUG -O1" ;; check) CXXFLAGS="-O2 -DDEBUG" ;; *) if [ -z "$CXXFLAGS" ]; then CXXFLAGS="-O3 -DNDEBUG" fi ;; esac BUILDPATH="build/${CONFIG}" if [[ $mt == 0 ]]; then CXXFLAGS="${CXXFLAGS} -DWITH_THREADS=0" else # try to find tbb headers echo -ne "Checking for TBB include path..." for i in "$TBB_INCLUDE" "$TBB30_INSTALL_DIR/include" "/opt/intel/tbb/include" "/usr/local/include" "/usr/include" "/opt/local/include"; do TBB_INCLUDE="" if [ -f "$i/tbb/tbb.h" ]; then TBB_INCLUDE="$i" echo "$TBB_INCLUDE" break fi done if [ -z "$TBB_INCLUDE" ]; then echo "FAIL" echo "*** Error: TBB include path not set!" echo "use '$0 TBB_INCLUDE='" exit 1 fi # try to find tbb lib echo -ne "Checking for TBB library path..." for i in "$TBB_LIB" "$TBB30_INSTALL_DIR/lib" "/opt/intel/tbb/lib" "/usr/local/lib" "/usr/lib" "/opt/local/lib" ; do TBB_LIB="" if [ -f "$i/libtbb.so" -o -f "$i/libtbb.dylib" ]; then TBB_LIB="$i" echo "$TBB_LIB" break fi done if [ -z "$TBB_LIB" ]; then echo "FAIL" echo "*** Error: TBB library path not set or 'libtbb.{so,dylib}' not found!" echo "use '$0 TBB_LIB='" exit 1 fi CXXFLAGS="${CXXFLAGS} -DWITH_THREADS=1 -I\"${TBB_INCLUDE}\"" LDFLAGS="${LDFLAGS} -L\"${TBB_LIB}\"" LDLIBS="-ltbb" if [[ $rpath == 1 ]]; then LDFLAGS="${LDFLAGS} -Xlinker \"--rpath=\"${TBB_LIB}\"\"" fi BUILDPATH="${BUILDPATH}_mt" fi CXXFLAGS="${CXXFLAGS} -DWITH_CLASPRE=${claspre}" if [[ $static == 1 ]]; then LDFLAGS="${LDFLAGS} -static" BUILDPATH="${BUILDPATH}_static" fi if [[ $machine != 0 ]]; then LDFLAGS="${LDFLAGS} -m${machine}" CXXFLAGS="${CXXFLAGS} -m${machine}" BUILDPATH="${BUILDPATH}_m${machine}" fi if [ -z "$BIN_DIR" ]; then INSTALLPATH="${PREFIX}/bin" else INSTALLPATH=$BIN_DIR fi # create & prepare build hierarchy ROOTPATH="../.." LIB_CLASP="libclasp" LIB_OPTS="libprogram_opts" mkdir -p "$BUILDPATH/app" mkdir -p "$BUILDPATH/bin" mkdir -p "$BUILDPATH/$LIB_CLASP/lib" mkdir -p "$BUILDPATH/$LIB_OPTS/lib" cd "$BUILDPATH" rm -f .CONFIG $LIB_CLASP/.CONFIG $LIB_OPTS/.CONFIG rm -f Makefile $LIB_CLASP/Makefile $LIB_OPTS/Makefile rm -f FLAGS # write FLAGS touch FLAGS if [ ! -z "$CXX" ]; then echo "CXX := ${CXX}" >> FLAGS else echo "CXX ?= g++" >> FLAGS fi echo "CXXFLAGS := ${CXXFLAGS}" >> FLAGS echo "WARNFLAGS := -W -Wall" >> FLAGS echo "LDFLAGS := ${LDFLAGS}" >> FLAGS echo "" >> FLAGS # create Makefiles LIB_MAKES="${ROOTPATH}/tools/Base.in ${ROOTPATH}/tools/LibRule.in ${ROOTPATH}/tools/BaseRule.in" PRO_MAKES="${ROOTPATH}/tools/Base.in ${ROOTPATH}/tools/ProjRule.in ${ROOTPATH}/tools/BaseRule.in" cat $LIB_MAKES >> $LIB_CLASP/Makefile cat $LIB_MAKES >> $LIB_OPTS/Makefile cat $PRO_MAKES >> Makefile # write project config touch .CONFIG echo "PROJECT_ROOT := $ROOTPATH" >> .CONFIG echo "TARGET := bin/clasp" >> .CONFIG echo "FLAGS := FLAGS" >> .CONFIG echo "SOURCE_DIR := \$(PROJECT_ROOT)/app" >> .CONFIG echo "INCLUDE_DIR := \$(PROJECT_ROOT)/app" >> .CONFIG echo "OUT_DIR := app" >> .CONFIG echo "INCLUDES := -I\$(PROJECT_ROOT)/${LIB_CLASP} -I\$(PROJECT_ROOT)/${LIB_OPTS}" >> .CONFIG echo "SUBDIRS := ${LIB_CLASP} ${LIB_OPTS}" >> .CONFIG echo "LIBS := ${LIB_CLASP}/lib/${LIB_CLASP}.a ${LIB_OPTS}/lib/${LIB_OPTS}.a" >> .CONFIG echo "LDLIBS := ${LDLIBS}" >> .CONFIG echo "INSTALL_DIR := \"${INSTALLPATH}\"" >> .CONFIG if [ ! -z "$POST_BUILD" ]; then echo "POST_BUILD := $POST_BUILD" >> .CONFIG fi echo "" >> .CONFIG # write lib configs touch $LIB_CLASP/.CONFIG $LIB_OPTS/.CONFIG echo "PROJECT_ROOT := ${ROOTPATH}/.." >> $LIB_CLASP/.CONFIG echo "PROJECT_ROOT := ${ROOTPATH}/.." >> $LIB_OPTS/.CONFIG echo "TARGET := lib/${LIB_CLASP}.a" >> $LIB_CLASP/.CONFIG echo "TARGET := lib/${LIB_OPTS}.a" >> $LIB_OPTS/.CONFIG echo "FLAGS := ../FLAGS" >> $LIB_CLASP/.CONFIG echo "FLAGS := ../FLAGS" >> $LIB_OPTS/.CONFIG echo "SOURCE_DIR := \$(PROJECT_ROOT)/${LIB_CLASP}/src" >> $LIB_CLASP/.CONFIG echo "TEST_DIR := \$(PROJECT_ROOT)/${LIB_CLASP}/tests" >> $LIB_CLASP/.CONFIG echo "TEST_TARGET := ./test-lib" >> $LIB_CLASP/.CONFIG echo "SOURCE_DIR := \$(PROJECT_ROOT)/${LIB_OPTS}/src" >> $LIB_OPTS/.CONFIG echo "INCLUDE_DIR := \$(PROJECT_ROOT)/${LIB_CLASP}/clasp" >> $LIB_CLASP/.CONFIG echo "INCLUDE_DIR := \$(PROJECT_ROOT)/${LIB_OPTS}/program_opts" >> $LIB_OPTS/.CONFIG echo "INCLUDES := -I\$(PROJECT_ROOT)/${LIB_CLASP}" >> $LIB_CLASP/.CONFIG echo "INCLUDES := -I\$(PROJECT_ROOT)/${LIB_OPTS}" >> $LIB_OPTS/.CONFIG echo "" >> $LIB_CLASP/.CONFIG echo "" >> $LIB_OPTS/.CONFIG # DONE echo echo "Configuration successfully written to ${BUILDPATH}." echo "Make flags written to ${BUILDPATH}/FLAGS." echo echo "To compile clasp type:" echo " cd ${BUILDPATH}" echo " make" echo echo "To install clasp afterwards type:" echo " make install" echo "or copy '${BUILDPATH}/clasp' to a directory of your choice." if [ ! -d "$INSTALLPATH" ]; then echo echo "Note: install path '$INSTALLPATH' does not exist" echo " 'make install' will fail unless it is first created!" fi echo echo "Note: \"make\" must correspond to GNU Make 3.8 or later." echo clasp-2.1.4/configure.bat0000644000404600007640000001730512016165013015000 0ustar kaufmanncools@ECHO OFF SETLOCAL REM OPTIONS set claspre=0 set static=0 set machine=0 set mt=0 set PREFIX=%HOMEPATH% set BIN_DIR= set CONFIG= REM CONFIGURATION set CXXFLAGS=%CXXFLAGS% set LDFLAGS=%LDFLAGS% set LDLIBS= set BUILDPATH=build\release set INSTALLPATH=%PREFIX%\bin set CXX= set POST_BUILD= SET TBB_LIB= SET TBB_INCLUDE= REM Scan arguments. :ARG_LOOP IF [%1]==[] ( GOTO DONE ) ELSE IF [%1]==[/?] ( goto o_help ) ELSE IF [%1]==[--help] ( :o_help ECHO. ECHO. %0 [ options ] ECHO. ECHO.Options: ECHO. ?,--help : print this page ECHO. --prefix=PATH : set install prefix to PATH ECHO. --bindir=PATH : set install path to PATH ECHO. ECHO. --config=NAME : set configuration to NAME ECHO. NAME=release: configure for optimized release version ECHO. NAME=debug : configure for debug version ECHO. NAME=check : configure for release version with assertions enabled ECHO. ELSE : configure for custom configuration ECHO. ECHO --with-mt : enable multi-thread support ^(see below^) ECHO --with-claspre : enable claspre features in clasp ECHO --static : link statically ^(if supported^) ECHO. --m32 : force 32-bit binary ^(if supported^) ECHO. --m64 : force 64-bit binary ^(if supported^) ECHO. --strip : discard symbols ^(calls strip after build^) ECHO. --clean : remove all generated files ECHO. ECHO. Note: Multi-thread support requires Intel Threading Building Blocks 3.x. ECHO. Use option --with-mt and either set TBB30_INSTALL_DIR environment ECHO. variable or explicitly set include and/or library path via: ECHO. %0 --with-mt TBB_INCLUDE=^ TBB_LIB=^ ECHO. ECHO. Note: To create a custom configuration call %0 like this: ECHO. %0 --config=my_c CXX=my_gcc CXXFLAGS=my_cxxf LDFLAGS=my_ldf ECHO. GOTO EXIT ) ELSE IF [%1]==[CXX] ( SET CXX=%2 SHIFT ) ELSE IF [%1]==[CXXFLAGS] ( SET CXXFLAGS=%2 SHIFT ) ELSE IF [%1]==[LDFLAGS] ( SET LDFLAGS=%2 SHIFT ) ELSE IF [%1]==[TBB_INCLUDE] ( SET TBB_INCLUDE=%2 SHIFT ) ELSE IF [%1]==[TBB_LIB] ( SET TBB_LIB=%2 SHIFT ) ELSE IF [%1]==[--prefix] ( SET PREFIX=%2 SHIFT ) ELSE IF [%1]==[--bindir] ( SET BIN_DIR=%2 SHIFT ) ELSE IF [%1]==[--config] ( if not [%CONFIG%]==[] ( ECHO *** Error: multiple values for option '--config' goto EXIT ) set CONFIG=%2 SHIFT ) ELSE IF [%1]==[--static] ( SET static=1 ) ELSE IF [%1]==[--with-mt] ( SET mt=1 ) ELSE IF [%1]==[--with-claspre] ( SET claspre=1 ) ELSE IF [%1]==[--m32] ( SET machine=32 ) ELSE IF [%1]==[--m64] ( SET machine=64 ) ELSE IF [%1]==[--strip] ( SET POST_BUILD=strip ) ELSE IF [%1]==[--clean] ( IF NOT EXIST build goto EXIT RD /S /Q build goto EXIT ) ELSE ( ECHO *** Error: Unknown parameter '%1'. ECHO Type '%0 /?' for an overview of supported options. GOTO EXIT ) SHIFT GOTO ARG_LOOP :DONE if [%CONFIG%]==[] ( set CONFIG=release ) if [%CONFIG%]==[release] ( SET CXXFLAGS=-O3 -DNDEBUG ) ELSE IF [%CONFIG%]==[debug] ( SET CXXFLAGS=-g -D_DEBUG -DDEBUG -O1 ) ELSE IF [%CONFIG%]==[check] ( SET CXXFLAGS=-O2 -DDEBUG ) IF ["%CXXFLAGS%"]==[""] ( SET CXXFLAGS=-O3 -DNDEBUG ) SET BUILDPATH=build\%CONFIG% IF %mt%==0 ( SET CXXFLAGS=%CXXFLAGS% -DWITH_THREADS=0 ) ELSE ( if [%TBB_INCLUDE%]==[] ( set TBB_INCLUDE=%TBB30_INSTALL_DIR%/include ) if [%TBB_LIB%]==[] ( set TBB_LIB=%TBB30_INSTALL_DIR%/lib ) IF NOT EXIST "%TBB_INCLUDE%/tbb/tbb.h" ( ECHO *** Error: TBB include path not set! ECHO Use 'configure TBB_INCLUDE=^/include' GOTO EXIT ) IF NOT EXIST "%TBB_LIB%/tbb.lib" ( ECHO *** Error: TBB library path not set or '%TBB_LIB%/tbb.lib' not found! ECHO Use 'configure TBB_LIB=^' GOTO EXIT ) SET CXXFLAGS=%CXXFLAGS% -DWITH_THREADS=1 -I"%TBB_INCLUDE%" SET LDFLAGS=%LDFLAGS% -L"%TBB_LIB%" -Xlinker "--rpath="%TBB_LIB%"" SET LDLIBS=-ltbb SET BUILDPATH=%BUILDPATH%_mt ) SET CXXFLAGS=%CXXFLAGS% -DWITH_CLASPRE=%claspre% IF %static%==1 ( SET LDFLAGS=%LDFLAGS% -static SET BUILDPATH=%BUILDPATH%_static ) IF NOT %machine%==0 ( SET LDFLAGS=%LDFLAGS% -m%machine% SET CXXFLAGS=%CXXFLAGS% -m%machine% SET BUILDPATH=%BUILDPATH%_m%machine% ) IF [%BIN_DIR%]==[] ( SET INSTALLPATH=%PREFIX%\bin ) ELSE ( SET INSTALLPATH=%BIN_DIR% ) REM create & prepare build hierarchy IF NOT EXIST "%BUILDPATH%" goto CREATEDIR RD /S /Q "%BUILDPATH%" :CREATEDIR MKDIR "%BUILDPATH%\app" MKDIR "%BUILDPATH%\bin" MKDIR "%BUILDPATH%\libclasp\lib" MKDIR "%BUILDPATH%\libprogram_opts\lib" SET ROOTPATH=../.. SET TARGET=bin/clasp.exe SET LIB_CLASP=libclasp SET LIB_OPTS=libprogram_opts cd "%BUILDPATH%" REM write FLAGS if ["%CXX%"]==[""] ( echo CXX ?= g++# >> FLAGS ) ELSE ( echo CXX := %CXX%# >> FLAGS ) echo CXXFLAGS := %CXXFLAGS%# >> FLAGS echo WARNFLAGS := -W -Wall# >> FLAGS echo LDFLAGS := %LDFLAGS%# >> FLAGS echo.#>> FLAGS REM create Makefiles SET TOOL_PATH=..\..\tools SET LIB_MAKES=%TOOL_PATH%\Base.in %TOOL_PATH%\LibRule.in %TOOL_PATH%\BaseRule.in SET PRO_MAKES=%TOOL_PATH%\Base.in %TOOL_PATH%\ProjRule.in %TOOL_PATH%\BaseRule.in type %LIB_MAKES% > %LIB_CLASP%\Makefile 2>nul type %LIB_MAKES% > %LIB_OPTS%\Makefile 2>nul type %PRO_MAKES% > Makefile 2>nul REM write project config echo PROJECT_ROOT := %ROOTPATH%# >> .CONFIG echo TARGET := %TARGET%# >> .CONFIG echo FLAGS := FLAGS# >> .CONFIG echo SOURCE_DIR := $(PROJECT_ROOT)/app# >> .CONFIG echo INCLUDE_DIR := $(PROJECT_ROOT)/app# >> .CONFIG echo OUT_DIR := app# >> .CONFIG echo INCLUDES := -I$(PROJECT_ROOT)/%LIB_CLASP% -I$(PROJECT_ROOT)/%LIB_OPTS%# >> .CONFIG echo SUBDIRS := %LIB_CLASP% %LIB_OPTS%# >> .CONFIG echo LIBS := %LIB_CLASP%/lib/%LIB_CLASP%.a %LIB_OPTS%/lib/%LIB_OPTS%.a# >> .CONFIG echo LDLIBS := %LDLIBS%# >> .CONFIG echo INSTALL_DIR := "%INSTALLPATH%"# >> .CONFIG echo INSTALL := copy# >> .CONFIG if not [%POST_BUILD%]==[] ( ECHO POST_BUILD := %POST_BUILD%# >> .CONFIG ) echo.#>>.CONFIG REM write lib configs echo PROJECT_ROOT := %ROOTPATH%/..# >> %LIB_CLASP%\.CONFIG echo PROJECT_ROOT := %ROOTPATH%/..# >> %LIB_OPTS%\.CONFIG echo TARGET := lib/%LIB_CLASP%.a# >> %LIB_CLASP%\.CONFIG echo TARGET := lib/%LIB_OPTS%.a# >> %LIB_OPTS%\.CONFIG echo FLAGS := ../FLAGS# >> %LIB_CLASP%\.CONFIG echo FLAGS := ../FLAGS# >> %LIB_OPTS%\.CONFIG echo SOURCE_DIR := $(PROJECT_ROOT)/%LIB_CLASP%/src# >> %LIB_CLASP%\.CONFIG echo SOURCE_DIR := $(PROJECT_ROOT)/%LIB_OPTS%/src# >> %LIB_OPTS%\.CONFIG echo INCLUDE_DIR := $(PROJECT_ROOT)/%LIB_CLASP%/clasp# >> %LIB_CLASP%\.CONFIG echo INCLUDE_DIR := $(PROJECT_ROOT)/%LIB_OPTS%/program_opts# >> %LIB_OPTS%\.CONFIG echo INCLUDES := -I$(PROJECT_ROOT)/%LIB_CLASP%# >> %LIB_CLASP%\.CONFIG echo INCLUDES := -I$(PROJECT_ROOT)/%LIB_OPTS%# >> %LIB_OPTS%\.CONFIG echo.# >> %LIB_CLASP%\.CONFIG echo.# >> %LIB_OPTS%\.CONFIG REM DONE ECHO. ECHO Configuration successfully written to %BUILDPATH%. ECHO Make flags written to "%BUILDPATH%\FLAGS". ECHO. ECHO To compile clasp type: ECHO cd "%BUILDPATH%" ECHO make ECHO. ECHO To install clasp afterwards type: ECHO make install ECHO or copy "%BUILDPATH%\%TARGET%" to a directory of your choice. IF EXIST "%INSTALLPATH%" goto skip_warn ECHO. ECHO Note: Path "%INSTALLPATH%" does not exist! ECHO Installation will fail unless it is first created! :skip_warn ECHO. ECHO Note: 'make' must correspond to GNU Make 3.8 or later. ECHO. :EXIT (set static=) (set machine=) (set mt=) (set PREFIX=) (set BIN_DIR=) (set CONFIG=) (set LDFLAGS=) (set LDLIBS=) (set BUILDPATH=) (set CXXFLAGS=) (set INSTALLPATH=) (set CXX=) (set TARGET=) (set POST_BUILD=) (set LIB_CLASP=) (set LIB_OPTS=) (set LIB_MAKES=) (set PRO_MAKES=) (set TOOL_PATH=) (set TBB_LIB=) (set TBB_INCLUDE=) clasp-2.1.4/libprogram_opts/0000755000404600007640000000000012245072211015525 5ustar kaufmanncoolsclasp-2.1.4/libprogram_opts/CMakeLists.txt0000644000404600007640000000027611343201606020272 0ustar kaufmanncoolsfile(GLOB LIBOPTS_SRC src/*.cpp) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) SET(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/lib) add_library(libprogram_opts STATIC ${LIBOPTS_SRC}) clasp-2.1.4/libprogram_opts/Makefile0000644000404600007640000000220511266343704017176 0ustar kaufmanncoolsSHELL ?= /bin/sh AR ?= ar CXX ?= g++ BUILD_DIR ?= . ROOT_DIR ?= . CXXFLAGS ?= -O3 -DNDEBUG FLAGS ?= ifneq ($(FLAGS),) -include $(FLAGS) endif INCLUDE := -I $(ROOT_DIR) ALL_CXXFLAGS := -W -Wall $(INCLUDE) $(CXXFLAGS) TARGET := $(BUILD_DIR)/lib/libprogram_opts.a SOURCES := $(patsubst $(ROOT_DIR)/src/%.cpp,%.cpp,$(wildcard $(ROOT_DIR)/src/*.cpp)) DEPS := $(patsubst %.cpp,$(BUILD_DIR)/%.dep, $(SOURCES)) OBJECTS := $(patsubst %.cpp,$(BUILD_DIR)/%.o, $(SOURCES)) vpath %.cpp $(ROOT_DIR)/src vpath %.h $(ROOT_DIR)/program_opts $(TARGET): $(FLAGS) $(DEPS) $(OBJECTS) $(AR) cvrs $(TARGET) $(OBJECTS) ifneq ($(MAKECMDGOALS),clean) -include $(DEPS) endif $(BUILD_DIR)/%.dep: %.cpp $(FLAGS) $(CXX) $(ALL_CXXFLAGS) -MT $(BUILD_DIR)/$*.o -MM $< > $@ $(BUILD_DIR)/%.o: %.cpp $(FLAGS) $(CXX) $(ALL_CXXFLAGS) -c $< -o $@ .PHONY: clean ifeq ($(findstring Windows,$(OS)),) clean: @$(RM) $(TARGET) @$(RM) $(OBJECTS) @$(RM) $(DEPS) else RM := del /F /Q clean: @$(RM) $(subst /,\,$(TARGET)) 2>nul @$(RM) $(subst /,\,$(OBJECTS)) 2>nul @$(RM) $(subst /,\,$(DEPS)) 2>nul endif clasp-2.1.4/libprogram_opts/program_opts/0000755000404600007640000000000012245072211020241 5ustar kaufmanncoolsclasp-2.1.4/libprogram_opts/program_opts/typed_value.h0000644000404600007640000001645011662210034022740 0ustar kaufmanncools// // Copyright (c) Benjamin Kaufmann 2004 // // This is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This file is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this file; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // // NOTE: ProgramOptions is inspired by Boost.Program_options // see: www.boost.org/libs/program_options // #ifndef PROGRAM_OPTIONS_TYPED_VALUE_H_INCLUDED #define PROGRAM_OPTIONS_TYPED_VALUE_H_INCLUDED #ifdef _MSC_VER #pragma warning (disable : 4786) #pragma warning (disable : 4503) #pragma warning (disable : 4200) #endif #include "value.h" #include "value_parser.h" #include "detail/notifier.h" #include "errors.h" #include namespace ProgramOptions { namespace detail { template struct Parser { typedef bool (*type)(const std::string&, T&); }; } // end namespace detail /////////////////////////////////////////////////////////////////////////////// // StoredValue - a typed value that writes to an existing variable /////////////////////////////////////////////////////////////////////////////// template class StoredValue : public Value { public: typedef typename detail::Parser::type parser_type; StoredValue(T& var, parser_type p) : Value(0) , address_(&var) , parser_(p) { this->setProperty(Value::property_location); } bool doParse(const std::string&, const std::string& value) { return this->parser_(value, *address_); } protected: T* address_; // storage location of this value parser_type parser_; // str -> T }; //////////////////////////////////////////////////////////////////////////////////// // NotifiedValue - a typed value that is created on demand and passed to a callback //////////////////////////////////////////////////////////////////////////////////// template class NotifiedValue : public Value { public: typedef typename detail::Parser::type parser_type; typedef detail::Notifier notifier_type; NotifiedValue(T* (*cf)(), const notifier_type& n, parser_type p) : Value(0) , parser_(p) , notify_(n) { value_.create = cf; } NotifiedValue* storeTo(T& obj) { value_.address = &obj; this->setProperty(Value::property_location); return this; } bool doParse(const std::string& name, const std::string& value) { bool ret; T* pv = 0; std::auto_ptr holder; if (this->hasProperty(Value::property_location)) { pv = value_.address; } else { holder.reset(value_.create()); pv = holder.get(); } ret = this->parser_(value, *pv); if (ret && notify_.notify(name, pv)) { this->storeTo(*pv); holder.release(); } return ret; } protected: union { T* address; T* (*create)(); } value_; parser_type parser_; notifier_type notify_; }; /////////////////////////////////////////////////////////////////////////////// // CustomValue - a value that must be parsed/interpreted by a custom context /////////////////////////////////////////////////////////////////////////////// class CustomValue : public Value { public: typedef detail::Notifier notifier_type; CustomValue(const notifier_type& n) : Value(0) , notify_(n) { } bool doParse(const std::string& name, const std::string& value) { return notify_.notify(name, value); } protected: notifier_type notify_; }; /////////////////////////////////////////////////////////////////////////////// // value factories /////////////////////////////////////////////////////////////////////////////// #define LIT_TO_STRING_X(lit) #lit //! stringifies a literal like 1 or 23.0 #define LIT_TO_STRING(lit) LIT_TO_STRING_X(lit) enum FlagAction { store_false= 0, store_true = 1 }; /*! * Creates a value that is bound to an existing variable. * Assignments to the created value are directly stored in the * given variable. * * \param v The variable to which the new value object is bound * \param p The parser to use for parsing the value. If no parser is given, * type T must provide an operator>>(std::istream&, T&). */ template inline StoredValue* storeTo(T& v, typename detail::Parser::type p = &DefaultParser::parse) { return new StoredValue(v, p); } inline StoredValue* flag(bool& b, FlagAction x = store_true) { return static_cast*>(storeTo(b, FlagStr::parser(x))->flag()); } /*! * Creates a notified value, i.e. a value for which * a notification function is called once it was parsed. * The return value of that function determines whether the * value is kept (true) or deleted (false). In the former * case ownership of the value is transferred to the notified context. * * \param p0 A pointer to an object that should be passed * to the notification function once invoked. * \param nf The function to be invoked once a value is created. * On invocation, the first parameter will be p0. The second * parameter will be the value's option name and the third * the location of the newly created value. * * \param parser The parser to use for parsing the value * * \see OptionGroup::addOptions() */ template inline NotifiedValue* notify(ParamT* p0, typename detail::Notify::type nf, typename detail::Parser::type parser = &DefaultParser::parse) { return new NotifiedValue(&DefaultCreator::create, detail::Notifier(p0, nf), parser); } template inline NotifiedValue* storeNotify(T& obj, ParamT* p0, typename detail::Notify::type nf, typename detail::Parser::type parser = &DefaultParser::parse) { return notify(p0, nf, parser)->storeTo(obj); } template inline NotifiedValue* flag(ParamT* p0, typename detail::Notify::type nf, FlagAction a = store_true) { return static_cast*>(notify(p0, nf, FlagStr::parser(a))->flag()); } /*! * Creates a custom value, i.e. a value that is fully controlled * (parsed and created) by a notified context. * * During parsing of options, the notification function of a custom * value is called with its option name and the parsed value. * The return value of that function determines whether the * value is considered valid (true) or invalid (false). * * \param p0 A pointer to an object that should be passed * to the notification function once invoked. * \param nf The function to be invoked once a value is parsed. * On invocation, the first parameter will be p0. The second * parameter will be the value's option name and the third * a pointer to the parsed value string. * * \see OptionGroup::addOptions() */ template inline CustomValue* notify(ParamT* p0, typename detail::Notify::type nf) { return new CustomValue(detail::Notifier(p0, nf)); } } #endif clasp-2.1.4/libprogram_opts/program_opts/value.h0000644000404600007640000001613611774547534021562 0ustar kaufmanncools// // Copyright (c) Benjamin Kaufmann 2004 // // This is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This file is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this file; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // // NOTE: ProgramOptions is inspired by Boost.Program_options // see: www.boost.org/libs/program_options // #ifndef PROGRAM_OPTIONS_VALUE_H_INCLUDED #define PROGRAM_OPTIONS_VALUE_H_INCLUDED #ifdef _MSC_VER #pragma warning (disable : 4786) #pragma warning (disable : 4503) #endif #include #include #include #if defined(_MSC_VER) && _MSC_VER <= 1200 namespace std { using ::size_t; } #endif namespace ProgramOptions { enum DescriptionLevel { desc_level_default = 0, /**< Always shown in description */ desc_level_e1 = 1, desc_level_e2 = 2, desc_level_e3 = 3, desc_level_all = 4, desc_level_hidden = 5 /**< Never shown in description */ }; //! Manages the value of an option and defines how it is parsed from a string. /*! * The library maintains a 1:1-relationship between options and their values. * That is, an option has exactly one value and a value has exactly one * state w.r.t its option. */ class Value { public: //! Possible (tentative) states of an option value. enum State { value_unassigned = 0, /**< no value assigned */ value_defaulted = 1, /**< a default value is assigned */ value_fixed = 2 /**< a parsed value is assigned */ }; //! Possible value descriptions. enum DescType { desc_name = 1 , desc_default = 2 , desc_implicit= 4 }; virtual ~Value(); //! Returns the current state of this value. State state() const { return static_cast(state_); } /*! * Sets the (initial) state of this value to s. */ Value* state(Value::State s) { state(true, s); return this; } //! Returns the name of this value. /*! * \note The default name is "" unless isFlag() is true in which * case the default is "". */ const char* arg() const; Value* arg(const char* n) { return desc(desc_name, n); } //! Sets an alias name for the corresponding option. Value* alias(char c) { optAlias_ = c; return this; } char alias() const { return optAlias_; } //! Sets a description level for the corresponding option. /*! * Description levels can be used to suppress * certain options when generating option descriptions. */ Value* level(DescriptionLevel lev) { unsigned x = (lev * level_shift); flags_ = x | (flags_&(level_shift-1)); return this; } //! Returns the description level of the corresponding option. DescriptionLevel level() const { return DescriptionLevel(flags_ / level_shift); } //! Returns true if this is the value of an negatable option. /*! * If an option '--option' is negatable, passing '--no-option' * on the command-line will set the value of '--option' to 'no'. */ bool isNegatable() const { return hasProperty(property_negatable); } Value* negatable() { setProperty(property_negatable); return this; } //! Returns true if value can be implicitly created from an empty string. /*! * \note the implicit value comes into play if the corresponding * option is present but without an adjacent value. * * \note an explicit value for an implicit value is only used if * it is unambiguously given. E.g. on the command-line one has * to use '--option=value' or '-ovalue' but *not* '--option value' * or '-o value'. */ bool isImplicit() const { return hasProperty(property_implicit); } //! Returns true if this is the value of an option flag. /*! * Similar to isImplicit but with the difference that * no value is accepted on the command-line. * * Used for options like '--help' or '--version'. */ bool isFlag() const { return hasProperty(property_flag); } /*! * Marks the value as flag. * \see bool Value::isFlag() const */ Value* flag() { setProperty(property_flag); return this; } //! Returns true if the value of this option can be composed from multiple source. bool isComposing() const { return hasProperty(property_composing); } /*! * Marks the value as composing. * \see Value::isComposing() */ Value* composing() { setProperty(property_composing); return this; } /*! * Sets a default value for this value. */ Value* defaultsTo(const char* v){ return desc(desc_default, v); } //! Returns the default value of this or 0 none exists const char* defaultsTo() const { return desc(desc_default); } /*! * Sets an implicit value, which will be used * if option is given without an adjacent value, * e.g. '--option' instead of '--option value' * \see bool Value::isImplicit() const */ Value* implicit(const char* str) { return desc(desc_implicit, str); } //! Returns the implicit value of this or 0 if isImplicit() == false. const char* implicit() const; //! Parses the given string and updates the value's state. /*! * \param name The name of the option associated with this value. * \param value The value to parse. * \param st The state to which the value should transition if parsing is succesful. * * \return * - true if the given string contains a valid value * - false otherwise * * \post if true is returned, state() is st */ bool parse(const std::string& name, const std::string& value, State st = value_fixed); protected: typedef unsigned char byte_t; enum Property { property_implicit = 1 // implicit value? , property_flag = 3 // implicit and type bool? , property_composing = 4 // multiple values allowed? , property_negatable = 8 // negatable form allowed? , property_location =16 // fixed storage location? , not_a_property =32 }; Value(byte_t flagSet, State initial = value_unassigned); void setProperty(Property f) { flags_ |= byte_t(f); } void clearProperty(Property f) { flags_ &= ~byte_t(f);} bool hasProperty(Property f)const{ return (flags_ & byte_t(f)) == f; } bool state(bool b, State s) { if (b) { state_ = s; } return b; } virtual bool doParse(const std::string& name, const std::string& value) = 0; const char* desc(DescType t) const; Value* desc(DescType t, const char* d); private: enum { desc_pack = 8, level_shift = not_a_property, levels = 255/level_shift }; byte_t state_; // state: one of State byte_t flags_; // flag set holding properties byte_t descFlag_; // either desc_pack or one of DescType byte_t optAlias_; // alias name of option union ValueDesc { // optional value descriptions either const char* value;// a single value or const char** pack; // a pointer to a full pack } desc_; }; } #endif clasp-2.1.4/libprogram_opts/program_opts/value_parser.h0000644000404600007640000000767411770053101023117 0ustar kaufmanncools// // Copyright (c) Benjamin Kaufmann 2004 // // This is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This file is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this file; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // // NOTE: ProgramOptions is inspired by Boost.Program_options // see: www.boost.org/libs/program_options // #ifndef PROGRAM_OPTIONS_VALUE_PARSER_H_INCLUDED #define PROGRAM_OPTIONS_VALUE_PARSER_H_INCLUDED #include "detail/input_stream.h" namespace ProgramOptions { struct StringSlice { StringSlice(const std::string& s) : ptr_(s.c_str()), len_(s.size()<<1) {} StringSlice(const char* p, size_t s) : ptr_(p), len_(s<<1) {} StringSlice parsed(bool ok, size_t numParsed = 0) const { StringSlice ret(*this); if (!ok) ret.len_ |= 1; else ret.skip(numParsed); return ret; } const char* data() const { return ptr_; } size_t size() const { return len_>>1; } bool ok() const { return !error(); } bool error() const { return (len_&1) != 0; } bool complete() const { return ok() && size() == 0; } operator bool() const { return complete(); } private: void skip(size_t num); const char* ptr_; size_t len_; }; template struct ComponentSeparator { static bool isSeparator(char x) { return x == ',' || x == ';'; } }; template struct no_parser_for_type; //! called if no parser for T was found template StringSlice parseValue(const StringSlice& in, T&, ...) { (void)sizeof(no_parser_for_type); return in.parsed(false); } struct FlagStr { typedef bool (*parser_type)(const std::string&, bool&); std::string str; bool val; static const FlagStr* find(const std::string& s); static const FlagStr* find(const char* s); static const FlagStr* findImpl(const char* s, std::size_t len); //! parses "1" | "0" | "yes" | "no" | "true" | "false" | "on" | "off" static StringSlice parse(const StringSlice& slice, bool& out, int); static parser_type parser(int x) { return x ? store_true : store_false; } static bool store_true(const std::string&, bool&); static bool store_false(const std::string&, bool&); static FlagStr map_s[8]; }; std::string toLower(const std::string& in); //! calls operator>>(std::istream&, T&) to parse a value template StringSlice parseValue(const StringSlice& in, T& v, double extra) { detail::input_stream str(in.data(), in.size()); if ( (str>>v) ) { size_t parsed = str.eof() ? in.size() : static_cast(str.tellg()); StringSlice ret = in.parsed(true, parsed); return ret.complete() || extra > 0.0 ? ret : in.parsed(false); } return in.parsed(false); } inline StringSlice parseValue(const StringSlice& in, bool& v, int extra) { return FlagStr::parse(in, v, extra); } inline StringSlice parseValue(const StringSlice& in, std::string& v, int extra) { if (extra == 0) { v.assign(in.data(), in.size()); return in.parsed(true, in.size()); } // find end of part const char* ptr = in.data(); const char* end = in.data() + in.size(); while (ptr != end && !ComponentSeparator::isSeparator(*ptr)) { ++ptr; } size_t parsed = ptr - in.data(); v.assign(in.data(), parsed); return in.parsed(true, parsed); } template struct DefaultParser { static bool parse(const std::string& str, T& out) { return parseValue(StringSlice(str), out, 0); } }; template struct DefaultCreator { static T* create() { return new T(); } }; } #endif clasp-2.1.4/libprogram_opts/program_opts/detail/0000755000404600007640000000000012245072211021503 5ustar kaufmanncoolsclasp-2.1.4/libprogram_opts/program_opts/detail/notifier.h0000644000404600007640000000420011660235120023467 0ustar kaufmanncools// // Copyright (c) Benjamin Kaufmann 2010 // // This is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This file is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this file; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // // NOTE: ProgramOptions is inspired by Boost.Program_options // see: www.boost.org/libs/program_options // #ifndef PROGRAM_OPTIONS_NOTIFIER_H_INCLUDED #define PROGRAM_OPTIONS_NOTIFIER_H_INCLUDED namespace ProgramOptions { namespace detail { /////////////////////////////////////////////////////////////////////////////// // Notifier /////////////////////////////////////////////////////////////////////////////// // HACK: // This should actually be replaced with a proper and typesafe delegate class. // At least, it should be parametrized on the actual parameter type since // the invocation of f via the generic func is not strictly conforming. // Yet, it should work on all major compilers - we do not mess with // the address and the alignment of void* should be compatible with that of T*. template struct Notifier { typedef bool (*notify_func_type)(void*, const std::string& name, ParamT); Notifier() : obj(0), func(0) {} template Notifier(O* o, bool (*f)(O*, const std::string&, ParamT)) { obj = o; func= reinterpret_cast(f); } void* obj; notify_func_type func; bool notify(const std::string& name, ParamT val) const { return func(obj, name, val); } bool empty() const { return func == 0; } }; template struct Notify { typedef bool (*type)(ObjT*, const std::string& name, ParamT); }; } } #endif clasp-2.1.4/libprogram_opts/program_opts/detail/input_stream.h0000644000404600007640000000634611470473110024401 0ustar kaufmanncools// // Copyright (c) Benjamin Kaufmann 2004 // // This is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This file is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this file; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // // NOTE: ProgramOptions is inspired by Boost.Program_options // see: www.boost.org/libs/program_options // #ifndef PROGRAM_OPTIONS_INPUT_STREAM_H_INCLUDED #define PROGRAM_OPTIONS_INPUT_STREAM_H_INCLUDED #include #include namespace ProgramOptions { namespace detail { // A primitive input stream buffer for fast extraction from a given string // NOTE: The input string is NOT COPIED, hence it // MUST NOT CHANGE during extraction template > class input_from_string : public std::basic_streambuf { typedef std::basic_streambuf base_type; typedef typename Traits::char_type* pointer_type; typedef const typename Traits::char_type* const_pointer_type; typedef typename base_type::pos_type pos_type; typedef typename base_type::off_type off_type; public: explicit input_from_string(const_pointer_type p, size_t size) : buffer_(const_cast(p)) , size_(size) { base_type::setp(0, 0); // no write buffer base_type::setg(buffer_, buffer_, buffer_+size_); // read buffer } pos_type seekoff(off_type offset, std::ios_base::seekdir dir, std::ios_base::openmode which) { if(which & std::ios_base::out) { // not supported! return base_type::seekoff(offset, dir, which); } if(dir == std::ios_base::cur) { offset += static_cast(base_type::gptr() - base_type::eback()); } else if(dir == std::ios_base::end) { offset = static_cast(size_) - offset; } return seekpos(offset, which); } pos_type seekpos(pos_type offset, std::ios_base::openmode which) { if((which & std::ios_base::out) == 0 && offset >= pos_type(0) && ((size_t)offset) <= size_) { base_type::setg(buffer_, buffer_+(size_t)offset, buffer_+size_); return offset; } return base_type::seekpos(offset, which); } private: input_from_string(const input_from_string&); input_from_string& operator=(const input_from_string&); protected: pointer_type buffer_; size_t size_; }; template > class input_stream : public std::basic_istream { public: input_stream(const std::string& str) : std::basic_istream(0) , buffer_(str.data(), str.size()) { std::basic_istream::rdbuf(&buffer_); } input_stream(const char* x, size_t size) : std::basic_istream(0) , buffer_(x, size) { std::basic_istream::rdbuf(&buffer_); } private: input_from_string buffer_; }; } } #endif clasp-2.1.4/libprogram_opts/program_opts/detail/refcountable.h0000644000404600007640000000444711470473110024340 0ustar kaufmanncools// // Copyright (c) Benjamin Kaufmann 2010 // // This is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This file is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this file; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // // NOTE: ProgramOptions is inspired by Boost.Program_options // see: www.boost.org/libs/program_options // #ifndef PROGRAM_OPTIONS_REFCOUNTABLE_H_INCLUDED #define PROGRAM_OPTIONS_REFCOUNTABLE_H_INCLUDED namespace ProgramOptions { namespace detail { class RefCountable { public: RefCountable() : refCount_(1) {} int addRef() { return ++refCount_; } int release() { return --refCount_; } int refCount() const { return refCount_; } private: int refCount_; }; template class IntrusiveSharedPtr { public: typedef T element_type; explicit IntrusiveSharedPtr(T* p = 0) throw() : ptr_(p) { /* NO add ref */ } IntrusiveSharedPtr(const IntrusiveSharedPtr& o) throw() : ptr_(o.ptr_) { addRef(); } ~IntrusiveSharedPtr() throw () { release(); } IntrusiveSharedPtr& operator=(const IntrusiveSharedPtr& other) { other.addRef(); this->release(); this->ptr_ = other.ptr_; return *this; } T& operator*() const throw() { return *ptr_; } T* operator->() const throw() { return ptr_; } T* get() const throw() { return ptr_; } void reset() throw() { release(); ptr_ = 0; } bool unique() const throw() { return !ptr_ || ptr_->refCount() == 1; } int count() const throw() { return ptr_ ? ptr_->refCount() : 0; } void swap(IntrusiveSharedPtr& b) { T* temp = ptr_; ptr_ = b.ptr_; b.ptr_ = temp; } private: T* ptr_; void addRef() const { if (ptr_) ptr_->addRef(); } void release() const { if (ptr_ && ptr_->release() == 0) { delete ptr_; } } }; }} #endif clasp-2.1.4/libprogram_opts/program_opts/detail/value_store.h0000644000404600007640000000464511661307173024226 0ustar kaufmanncools// // Copyright (c) Benjamin Kaufmann 2010 // // This is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This file is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this file; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // // NOTE: ProgramOptions is inspired by Boost.Program_options // see: www.boost.org/libs/program_options // #ifndef PROGRAM_OPTIONS_VALUE_STORE_IMPL_H_INCLUDED #define PROGRAM_OPTIONS_VALUE_STORE_IMPL_H_INCLUDED #include namespace detail { template struct VTable { static void clone(const void* o, void** out) { *out = new T(*static_cast(o)); } static void destroy(const void* o, void** out) { delete static_cast(o); *out = 0; } static void typeinfo(const void*, void** out) { *out = const_cast( static_cast(&typeid(T)) ); } static vtable_type vtable_s; }; template struct OptVTable { static void clone(const void* o, void** out) { new (&*out) T(*static_cast(o)); } static void destroy(const void* o, void** out) { static_cast(o)->~T(); *out = 0; } static vtable_type vtable_s; }; template vtable_type VTable::vtable_s = { 0 , &VTable::clone , &VTable::destroy , &VTable::typeinfo }; template vtable_type OptVTable::vtable_s = { (vcall_type)0x1 , &OptVTable::clone , &OptVTable::destroy , &VTable::typeinfo }; template struct bool2type {}; template inline vptr_type vtable_select(bool2type<0>, const T* = 0) { return &VTable::vtable_s; } template inline vptr_type vtable_select(bool2type<1>, const T* = 0) { return &OptVTable::vtable_s; } template inline vptr_type vtable(const T* x) { return vtable_select(bool2type(), x); } template inline vptr_type base_vtable(const T* x) { return vtable_select(bool2type<0>(), x); } } #endif clasp-2.1.4/libprogram_opts/program_opts/composite_value_parser.h0000644000404600007640000000630612064610706025177 0ustar kaufmanncools// // Copyright (c) Benjamin Kaufmann 2010 // // This is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This file is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this file; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // // NOTE: ProgramOptions is inspired by Boost.Program_options // see: www.boost.org/libs/program_options // #ifndef PROGRAM_OPTIONS_COMPOSITE_VALUE_PARSER_H_INCLUDED #define PROGRAM_OPTIONS_COMPOSITE_VALUE_PARSER_H_INCLUDED #include #include "value_parser.h" #include #include #include #include namespace ProgramOptions { namespace Detail { inline StringSlice match(const StringSlice& x, char t) { if (!x.ok() || x.complete()) { return x; } return x.parsed(x.data()[0] == t, 1); } } //! parses a sequence of Ts as '['? val1 [, ...][, valn] ']'? template StringSlice parseSequence(const StringSlice& in, Out out, int maxNum, int extra) { if (in.size() == 0) return in.parsed(false); StringSlice x = in, term = Detail::match(in, '['); if (term.ok()) { x = term; } for (int num = 0, ext = extra + term.ok();;) { T temp; x = parseValue(x, temp, 1); if (!x.ok()) { return in.parsed(false); } *out = temp; ++out; ++num; if (x.complete()) { break; } if (num == maxNum || !ComponentSeparator::isSeparator(x.data()[0])) { x = ext ? x : in.parsed(false); break; } x = x.parsed(true, 1); if (x.complete()) { return in.parsed(false); } } if (term.ok()) { x = Detail::match(x, ']'); } return x.ok () && (extra != 0 || x.complete()) ? x : in.parsed(false); } //! parses a vector as sequence of Ts. template StringSlice parseValue(const StringSlice& in, std::vector& result, int extra) { size_t rSize = result.size(); StringSlice x= parseSequence(in, std::back_inserter(result), -1, extra); if (!x.ok() || (extra == 0 && !x.complete())) { result.resize(rSize); return in.parsed(false); } return x; } //! parses a pair as '('? valT [, valU] ')'? template StringSlice parseValue(const StringSlice& in, std::pair& result, int extra) { if (in.size() == 0) return in.parsed(false); StringSlice x = in, term = Detail::match(in, '('); if (term.ok()) { x = term; } T tempT(result.first); x = parseValue(x, tempT, extra+1); if (x.complete()) { if (term.ok()) { return in.parsed(false); } result.first = tempT; return x; } U tempU(result.second); if (x.ok() && x.data()[0] == ',') { x = parseValue(x.parsed(true, 1), tempU, extra + term.ok()); } if (term.ok()) { x = Detail::match(x, ')'); } if (!x.ok() || (extra == 0 && !x.complete())) { return in.parsed(false); } result.first = tempT; result.second = tempU; return x; } } #endif clasp-2.1.4/libprogram_opts/program_opts/errors.h0000644000404600007640000000653311777312266021755 0ustar kaufmanncools// // Copyright (c) Benjamin Kaufmann 2004 // // This is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This file is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this file; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // // NOTE: ProgramOptions is inspired by Boost.Program_options // see: www.boost.org/libs/program_options // #ifndef PROGRAM_OPTIONS_ERRORS_H_INCLUDED #define PROGRAM_OPTIONS_ERRORS_H_INCLUDED #include #include namespace ProgramOptions { //! Base class for all exceptions. class Error : public std::logic_error { public: explicit Error(const std::string& what) : std::logic_error(what) {} }; //! Used for signaling errors on command-line and in declaring options. class SyntaxError : public Error { public: enum Type { missing_value, extra_value, invalid_format }; SyntaxError(Type t, const std::string& key); ~SyntaxError() throw () {} Type type() const { return type_; } const std::string& key() const { return key_; } private: std::string key_; Type type_; }; //! Used for signaling errors in OptionContext. class ContextError : public Error { public: enum Type { duplicate_option, unknown_option, ambiguous_option, unknown_group, }; ContextError(const std::string& ctx, Type t, const std::string& key, const std::string& desc = ""); ~ContextError() throw () {} Type type() const { return type_; } const std::string& key() const { return key_; } const std::string& ctx() const { return ctx_; } private: std::string ctx_; std::string key_; Type type_; }; class DuplicateOption : public ContextError { public: DuplicateOption(const std::string& ctx, const std::string& key) : ContextError(ctx, ContextError::duplicate_option, key) {} ~DuplicateOption() throw () {} }; class UnknownOption : public ContextError { public: UnknownOption(const std::string& ctx, const std::string& key) : ContextError(ctx, ContextError::unknown_option, key) {} ~UnknownOption() throw () {} }; class AmbiguousOption : public ContextError { public: AmbiguousOption(const std::string& ctx, const std::string& key, const std::string& alt) : ContextError(ctx, ContextError::ambiguous_option, key, alt) {} ~AmbiguousOption() throw () {} }; //! Used for signaling validation errors when trying to assign option values. class ValueError : public Error { public: enum Type { multiple_occurences, invalid_default, invalid_value }; ValueError(const std::string& ctx, Type t, const std::string& opt, const std::string& value); ~ValueError() throw () {} Type type() const { return type_; } const std::string& key() const { return key_; } const std::string& ctx() const { return ctx_; } const std::string& value()const { return value_;} private: std::string ctx_; std::string key_; std::string value_; Type type_; }; } #endif clasp-2.1.4/libprogram_opts/program_opts/mapped_value.h0000644000404600007640000000567311665140553023101 0ustar kaufmanncools// // Copyright (c) Benjamin Kaufmann 2010 // // This is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This file is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this file; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // // NOTE: ProgramOptions is inspired by Boost.Program_options // see: www.boost.org/libs/program_options // #ifndef PROGRAM_OPTIONS_MAPPED_VALUE_H_INCLUDED #define PROGRAM_OPTIONS_MAPPED_VALUE_H_INCLUDED #ifdef _MSC_VER #pragma warning (disable : 4786) #pragma warning (disable : 4503) #endif #include "typed_value.h" #include "value_store.h" #include #include #include #if defined(_MSC_VER) && _MSC_VER <= 1200 namespace std { using ::size_t; } #endif namespace ProgramOptions { /////////////////////////////////////////////////////////////////////////////// // ValueMap /////////////////////////////////////////////////////////////////////////////// //! Type for storing anonymous values /*! * Maps option names to their values */ class ValueMap { public: ValueMap() {} ~ValueMap(){} bool empty() const { return map_.empty(); } size_t size() const { return map_.size(); } size_t count(const std::string& name) const { return map_.count(name); } void clear() { map_.clear(); } const ValueStore& operator[](const std::string& name) const { MapType::const_iterator it = map_.find(name); if (it == map_.end()) { throw UnknownOption("ValueMap", name); } return it->second; } template static bool add(ValueMap* this_, const std::string& name, const T* value) { MapType::iterator it = this_->map_.find(name); if (it == this_->map_.end()) { it = this_->map_.insert(it, MapType::value_type(name, ValueStore())); } if (it->second.extract_raw() != value) { it->second.assimilate(const_cast(value)); } return true; } private: ValueMap(const ValueMap&); ValueMap& operator=(const ValueMap&); typedef std::map MapType; MapType map_; }; /*! * Creates a value that is created on demand and stored in a given value map. * * \see OptionGroup::addOptions() */ template inline NotifiedValue* store(ValueMap& map, typename detail::Parser::type p = &DefaultParser::parse) { return notify(&map, &ValueMap::add, p); } inline NotifiedValue* flag(ValueMap& map, FlagAction a = store_true) { return flag(&map, &ValueMap::add, a); } } #endif clasp-2.1.4/libprogram_opts/program_opts/value_store.h0000644000404600007640000001065411717477572022776 0ustar kaufmanncools// // Copyright (c) Benjamin Kaufmann 2010 // // This is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This file is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this file; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // // NOTE: ProgramOptions is inspired by Boost.Program_options // see: www.boost.org/libs/program_options // #ifndef PROGRAM_OPTIONS_VALUE_STORE_H_INCLUDED #define PROGRAM_OPTIONS_VALUE_STORE_H_INCLUDED #include #include namespace ProgramOptions { namespace detail { typedef void (*vcall_type)(const void* in, void** out); typedef vcall_type vtable_type[4]; typedef vtable_type* vptr_type; // workaround: some compilers don't support // out-of-class definition of member templates. template inline vptr_type vtable(const T* = 0); template inline vptr_type base_vtable(const T* = 0); } //! A type that can hold any kind of value type class ValueStore { public: //! creates an empty object ValueStore(); //! copies the value in other ValueStore(const ValueStore& other); //! stores a copy of obj template ValueStore(const T& obj) : vptr_(detail::vtable(static_cast(0))) , value_(0) { clone(&obj, &value_); } //! releases any stored value ~ValueStore(); //! stores a copy of other releasing any previous value ValueStore& operator=(ValueStore other); //! stores a copy of obj releasing any previous value template ValueStore& operator=(const T& obj) { ValueStore(obj).swap(*this); return *this; } //! stores obj in this and takes over ownership of obj /*! * \pre delete obj is valid */ template ValueStore& assimilate(T* obj) { clear(); vptr_ = detail::base_vtable(static_cast(0)); value_= obj; return *this; } //! swaps this with other void swap(ValueStore& other); //! Returns true if holder does not contain a value. bool empty() const { return vptr_ == 0; } //! Returns the type of the stored value. const std::type_info& type() const; //! destroys and releases any stored value void clear(); //! surrenders any stored value without destroying it void surrender(); void* extract_raw() const { return !empty() ? extract(const_cast(&value_)) : 0; } private: enum { call_extract = 0, vcall_clone = 1, vcall_destroy = 2, vcall_typeid = 3 }; typedef detail::vptr_type vptr_type; void clone(const void* obj, void** out) const; void* extract(void** o) const; vptr_type vptr_; void* value_; }; struct bad_value_cast : std::bad_cast { const char * what() const throw() { return "value_cast: invalid conversion on ValueStore"; } }; //! Extracts a typed value from a ValueStore. /*! * \throw bad_value_cast if value is not of type T */ template const T& value_cast(const ValueStore& v, const T* = 0) { if (v.type() == typeid(T)) { return *static_cast(const_cast(v.extract_raw())); } throw bad_value_cast(); } //! Returns 0 on error template const T* value_cast(const ValueStore* v, const T* = 0) { if (v->type() == typeid(T)) { return static_cast(const_cast(v->extract_raw())); } return 0; } /*! * \overload */ template T& value_cast(ValueStore& v, const T* p = 0) { return const_cast(value_cast(const_cast(v), p)); } template T* value_cast(ValueStore* v, const T* p = 0) { return const_cast(value_cast(const_cast(v), p)); } //! Extracts a typed value from a ValueStore *without* checking if the type matches template const T* unsafe_value_cast(const ValueStore* v, const T* = 0) { return static_cast(const_cast(v->extract_raw())); } /*! * \overload */ template T* unsafe_value_cast(ValueStore* v, const T* p = 0) { return const_cast(unsafe_value_cast(const_cast(v), p)); } #include "detail/value_store.h" } #endif clasp-2.1.4/libprogram_opts/program_opts/program_options.h0000644000404600007640000004170611777312266023664 0ustar kaufmanncools// // Copyright (c) Benjamin Kaufmann 2004 // // This is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This file is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this file; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // // NOTE: ProgramOptions is inspired by Boost.Program_options // see: www.boost.org/libs/program_options // #ifndef PROGRAM_OPTIONS_PROGRAM_OPTIONS_H_INCLUDED #define PROGRAM_OPTIONS_PROGRAM_OPTIONS_H_INCLUDED #include "value.h" #include "detail/refcountable.h" #include #include #include #include #include #include namespace ProgramOptions { //! Represents one program option. /*! * An Option consists of a description (long name, short name, description), * a (typed) value, and an optional default value. * * \note * When printing an option, occurrences of %D, %I and %A in its description are replaced * with the option's default value, implicit value and the argument name, * respectively. */ class Option : public detail::RefCountable { public: /*! * \pre longName != "" * \pre vd != 0 * \param longName name (and unique key) of the option * \param shortName possible alias name * \param description description of the option, used for printing help * \param value value object to be associated with this option */ Option( const std::string& longName, char shortName, const char* description, Value* value); ~Option(); const std::string& name() const { return name_; } char alias() const { return value_->alias(); } Value* value() const { return value_; } const char* description() const { return description_; } const char* argName() const { return value_->arg(); } bool assignDefault() const; std::size_t maxColumn() const; DescriptionLevel descLevel() const { return value_->level(); } private: std::string name_; // name (and unique key) of option const char* description_; // description of the option (used for --help) Value* value_; // the option's value manager }; typedef detail::IntrusiveSharedPtr