1 //=========================================================================
2 // How to create and use a script defined black box
3 //=========================================================================
5 //=========================================================================
6 #include <bbtkInterpreter.h>
7 //=========================================================================
9 //=========================================================================
10 int main(int argv, char* argc[])
13 // bbtk::MessageManager::SetMessageLevel("all",9);
17 // Create an interpreter
18 bbtk::Interpreter::Pointer I = bbtk::Interpreter::New();
20 // We tell the interpreter to throw exceptions on error
23 // Interpret the file supposed to define a box called 'Processing'
24 I->InterpretFile("bbProcessing.bbs");
26 // Create an instance 'p' of the 'Processing' box
27 bbtk::BlackBox::Pointer p
28 = I->GetExecuter()->GetFactory()->NewBlackBox("Processing","p");
31 std::cout << "Enter a number : ";
34 // Set its input 'In' to 1
35 p->bbSetInput("In",num);
40 // Print out the output 'Out':
41 // 1) We get the output with the generic bbGetOutput method.
42 // 2) It returns a bbtk::Data which can store any data type
43 // 3) We get the value of the data as a double using get<TYPE>()
44 // (because we know it's a double !)
45 double v = p->bbGetOutput("Out").get<double>();
47 std::cout << num << "+1 = "<<v<<std::endl;
50 catch (bbtk::Exception e)
52 std::cout << "* ERROR : "<<e.GetErrorMessage()<<std::endl;
58 // To get the list of bbtk object still allocated after main ends
59 // bbtk::StaticInitTime::PrintObjectListInfo = true;
60 // bbtk::MessageManager::SetMessageLevel("object",1);
62 //=========================================================================