Object::operator const Poco::DynamicStruct& () const { if (!_pStruct) { ValueMap::const_iterator it = _values.begin(); ValueMap::const_iterator end = _values.end(); _pStruct = new Poco::DynamicStruct; for (; it != end; ++it) { if (isObject(it)) { _pStruct->insert(it->first, makeStruct(getObject(it->first))); } else if (isArray(it)) { _pStruct->insert(it->first, Poco::JSON::Array::makeArray(getArray(it->first))); } else { _pStruct->insert(it->first, it->second); } } } return *_pStruct; }
Poco::DynamicStruct Object::makeStruct(const Object::Ptr& obj) { Poco::DynamicStruct ds; ConstIterator it = obj->begin(); ConstIterator end = obj->end(); for (; it != end; ++it) { if (obj->isObject(it)) { Object::Ptr pObj = obj->getObject(it->first); DynamicStruct str = makeStruct(pObj); ds.insert(it->first, str); } else if (obj->isArray(it)) { Array::Ptr pArr = obj->getArray(it->first); std::vector<Poco::Dynamic::Var> v = Poco::JSON::Array::makeArray(pArr); ds.insert(it->first, v); } else ds.insert(it->first, it->second); } return ds; }
void makeVisit() { //각 사람별로 모든 영화에 대해 관객수에 따라 영화를 볼것인지 아닌지 선택 srand(time(NULL)); int percent = 0; movie* temp; temp = chart; for (int i = 0; i < 1; i++) { for (int j = 0; j < MOVIE_NUM; j++) { percent = temp->audience / POPULATION; // 관객수를 POPULATION으로 나누어 확률(0~100사이)를 구함 test_aud[i]->visit[j] = 1; if (test_aud[i]->visit[j]) { test_aud[i]->view_count++; makeStruct(temp); } temp = temp->nextmovie; } } }
void BuiltIns::defineBuiltIns() { auto factory = SymbolFactory{ }; auto makeRef = [](auto&& type, bool is_const) { return VariableType(TypeFactory::getReference(type.get()), is_const); }; auto global_scope = std::make_shared<GlobalScope>(); auto int_ = factory.makeStruct("int", new StructScope("int", global_scope.get())); auto ref_int = makeRef(int_, false); auto const_ref_int = makeRef(int_, true); auto char_ = factory.makeStruct("char", new StructScope("char", global_scope.get())); auto ref_char = makeRef(char_, false); auto const_ref_char = makeRef(char_, true); auto str = factory.makeStruct("string", new StructScope("string", global_scope.get())); auto ref_str = makeRef(str, false); auto const_ref_str = makeRef(str, true); auto int_builtin = VariableType(new BuiltInTypeSymbol("~~int", Comp::config().int_size), false); auto char_builtin = VariableType(new BuiltInTypeSymbol("~~char", Comp::config().int_size), false); auto simple_traits = FunctionTraits::simple(); auto op_traits = FunctionTraits::methodOper(); auto meth_traits = FunctionTraits::method(); auto constr_traits = FunctionTraits::constructor(); auto tp = FunctionType(int_.get(), {ref_int, int_.get()}); auto void_type = std::make_unique<BuiltInTypeSymbol>("void", 0); global_scope -> define(factory.makeFunction("putchar", FunctionType(void_type.get(), {char_.get()}), simple_traits, false)); global_scope -> define(factory.makeFunction("getchar", FunctionType(int_.get(), { }), simple_traits, false)); auto string_builtin = VariableType(new BuiltInTypeSymbol("~~string", 256), false); str -> defineMember(factory.makeVariable("~~impl", string_builtin, VariableSymbolType::FIELD)); auto str_tp = FunctionType(ref_str, {ref_str, const_ref_str}); int_ -> defineMember(factory.makeVariable("~~impl", int_builtin, VariableSymbolType::FIELD)); int_ -> defineMethod(factory.makeFunction("int", FunctionType(ref_int, {ref_int}), constr_traits, false)); int_ -> defineMethod(factory.makeFunction("int", FunctionType(ref_int, {ref_int, const_ref_int}), constr_traits, false)); int_ -> defineMethod(factory.makeFunction("operator=", FunctionType(ref_int, {ref_int, const_ref_int}), op_traits, false)); int_ -> defineMethod(factory.makeFunction("operator+", tp, op_traits, false)); int_ -> defineMethod(factory.makeFunction("operator-", tp, op_traits, false)); int_ -> defineMethod(factory.makeFunction("operator*", tp, op_traits, false)); int_ -> defineMethod(factory.makeFunction("operator/", tp, op_traits, false)); int_ -> defineMethod(factory.makeFunction("operator%", tp, op_traits, false)); int_ -> defineMethod(factory.makeFunction("operator==", tp, op_traits, false)); int_ -> defineMethod(factory.makeFunction("operator!=", tp, op_traits, false)); int_ -> defineMethod(factory.makeFunction("operator&&", tp, op_traits, false)); int_ -> defineMethod(factory.makeFunction("operator||", tp, op_traits, false)); int_ -> defineMethod(factory.makeFunction("int", FunctionType(ref_int, {ref_int, char_.get()}), constr_traits, false)); char_ -> defineMember(factory.makeVariable("~~impl", char_builtin, VariableSymbolType::FIELD)); char_ -> defineMethod(factory.makeFunction("char", FunctionType(ref_char, {ref_char}), constr_traits, false)); char_ -> defineMethod(factory.makeFunction("char", FunctionType(ref_char, {ref_char, const_ref_char}), constr_traits, false)); char_ -> defineMethod(factory.makeFunction("char", FunctionType(ref_char, {ref_char, const_ref_int}), constr_traits, false)); char_ -> defineMethod(factory.makeFunction("operator=", FunctionType(ref_char, {ref_char, const_ref_char}), constr_traits, false)); str -> defineMethod(factory.makeFunction("string", str_tp, constr_traits, false)); str -> defineMethod(factory.makeFunction("length", FunctionType(int_.get(), {ref_str}), meth_traits, false)); str -> defineMethod(factory.makeFunction("operator[]", FunctionType(ref_char, {ref_str, int_.get()}), op_traits, false)); str -> defineMethod(factory.makeFunction("operator+", FunctionType(str.get(), {ref_str, const_ref_str}), op_traits, false)); str -> defineMethod(factory.makeFunction("operator=", str_tp, op_traits, false)); global_scope -> define(factory.makeFunction("print", FunctionType(void_type.get(), {const_ref_str}), simple_traits, false)); BuiltIns::int_type = int_.get(); BuiltIns::char_type = char_.get(); BuiltIns::ASCII_string_type = str.get(); BuiltIns::void_type = void_type.get(); global_scope -> define(std::move(void_type)); global_scope -> define(std::move(int_)); global_scope -> define(std::move(str)); global_scope -> define(std::move(char_)); BuiltIns::global_scope = global_scope; }