diff options
author | fcolin | 2011-11-18 12:14:12 +0000 |
---|---|---|
committer | fcolin | 2011-11-18 12:14:12 +0000 |
commit | 6bcf419d2e8f739b432d4790d1ba9d48ab65365b (patch) | |
tree | 92815e16f189c8e328dff4fcfa38ebe1d0217fdd /ARMFCaptureD3D/ConfigFile/example.cpp | |
parent | 487e963b081d7ffe2ddf489e11d927982c9101a6 (diff) | |
download | amilis-master.zip amilis-master.tar.gz amilis-master.tar.bz2 amilis-master.tar.xz |
Diffstat (limited to 'ARMFCaptureD3D/ConfigFile/example.cpp')
-rw-r--r-- | ARMFCaptureD3D/ConfigFile/example.cpp | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/ARMFCaptureD3D/ConfigFile/example.cpp b/ARMFCaptureD3D/ConfigFile/example.cpp new file mode 100644 index 0000000..e0d24c0 --- /dev/null +++ b/ARMFCaptureD3D/ConfigFile/example.cpp @@ -0,0 +1,111 @@ +// example.cpp
+// Program to demonstrate ConfigFile class
+
+#include <string>
+#include <iostream>
+#include "ConfigFile.h"
+#include "Triplet.h"
+
+using std::string;
+using std::cout;
+using std::endl;
+
+int main( void )
+{
+ // A configuration file can be loaded with a simple
+
+ ConfigFile config( "example.inp" );
+
+ // Values can be read from the file by name
+
+ int apples;
+ config.readInto( apples, "apples" );
+ cout << "The number of apples is " << apples << endl;
+
+ double price;
+ config.readInto( price, "price" );
+ cout << "The price is $" << price << endl;
+
+ string title;
+ config.readInto( title, "title" );
+ cout << "The title of the song is " << title << endl;
+
+ // We can provide default values in case the name is not found
+
+ int oranges;
+ config.readInto( oranges, "oranges", 0 );
+ cout << "The number of oranges is " << oranges << endl;
+
+ int fruit = 0;
+ fruit += config.read( "apples", 0 );
+ fruit += config.read( "pears", 0 );
+ fruit += config.read( "oranges", 0 );
+ cout << "The total number of apples, pears, and oranges is ";
+ cout << fruit << endl;
+
+ // Sometimes we must tell the compiler what data type we want to
+ // read when it's not clear from arguments given to read()
+
+ int pears = config.read<int>( "pears" );
+ cout << "The number of pears is " << pears;
+ cout << ", but you knew that already" << endl;
+
+ // The value is interpreted as the requested data type
+
+ cout << "The weight is ";
+ cout << config.read<string>("weight");
+ cout << " as a string" << endl;
+
+ cout << "The weight is ";
+ cout << config.read<double>("weight");
+ cout << " as a double" << endl;
+
+ cout << "The weight is ";
+ cout << config.read<int>("weight");
+ cout << " as an integer" << endl;
+
+ // When reading boolean values, a wide variety of words are
+ // recognized, including "true", "yes", and "1"
+
+ if( config.read( "sale", false ) )
+ cout << "The fruit is on sale" << endl;
+ else
+ cout << "The fruit is full price" << endl;
+
+ // We can also read user-defined types, as long as the input and
+ // output operators, >> and <<, are defined
+
+ Triplet point;
+ config.readInto( point, "zone" );
+ cout << "The first point in the zone is " << point << endl;
+
+ // The readInto() functions report whether the named value was found
+
+ int pommes = 0;
+ if( config.readInto( pommes, "pommes" ) )
+ cout << "The input file is in French: ";
+ else if( config.readInto( pommes, "apples" ) )
+ cout << "The input file is in English: ";
+ cout << "The number of pommes (apples) is " << pommes << endl;
+
+ // Named values can be added to a ConfigFile
+
+ config.add( "zucchini", 12 );
+ int zucchini = config.read( "zucchini", 0 );
+ cout << "The number of zucchini was set to " << zucchini << endl;
+
+ // And values can be removed
+
+ config.remove( "pears" );
+ if( config.readInto( pears, "pears" ) )
+ cout << "The pears are ready" << endl;
+ else
+ cout << "The pears have been eaten" << endl;
+
+ // An entire ConfigFile can written (and restored)
+
+ cout << "Here is the modified configuration file:" << endl;
+ cout << config;
+
+ return 0;
+}
|