From: <ro...@us...> - 2011-06-14 19:35:17
|
Revision: 1878 http://nsclspectcl.svn.sourceforge.net/nsclspectcl/?rev=1878&view=rev Author: ron-fox Date: 2011-06-14 19:35:10 +0000 (Tue, 14 Jun 2011) Log Message: ----------- wsSpecTypes command now works. Modified Paths: -------------- trunk/nextgen/bindings/tcl/Makefile.am trunk/nextgen/bindings/tcl/packageStartup.cpp trunk/nextgen/bindings/tcl/tcltests trunk/nextgen/bindings/tcl/wsuuid.test Added Paths: ----------- trunk/nextgen/bindings/tcl/TclWsSpecTypes.cpp trunk/nextgen/bindings/tcl/TclWsSpecTypes.h trunk/nextgen/bindings/tcl/wsspectypes.tcl Modified: trunk/nextgen/bindings/tcl/Makefile.am =================================================================== --- trunk/nextgen/bindings/tcl/Makefile.am 2011-06-14 18:10:48 UTC (rev 1877) +++ trunk/nextgen/bindings/tcl/Makefile.am 2011-06-14 19:35:10 UTC (rev 1878) @@ -13,7 +13,7 @@ TclAttach.h TclDetach.h TclLoadEvents.h TclAugment.h \ TclEvRun.h TclEvtRunInfo.h TclEvtUUID.h TclWsCreate.h TclWsAttach.h TclWsDetach.h TclWsOpen.h \ - TclWsClose.h TclWsUUID.h + TclWsClose.h TclWsUUID.h TclWsSpecTypes.h libSpecTclExperiment_la_SOURCES= packageStartup.cpp \ handleManager.cpp TclCreate.cpp TclOpen.cpp \ @@ -23,7 +23,7 @@ TclDetach.cpp TclLoadEvents.cpp TclAugment.cpp \ TclEvRun.cpp TclEvtRunInfo.cpp TclEvtUUID.cpp \ TclWsCreate.cpp TclWsAttach.cpp TclWsDetach.cpp TclWsOpen.cpp \ - TclWsClose.cpp TclWsUUID.cpp + TclWsClose.cpp TclWsUUID.cpp TclWsSpecTypes.cpp libSpecTclExperiment_la_CXXFLAGS=@TCL_FLAGS@ -I@top_builddir@/Utility -I@top_builddir@/TclPlus libSpecTclExperiment_la_LIBADD=@top_builddir@/TclPlus/libtclPlus.la \ Added: trunk/nextgen/bindings/tcl/TclWsSpecTypes.cpp =================================================================== --- trunk/nextgen/bindings/tcl/TclWsSpecTypes.cpp (rev 0) +++ trunk/nextgen/bindings/tcl/TclWsSpecTypes.cpp 2011-06-14 19:35:10 UTC (rev 1878) @@ -0,0 +1,145 @@ +/* + This software is Copyright by the Board of Trustees of Michigan + State University (c) Copyright 2008 + + You may use this software under the terms of the GNU public license + (GPL). The terms of this license are described at: + + http://www.gnu.org/licenses/gpl.txt + + Author: + Ron Fox + NSCL + Michigan State University + East Lansing, MI 48824-1321 +*/ +#include <config.h> +#include "TclWsSpecTypes.h" +#include "handleManager.h" +#include <TCLInterpreter.h> +#include <TCLObject.h> +#include <spectcl_experiment.h> +#include <uuid/uuid.h> +#include <stdlib.h> +#include <uuid/uuid.h> + +/** + * The constructor uses the bas class constructor + * to do all the real work. + * @param interp - Reference to the interpreter on which this + * command (wsSpecTypese) will be registered. + */ +CTclWsSpecTypes::CTclWsSpecTypes(CTCLInterpreter& interp) : + CTclDBCommand(interp, "wsSpecTypes", true) +{} + +/** + * Simlarly the destructor uses the base class destructor to do + * all the real work: + */ +CTclWsSpecTypes::~CTclWsSpecTypes() +{ +} +/** + * This function is dispatched to when the wsSpecTypes command is actually + * executed. See the header file for a description of the syntax of the + * command. + * @param interp - Reference to the interpreter that is executing this command. + * @param objv - std::vector of object encapsulated Tcl_Obj*'s that make + * up the command keywords. + * @return int + * @retval TCL_OK - the command successfully returned information about + * the supported spectrum types. The format of this + * returned value is described in the header. + * @retval TCL_ERROR - the command failed for some reason. + * the command result is the human readable error message + * that describes why the command failed + */ +int +CTclWsSpecTypes::operator()(CTCLInterpreter& interp, + std::vector<CTCLObject>& objv) +{ + try { + + // Check for too many command line parameters: + // the code below automatically checks for too few: + + if (objv.size() > 3) { + throw std::string("Incorrect number of command line parameters"); + } + + // Get the database handle from the command, convert it to a spectcl handle + + + spectcl_experiment expHandle = getDatabaseHandle(interp, objv, 1, "spectcl::wsSpecTypes"); + + /// Figure out the attach point: + + const char* pAttachPoint(0); + std::string sAttachPoint; + + if (objv.size() == 3) { + sAttachPoint = getParameter<std::string>(interp, objv, 2); + pAttachPoint = sAttachPoint.c_str(); + + } + + // Get the spectrum types, throwing on error. + + spectcl_spectrum_type** types = spectcl_experiment_spectrumTypes(expHandle, pAttachPoint); + if (!types) { + throw std::string(spectcl_experiment_error_msg(spectcl_experiment_errno)); + } + // Success, marshall the result string, release the types storage and + // fall through to the success return: + + interp.setResult(marshallList(interp, types)); + spectcl_workspace_free_typelist(types); + + } + catch (std::string msg) { + interp.setResult(msg); + return TCL_ERROR; + } + + return TCL_OK; +} +/*----------------- Utilities -------------------------- */ + +/** + * Marshall the type list to a result list. + * The form of the result list is documented in + * the header. The format of the data structure in spectcl_experiment.h + * + * @param interp -reference to the interpreter we are running. + * @param types - The result struct of froim spectcl_experiment_spectrumTypes. + * @return std::string - stringified result list. + */ +std::string +CTclWsSpecTypes::marshallList(CTCLInterpreter& interp, spectcl_spectrum_type** types) +{ + CTCLObject resultObj; + resultObj.Bind(interp); + + // Iterate over the defined types: + + while (*types) { + spectcl_spectrum_type* item = *types; + CTCLObject element; + element.Bind(interp); + + // Build the sublist: + + element += item->s_type; + element += item->s_description; + + // Append it to the result list. + + resultObj += element; + + types++; + } + // Conver the result objec to a string: + + return std::string(resultObj); +} Added: trunk/nextgen/bindings/tcl/TclWsSpecTypes.h =================================================================== --- trunk/nextgen/bindings/tcl/TclWsSpecTypes.h (rev 0) +++ trunk/nextgen/bindings/tcl/TclWsSpecTypes.h 2011-06-14 19:35:10 UTC (rev 1878) @@ -0,0 +1,77 @@ +/* + This software is Copyright by the Board of Trustees of Michigan + State University (c) Copyright 2008 + + You may use this software under the terms of the GNU public license + (GPL). The terms of this license are described at: + + http://www.gnu.org/licenses/gpl.txt + + Author: + Ron Fox + NSCL + Michigan State University + East Lansing, MI 48824-1321 +*/ + +#ifndef _TCLWSSPECTYPES_H +#define _TCLWSSPECTYPES_H + +#ifndef _TCLDBCOMMAND_H +#include "TclDBCommand.h" +#endif + +// forward declarations: + +typedef struct _spectcl_spectrum_type spectcl_spectrum_type; + + +/** + * Implement the ::spectcl::wsSpecTypes command. This command returns the + * set of spectrum types that are currently known to the database schema + * The form of this command is: + \verbatim +::spectcl::wsSpecTypes exp-handle ?attach-point? +\endverbatim + * Where: + * - exp-handle - is a handle to an experiment database that has a workspace + * attached to it. + * - attach-point - is an optional parameter that indicates where the workspace + * is attached. If omitted, the workspace is assumed to be attached + * at WORKSPACE. + * + * The command returns a list. Each element of the list is itslef a two element list + * containing: + * - the spectrum type (used in defining a spectrum). + * - a description of what that spectrum type means. + * + * The idea is that the spectrum type is brief to make spectrum generating commands + * concise while the description is 'human readable'. + */ + +class CTclWsSpecTypes : public CTclDBCommand +{ + /* Canonicals */ +public: + CTclWsSpecTypes(CTCLInterpreter& interp); + virtual ~CTclWsSpecTypes(); + +private: + CTclWsSpecTypes& operator=(const CTclWsSpecTypes&); + int operator==(const CTclWsSpecTypes&) const; + int operator!=(const CTclWsSpecTypes&) const; + + /* Command entry point: */ + +public: + int operator()(CTCLInterpreter& interp, + std::vector<CTCLObject>& objv); + + // Utilities: + +private: + std::string marshallList(CTCLInterpreter& interp, spectcl_spectrum_type** types); +}; + + +#endif Modified: trunk/nextgen/bindings/tcl/packageStartup.cpp =================================================================== --- trunk/nextgen/bindings/tcl/packageStartup.cpp 2011-06-14 18:10:48 UTC (rev 1877) +++ trunk/nextgen/bindings/tcl/packageStartup.cpp 2011-06-14 19:35:10 UTC (rev 1878) @@ -39,7 +39,9 @@ #include "TclWsOpen.h" #include "TclWsClose.h" #include "TclWsUUID.h" +#include "TclWsSpecTypes.h" + /** Include command processor headers here */ const static char* version="1.0"; @@ -92,6 +94,7 @@ new CTclWsOpen(*interp); new CTclWsClose(*interp); new CTclWsUUID(*interp); + new CTclWsSpecTypes(*interp); return TCL_OK; } Modified: trunk/nextgen/bindings/tcl/tcltests =================================================================== --- trunk/nextgen/bindings/tcl/tcltests 2011-06-14 18:10:48 UTC (rev 1877) +++ trunk/nextgen/bindings/tcl/tcltests 2011-06-14 19:35:10 UTC (rev 1878) @@ -1,6 +1,6 @@ package require tcltest - tcltest::matchFiles [list wsuuid.test] + tcltest::matchFiles [list wsspectypes.test] tcltest::runAllTests Added: trunk/nextgen/bindings/tcl/wsspectypes.tcl =================================================================== Modified: trunk/nextgen/bindings/tcl/wsuuid.test =================================================================== --- trunk/nextgen/bindings/tcl/wsuuid.test 2011-06-14 18:10:48 UTC (rev 1877) +++ trunk/nextgen/bindings/tcl/wsuuid.test 2011-06-14 19:35:10 UTC (rev 1878) @@ -9,7 +9,7 @@ #-------------------------- The tests ---------------- -test fail_1 {wsUUID needs a database handle} \ +test exists {wsUUID command must exist} \ -body { info commands ::spectcl::wsUUID } -result ::spectcl::wsUUID This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |