From a12deb460d12294cc8f3ef4e489b5b28640d0178 Mon Sep 17 00:00:00 2001 From: guigues Date: Wed, 11 Feb 2009 11:35:20 +0000 Subject: [PATCH] *** empty log message *** --- kernel/src/bbtkWxGUIPackageBrowser2.cxx | 5 +- samples/CMakeLists.txt | 1 + samples/SampleInterpreter/CMakeLists.txt | 24 +++++++ samples/SampleInterpreter/bbProcessing.bbs | 15 +++++ .../bbtkSampleInterpreter.cxx | 62 +++++++++++++++++++ 5 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 samples/SampleInterpreter/CMakeLists.txt create mode 100644 samples/SampleInterpreter/bbProcessing.bbs create mode 100644 samples/SampleInterpreter/bbtkSampleInterpreter.cxx diff --git a/kernel/src/bbtkWxGUIPackageBrowser2.cxx b/kernel/src/bbtkWxGUIPackageBrowser2.cxx index 5d95e06..00a8c09 100644 --- a/kernel/src/bbtkWxGUIPackageBrowser2.cxx +++ b/kernel/src/bbtkWxGUIPackageBrowser2.cxx @@ -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); diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index c6abdf6..f1f9920 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -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 index 0000000..7b32e37 --- /dev/null +++ b/samples/SampleInterpreter/CMakeLists.txt @@ -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 index 0000000..f4baaf6 --- /dev/null +++ b/samples/SampleInterpreter/bbProcessing.bbs @@ -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 index 0000000..91f4ff0 --- /dev/null +++ b/samples/SampleInterpreter/bbtkSampleInterpreter.cxx @@ -0,0 +1,62 @@ +//========================================================================= +// How to create and use a script defined black box +//========================================================================= + +//========================================================================= +#include +//========================================================================= + +//========================================================================= +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() + // (because we know it's a double !) + double v = p->bbGetOutput("Out").get(); + + std::cout << num << "+1 = "<