Synopsis - Cross-Reference
File: /tests/Cxx-API/Python/src/Dict.cc1#include <Synopsis/Python/Object.hh> 2#include "Guard.hh" 3#include <string> 4#include <iostream> 5 6using namespace Synopsis::Python; 7 8void test1() 9{ 10 Dict dict; 11 dict.set('a', 'A'); 12 dict.set(1, 2); 13 dict.set("hello", "world"); 14 std::cout << Object::narrow<const char *>(dict.str()) << std::endl; 15 std::cout << Object::narrow<const char *>(dict.keys().str()) << std::endl; 16 std::cout << Object::narrow<const char *>(dict.values().str()) << std::endl; 17 std::cout << Object::narrow<const char *>(dict.items().str()) << std::endl; 18} 19 20void test2() 21{ 22 Dict dict; 23 dict.set('a', 'A'); 24 std::cout << Object::narrow<const char *>(dict.get('a').str()) << std::endl; 25 std::cout << Object::narrow<const char *>(dict.get('b').str()) << std::endl; 26 dict.set(1, 2); 27 dict.set("hello", "world"); 28 for (Dict::iterator i = dict.begin(); i != dict.end(); ++i) 29 std::cout << Object::narrow<const char *>((*i).str()) << std::endl; 30} 31 32int main(int, char **) 33{ 34 try 35 { 36 test1(); 37 test2(); 38 } 39 catch (const std::exception &e) 40 { 41 std::cout << "Error : " << e.what() << std::endl; 42 } 43}