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 : ";
35 // Set its input 'In' to num
36 p->bbSetInput("In",num);
41 // Print out the output 'Out':
42 // 1) We get the output with the generic bbGetOutput method.
43 // 2) It returns a bbtk::Data which can store any data type
44 // 3) We get the value of the data as a double using get<TYPE>()
45 // (because we know it's a double !)
46 double v = p->bbGetOutput("Out").get<double>();
48 std::cout << num << "+1 = "<<v<<std::endl;
50 //============================================================
51 // Second example : imagine the bbProcessing.bbs script has created
52 // the box "a" of type Processing
53 // Here we simulate it using:
54 I->InterpretLine("new Processing a");
55 // We get a the black box "a" in the workspace:
56 bbtk::BlackBox::Pointer a
57 = I->GetExecuter()->GetWorkspace()->GetPrototype()->bbGetBlackBox("a");
58 // Then the same as previously...
59 a->bbSetInput("In",num);
61 double w = p->bbGetOutput("Out").get<double>();
62 std::cout << "In case you did not understand:"<<std::endl<<num << "+1 = "<<w<<std::endl;
66 catch (bbtk::Exception e)
68 std::cout << "* ERROR : "<<e.GetErrorMessage()<<std::endl;
74 // To get the list of bbtk object still allocated after main ends
75 // bbtk::StaticInitTime::PrintObjectListInfo = true;
76 // bbtk::MessageManager::SetMessageLevel("object",1);
78 //=========================================================================