[cig-commits] r8948 - cs/benchmark/cigma/trunk/src

luis at geodynamics.org luis at geodynamics.org
Wed Dec 19 12:06:53 PST 2007


Author: luis
Date: 2007-12-19 12:06:53 -0800 (Wed, 19 Dec 2007)
New Revision: 8948

Added:
   cs/benchmark/cigma/trunk/src/SkelCmd.cpp
   cs/benchmark/cigma/trunk/src/SkelCmd.h
Modified:
   cs/benchmark/cigma/trunk/src/CommandSet.cpp
Log:
Added example SkelCmd class

Modified: cs/benchmark/cigma/trunk/src/CommandSet.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/CommandSet.cpp	2007-12-19 20:06:46 UTC (rev 8947)
+++ cs/benchmark/cigma/trunk/src/CommandSet.cpp	2007-12-19 20:06:53 UTC (rev 8948)
@@ -2,6 +2,7 @@
 #include <cstdlib>
 #include <cassert>
 #include "CommandSet.h"
+#include "SkelCmd.h"
 #include "HelpCmd.h"
 #include "ExtractCmd.h"
 #include "EvalCmd.h"
@@ -31,6 +32,7 @@
     addCommand(new ExtractCmd());
     addCommand(new EvalCmd());
     addCommand(new CompareCmd());
+    addCommand(new SkelCmd());
 
     /* once assembled, pass set of commands to help command */
     help->setCmdMap(&commands);

Added: cs/benchmark/cigma/trunk/src/SkelCmd.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/SkelCmd.cpp	2007-12-19 20:06:46 UTC (rev 8947)
+++ cs/benchmark/cigma/trunk/src/SkelCmd.cpp	2007-12-19 20:06:53 UTC (rev 8948)
@@ -0,0 +1,86 @@
+#include <iostream>
+#include <cassert>
+#include "SkelCmd.h"
+
+
+// ---------------------------------------------------------------------------
+
+cigma::SkelCmd::SkelCmd()
+{
+    name = "skel"; // XXX: change name of your command here
+}
+
+
+cigma::SkelCmd::~SkelCmd()
+{
+}
+
+
+// ---------------------------------------------------------------------------
+
+void cigma::SkelCmd::setupOptions(AnyOption *opt)
+{
+    /*
+     * Here, we define the command line options and flags that will be read
+     * from the cmdline params (argc,argv). We also define the usage in
+     * here (triggered by `cigma help skel').
+     */
+    std::cout << "Calling cigma::SkelCmd::setupOptions()" << std::endl;
+    assert(opt != 0);
+
+    /* setup usage */
+
+    opt->addUsage("Usage:");
+    opt->addUsage("");
+    opt->addUsage("   cigma skel [args]");
+    opt->addUsage("");
+    opt->addUsage("");
+
+
+    /* setup flags and options */
+
+    opt->setFlag("help",'h'); // XXX: need to set at least one flag or option (bug in AnyOption)
+}
+
+
+void cigma::SkelCmd::configure(AnyOption *opt)
+{
+    /*
+     * Here, we perform validation on the flag and option values, and
+     * correspondingly change the internal state of our object
+     */
+    std::cout << "Calling cigma::SkelCmd::configure()" << std::endl;
+    assert(opt != 0);
+    myVar1 = 1;
+    myVar2 = 2.0;
+}
+
+
+int cigma::SkelCmd::run()
+{
+    /*
+     * Here we perform the action that represents our command,
+     * and then return an appropriate exit code.
+     */
+    std::cout << "Calling cigma::SkelCmd::run()" << std::endl;
+
+    myMethod1();
+    myMethod2();
+
+    return 0;
+}
+
+
+// ---------------------------------------------------------------------------
+
+void cigma::SkelCmd::myMethod1()
+{
+    myVar1 += 1;
+}
+
+void cigma::SkelCmd::myMethod2()
+{
+    myVar2 += 2.0;
+}
+
+// ---------------------------------------------------------------------------

Added: cs/benchmark/cigma/trunk/src/SkelCmd.h
===================================================================
--- cs/benchmark/cigma/trunk/src/SkelCmd.h	2007-12-19 20:06:46 UTC (rev 8947)
+++ cs/benchmark/cigma/trunk/src/SkelCmd.h	2007-12-19 20:06:53 UTC (rev 8948)
@@ -0,0 +1,38 @@
+#ifndef __SKEL_CMD_H__
+#define __SKEL_CMD_H__
+
+#include <vector>
+#include "Command.h"
+
+namespace cigma
+{
+    class SkelCmd;
+}
+
+
+/**
+ * @brief Skeleton class for creating a new command
+ *
+ */
+class cigma::SkelCmd : public Command
+{
+public:
+    SkelCmd();
+    ~SkelCmd();
+
+public:
+    void setupOptions(AnyOption *opt);
+    void configure(AnyOption *opt);
+    int run();
+
+public:
+    void myMethod1();
+    void myMethod2();
+
+public:
+    int myVar1;
+    double myVar2;
+};
+
+
+#endif



More information about the cig-commits mailing list