]> Creatis software - bbtk.git/commitdiff
*** empty log message ***
authorguigues <guigues>
Wed, 11 Feb 2009 11:35:20 +0000 (11:35 +0000)
committerguigues <guigues>
Wed, 11 Feb 2009 11:35:20 +0000 (11:35 +0000)
kernel/src/bbtkWxGUIPackageBrowser2.cxx
samples/CMakeLists.txt
samples/SampleInterpreter/CMakeLists.txt [new file with mode: 0644]
samples/SampleInterpreter/bbProcessing.bbs [new file with mode: 0644]
samples/SampleInterpreter/bbtkSampleInterpreter.cxx [new file with mode: 0644]

index 5d95e06092ef7c32c6da89eec25c141da3e2ad17..00a8c099c2c623e869ebf57977fd7c05f64ed0c4 100644 (file)
@@ -2,8 +2,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkWxGUIPackageBrowser2.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/10/17 08:18:15 $
-  Version:   $Revision: 1.11 $
+  Date:      $Date: 2009/02/11 11:35:20 $
+  Version:   $Revision: 1.12 $
 =========================================================================*/
 
 /* ---------------------------------------------------------------------
@@ -961,6 +961,7 @@ namespace bbtk
     if (!mInterpreter) mInterpreter =bbtk::Interpreter::New();
     mInterpreter->SetCommandLine(true);
     std::stringstream* buf = new std::stringstream;
+    *buf << "exec freeze_no_error" << std::endl;
     *buf << "message max 0" << std::endl; 
     *buf << "include *" << std::endl;
     mInterpreter->InterpretBuffer(buf);
index c6abdf67165c7111e41f0c3bd51b75b3c764c57d..f1f9920d128d52f6bed9543bb89ac9353c5c8161 100644 (file)
@@ -17,3 +17,4 @@ SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})
 SUBDIRS(SampleWidgetsBase)
 SUBDIRS(SampleOutputObserver)
 SUBDIRS(SampleInsertWxBlackBoxInOwnFrame)
+SUBDIRS(SampleInterpreter)
diff --git a/samples/SampleInterpreter/CMakeLists.txt b/samples/SampleInterpreter/CMakeLists.txt
new file mode 100644 (file)
index 0000000..7b32e37
--- /dev/null
@@ -0,0 +1,24 @@
+# Find bbtk
+
+# Set 'FIND_PACKAGE_VERBOSE' to have information on the packages found
+SET(FIND_PACKAGE_VERBOSE 1)
+# Find 
+FIND_PACKAGE(BBTK)
+# Use if found
+IF(BBTK_FOUND)
+INCLUDE(${BBTK_USE_FILE})
+ENDIF(BBTK_FOUND)
+
+SET(SAMPLE bbtkSampleInterpreter)
+
+# main 
+ADD_EXECUTABLE(${SAMPLE} ${SAMPLE})
+# Link with bbtk
+TARGET_LINK_LIBRARIES(${SAMPLE} ${BBTK_LIBRARIES})
+
+
+# Configure the script bbProcessing.bbs to binary dir so that the 
+# sample find it !
+CONFIGURE_FILE(bbProcessing.bbs
+  ${EXECUTABLE_OUTPUT_PATH}/bbProcessing.bbs
+  COPYONLY)
diff --git a/samples/SampleInterpreter/bbProcessing.bbs b/samples/SampleInterpreter/bbProcessing.bbs
new file mode 100644 (file)
index 0000000..f4baaf6
--- /dev/null
@@ -0,0 +1,15 @@
+# Defines the pipeline used by SampleInterpreter
+# Here simply adds 1 to a double 
+load std
+define Processing
+  new Add a
+  set a.In2 1
+
+  # create the input : plug it in a.In1
+  input In a.In1 "Input number"
+  # create the output : get it from a.Out
+  output Out a.Out "Output number"
+
+  # executing the complex box executes a
+  exec a
+endefine
diff --git a/samples/SampleInterpreter/bbtkSampleInterpreter.cxx b/samples/SampleInterpreter/bbtkSampleInterpreter.cxx
new file mode 100644 (file)
index 0000000..91f4ff0
--- /dev/null
@@ -0,0 +1,62 @@
+//=========================================================================
+// How to create and use a script defined black box
+//=========================================================================
+
+//=========================================================================
+#include <bbtkInterpreter.h>
+//=========================================================================
+
+//=========================================================================
+int main(int argv, char* argc[])
+{
+  // To track all ...
+  //  bbtk::MessageManager::SetMessageLevel("all",9);
+  
+  try
+    {
+      // Create an interpreter
+      bbtk::Interpreter::Pointer I = bbtk::Interpreter::New();
+      
+      // We tell the interpreter to throw exceptions on error
+      I->SetThrow(true);
+
+      // Interpret the file supposed to define a box called 'Processing'
+      I->InterpretFile("bbProcessing.bbs");
+      
+      // Create an instance 'p' of the 'Processing' box
+      bbtk::BlackBox::Pointer p 
+       = I->GetExecuter()->GetFactory()->NewBlackBox("Processing","p");
+      
+      // Prompt the user
+      std::cout << "Enter a number : ";
+      double num = 0;
+      std::cin >> num;
+      // Set its input 'In' to 1
+      p->bbSetInput("In",num);
+
+      // Execute it
+      p->bbExecute();
+      
+      // Print out the output 'Out':
+      // 1) We get the output with the generic bbGetOutput method.
+      // 2) It returns a bbtk::Data which can store any data type
+      // 3) We get the value of the data as a double using get<TYPE>()
+      // (because we know it's a double !)
+      double v = p->bbGetOutput("Out").get<double>();
+      
+      std::cout << num << "+1 = "<<v<<std::endl;
+       
+    }
+  catch (bbtk::Exception e)
+    {
+      std::cout << "* ERROR : "<<e.GetErrorMessage()<<std::endl;
+      return 1;
+    }
+  return 0; 
+
+
+  // To get the list of bbtk object still allocated after main ends
+  // bbtk::StaticInitTime::PrintObjectListInfo = true;
+  // bbtk::MessageManager::SetMessageLevel("object",1);
+}
+//=========================================================================