summaryrefslogtreecommitdiffstats
path: root/examples/features
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2009-10-11 14:18:55 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2009-10-11 14:18:55 +0200
commitc16222907ea84936f43f5fdd8500a6a19be993ee (patch)
tree63cc98ecc60eb349f1eab279fdeb12b567adf5f7 /examples/features
parent5d6f8aad8aaa3cdc3c52848c8adbc271dbe8e5e2 (diff)
downloadcli-c16222907ea84936f43f5fdd8500a6a19be993ee.tar.gz
cli-c16222907ea84936f43f5fdd8500a6a19be993ee.tar.xz
cli-c16222907ea84936f43f5fdd8500a6a19be993ee.zip
Add another example, README files, and VC++ projects/solutions
Diffstat (limited to 'examples/features')
-rw-r--r--examples/features/README21
-rw-r--r--examples/features/driver.cxx62
-rw-r--r--examples/features/features-8.0.vcproj237
-rw-r--r--examples/features/features-9.0.vcproj233
-rw-r--r--examples/features/makefile63
-rw-r--r--examples/features/options.cli39
6 files changed, 655 insertions, 0 deletions
diff --git a/examples/features/README b/examples/features/README
new file mode 100644
index 0000000..fc30a53
--- /dev/null
+++ b/examples/features/README
@@ -0,0 +1,21 @@
+This example shows how to use various features of the CLI language.
+
+The example consists of the following files:
+
+options.cli
+ Options class definition in the CLI language.
+
+options.hxx
+options.ixx
+options.cxx
+ Options class implementation in C++. These files are generated by the CLI
+ compiler from hello.cli using the following command line:
+
+ cli options.cli
+
+driver.cxx
+ Driver for the example. It first instantiates the option class which parses
+ the command line. The driver then examines and prints the options values.
+
+To run the example you can try various command lines suggested in the
+options.cli file.
diff --git a/examples/features/driver.cxx b/examples/features/driver.cxx
new file mode 100644
index 0000000..339f4c1
--- /dev/null
+++ b/examples/features/driver.cxx
@@ -0,0 +1,62 @@
+// file : examples/features/driver.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#include <iostream>
+#include <iterator>
+#include <algorithm>
+
+#include "options.hxx"
+
+using namespace std;
+
+int
+main (int argc, char* argv[])
+{
+ try
+ {
+ features::options o (argc, argv);
+
+ // --out-dir | -o
+ //
+ if (!o.out_dir ().empty ())
+ cerr << "output dir: " << o.out_dir () << endl;
+
+ // --first-name & --last-name
+ //
+ cerr << "first name: " << o.first_name () << endl
+ << "last name : " << o.last_name () << endl;
+
+ // --vector | -v & --set | -s
+ //
+ if (!o.vector ().empty ())
+ {
+ copy (o.vector ().begin (), o.vector ().end (),
+ ostream_iterator<int> (cerr, " "));
+ cerr << endl;
+ }
+
+ if (!o.set ().empty ())
+ {
+ copy (o.set ().begin (), o.set ().end (),
+ ostream_iterator<int> (cerr, " "));
+ cerr << endl;
+ }
+
+ // --map | -m
+ //
+ typedef map<std::string, std::string> str_map;
+ const str_map& m (o.map ());
+ str_map::const_iterator i (m.find ("a"));
+
+ if (i != m.end ())
+ cerr << "value for the 'a' key: " << i->second << endl;
+
+ }
+ catch (const cli::exception& e)
+ {
+ cerr << e << endl;
+ return 1;
+ }
+}
diff --git a/examples/features/features-8.0.vcproj b/examples/features/features-8.0.vcproj
new file mode 100644
index 0000000..e7d27b8
--- /dev/null
+++ b/examples/features/features-8.0.vcproj
@@ -0,0 +1,237 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="features"
+ ProjectGUID="{FA7FD071-4FF6-4EB3-96E0-95366AB2CA6F}"
+ RootNamespace="features"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="2"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ RuntimeLibrary="2"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{6A1107DB-7C6A-4A11-9CFE-459920046C0F}"
+ >
+ <File
+ RelativePath=".\driver.cxx"
+ >
+ </File>
+ <File
+ RelativePath=".\options.cxx"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{D90959E6-C0B2-4EFA-90D2-B89A6CB5705B}"
+ >
+ <File
+ RelativePath=".\options.hxx"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="CLI Files"
+ Filter="*.cli"
+ >
+ <File
+ RelativePath=".\options.cli"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ Description="cli options.cli"
+ CommandLine="..\..\cli\cli.exe options.cli"
+ Outputs="options.hxx;options.ixx;options.cxx"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ Description="cli options.cli"
+ CommandLine="..\..\cli\cli.exe options.cli"
+ Outputs="options.hxx;options.ixx;options.cxx"
+ />
+ </FileConfiguration>
+ </File>
+ </Filter>
+ <Filter
+ Name="Inline Files"
+ Filter="*.ixx"
+ >
+ <File
+ RelativePath=".\options.ixx"
+ >
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/examples/features/features-9.0.vcproj b/examples/features/features-9.0.vcproj
new file mode 100644
index 0000000..bf18ffc
--- /dev/null
+++ b/examples/features/features-9.0.vcproj
@@ -0,0 +1,233 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9.00"
+ Name="features"
+ ProjectGUID="{A2A8DB0D-FA16-4F85-9775-8ADBDD06AE90}"
+ RootNamespace="features"
+ Keyword="Win32Proj"
+ TargetFrameworkVersion="196613"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="2"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ EnableIntrinsicFunctions="true"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ RuntimeLibrary="2"
+ EnableFunctionLevelLinking="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{BFE61235-527C-4E63-BD47-3FE0704D9142}"
+ >
+ <File
+ RelativePath=".\driver.cxx"
+ >
+ </File>
+ <File
+ RelativePath=".\options.cxx"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{FD0912F2-D273-4BA9-B66D-81BA1C037991}"
+ >
+ <File
+ RelativePath=".\options.hxx"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Inline Files"
+ Filter="*.ixx"
+ >
+ <File
+ RelativePath=".\options.ixx"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="CLI Files"
+ Filter="*.cli"
+ >
+ <File
+ RelativePath=".\options.cli"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ Description="cli options.cli"
+ CommandLine="..\..\cli\cli.exe options.cli"
+ Outputs="options.hxx;options.ixx;options.cxx"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ Description="cli options.cli"
+ CommandLine="..\..\cli\cli.exe options.cli"
+ Outputs="options.hxx;options.ixx;options.cxx"
+ />
+ </FileConfiguration>
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/examples/features/makefile b/examples/features/makefile
new file mode 100644
index 0000000..c599afe
--- /dev/null
+++ b/examples/features/makefile
@@ -0,0 +1,63 @@
+# file : examples/features/makefile
+# author : Boris Kolpackov <boris@codesynthesis.com>
+# copyright : Copyright (c) 2009 Code Synthesis Tools CC
+# license : MIT; see accompanying LICENSE file
+
+include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make
+
+cli := options.cli
+cxx := driver.cxx
+
+obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(cli:.cli=.o))
+dep := $(obj:.o=.o.d)
+
+driver := $(out_base)/driver
+clean := $(out_base)/.clean
+
+# Build.
+#
+$(driver): $(obj)
+
+$(obj) $(dep): cpp_options := -I$(out_base)
+
+genf := $(cli:.cli=.hxx) $(cli:.cli=.ixx) $(cli:.cli=.cxx)
+gen := $(addprefix $(out_base)/,$(genf))
+
+$(gen): cli := $(out_root)/cli/cli
+$(gen): $(out_root)/cli/cli
+
+$(call include-dep,$(dep),$(obj),$(gen))
+
+# Convenience alias for default target.
+#
+$(out_base)/: $(driver)
+
+# Clean.
+#
+$(clean): $(driver).o.clean \
+ $(addsuffix .cxx.clean,$(obj)) \
+ $(addsuffix .cxx.clean,$(dep)) \
+ $(addprefix $(out_base)/,$(cli:.cli=.cxx.cli.clean))
+
+# Generated .gitignore.
+#
+ifeq ($(out_base),$(src_base))
+$(gen): | $(out_base)/.gitignore
+$(driver): | $(out_base)/.gitignore
+
+$(out_base)/.gitignore: files := driver $(genf)
+$(clean): $(out_base)/.gitignore.clean
+
+$(call include,$(bld_root)/git/gitignore.make)
+endif
+
+# How to.
+#
+$(call include,$(bld_root)/cxx/o-e.make)
+$(call include,$(bld_root)/cxx/cxx-o.make)
+$(call include,$(bld_root)/cxx/cxx-d.make)
+$(call include,$(scf_root)/cli/cli-cxx.make)
+
+# Dependencies.
+#
+$(call import,$(src_root)/cli/makefile)
diff --git a/examples/features/options.cli b/examples/features/options.cli
new file mode 100644
index 0000000..e6a8738
--- /dev/null
+++ b/examples/features/options.cli
@@ -0,0 +1,39 @@
+include <set>;
+include <map>;
+include <vector>;
+include <string>;
+
+// We can place the options classes into namespaces which mapped to C++
+// namespaces.
+//
+namespace features
+{
+ class options
+ {
+ // We can have several aliases for the same option. The first one is used
+ // to derive the accessor name.
+ //
+ std::string --out-dir | -o;
+
+ // We can use both assignment and constructor notations to provide the
+ // default option value.
+ //
+ std::string --first-name = "John";
+ std::string --last-name ("Mr John Doe", 8, 3);
+
+ // We can use containers to to collect option value. If we have a command
+ // line like this: -v 1 -v 2 -v 1 -s 1 -s 2 -s 1 then the vector returned
+ // by the vector() accessor will contain three elements: 1, 2, and 1 while
+ // the set returned by the set() accessor will contain two elements: 1 and
+ // 2.
+ //
+ std::vector<int> --vector | -v;
+ std::set<int> --set | -s;
+
+ // We can also use maps. In this case the option value is expected to have
+ // two part, the key and the value, separated by '='. For example: -m a=A
+ // -m =B -m c= -m d (same as -m d=).
+ //
+ std::map<std::string, std::string> --map | -m;
+ };
+}