{"text":"\/*\n * Copyright 2019 ScyllaDB\n *\/\n\n\/*\n * This file is part of Scylla.\n *\n * See the LICENSE.PROPRIETARY file in the top-level directory for licensing information.\n *\/\n\n#include \"base64.hh\"\n#include \"log.hh\"\n#include \"serialization.hh\"\n#include \"error.hh\"\n#include \"rapidjson\/writer.h\"\n\nstatic logging::logger slogger(\"alternator-serialization\");\n\nnamespace alternator {\n\ntype_info type_info_from_string(std::string type) {\n static thread_local const std::unordered_map type_infos = {\n {\"S\", {alternator_type::S, utf8_type}},\n {\"B\", {alternator_type::B, bytes_type}},\n {\"BOOL\", {alternator_type::BOOL, boolean_type}},\n {\"N\", {alternator_type::N, decimal_type}}, \/\/FIXME: Replace with custom Alternator type when implemented\n };\n auto it = type_infos.find(type);\n if (it == type_infos.end()) {\n return {alternator_type::NOT_SUPPORTED_YET, utf8_type};\n }\n return it->second;\n}\n\ntype_representation represent_type(alternator_type atype) {\n static thread_local const std::unordered_map type_representations = {\n {alternator_type::S, {\"S\", utf8_type}},\n {alternator_type::B, {\"B\", bytes_type}},\n {alternator_type::BOOL, {\"BOOL\", boolean_type}},\n {alternator_type::N, {\"N\", decimal_type}}, \/\/FIXME: Replace with custom Alternator type when implemented\n };\n auto it = type_representations.find(atype);\n if (it == type_representations.end()) {\n throw std::runtime_error(format(\"Unknown alternator type {}\", int8_t(atype)));\n }\n return it->second;\n}\n\nbytes serialize_item(const rjson::value& item) {\n if (item.IsNull() || item.MemberCount() != 1) {\n throw api_error(\"ValidationException\", format(\"An item can contain only one attribute definition: {}\", item));\n }\n auto it = item.MemberBegin();\n type_info type_info = type_info_from_string(it->name.GetString()); \/\/ JSON keys are guaranteed to be strings\n\n if (type_info.atype == alternator_type::NOT_SUPPORTED_YET) {\n slogger.trace(\"Non-optimal serialization of type {}\", it->name.GetString());\n return bytes{int8_t(type_info.atype)} + to_bytes(rjson::print(item));\n }\n\n bytes serialized;\n \/\/ Alternator bytes representation does not start with \"0x\" followed by hex digits as Scylla-JSON does,\n \/\/ but instead uses base64.\n\n if (type_info.dtype == bytes_type) {\n std::string raw_value = it->value.GetString();\n serialized = base64_decode(std::string_view(raw_value));\n } else if (type_info.dtype == decimal_type) {\n serialized = type_info.dtype->from_string(it->value.GetString());\n } else if (type_info.dtype == boolean_type) {\n serialized = type_info.dtype->from_json_object(Json::Value(it->value.GetBool()), cql_serialization_format::internal());\n } else {\n \t\/\/FIXME(sarna): Once we have type visitors, this double conversion hack should be replaced with parsing straight from rapidjson\n serialized = type_info.dtype->from_json_object(Json::Value(rjson::print(it->value)), cql_serialization_format::internal());\n }\n\n \/\/NOTICE: redundant copy here, from_json_object should accept bytes' output iterator too.\n \/\/ Or, we could append type info to the end, but that's unorthodox.\n return bytes{int8_t(type_info.atype)} + std::move(serialized);\n}\n\nrjson::value deserialize_item(bytes_view bv) {\n rjson::value deserialized(rapidjson::kObjectType);\n if (bv.empty()) {\n throw api_error(\"ValidationException\", \"Serialized value empty\");\n }\n\n alternator_type atype = alternator_type(bv[0]);\n bv.remove_prefix(1);\n\n if (atype == alternator_type::NOT_SUPPORTED_YET) {\n slogger.trace(\"Non-optimal deserialization of alternator type {}\", int8_t(atype));\n return rjson::parse_raw(reinterpret_cast(bv.data()), bv.size());\n }\n\n type_representation type_representation = represent_type(atype);\n if (type_representation.dtype == bytes_type) {\n std::string b64 = base64_encode(bv);\n rjson::set_with_string_name(deserialized, type_representation.ident, rjson::from_string(b64));\n } else if (type_representation.dtype == decimal_type) {\n auto s = decimal_type->to_json_string(bytes(bv)); \/\/FIXME(sarna): unnecessary copy\n rjson::set_with_string_name(deserialized, type_representation.ident, rjson::from_string(s));\n } else {\n rjson::set_with_string_name(deserialized, type_representation.ident, rjson::parse(type_representation.dtype->to_string(bytes(bv))));\n }\n\n return deserialized;\n}\n\nstd::string type_to_string(data_type type) {\n static thread_local std::unordered_map types = {\n {utf8_type, \"S\"},\n {bytes_type, \"B\"},\n {boolean_type, \"BOOL\"},\n {decimal_type, \"N\"}, \/\/ FIXME: use a specialized Alternator number type instead of the general decimal_type\n };\n auto it = types.find(type);\n if (it == types.end()) {\n throw std::runtime_error(format(\"Unknown type {}\", type->name()));\n }\n return it->second;\n}\n\nbytes get_key_column_value(const rjson::value& item, const column_definition& column) {\n std::string column_name = column.name_as_text();\n std::string expected_type = type_to_string(column.type);\n\n const rjson::value& key_typed_value = rjson::get(item, rjson::value::StringRefType(column_name.c_str()));\n if (!key_typed_value.IsObject() || key_typed_value.MemberCount() != 1) {\n throw api_error(\"ValidationException\",\n format(\"Missing or invalid value object for key column {}: {}\", column_name, item));\n }\n return get_key_from_typed_value(key_typed_value, column, expected_type);\n}\n\nbytes get_key_from_typed_value(const rjson::value& key_typed_value, const column_definition& column, const std::string& expected_type) {\n auto it = key_typed_value.MemberBegin();\n if (it->name.GetString() != expected_type) {\n throw api_error(\"ValidationException\",\n format(\"Expected type {} for key column {}, got type {}\",\n expected_type, column.name_as_text(), it->name.GetString()));\n }\n if (column.type == bytes_type) {\n return base64_decode(it->value.GetString());\n } else {\n return column.type->from_string(it->value.GetString());\n }\n\n}\n\nrjson::value json_key_column_value(bytes_view cell, const column_definition& column) {\n if (column.type == bytes_type) {\n std::string b64 = base64_encode(cell);\n return rjson::from_string(b64);\n } if (column.type == utf8_type) {\n return rjson::from_string(std::string(reinterpret_cast(cell.data()), cell.size()));\n } else if (column.type == decimal_type) {\n \/\/ FIXME: use specialized Alternator number type, not the more\n \/\/ general \"decimal_type\". A dedicated type can be more efficient\n \/\/ in storage space and in parsing speed.\n auto s = decimal_type->to_json_string(bytes(cell));\n return rjson::from_string(s);\n } else {\n \/\/ We shouldn't get here, we shouldn't see such key columns.\n throw std::runtime_error(format(\"Unexpected key type: {}\", column.type->name()));\n }\n}\n\n\npartition_key pk_from_json(const rjson::value& item, schema_ptr schema) {\n std::vector raw_pk;\n \/\/ FIXME: this is a loop, but we really allow only one partition key column.\n for (const column_definition& cdef : schema->partition_key_columns()) {\n bytes raw_value = get_key_column_value(item, cdef);\n raw_pk.push_back(std::move(raw_value));\n }\n return partition_key::from_exploded(raw_pk);\n}\n\nclustering_key ck_from_json(const rjson::value& item, schema_ptr schema) {\n if (schema->clustering_key_size() == 0) {\n return clustering_key::make_empty();\n }\n std::vector raw_ck;\n \/\/ FIXME: this is a loop, but we really allow only one clustering key column.\n for (const column_definition& cdef : schema->clustering_key_columns()) {\n bytes raw_value = get_key_column_value(item, cdef);\n raw_ck.push_back(std::move(raw_value));\n }\n\n return clustering_key::from_exploded(raw_ck);\n}\n\n}\nalternator: migrate to visitor pattern in serialization\/*\n * Copyright 2019 ScyllaDB\n *\/\n\n\/*\n * This file is part of Scylla.\n *\n * See the LICENSE.PROPRIETARY file in the top-level directory for licensing information.\n *\/\n\n#include \"base64.hh\"\n#include \"log.hh\"\n#include \"serialization.hh\"\n#include \"error.hh\"\n#include \"rapidjson\/writer.h\"\n#include \"concrete_types.hh\"\n\nstatic logging::logger slogger(\"alternator-serialization\");\n\nnamespace alternator {\n\ntype_info type_info_from_string(std::string type) {\n static thread_local const std::unordered_map type_infos = {\n {\"S\", {alternator_type::S, utf8_type}},\n {\"B\", {alternator_type::B, bytes_type}},\n {\"BOOL\", {alternator_type::BOOL, boolean_type}},\n {\"N\", {alternator_type::N, decimal_type}}, \/\/FIXME: Replace with custom Alternator type when implemented\n };\n auto it = type_infos.find(type);\n if (it == type_infos.end()) {\n return {alternator_type::NOT_SUPPORTED_YET, utf8_type};\n }\n return it->second;\n}\n\ntype_representation represent_type(alternator_type atype) {\n static thread_local const std::unordered_map type_representations = {\n {alternator_type::S, {\"S\", utf8_type}},\n {alternator_type::B, {\"B\", bytes_type}},\n {alternator_type::BOOL, {\"BOOL\", boolean_type}},\n {alternator_type::N, {\"N\", decimal_type}}, \/\/FIXME: Replace with custom Alternator type when implemented\n };\n auto it = type_representations.find(atype);\n if (it == type_representations.end()) {\n throw std::runtime_error(format(\"Unknown alternator type {}\", int8_t(atype)));\n }\n return it->second;\n}\n\nstruct from_json_visitor {\n const rjson::value& v;\n bytes_ostream& bo;\n\n void operator()(const reversed_type_impl& t) const { visit(*t.underlying_type(), from_json_visitor{v, bo}); };\n void operator()(const string_type_impl& t) {\n bo.write(t.from_string(v.GetString()));\n }\n void operator()(const bytes_type_impl& t) const {\n std::string raw_value = v.GetString();\n bo.write(base64_decode(std::string_view(raw_value)));\n }\n void operator()(const boolean_type_impl& t) const {\n bo.write(boolean_type->decompose(v.GetBool()));\n }\n void operator()(const decimal_type_impl& t) const {\n bo.write(t.from_string(v.GetString()));\n }\n \/\/ default\n void operator()(const abstract_type& t) const {\n bo.write(t.from_json_object(Json::Value(rjson::print(v)), cql_serialization_format::internal()));\n }\n};\n\nbytes serialize_item(const rjson::value& item) {\n if (item.IsNull() || item.MemberCount() != 1) {\n throw api_error(\"ValidationException\", format(\"An item can contain only one attribute definition: {}\", item));\n }\n auto it = item.MemberBegin();\n type_info type_info = type_info_from_string(it->name.GetString()); \/\/ JSON keys are guaranteed to be strings\n\n if (type_info.atype == alternator_type::NOT_SUPPORTED_YET) {\n slogger.trace(\"Non-optimal serialization of type {}\", it->name.GetString());\n return bytes{int8_t(type_info.atype)} + to_bytes(rjson::print(item));\n }\n\n bytes_ostream bo;\n bo.write(bytes{int8_t(type_info.atype)});\n visit(*type_info.dtype, from_json_visitor{it->value, bo});\n\n return bytes(bo.linearize());\n}\n\nstruct to_json_visitor {\n rjson::value& deserialized;\n const std::string& type_ident;\n bytes_view bv;\n\n void operator()(const reversed_type_impl& t) const { visit(*t.underlying_type(), to_json_visitor{deserialized, type_ident, bv}); };\n void operator()(const decimal_type_impl& t) const {\n auto s = decimal_type->to_json_string(bytes(bv));\n \/\/FIXME(sarna): unnecessary copy\n rjson::set_with_string_name(deserialized, type_ident, rjson::from_string(s));\n }\n void operator()(const string_type_impl& t) {\n rjson::set_with_string_name(deserialized, type_ident, rjson::from_string(reinterpret_cast(bv.data()), bv.size()));\n }\n void operator()(const bytes_type_impl& t) const {\n std::string b64 = base64_encode(bv);\n rjson::set_with_string_name(deserialized, type_ident, rjson::from_string(b64));\n }\n \/\/ default\n void operator()(const abstract_type& t) const {\n rjson::set_with_string_name(deserialized, type_ident, rjson::parse(t.to_string(bytes(bv))));\n }\n};\n\nrjson::value deserialize_item(bytes_view bv) {\n rjson::value deserialized(rapidjson::kObjectType);\n if (bv.empty()) {\n throw api_error(\"ValidationException\", \"Serialized value empty\");\n }\n\n alternator_type atype = alternator_type(bv[0]);\n bv.remove_prefix(1);\n\n if (atype == alternator_type::NOT_SUPPORTED_YET) {\n slogger.trace(\"Non-optimal deserialization of alternator type {}\", int8_t(atype));\n return rjson::parse_raw(reinterpret_cast(bv.data()), bv.size());\n }\n type_representation type_representation = represent_type(atype);\n visit(*type_representation.dtype, to_json_visitor{deserialized, type_representation.ident, bv});\n\n return deserialized;\n}\n\nstd::string type_to_string(data_type type) {\n static thread_local std::unordered_map types = {\n {utf8_type, \"S\"},\n {bytes_type, \"B\"},\n {boolean_type, \"BOOL\"},\n {decimal_type, \"N\"}, \/\/ FIXME: use a specialized Alternator number type instead of the general decimal_type\n };\n auto it = types.find(type);\n if (it == types.end()) {\n throw std::runtime_error(format(\"Unknown type {}\", type->name()));\n }\n return it->second;\n}\n\nbytes get_key_column_value(const rjson::value& item, const column_definition& column) {\n std::string column_name = column.name_as_text();\n std::string expected_type = type_to_string(column.type);\n\n const rjson::value& key_typed_value = rjson::get(item, rjson::value::StringRefType(column_name.c_str()));\n if (!key_typed_value.IsObject() || key_typed_value.MemberCount() != 1) {\n throw api_error(\"ValidationException\",\n format(\"Missing or invalid value object for key column {}: {}\", column_name, item));\n }\n return get_key_from_typed_value(key_typed_value, column, expected_type);\n}\n\nbytes get_key_from_typed_value(const rjson::value& key_typed_value, const column_definition& column, const std::string& expected_type) {\n auto it = key_typed_value.MemberBegin();\n if (it->name.GetString() != expected_type) {\n throw api_error(\"ValidationException\",\n format(\"Expected type {} for key column {}, got type {}\",\n expected_type, column.name_as_text(), it->name.GetString()));\n }\n if (column.type == bytes_type) {\n return base64_decode(it->value.GetString());\n } else {\n return column.type->from_string(it->value.GetString());\n }\n\n}\n\nrjson::value json_key_column_value(bytes_view cell, const column_definition& column) {\n if (column.type == bytes_type) {\n std::string b64 = base64_encode(cell);\n return rjson::from_string(b64);\n } if (column.type == utf8_type) {\n return rjson::from_string(std::string(reinterpret_cast(cell.data()), cell.size()));\n } else if (column.type == decimal_type) {\n \/\/ FIXME: use specialized Alternator number type, not the more\n \/\/ general \"decimal_type\". A dedicated type can be more efficient\n \/\/ in storage space and in parsing speed.\n auto s = decimal_type->to_json_string(bytes(cell));\n return rjson::from_string(s);\n } else {\n \/\/ We shouldn't get here, we shouldn't see such key columns.\n throw std::runtime_error(format(\"Unexpected key type: {}\", column.type->name()));\n }\n}\n\n\npartition_key pk_from_json(const rjson::value& item, schema_ptr schema) {\n std::vector raw_pk;\n \/\/ FIXME: this is a loop, but we really allow only one partition key column.\n for (const column_definition& cdef : schema->partition_key_columns()) {\n bytes raw_value = get_key_column_value(item, cdef);\n raw_pk.push_back(std::move(raw_value));\n }\n return partition_key::from_exploded(raw_pk);\n}\n\nclustering_key ck_from_json(const rjson::value& item, schema_ptr schema) {\n if (schema->clustering_key_size() == 0) {\n return clustering_key::make_empty();\n }\n std::vector raw_ck;\n \/\/ FIXME: this is a loop, but we really allow only one clustering key column.\n for (const column_definition& cdef : schema->clustering_key_columns()) {\n bytes raw_value = get_key_column_value(item, cdef);\n raw_ck.push_back(std::move(raw_value));\n }\n\n return clustering_key::from_exploded(raw_ck);\n}\n\n}\n<|endoftext|>"} {"text":"#include \"FSELightWorld.h\"\n#include \"..\/Application.h\"\n\n#include \n\n#include \n\nnamespace fse\n{\n\tFSELightWorld::FSELightWorld(Scene* scene) : FSELightWorld(scene, sf::Vector2f(0, 0))\n\t{\n\n\t}\n\n\tFSELightWorld::FSELightWorld(Scene* scene, const sf::Vector2f& spawnPos) : FSEObject(scene, spawnPos)\n\t{\n\t\tsetZOrder(255);\n\t\tlight_system_ = std::make_unique(normal_texture_, specular_texture_, true);\n\t\tbloom_texture_.create(1, 1);\n\t\tbloom_shader_.loadFromMemory(bloom_shader_str_, sf::Shader::Fragment);\n\t\tgauss_blur_shader_.loadFromMemory(gauss_blur_shader_str_, sf::Shader::Fragment);\n\t}\n\n\tFSELightWorld::~FSELightWorld()\n\t{\n\t\tif (sun_ != nullptr)\n\t\t\tlight_system_->removeLight(sun_);\n\t}\n\n\tvoid FSELightWorld::update(float deltaTime)\n\t{\n\n\t}\n\n\tvoid FSELightWorld::draw(sf::RenderTarget& target)\n\t{\n\t\tif (lighting_)\n\t\t{\n\t\t\tnormal_texture_.display();\n\t\t\tspecular_texture_.display();\n\t\t\tlight_system_->render(target);\n\n\t\t\tif (bloom_)\n\t\t\t{\n\t\t\t\tif (sf::RenderTexture* r_texture = dynamic_cast(&target))\n\t\t\t\t{\n\t\t\t\t\t\/\/r_texture->display();\n\t\t\t\t\tsf::Sprite sprite = sf::Sprite(bloom_texture_.getTexture());\n\t\t\t\t\tauto view = target.getView();\n\n\t\t\t\t\tbloom_shader_.setUniform(\"currTex\", r_texture->getTexture());\n\t\t\t\t\tbloom_shader_.setUniform(\"lightCompTex\", light_system_->getLightCompTexture().getTexture());\n\t\t\t\t\tbloom_shader_.setUniform(\"specCompTex\", light_system_->getSpecCompTexture().getTexture());\n\n\t\t\t\t\tbloom_texture_.draw(sprite, &bloom_shader_);\n\n\t\t\t\t\tgauss_blur_shader_.setUniform(\"currTex\", bloom_texture_.getTexture());\n\t\t\t\t\tgauss_blur_shader_.setUniform(\"texSize\", sf::Vector2f(target.getSize().x, target.getSize().y));\n\t\t\t\t\tbool horizontal = false;\n\t\t\t\t\tfor (int i = 0; i < 4; i++)\n\t\t\t\t\t{\n\t\t\t\t\t\thorizontal = !horizontal;\n\t\t\t\t\t\tgauss_blur_shader_.setUniform(\"horizontal\", horizontal);\n\t\t\t\t\t\tbloom_texture_.draw(sf::Sprite(bloom_texture_.getTexture()), &gauss_blur_shader_);\n\t\t\t\t\t}\n\n\t\t\t\t\tbloom_texture_.display();\n\n\t\t\t\t\tsprite.setPosition(view.getCenter() - view.getSize() \/ 2.f);\n\t\t\t\t\ttarget.draw(sprite, sf::BlendAdd);\n\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tvoid FSELightWorld::spawned()\n\t{\n\t}\n\n\tbool FSELightWorld::destroy()\n\t{\n\t\treturn false;\n\t}\n\n\tvoid FSELightWorld::init(sf::RenderTarget* target) const\n\t{\n\t\tlight_system_->create({ -1000.f, -1000.f, 1000.f, 1000.f }, target->getSize());\n\t\t\/\/sun_ = light_system_->createLightDirectionEmission();\n\t\t\/\/sun_->setColor(sf::Color::Black);\n\t}\n\n\tbool FSELightWorld::getLighting() const\n\t{\n\t\treturn lighting_;\n\t}\n\n\tvoid FSELightWorld::setLighting(bool lighting)\n\t{\n\t\tlighting_ = lighting;\n\t}\n\n\tbool FSELightWorld::getBloom() const\n\t{\n\t\treturn bloom_;\n\t}\n\n\tvoid FSELightWorld::setBloom(bool bloom)\n\t{\n\t\tif (sf::RenderTexture* rTexture = dynamic_cast(scene_->getRenderTarget()))\n\t\t{\n\t\t\tbloom_ = bloom;\n\t\t} \n\t\telse\n\t\t{\n\t\t\tstd::cout << \"Cannot use bloom directly on Window!\\n\";\n\t\t\tbloom_ = false;\n\t\t}\n\t}\n\n\tvoid FSELightWorld::updateView()\n\t{\n\t\tif (lighting_)\n\t\t{\n\t\t\tif (bloom_texture_.getSize() != scene_->getRenderTarget()->getSize())\n\t\t\t{\n\t\t\t\tbloom_texture_.create(scene_->getRenderTarget()->getSize().x, scene_->getRenderTarget()->getSize().y);\n\t\t\t}\n\n\t\t\tsf::View view = scene_->getRenderTarget()->getView();\n\t\t\tnormal_texture_.setView(view);\n\t\t\tspecular_texture_.setView(view);\n\t\t\tnormal_texture_.clear(sf::Color(128u, 128u, 255u));\n\t\t\tspecular_texture_.clear(sf::Color::Black);\n\t\t}\n\t}\n\n\tsf::Color FSELightWorld::getAmbientColor() const\n\t{\n\t\treturn light_system_->getAmbientColor();\n\t}\n\n\tvoid FSELightWorld::setAmbientColor(const sf::Color color) const\n\t{\n\t\tlight_system_->setAmbientColor(color);\n\t}\n\n\tltbl::LightDirectionEmission* FSELightWorld::getSun()\n\t{\n\t\tif (sun_ == nullptr)\n\t\t\tsun_ = light_system_->createLightDirectionEmission();\n\t\treturn sun_;\n\t}\n\n\tltbl::LightSystem* FSELightWorld::getLightSystem() const\n\t{\n\t\treturn light_system_.get();\n\t}\n\n\tsf::RenderTarget* FSELightWorld::getNormalTarget()\n\t{\n\t\treturn &normal_texture_;\n\t}\n\n\tsf::RenderTarget* FSELightWorld::getSpecularTarget()\n\t{\n\t\treturn &specular_texture_;\n\t}\n}\n\nRTTR_REGISTRATION\n{\n\tusing namespace rttr;\n\tusing namespace fse;\n\n\tregistration::class_(\"fse::FSELightWorld\")\n\t(\n\t\tmetadata(\"SERIALIZE_NO_RECRATE\", true)\n\t)\n\t.property(\"lighting_\", &FSELightWorld::lighting_)\n\t.property(\"bloom_\", &FSELightWorld::getBloom, &FSELightWorld::setBloom)\n\t.property(\"ambient_color_\", &FSELightWorld::getAmbientColor, &FSELightWorld::setAmbientColor)\n\t;\n}\nLights: Fix bloom when view is zoomed.#include \"FSELightWorld.h\"\n#include \"..\/Application.h\"\n\n#include \n\n#include \n\nnamespace fse\n{\n\tFSELightWorld::FSELightWorld(Scene* scene) : FSELightWorld(scene, sf::Vector2f(0, 0))\n\t{\n\n\t}\n\n\tFSELightWorld::FSELightWorld(Scene* scene, const sf::Vector2f& spawnPos) : FSEObject(scene, spawnPos)\n\t{\n\t\tsetZOrder(255);\n\t\tlight_system_ = std::make_unique(normal_texture_, specular_texture_, true);\n\t\tbloom_texture_.create(1, 1);\n\t\tbloom_shader_.loadFromMemory(bloom_shader_str_, sf::Shader::Fragment);\n\t\tgauss_blur_shader_.loadFromMemory(gauss_blur_shader_str_, sf::Shader::Fragment);\n\t}\n\n\tFSELightWorld::~FSELightWorld()\n\t{\n\t\tif (sun_ != nullptr)\n\t\t\tlight_system_->removeLight(sun_);\n\t}\n\n\tvoid FSELightWorld::update(float deltaTime)\n\t{\n\n\t}\n\n\tvoid FSELightWorld::draw(sf::RenderTarget& target)\n\t{\n\t\tif (lighting_)\n\t\t{\n\t\t\tnormal_texture_.display();\n\t\t\tspecular_texture_.display();\n\t\t\tlight_system_->render(target);\n\n\t\t\tif (bloom_)\n\t\t\t{\n\t\t\t\tif (sf::RenderTexture* r_texture = dynamic_cast(&target))\n\t\t\t\t{\n\t\t\t\t\t\/\/r_texture->display();\n\t\t\t\t\tsf::Sprite sprite = sf::Sprite(bloom_texture_.getTexture());\n\t\t\t\t\tauto view = target.getView();\n\n\t\t\t\t\tbloom_shader_.setUniform(\"currTex\", r_texture->getTexture());\n\t\t\t\t\tbloom_shader_.setUniform(\"lightCompTex\", light_system_->getLightCompTexture().getTexture());\n\t\t\t\t\tbloom_shader_.setUniform(\"specCompTex\", light_system_->getSpecCompTexture().getTexture());\n\n\t\t\t\t\tbloom_texture_.draw(sprite, &bloom_shader_);\n\n\t\t\t\t\tgauss_blur_shader_.setUniform(\"currTex\", bloom_texture_.getTexture());\n\t\t\t\t\tgauss_blur_shader_.setUniform(\"texSize\", sf::Vector2f(target.getSize().x, target.getSize().y));\n\t\t\t\t\tbool horizontal = false;\n\t\t\t\t\tfor (int i = 0; i < 4; i++)\n\t\t\t\t\t{\n\t\t\t\t\t\thorizontal = !horizontal;\n\t\t\t\t\t\tgauss_blur_shader_.setUniform(\"horizontal\", horizontal);\n\t\t\t\t\t\tbloom_texture_.draw(sf::Sprite(bloom_texture_.getTexture()), &gauss_blur_shader_);\n\t\t\t\t\t}\n\n\t\t\t\t\tbloom_texture_.display();\n\n\t\t\t\t\tauto sz = view.getSize();\n\t\t\t\t\tsprite.setPosition(view.getCenter() - view.getSize() \/ 2.f);\n\t\t\t\t\tsprite.setScale(sz.x \/ target.getSize().x, sz.y \/ target.getSize().y);\n\t\t\t\t\ttarget.draw(sprite, sf::BlendAdd);\n\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tvoid FSELightWorld::spawned()\n\t{\n\t}\n\n\tbool FSELightWorld::destroy()\n\t{\n\t\treturn false;\n\t}\n\n\tvoid FSELightWorld::init(sf::RenderTarget* target) const\n\t{\n\t\tlight_system_->create({ -1000.f, -1000.f, 1000.f, 1000.f }, target->getSize());\n\t\t\/\/sun_ = light_system_->createLightDirectionEmission();\n\t\t\/\/sun_->setColor(sf::Color::Black);\n\t}\n\n\tbool FSELightWorld::getLighting() const\n\t{\n\t\treturn lighting_;\n\t}\n\n\tvoid FSELightWorld::setLighting(bool lighting)\n\t{\n\t\tlighting_ = lighting;\n\t}\n\n\tbool FSELightWorld::getBloom() const\n\t{\n\t\treturn bloom_;\n\t}\n\n\tvoid FSELightWorld::setBloom(bool bloom)\n\t{\n\t\tif (sf::RenderTexture* rTexture = dynamic_cast(scene_->getRenderTarget()))\n\t\t{\n\t\t\tbloom_ = bloom;\n\t\t} \n\t\telse\n\t\t{\n\t\t\tstd::cout << \"Cannot use bloom directly on Window!\\n\";\n\t\t\tbloom_ = false;\n\t\t}\n\t}\n\n\tvoid FSELightWorld::updateView()\n\t{\n\t\tif (lighting_)\n\t\t{\n\t\t\tif (bloom_texture_.getSize() != scene_->getRenderTarget()->getSize())\n\t\t\t{\n\t\t\t\tbloom_texture_.create(scene_->getRenderTarget()->getSize().x, scene_->getRenderTarget()->getSize().y);\n\t\t\t}\n\n\t\t\tsf::View view = scene_->getRenderTarget()->getView();\n\t\t\tnormal_texture_.setView(view);\n\t\t\tspecular_texture_.setView(view);\n\t\t\tnormal_texture_.clear(sf::Color(128u, 128u, 255u));\n\t\t\tspecular_texture_.clear(sf::Color::Black);\n\t\t}\n\t}\n\n\tsf::Color FSELightWorld::getAmbientColor() const\n\t{\n\t\treturn light_system_->getAmbientColor();\n\t}\n\n\tvoid FSELightWorld::setAmbientColor(const sf::Color color) const\n\t{\n\t\tlight_system_->setAmbientColor(color);\n\t}\n\n\tltbl::LightDirectionEmission* FSELightWorld::getSun()\n\t{\n\t\tif (sun_ == nullptr)\n\t\t\tsun_ = light_system_->createLightDirectionEmission();\n\t\treturn sun_;\n\t}\n\n\tltbl::LightSystem* FSELightWorld::getLightSystem() const\n\t{\n\t\treturn light_system_.get();\n\t}\n\n\tsf::RenderTarget* FSELightWorld::getNormalTarget()\n\t{\n\t\treturn &normal_texture_;\n\t}\n\n\tsf::RenderTarget* FSELightWorld::getSpecularTarget()\n\t{\n\t\treturn &specular_texture_;\n\t}\n}\n\nRTTR_REGISTRATION\n{\n\tusing namespace rttr;\n\tusing namespace fse;\n\n\tregistration::class_(\"fse::FSELightWorld\")\n\t(\n\t\tmetadata(\"SERIALIZE_NO_RECRATE\", true)\n\t)\n\t.property(\"lighting_\", &FSELightWorld::lighting_)\n\t.property(\"bloom_\", &FSELightWorld::getBloom, &FSELightWorld::setBloom)\n\t.property(\"ambient_color_\", &FSELightWorld::getAmbientColor, &FSELightWorld::setAmbientColor)\n\t;\n}\n<|endoftext|>"} {"text":"\/\/ Copyright 2014 The Chromium Authors. All rights reserved.\n\/\/ Use of this source code is governed by a BSD-style license that can be\n\/\/ found in the LICENSE file.\n\n#include \"chrome\/browser\/bookmarks\/chrome_bookmark_client.h\"\n\n#include \"base\/bind.h\"\n#include \"base\/bind_helpers.h\"\n#include \"base\/logging.h\"\n#include \"base\/values.h\"\n#include \"chrome\/browser\/chrome_notification_types.h\"\n#include \"chrome\/browser\/favicon\/favicon_changed_details.h\"\n#include \"chrome\/browser\/favicon\/favicon_service.h\"\n#include \"chrome\/browser\/favicon\/favicon_service_factory.h\"\n#include \"chrome\/browser\/history\/history_service.h\"\n#include \"chrome\/browser\/history\/history_service_factory.h\"\n#include \"chrome\/browser\/history\/url_database.h\"\n#include \"chrome\/browser\/policy\/profile_policy_connector.h\"\n#include \"chrome\/browser\/policy\/profile_policy_connector_factory.h\"\n#include \"chrome\/browser\/profiles\/profile.h\"\n#include \"chrome\/browser\/profiles\/startup_task_runner_service.h\"\n#include \"chrome\/browser\/profiles\/startup_task_runner_service_factory.h\"\n#include \"components\/bookmarks\/browser\/bookmark_model.h\"\n#include \"components\/bookmarks\/browser\/bookmark_node.h\"\n#include \"content\/public\/browser\/browser_thread.h\"\n#include \"content\/public\/browser\/notification_details.h\"\n#include \"content\/public\/browser\/notification_source.h\"\n#include \"content\/public\/browser\/user_metrics.h\"\n#include \"grit\/components_strings.h\"\n#include \"policy\/policy_constants.h\"\n#include \"ui\/base\/l10n\/l10n_util.h\"\n\nnamespace {\n\nvoid NotifyHistoryOfRemovedURLs(Profile* profile,\n const std::set& removed_urls) {\n HistoryService* history_service =\n HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS);\n if (history_service)\n history_service->URLsNoLongerBookmarked(removed_urls);\n}\n\n} \/\/ namespace\n\nChromeBookmarkClient::ChromeBookmarkClient(Profile* profile)\n : profile_(profile), model_(NULL) {\n}\n\nChromeBookmarkClient::~ChromeBookmarkClient() {\n}\n\nvoid ChromeBookmarkClient::Init(BookmarkModel* model) {\n DCHECK(model);\n DCHECK(!model_);\n model_ = model;\n model_->AddObserver(this);\n\n managed_bookmarks_tracker_.reset(new policy::ManagedBookmarksTracker(\n model_,\n profile_->GetPrefs(),\n base::Bind(&ChromeBookmarkClient::GetManagedBookmarksDomain,\n base::Unretained(this))));\n\n \/\/ Listen for changes to favicons so that we can update the favicon of the\n \/\/ node appropriately.\n registrar_.Add(this,\n chrome::NOTIFICATION_FAVICON_CHANGED,\n content::Source(profile_));\n}\n\nvoid ChromeBookmarkClient::Shutdown() {\n if (model_) {\n registrar_.RemoveAll();\n\n model_->RemoveObserver(this);\n model_ = NULL;\n }\n BookmarkClient::Shutdown();\n}\n\nbool ChromeBookmarkClient::IsDescendantOfManagedNode(const BookmarkNode* node) {\n return node && node->HasAncestor(managed_node_);\n}\n\nbool ChromeBookmarkClient::HasDescendantsOfManagedNode(\n const std::vector& list) {\n for (size_t i = 0; i < list.size(); ++i) {\n if (IsDescendantOfManagedNode(list[i]))\n return true;\n }\n return false;\n}\n\nbool ChromeBookmarkClient::PreferTouchIcon() {\n#if !defined(OS_IOS)\n return false;\n#else\n return true;\n#endif\n}\n\nbase::CancelableTaskTracker::TaskId ChromeBookmarkClient::GetFaviconImageForURL(\n const GURL& page_url,\n int icon_types,\n int desired_size_in_dip,\n const favicon_base::FaviconImageCallback& callback,\n base::CancelableTaskTracker* tracker) {\n FaviconService* favicon_service =\n FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);\n if (!favicon_service)\n return base::CancelableTaskTracker::kBadTaskId;\n return favicon_service->GetFaviconImageForPageURL(\n FaviconService::FaviconForPageURLParams(\n page_url, icon_types, desired_size_in_dip),\n callback,\n tracker);\n}\n\nbool ChromeBookmarkClient::SupportsTypedCountForNodes() {\n return true;\n}\n\nvoid ChromeBookmarkClient::GetTypedCountForNodes(\n const NodeSet& nodes,\n NodeTypedCountPairs* node_typed_count_pairs) {\n HistoryService* history_service =\n HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);\n history::URLDatabase* url_db =\n history_service ? history_service->InMemoryDatabase() : NULL;\n for (NodeSet::const_iterator i = nodes.begin(); i != nodes.end(); ++i) {\n int typed_count = 0;\n\n \/\/ If |url_db| is the InMemoryDatabase, it might not cache all URLRows, but\n \/\/ it guarantees to contain those with |typed_count| > 0. Thus, if we cannot\n \/\/ fetch the URLRow, it is safe to assume that its |typed_count| is 0.\n history::URLRow url;\n if (url_db && url_db->GetRowForURL((*i)->url(), &url))\n typed_count = url.typed_count();\n\n NodeTypedCountPair pair(*i, typed_count);\n node_typed_count_pairs->push_back(pair);\n }\n}\n\nbool ChromeBookmarkClient::IsPermanentNodeVisible(\n const BookmarkPermanentNode* node) {\n DCHECK(node->type() == BookmarkNode::BOOKMARK_BAR ||\n node->type() == BookmarkNode::OTHER_NODE ||\n node->type() == BookmarkNode::MOBILE ||\n node == managed_node_);\n if (node == managed_node_)\n return false;\n#if !defined(OS_IOS)\n return node->type() != BookmarkNode::MOBILE;\n#else\n return node->type() == BookmarkNode::MOBILE;\n#endif\n}\n\nvoid ChromeBookmarkClient::RecordAction(const base::UserMetricsAction& action) {\n content::RecordAction(action);\n}\n\nbookmarks::LoadExtraCallback ChromeBookmarkClient::GetLoadExtraNodesCallback() {\n \/\/ Create the managed_node now; it will be populated in the LoadExtraNodes\n \/\/ callback.\n managed_node_ = new BookmarkPermanentNode(0);\n return base::Bind(\n &ChromeBookmarkClient::LoadExtraNodes,\n StartupTaskRunnerServiceFactory::GetForProfile(profile_)\n ->GetBookmarkTaskRunner(),\n managed_node_,\n base::Passed(managed_bookmarks_tracker_->GetInitialManagedBookmarks()));\n}\n\nbool ChromeBookmarkClient::CanSetPermanentNodeTitle(\n const BookmarkNode* permanent_node) {\n \/\/ The |managed_node_| can have its title updated if the user signs in or\n \/\/ out.\n return !IsDescendantOfManagedNode(permanent_node) ||\n permanent_node == managed_node_;\n}\n\nbool ChromeBookmarkClient::CanSyncNode(const BookmarkNode* node) {\n return !IsDescendantOfManagedNode(node);\n}\n\nbool ChromeBookmarkClient::CanBeEditedByUser(const BookmarkNode* node) {\n return !IsDescendantOfManagedNode(node);\n}\n\nvoid ChromeBookmarkClient::Observe(\n int type,\n const content::NotificationSource& source,\n const content::NotificationDetails& details) {\n switch (type) {\n case chrome::NOTIFICATION_FAVICON_CHANGED: {\n content::Details favicon_details(details);\n model_->OnFaviconChanged(favicon_details->urls);\n break;\n }\n\n default:\n NOTREACHED();\n break;\n }\n}\n\nvoid ChromeBookmarkClient::BookmarkModelChanged() {\n}\n\nvoid ChromeBookmarkClient::BookmarkNodeRemoved(\n BookmarkModel* model,\n const BookmarkNode* parent,\n int old_index,\n const BookmarkNode* node,\n const std::set& removed_urls) {\n NotifyHistoryOfRemovedURLs(profile_, removed_urls);\n}\n\nvoid ChromeBookmarkClient::BookmarkAllUserNodesRemoved(\n BookmarkModel* model,\n const std::set& removed_urls) {\n NotifyHistoryOfRemovedURLs(profile_, removed_urls);\n}\n\nvoid ChromeBookmarkClient::BookmarkModelLoaded(BookmarkModel* model,\n bool ids_reassigned) {\n \/\/ Start tracking the managed bookmarks. This will detect any changes that\n \/\/ may have occurred while the initial managed bookmarks were being loaded\n \/\/ on the background.\n managed_bookmarks_tracker_->Init(managed_node_);\n}\n\n\/\/ static\nbookmarks::BookmarkPermanentNodeList ChromeBookmarkClient::LoadExtraNodes(\n const scoped_refptr& profile_io_runner,\n BookmarkPermanentNode* managed_node,\n scoped_ptr initial_managed_bookmarks,\n int64* next_node_id) {\n DCHECK(profile_io_runner->RunsTasksOnCurrentThread());\n \/\/ Load the initial contents of the |managed_node| now, and assign it an\n \/\/ unused ID.\n int64 managed_id = *next_node_id;\n managed_node->set_id(managed_id);\n *next_node_id = policy::ManagedBookmarksTracker::LoadInitial(\n managed_node, initial_managed_bookmarks.get(), managed_id + 1);\n managed_node->set_visible(!managed_node->empty());\n managed_node->SetTitle(\n l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_MANAGED_FOLDER_DEFAULT_NAME));\n\n bookmarks::BookmarkPermanentNodeList extra_nodes;\n extra_nodes.push_back(managed_node);\n return extra_nodes.Pass();\n}\n\nstd::string ChromeBookmarkClient::GetManagedBookmarksDomain() {\n policy::ProfilePolicyConnector* connector =\n policy::ProfilePolicyConnectorFactory::GetForProfile(profile_);\n if (connector->IsPolicyFromCloudPolicy(policy::key::kManagedBookmarks))\n return connector->GetManagementDomain();\n return std::string();\n}\nFixed uninitialized read in ChromeBookmarkClient.\/\/ Copyright 2014 The Chromium Authors. All rights reserved.\n\/\/ Use of this source code is governed by a BSD-style license that can be\n\/\/ found in the LICENSE file.\n\n#include \"chrome\/browser\/bookmarks\/chrome_bookmark_client.h\"\n\n#include \"base\/bind.h\"\n#include \"base\/bind_helpers.h\"\n#include \"base\/logging.h\"\n#include \"base\/values.h\"\n#include \"chrome\/browser\/chrome_notification_types.h\"\n#include \"chrome\/browser\/favicon\/favicon_changed_details.h\"\n#include \"chrome\/browser\/favicon\/favicon_service.h\"\n#include \"chrome\/browser\/favicon\/favicon_service_factory.h\"\n#include \"chrome\/browser\/history\/history_service.h\"\n#include \"chrome\/browser\/history\/history_service_factory.h\"\n#include \"chrome\/browser\/history\/url_database.h\"\n#include \"chrome\/browser\/policy\/profile_policy_connector.h\"\n#include \"chrome\/browser\/policy\/profile_policy_connector_factory.h\"\n#include \"chrome\/browser\/profiles\/profile.h\"\n#include \"chrome\/browser\/profiles\/startup_task_runner_service.h\"\n#include \"chrome\/browser\/profiles\/startup_task_runner_service_factory.h\"\n#include \"components\/bookmarks\/browser\/bookmark_model.h\"\n#include \"components\/bookmarks\/browser\/bookmark_node.h\"\n#include \"content\/public\/browser\/browser_thread.h\"\n#include \"content\/public\/browser\/notification_details.h\"\n#include \"content\/public\/browser\/notification_source.h\"\n#include \"content\/public\/browser\/user_metrics.h\"\n#include \"grit\/components_strings.h\"\n#include \"policy\/policy_constants.h\"\n#include \"ui\/base\/l10n\/l10n_util.h\"\n\nnamespace {\n\nvoid NotifyHistoryOfRemovedURLs(Profile* profile,\n const std::set& removed_urls) {\n HistoryService* history_service =\n HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS);\n if (history_service)\n history_service->URLsNoLongerBookmarked(removed_urls);\n}\n\n} \/\/ namespace\n\nChromeBookmarkClient::ChromeBookmarkClient(Profile* profile)\n : profile_(profile), model_(NULL), managed_node_(NULL) {\n}\n\nChromeBookmarkClient::~ChromeBookmarkClient() {\n}\n\nvoid ChromeBookmarkClient::Init(BookmarkModel* model) {\n DCHECK(model);\n DCHECK(!model_);\n model_ = model;\n model_->AddObserver(this);\n\n managed_bookmarks_tracker_.reset(new policy::ManagedBookmarksTracker(\n model_,\n profile_->GetPrefs(),\n base::Bind(&ChromeBookmarkClient::GetManagedBookmarksDomain,\n base::Unretained(this))));\n\n \/\/ Listen for changes to favicons so that we can update the favicon of the\n \/\/ node appropriately.\n registrar_.Add(this,\n chrome::NOTIFICATION_FAVICON_CHANGED,\n content::Source(profile_));\n}\n\nvoid ChromeBookmarkClient::Shutdown() {\n if (model_) {\n registrar_.RemoveAll();\n\n model_->RemoveObserver(this);\n model_ = NULL;\n }\n BookmarkClient::Shutdown();\n}\n\nbool ChromeBookmarkClient::IsDescendantOfManagedNode(const BookmarkNode* node) {\n return node && node->HasAncestor(managed_node_);\n}\n\nbool ChromeBookmarkClient::HasDescendantsOfManagedNode(\n const std::vector& list) {\n for (size_t i = 0; i < list.size(); ++i) {\n if (IsDescendantOfManagedNode(list[i]))\n return true;\n }\n return false;\n}\n\nbool ChromeBookmarkClient::PreferTouchIcon() {\n#if !defined(OS_IOS)\n return false;\n#else\n return true;\n#endif\n}\n\nbase::CancelableTaskTracker::TaskId ChromeBookmarkClient::GetFaviconImageForURL(\n const GURL& page_url,\n int icon_types,\n int desired_size_in_dip,\n const favicon_base::FaviconImageCallback& callback,\n base::CancelableTaskTracker* tracker) {\n FaviconService* favicon_service =\n FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);\n if (!favicon_service)\n return base::CancelableTaskTracker::kBadTaskId;\n return favicon_service->GetFaviconImageForPageURL(\n FaviconService::FaviconForPageURLParams(\n page_url, icon_types, desired_size_in_dip),\n callback,\n tracker);\n}\n\nbool ChromeBookmarkClient::SupportsTypedCountForNodes() {\n return true;\n}\n\nvoid ChromeBookmarkClient::GetTypedCountForNodes(\n const NodeSet& nodes,\n NodeTypedCountPairs* node_typed_count_pairs) {\n HistoryService* history_service =\n HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);\n history::URLDatabase* url_db =\n history_service ? history_service->InMemoryDatabase() : NULL;\n for (NodeSet::const_iterator i = nodes.begin(); i != nodes.end(); ++i) {\n int typed_count = 0;\n\n \/\/ If |url_db| is the InMemoryDatabase, it might not cache all URLRows, but\n \/\/ it guarantees to contain those with |typed_count| > 0. Thus, if we cannot\n \/\/ fetch the URLRow, it is safe to assume that its |typed_count| is 0.\n history::URLRow url;\n if (url_db && url_db->GetRowForURL((*i)->url(), &url))\n typed_count = url.typed_count();\n\n NodeTypedCountPair pair(*i, typed_count);\n node_typed_count_pairs->push_back(pair);\n }\n}\n\nbool ChromeBookmarkClient::IsPermanentNodeVisible(\n const BookmarkPermanentNode* node) {\n DCHECK(node->type() == BookmarkNode::BOOKMARK_BAR ||\n node->type() == BookmarkNode::OTHER_NODE ||\n node->type() == BookmarkNode::MOBILE ||\n node == managed_node_);\n if (node == managed_node_)\n return false;\n#if !defined(OS_IOS)\n return node->type() != BookmarkNode::MOBILE;\n#else\n return node->type() == BookmarkNode::MOBILE;\n#endif\n}\n\nvoid ChromeBookmarkClient::RecordAction(const base::UserMetricsAction& action) {\n content::RecordAction(action);\n}\n\nbookmarks::LoadExtraCallback ChromeBookmarkClient::GetLoadExtraNodesCallback() {\n \/\/ Create the managed_node now; it will be populated in the LoadExtraNodes\n \/\/ callback.\n managed_node_ = new BookmarkPermanentNode(0);\n return base::Bind(\n &ChromeBookmarkClient::LoadExtraNodes,\n StartupTaskRunnerServiceFactory::GetForProfile(profile_)\n ->GetBookmarkTaskRunner(),\n managed_node_,\n base::Passed(managed_bookmarks_tracker_->GetInitialManagedBookmarks()));\n}\n\nbool ChromeBookmarkClient::CanSetPermanentNodeTitle(\n const BookmarkNode* permanent_node) {\n \/\/ The |managed_node_| can have its title updated if the user signs in or\n \/\/ out.\n return !IsDescendantOfManagedNode(permanent_node) ||\n permanent_node == managed_node_;\n}\n\nbool ChromeBookmarkClient::CanSyncNode(const BookmarkNode* node) {\n return !IsDescendantOfManagedNode(node);\n}\n\nbool ChromeBookmarkClient::CanBeEditedByUser(const BookmarkNode* node) {\n return !IsDescendantOfManagedNode(node);\n}\n\nvoid ChromeBookmarkClient::Observe(\n int type,\n const content::NotificationSource& source,\n const content::NotificationDetails& details) {\n switch (type) {\n case chrome::NOTIFICATION_FAVICON_CHANGED: {\n content::Details favicon_details(details);\n model_->OnFaviconChanged(favicon_details->urls);\n break;\n }\n\n default:\n NOTREACHED();\n break;\n }\n}\n\nvoid ChromeBookmarkClient::BookmarkModelChanged() {\n}\n\nvoid ChromeBookmarkClient::BookmarkNodeRemoved(\n BookmarkModel* model,\n const BookmarkNode* parent,\n int old_index,\n const BookmarkNode* node,\n const std::set& removed_urls) {\n NotifyHistoryOfRemovedURLs(profile_, removed_urls);\n}\n\nvoid ChromeBookmarkClient::BookmarkAllUserNodesRemoved(\n BookmarkModel* model,\n const std::set& removed_urls) {\n NotifyHistoryOfRemovedURLs(profile_, removed_urls);\n}\n\nvoid ChromeBookmarkClient::BookmarkModelLoaded(BookmarkModel* model,\n bool ids_reassigned) {\n \/\/ Start tracking the managed bookmarks. This will detect any changes that\n \/\/ may have occurred while the initial managed bookmarks were being loaded\n \/\/ on the background.\n managed_bookmarks_tracker_->Init(managed_node_);\n}\n\n\/\/ static\nbookmarks::BookmarkPermanentNodeList ChromeBookmarkClient::LoadExtraNodes(\n const scoped_refptr& profile_io_runner,\n BookmarkPermanentNode* managed_node,\n scoped_ptr initial_managed_bookmarks,\n int64* next_node_id) {\n DCHECK(profile_io_runner->RunsTasksOnCurrentThread());\n \/\/ Load the initial contents of the |managed_node| now, and assign it an\n \/\/ unused ID.\n int64 managed_id = *next_node_id;\n managed_node->set_id(managed_id);\n *next_node_id = policy::ManagedBookmarksTracker::LoadInitial(\n managed_node, initial_managed_bookmarks.get(), managed_id + 1);\n managed_node->set_visible(!managed_node->empty());\n managed_node->SetTitle(\n l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_MANAGED_FOLDER_DEFAULT_NAME));\n\n bookmarks::BookmarkPermanentNodeList extra_nodes;\n extra_nodes.push_back(managed_node);\n return extra_nodes.Pass();\n}\n\nstd::string ChromeBookmarkClient::GetManagedBookmarksDomain() {\n policy::ProfilePolicyConnector* connector =\n policy::ProfilePolicyConnectorFactory::GetForProfile(profile_);\n if (connector->IsPolicyFromCloudPolicy(policy::key::kManagedBookmarks))\n return connector->GetManagementDomain();\n return std::string();\n}\n<|endoftext|>"} {"text":"\/\/ Copyright (c) 2011 The Chromium Authors. All rights reserved.\n\/\/ Use of this source code is governed by a BSD-style license that can be\n\/\/ found in the LICENSE file.\n\n#include \"chrome\/browser\/first_run\/try_chrome_dialog_view.h\"\n\n#include \n\n#include \"base\/logging.h\"\n#include \"base\/message_loop.h\"\n#include \"base\/string16.h\"\n#include \"chrome\/browser\/process_singleton.h\"\n#include \"chrome\/installer\/util\/browser_distribution.h\"\n#include \"grit\/chromium_strings.h\"\n#include \"grit\/generated_resources.h\"\n#include \"grit\/theme_resources.h\"\n#include \"grit\/theme_resources_standard.h\"\n#include \"ui\/base\/l10n\/l10n_util.h\"\n#include \"ui\/base\/resource\/resource_bundle.h\"\n#include \"views\/controls\/button\/image_button.h\"\n#include \"views\/controls\/button\/radio_button.h\"\n#include \"views\/controls\/image_view.h\"\n#include \"views\/controls\/link.h\"\n#include \"views\/layout\/grid_layout.h\"\n#include \"views\/layout\/layout_constants.h\"\n#include \"views\/widget\/root_view.h\"\n#include \"views\/widget\/widget.h\"\n\nnamespace {\n\nconst wchar_t kHelpCenterUrl[] =\n L\"https:\/\/www.google.com\/support\/chrome\/bin\/answer.py?answer=150752\";\n\n} \/\/ namespace\n\n\/\/ static\nTryChromeDialogView::Result TryChromeDialogView::Show(\n size_t version,\n ProcessSingleton* process_singleton) {\n if (version > 10000) {\n \/\/ This is a test value. We want to make sure we exercise\n \/\/ returning this early. See EarlyReturnTest test harness.\n return NOT_NOW;\n }\n TryChromeDialogView dialog(version);\n return dialog.ShowModal(process_singleton);\n}\n\nTryChromeDialogView::TryChromeDialogView(size_t version)\n : version_(version),\n popup_(NULL),\n try_chrome_(NULL),\n kill_chrome_(NULL),\n result_(COUNT) {\n}\n\nTryChromeDialogView::~TryChromeDialogView() {\n}\n\nTryChromeDialogView::Result TryChromeDialogView::ShowModal(\n ProcessSingleton* process_singleton) {\n ResourceBundle& rb = ResourceBundle::GetSharedInstance();\n\n views::ImageView* icon = new views::ImageView();\n icon->SetImage(*rb.GetBitmapNamed(IDR_PRODUCT_ICON_32));\n gfx::Size icon_size = icon->GetPreferredSize();\n\n \/\/ An approximate window size. After Layout() we'll get better bounds.\n popup_ = new views::Widget;\n if (!popup_) {\n NOTREACHED();\n return DIALOG_ERROR;\n }\n\n views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);\n params.can_activate = true;\n params.bounds = gfx::Rect(310, 160);\n popup_->Init(params);\n\n views::RootView* root_view = popup_->GetRootView();\n \/\/ The window color is a tiny bit off-white.\n root_view->set_background(\n views::Background::CreateSolidBackground(0xfc, 0xfc, 0xfc));\n\n views::GridLayout* layout = views::GridLayout::CreatePanel(root_view);\n if (!layout) {\n NOTREACHED();\n return DIALOG_ERROR;\n }\n root_view->SetLayoutManager(layout);\n\n views::ColumnSet* columns;\n \/\/ First row: [icon][pad][text][button].\n columns = layout->AddColumnSet(0);\n columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 0,\n views::GridLayout::FIXED, icon_size.width(),\n icon_size.height());\n columns->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);\n columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,\n views::GridLayout::USE_PREF, 0, 0);\n columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, 1,\n views::GridLayout::USE_PREF, 0, 0);\n \/\/ Second row: [pad][pad][radio 1].\n columns = layout->AddColumnSet(1);\n columns->AddPaddingColumn(0, icon_size.width());\n columns->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);\n columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1,\n views::GridLayout::USE_PREF, 0, 0);\n \/\/ Third row: [pad][pad][radio 2].\n columns = layout->AddColumnSet(2);\n columns->AddPaddingColumn(0, icon_size.width());\n columns->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);\n columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1,\n views::GridLayout::USE_PREF, 0, 0);\n \/\/ Fourth row: [pad][pad][button][pad][button].\n columns = layout->AddColumnSet(3);\n columns->AddPaddingColumn(0, icon_size.width());\n columns->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);\n columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 0,\n views::GridLayout::USE_PREF, 0, 0);\n columns->AddPaddingColumn(0, views::kRelatedButtonHSpacing);\n columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 0,\n views::GridLayout::USE_PREF, 0, 0);\n \/\/ Fifth row: [pad][pad][link].\n columns = layout->AddColumnSet(4);\n columns->AddPaddingColumn(0, icon_size.width());\n columns->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);\n columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1,\n views::GridLayout::USE_PREF, 0, 0);\n \/\/ First row views.\n layout->StartRow(0, 0);\n layout->AddView(icon);\n\n \/\/ Find out what experiment we are conducting.\n BrowserDistribution* dist = BrowserDistribution::GetDistribution();\n if (!dist) {\n NOTREACHED() << \"Cannot determine browser distribution\";\n return DIALOG_ERROR;\n }\n BrowserDistribution::UserExperiment experiment;\n if (!dist->GetExperimentDetails(&experiment, version_) ||\n !experiment.heading) {\n NOTREACHED() << \"Cannot determine which headline to show.\";\n return DIALOG_ERROR;\n }\n string16 heading = l10n_util::GetStringUTF16(experiment.heading);\n views::Label* label = new views::Label(heading);\n label->SetFont(rb.GetFont(ResourceBundle::MediumBoldFont));\n label->SetMultiLine(true);\n label->SizeToFit(200);\n label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);\n layout->AddView(label);\n \/\/ The close button is custom.\n views::ImageButton* close_button = new views::ImageButton(this);\n close_button->SetImage(views::CustomButton::BS_NORMAL,\n rb.GetBitmapNamed(IDR_CLOSE_BAR));\n close_button->SetImage(views::CustomButton::BS_HOT,\n rb.GetBitmapNamed(IDR_CLOSE_BAR_H));\n close_button->SetImage(views::CustomButton::BS_PUSHED,\n rb.GetBitmapNamed(IDR_CLOSE_BAR_P));\n close_button->set_tag(BT_CLOSE_BUTTON);\n layout->AddView(close_button);\n\n \/\/ Second row views.\n const string16 try_it(l10n_util::GetStringUTF16(IDS_TRY_TOAST_TRY_OPT));\n layout->StartRowWithPadding(0, 1, 0, 10);\n try_chrome_ = new views::RadioButton(try_it, 1);\n layout->AddView(try_chrome_);\n try_chrome_->SetChecked(true);\n\n \/\/ Third row views.\n const string16 kill_it(l10n_util::GetStringUTF16(IDS_UNINSTALL_CHROME));\n layout->StartRow(0, 2);\n kill_chrome_ = new views::RadioButton(kill_it, 1);\n layout->AddView(kill_chrome_);\n\n \/\/ Fourth row views.\n const string16 ok_it(l10n_util::GetStringUTF16(IDS_OK));\n const string16 cancel_it(l10n_util::GetStringUTF16(IDS_TRY_TOAST_CANCEL));\n const string16 why_this(l10n_util::GetStringUTF16(IDS_TRY_TOAST_WHY));\n layout->StartRowWithPadding(0, 3, 0, 10);\n views::Button* accept_button = new views::NativeButton(this, ok_it);\n accept_button->set_tag(BT_OK_BUTTON);\n layout->AddView(accept_button);\n views::Button* cancel_button = new views::NativeButton(this, cancel_it);\n cancel_button->set_tag(BT_CLOSE_BUTTON);\n layout->AddView(cancel_button);\n \/\/ Fifth row views.\n layout->StartRowWithPadding(0, 4, 0, 10);\n views::Link* link = new views::Link(why_this);\n link->set_listener(this);\n layout->AddView(link);\n\n \/\/ We resize the window according to the layout manager. This takes into\n \/\/ account the differences between XP and Vista fonts and buttons.\n layout->Layout(root_view);\n gfx::Size preferred = layout->GetPreferredSize(root_view);\n gfx::Rect pos = ComputeWindowPosition(preferred.width(), preferred.height(),\n base::i18n::IsRTL());\n popup_->SetBounds(pos);\n\n \/\/ Carve the toast shape into the window.\n SetToastRegion(popup_->GetNativeView(),\n preferred.width(), preferred.height());\n\n \/\/ Time to show the window in a modal loop. We don't want this chrome\n \/\/ instance trying to serve WM_COPYDATA requests, as we'll surely crash.\n process_singleton->Lock(popup_->GetNativeView());\n popup_->Show();\n MessageLoop::current()->Run();\n process_singleton->Unlock();\n return result_;\n}\n\ngfx::Rect TryChromeDialogView::ComputeWindowPosition(int width,\n int height,\n bool is_RTL) {\n \/\/ The 'Shell_TrayWnd' is the taskbar. We like to show our window in that\n \/\/ monitor if we can. This code works even if such window is not found.\n HWND taskbar = ::FindWindowW(L\"Shell_TrayWnd\", NULL);\n HMONITOR monitor = ::MonitorFromWindow(taskbar, MONITOR_DEFAULTTOPRIMARY);\n MONITORINFO info = {sizeof(info)};\n if (!GetMonitorInfoW(monitor, &info)) {\n \/\/ Quite unexpected. Do a best guess at a visible rectangle.\n return gfx::Rect(20, 20, width + 20, height + 20);\n }\n \/\/ The |rcWork| is the work area. It should account for the taskbars that\n \/\/ are in the screen when we called the function.\n int left = is_RTL ? info.rcWork.left : info.rcWork.right - width;\n int top = info.rcWork.bottom - height;\n return gfx::Rect(left, top, width, height);\n}\n\nvoid TryChromeDialogView::SetToastRegion(HWND window, int w, int h) {\n static const POINT polygon[] = {\n {0, 4}, {1, 2}, {2, 1}, {4, 0}, \/\/ Left side.\n {w-4, 0}, {w-2, 1}, {w-1, 2}, {w, 4}, \/\/ Right side.\n {w, h}, {0, h}\n };\n HRGN region = ::CreatePolygonRgn(polygon, arraysize(polygon), WINDING);\n ::SetWindowRgn(window, region, FALSE);\n}\n\nvoid TryChromeDialogView::ButtonPressed(views::Button* sender,\n const views::Event& event) {\n if (sender->tag() == BT_CLOSE_BUTTON) {\n \/\/ The user pressed cancel or the [x] button.\n result_ = NOT_NOW;\n } else if (!try_chrome_) {\n \/\/ We don't have radio buttons, the user pressed ok.\n result_ = TRY_CHROME;\n } else {\n \/\/ The outcome is according to the selected ratio button.\n result_ = try_chrome_->checked() ? TRY_CHROME : UNINSTALL_CHROME;\n }\n popup_->Close();\n MessageLoop::current()->Quit();\n}\n\nvoid TryChromeDialogView::LinkClicked(views::Link* source, int event_flags) {\n ::ShellExecuteW(NULL, L\"open\", kHelpCenterUrl, NULL, NULL, SW_SHOW);\n}\nfirst_run: Call ResourceBundle::GetNativeImageNamed() instead of GetBitmapNamed().\/\/ Copyright (c) 2011 The Chromium Authors. All rights reserved.\n\/\/ Use of this source code is governed by a BSD-style license that can be\n\/\/ found in the LICENSE file.\n\n#include \"chrome\/browser\/first_run\/try_chrome_dialog_view.h\"\n\n#include \n\n#include \"base\/logging.h\"\n#include \"base\/message_loop.h\"\n#include \"base\/string16.h\"\n#include \"chrome\/browser\/process_singleton.h\"\n#include \"chrome\/installer\/util\/browser_distribution.h\"\n#include \"grit\/chromium_strings.h\"\n#include \"grit\/generated_resources.h\"\n#include \"grit\/theme_resources.h\"\n#include \"grit\/theme_resources_standard.h\"\n#include \"ui\/base\/l10n\/l10n_util.h\"\n#include \"ui\/base\/resource\/resource_bundle.h\"\n#include \"ui\/gfx\/image.h\"\n#include \"views\/controls\/button\/image_button.h\"\n#include \"views\/controls\/button\/radio_button.h\"\n#include \"views\/controls\/image_view.h\"\n#include \"views\/controls\/link.h\"\n#include \"views\/layout\/grid_layout.h\"\n#include \"views\/layout\/layout_constants.h\"\n#include \"views\/widget\/root_view.h\"\n#include \"views\/widget\/widget.h\"\n\nnamespace {\n\nconst wchar_t kHelpCenterUrl[] =\n L\"https:\/\/www.google.com\/support\/chrome\/bin\/answer.py?answer=150752\";\n\n} \/\/ namespace\n\n\/\/ static\nTryChromeDialogView::Result TryChromeDialogView::Show(\n size_t version,\n ProcessSingleton* process_singleton) {\n if (version > 10000) {\n \/\/ This is a test value. We want to make sure we exercise\n \/\/ returning this early. See EarlyReturnTest test harness.\n return NOT_NOW;\n }\n TryChromeDialogView dialog(version);\n return dialog.ShowModal(process_singleton);\n}\n\nTryChromeDialogView::TryChromeDialogView(size_t version)\n : version_(version),\n popup_(NULL),\n try_chrome_(NULL),\n kill_chrome_(NULL),\n result_(COUNT) {\n}\n\nTryChromeDialogView::~TryChromeDialogView() {\n}\n\nTryChromeDialogView::Result TryChromeDialogView::ShowModal(\n ProcessSingleton* process_singleton) {\n ResourceBundle& rb = ResourceBundle::GetSharedInstance();\n\n views::ImageView* icon = new views::ImageView();\n icon->SetImage(*rb.GetNativeImageNamed(IDR_PRODUCT_ICON_32));\n gfx::Size icon_size = icon->GetPreferredSize();\n\n \/\/ An approximate window size. After Layout() we'll get better bounds.\n popup_ = new views::Widget;\n if (!popup_) {\n NOTREACHED();\n return DIALOG_ERROR;\n }\n\n views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);\n params.can_activate = true;\n params.bounds = gfx::Rect(310, 160);\n popup_->Init(params);\n\n views::RootView* root_view = popup_->GetRootView();\n \/\/ The window color is a tiny bit off-white.\n root_view->set_background(\n views::Background::CreateSolidBackground(0xfc, 0xfc, 0xfc));\n\n views::GridLayout* layout = views::GridLayout::CreatePanel(root_view);\n if (!layout) {\n NOTREACHED();\n return DIALOG_ERROR;\n }\n root_view->SetLayoutManager(layout);\n\n views::ColumnSet* columns;\n \/\/ First row: [icon][pad][text][button].\n columns = layout->AddColumnSet(0);\n columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 0,\n views::GridLayout::FIXED, icon_size.width(),\n icon_size.height());\n columns->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);\n columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,\n views::GridLayout::USE_PREF, 0, 0);\n columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, 1,\n views::GridLayout::USE_PREF, 0, 0);\n \/\/ Second row: [pad][pad][radio 1].\n columns = layout->AddColumnSet(1);\n columns->AddPaddingColumn(0, icon_size.width());\n columns->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);\n columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1,\n views::GridLayout::USE_PREF, 0, 0);\n \/\/ Third row: [pad][pad][radio 2].\n columns = layout->AddColumnSet(2);\n columns->AddPaddingColumn(0, icon_size.width());\n columns->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);\n columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1,\n views::GridLayout::USE_PREF, 0, 0);\n \/\/ Fourth row: [pad][pad][button][pad][button].\n columns = layout->AddColumnSet(3);\n columns->AddPaddingColumn(0, icon_size.width());\n columns->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);\n columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 0,\n views::GridLayout::USE_PREF, 0, 0);\n columns->AddPaddingColumn(0, views::kRelatedButtonHSpacing);\n columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 0,\n views::GridLayout::USE_PREF, 0, 0);\n \/\/ Fifth row: [pad][pad][link].\n columns = layout->AddColumnSet(4);\n columns->AddPaddingColumn(0, icon_size.width());\n columns->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);\n columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1,\n views::GridLayout::USE_PREF, 0, 0);\n \/\/ First row views.\n layout->StartRow(0, 0);\n layout->AddView(icon);\n\n \/\/ Find out what experiment we are conducting.\n BrowserDistribution* dist = BrowserDistribution::GetDistribution();\n if (!dist) {\n NOTREACHED() << \"Cannot determine browser distribution\";\n return DIALOG_ERROR;\n }\n BrowserDistribution::UserExperiment experiment;\n if (!dist->GetExperimentDetails(&experiment, version_) ||\n !experiment.heading) {\n NOTREACHED() << \"Cannot determine which headline to show.\";\n return DIALOG_ERROR;\n }\n string16 heading = l10n_util::GetStringUTF16(experiment.heading);\n views::Label* label = new views::Label(heading);\n label->SetFont(rb.GetFont(ResourceBundle::MediumBoldFont));\n label->SetMultiLine(true);\n label->SizeToFit(200);\n label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);\n layout->AddView(label);\n \/\/ The close button is custom.\n views::ImageButton* close_button = new views::ImageButton(this);\n close_button->SetImage(views::CustomButton::BS_NORMAL,\n rb.GetNativeImageNamed(IDR_CLOSE_BAR));\n close_button->SetImage(views::CustomButton::BS_HOT,\n rb.GetNativeImageNamed(IDR_CLOSE_BAR_H));\n close_button->SetImage(views::CustomButton::BS_PUSHED,\n rb.GetNativeImageNamed(IDR_CLOSE_BAR_P));\n close_button->set_tag(BT_CLOSE_BUTTON);\n layout->AddView(close_button);\n\n \/\/ Second row views.\n const string16 try_it(l10n_util::GetStringUTF16(IDS_TRY_TOAST_TRY_OPT));\n layout->StartRowWithPadding(0, 1, 0, 10);\n try_chrome_ = new views::RadioButton(try_it, 1);\n layout->AddView(try_chrome_);\n try_chrome_->SetChecked(true);\n\n \/\/ Third row views.\n const string16 kill_it(l10n_util::GetStringUTF16(IDS_UNINSTALL_CHROME));\n layout->StartRow(0, 2);\n kill_chrome_ = new views::RadioButton(kill_it, 1);\n layout->AddView(kill_chrome_);\n\n \/\/ Fourth row views.\n const string16 ok_it(l10n_util::GetStringUTF16(IDS_OK));\n const string16 cancel_it(l10n_util::GetStringUTF16(IDS_TRY_TOAST_CANCEL));\n const string16 why_this(l10n_util::GetStringUTF16(IDS_TRY_TOAST_WHY));\n layout->StartRowWithPadding(0, 3, 0, 10);\n views::Button* accept_button = new views::NativeButton(this, ok_it);\n accept_button->set_tag(BT_OK_BUTTON);\n layout->AddView(accept_button);\n views::Button* cancel_button = new views::NativeButton(this, cancel_it);\n cancel_button->set_tag(BT_CLOSE_BUTTON);\n layout->AddView(cancel_button);\n \/\/ Fifth row views.\n layout->StartRowWithPadding(0, 4, 0, 10);\n views::Link* link = new views::Link(why_this);\n link->set_listener(this);\n layout->AddView(link);\n\n \/\/ We resize the window according to the layout manager. This takes into\n \/\/ account the differences between XP and Vista fonts and buttons.\n layout->Layout(root_view);\n gfx::Size preferred = layout->GetPreferredSize(root_view);\n gfx::Rect pos = ComputeWindowPosition(preferred.width(), preferred.height(),\n base::i18n::IsRTL());\n popup_->SetBounds(pos);\n\n \/\/ Carve the toast shape into the window.\n SetToastRegion(popup_->GetNativeView(),\n preferred.width(), preferred.height());\n\n \/\/ Time to show the window in a modal loop. We don't want this chrome\n \/\/ instance trying to serve WM_COPYDATA requests, as we'll surely crash.\n process_singleton->Lock(popup_->GetNativeView());\n popup_->Show();\n MessageLoop::current()->Run();\n process_singleton->Unlock();\n return result_;\n}\n\ngfx::Rect TryChromeDialogView::ComputeWindowPosition(int width,\n int height,\n bool is_RTL) {\n \/\/ The 'Shell_TrayWnd' is the taskbar. We like to show our window in that\n \/\/ monitor if we can. This code works even if such window is not found.\n HWND taskbar = ::FindWindowW(L\"Shell_TrayWnd\", NULL);\n HMONITOR monitor = ::MonitorFromWindow(taskbar, MONITOR_DEFAULTTOPRIMARY);\n MONITORINFO info = {sizeof(info)};\n if (!GetMonitorInfoW(monitor, &info)) {\n \/\/ Quite unexpected. Do a best guess at a visible rectangle.\n return gfx::Rect(20, 20, width + 20, height + 20);\n }\n \/\/ The |rcWork| is the work area. It should account for the taskbars that\n \/\/ are in the screen when we called the function.\n int left = is_RTL ? info.rcWork.left : info.rcWork.right - width;\n int top = info.rcWork.bottom - height;\n return gfx::Rect(left, top, width, height);\n}\n\nvoid TryChromeDialogView::SetToastRegion(HWND window, int w, int h) {\n static const POINT polygon[] = {\n {0, 4}, {1, 2}, {2, 1}, {4, 0}, \/\/ Left side.\n {w-4, 0}, {w-2, 1}, {w-1, 2}, {w, 4}, \/\/ Right side.\n {w, h}, {0, h}\n };\n HRGN region = ::CreatePolygonRgn(polygon, arraysize(polygon), WINDING);\n ::SetWindowRgn(window, region, FALSE);\n}\n\nvoid TryChromeDialogView::ButtonPressed(views::Button* sender,\n const views::Event& event) {\n if (sender->tag() == BT_CLOSE_BUTTON) {\n \/\/ The user pressed cancel or the [x] button.\n result_ = NOT_NOW;\n } else if (!try_chrome_) {\n \/\/ We don't have radio buttons, the user pressed ok.\n result_ = TRY_CHROME;\n } else {\n \/\/ The outcome is according to the selected ratio button.\n result_ = try_chrome_->checked() ? TRY_CHROME : UNINSTALL_CHROME;\n }\n popup_->Close();\n MessageLoop::current()->Quit();\n}\n\nvoid TryChromeDialogView::LinkClicked(views::Link* source, int event_flags) {\n ::ShellExecuteW(NULL, L\"open\", kHelpCenterUrl, NULL, NULL, SW_SHOW);\n}\n<|endoftext|>"} {"text":"\/\/ Copyright (c) 2010 The Chromium Authors. All rights reserved.\n\/\/ Use of this source code is governed by a BSD-style license that can be\n\/\/ found in the LICENSE file.\n\n#include \"chrome\/browser\/in_process_webkit\/webkit_context.h\"\n\n#include \"base\/command_line.h\"\n#include \"chrome\/browser\/browser_thread.h\"\n#include \"chrome\/browser\/profile.h\"\n#include \"chrome\/common\/chrome_switches.h\"\n\nWebKitContext::WebKitContext(Profile* profile)\n : data_path_(profile->IsOffTheRecord() ? FilePath() : profile->GetPath()),\n is_incognito_(profile->IsOffTheRecord()),\n ALLOW_THIS_IN_INITIALIZER_LIST(\n dom_storage_context_(new DOMStorageContext(this))),\n ALLOW_THIS_IN_INITIALIZER_LIST(\n indexed_db_context_(new IndexedDBContext(this))) {\n}\n\nWebKitContext::~WebKitContext() {\n \/\/ If the WebKit thread was ever spun up, delete the object there. The task\n \/\/ will just get deleted if the WebKit thread isn't created (which only\n \/\/ happens during testing).\n DOMStorageContext* dom_storage_context = dom_storage_context_.release();\n if (!BrowserThread::DeleteSoon(\n BrowserThread::WEBKIT, FROM_HERE, dom_storage_context)) {\n \/\/ The WebKit thread wasn't created, and the task got deleted without\n \/\/ freeing the DOMStorageContext, so delete it manually.\n delete dom_storage_context;\n }\n\n IndexedDBContext* indexed_db_context = indexed_db_context_.release();\n if (!BrowserThread::DeleteSoon(\n BrowserThread::WEBKIT, FROM_HERE, indexed_db_context)) {\n delete indexed_db_context;\n }\n}\n\nvoid WebKitContext::PurgeMemory() {\n if (!BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)) {\n bool result = BrowserThread::PostTask(\n BrowserThread::WEBKIT, FROM_HERE,\n NewRunnableMethod(this, &WebKitContext::PurgeMemory));\n DCHECK(result);\n return;\n }\n\n dom_storage_context_->PurgeMemory();\n}\n\nvoid WebKitContext::DeleteDataModifiedSince(\n const base::Time& cutoff,\n const char* url_scheme_to_be_skipped,\n const std::vector& protected_origins) {\n if (!BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)) {\n bool result = BrowserThread::PostTask(\n BrowserThread::WEBKIT, FROM_HERE,\n NewRunnableMethod(this, &WebKitContext::DeleteDataModifiedSince,\n cutoff, url_scheme_to_be_skipped, protected_origins));\n DCHECK(result);\n return;\n }\n\n dom_storage_context_->DeleteDataModifiedSince(\n cutoff, url_scheme_to_be_skipped, protected_origins);\n}\n\n\nvoid WebKitContext::DeleteSessionStorageNamespace(\n int64 session_storage_namespace_id) {\n if (!BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)) {\n BrowserThread::PostTask(\n BrowserThread::WEBKIT, FROM_HERE,\n NewRunnableMethod(this, &WebKitContext::DeleteSessionStorageNamespace,\n session_storage_namespace_id));\n return;\n }\n\n dom_storage_context_->DeleteSessionStorageNamespace(\n session_storage_namespace_id);\n}\nDon't assert if PostTask fails for WEBKIT thread, since it doesn't exist on single-process mode. This asserts when the cache is cleared. Review URL: http:\/\/codereview.chromium.org\/4165007\/\/ Copyright (c) 2010 The Chromium Authors. All rights reserved.\n\/\/ Use of this source code is governed by a BSD-style license that can be\n\/\/ found in the LICENSE file.\n\n#include \"chrome\/browser\/in_process_webkit\/webkit_context.h\"\n\n#include \"base\/command_line.h\"\n#include \"chrome\/browser\/browser_thread.h\"\n#include \"chrome\/browser\/profile.h\"\n#include \"chrome\/common\/chrome_switches.h\"\n\nWebKitContext::WebKitContext(Profile* profile)\n : data_path_(profile->IsOffTheRecord() ? FilePath() : profile->GetPath()),\n is_incognito_(profile->IsOffTheRecord()),\n ALLOW_THIS_IN_INITIALIZER_LIST(\n dom_storage_context_(new DOMStorageContext(this))),\n ALLOW_THIS_IN_INITIALIZER_LIST(\n indexed_db_context_(new IndexedDBContext(this))) {\n}\n\nWebKitContext::~WebKitContext() {\n \/\/ If the WebKit thread was ever spun up, delete the object there. The task\n \/\/ will just get deleted if the WebKit thread isn't created (which only\n \/\/ happens during testing).\n DOMStorageContext* dom_storage_context = dom_storage_context_.release();\n if (!BrowserThread::DeleteSoon(\n BrowserThread::WEBKIT, FROM_HERE, dom_storage_context)) {\n \/\/ The WebKit thread wasn't created, and the task got deleted without\n \/\/ freeing the DOMStorageContext, so delete it manually.\n delete dom_storage_context;\n }\n\n IndexedDBContext* indexed_db_context = indexed_db_context_.release();\n if (!BrowserThread::DeleteSoon(\n BrowserThread::WEBKIT, FROM_HERE, indexed_db_context)) {\n delete indexed_db_context;\n }\n}\n\nvoid WebKitContext::PurgeMemory() {\n if (!BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)) {\n BrowserThread::PostTask(\n BrowserThread::WEBKIT, FROM_HERE,\n NewRunnableMethod(this, &WebKitContext::PurgeMemory));\n return;\n }\n\n dom_storage_context_->PurgeMemory();\n}\n\nvoid WebKitContext::DeleteDataModifiedSince(\n const base::Time& cutoff,\n const char* url_scheme_to_be_skipped,\n const std::vector& protected_origins) {\n if (!BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)) {\n BrowserThread::PostTask(\n BrowserThread::WEBKIT, FROM_HERE,\n NewRunnableMethod(this, &WebKitContext::DeleteDataModifiedSince,\n cutoff, url_scheme_to_be_skipped, protected_origins));\n return;\n }\n\n dom_storage_context_->DeleteDataModifiedSince(\n cutoff, url_scheme_to_be_skipped, protected_origins);\n}\n\n\nvoid WebKitContext::DeleteSessionStorageNamespace(\n int64 session_storage_namespace_id) {\n if (!BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)) {\n BrowserThread::PostTask(\n BrowserThread::WEBKIT, FROM_HERE,\n NewRunnableMethod(this, &WebKitContext::DeleteSessionStorageNamespace,\n session_storage_namespace_id));\n return;\n }\n\n dom_storage_context_->DeleteSessionStorageNamespace(\n session_storage_namespace_id);\n}\n<|endoftext|>"} {"text":"#include \n#include \n#include \n#ifndef _WIN32\n#include \n#else\n#include \n\n\/\/#define sleep(n) Sleep(n)\n#endif\n\nint main(int argc, char *argv[]) {\n\t\/\/ Prepare our context and socket\n\tzmq::context_t context(1);\n\tzmq::socket_t socket(context, ZMQ_REP);\n\tsocket.bind(\"tcp:\/\/*:5577\");\n\n\twhile (true) {\n\t\tzmq::message_t request;\n\n\t\t\/\/ Wait for next request from client\n\t\tsocket.recv(&request);\n\t\tstd::cout << \"Received: \" << (char *)request.data() << std::endl;\n\n\t\t\/\/ Do some 'work'\n\t\t\/\/ sleep(1);\n\n\t\t\/\/ Send reply back to client\n\t\tzmq::message_t reply(5);\n\t\tmemcpy(reply.data(), \"DONE\", 5);\n\t\tsocket.send(reply);\n\t}\n\treturn 0;\n}\nEnable IPV6#include \n#include \n#include \n#ifndef _WIN32\n#include \n#else\n#include \n\n\/\/#define sleep(n) Sleep(n)\n#endif\n\nint main(int argc, char *argv[]) {\n\n\t\/\/ Prepare our context and socket\n\tzmq::context_t context(1);\n\tzmq::socket_t socket(context, ZMQ_REP);\n\n\tint opt = 1;\n\tsocket.setsockopt(ZMQ_IPV6, &opt, sizeof(int));\n\tsocket.bind(\"tcp:\/\/*:5577\");\n\n\twhile (true) {\n\t\tzmq::message_t request;\n\n\t\t\/\/ Wait for next request from client\n\t\tsocket.recv(&request);\n\t\tstd::cout << \"Received: \" << (char *)request.data() << std::endl;\n\n\t\t\/\/ Do some 'work'\n\t\t\/\/ sleep(1);\n\n\t\t\/\/ Send reply back to client\n\t\tzmq::message_t reply(5);\n\t\tmemcpy(reply.data(), \"DONE\", 5);\n\t\tsocket.send(reply);\n\t}\n\treturn 0;\n}\n<|endoftext|>"} {"text":"#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n#include \"Graph.h\"\n\nusing namespace std;\n\nclass VertexEntry\n{\n public:\n\n Vertex* v;\n \/\/static int idc;\n\n VertexEntry(const Vertex* pV)\n {\n v = (Vertex*) &(*pV);\n }\n\/*\n VertexEntry& operator=(const VertexEntry & rhs)\n {\n if(this != &rhs)\n {\n if(rhs.v){ v = new Vertex(*rhs.v); }\n \/\/v = (Vertex*) &(*rhs.v);\n }\n return *this;\n }\n*\/\n bool operator==(const VertexEntry & rhs)\n {\n return *v == *(rhs.v);\n }\n\n bool operator<(const VertexEntry & rhs)\n {\n return v->d < rhs.v->d;\n }\n\n bool operator>(const VertexEntry & rhs)\n {\n \/\/return !(*this < rhs);\n return v->d > rhs.v->d;\n }\n\n};\n\n\/\/int VertexEntry::idc = 0;\nbool operator==(VertexEntry lhs, VertexEntry rhs) { return *lhs.v == *rhs.v; };\nbool operator>(VertexEntry lhs, VertexEntry rhs) { return lhs.v->d > rhs.v->d; };\nbool operator<(VertexEntry lhs, VertexEntry rhs) { return lhs.v->d < rhs.v->d; };\n\n\/*\nvoid set_input()\n{\n src = 0; tgt = 5;\n cout << \"Input source city index: \" << src << endl;\n cout << \"Input destination city index: \" << tgt << endl;\n cout << \"Computing shortest path from: \" << src << \" to \"\n << tgt << endl;\n}\n*\/\n\nstring srcstr, tgtstr;\nGraph g(false, true);\nmap cities;\nint NV, NE;\n\n\/**\n *\n *\/\nvoid get_input()\n{\n cout << \"Input source city index: \";\n cin >> srcstr;\n cout << \"Input destination city index: \";\n cin >> tgtstr;\n cout << \"Computing shortest path from: \" << srcstr << \" to \"\n << tgtstr << endl;\n}\n\n\/**\n *\n *\/\nbool make_graph(string input = \".\/doc\/sample.txt\")\n{\n int i = 0;\n bool ok = true;\n Point p;\n string s;\n stringstream ss;\n Vertex *u,\n *v;\n\n cout << \"Generating graph from file: \" << input << endl;\n\n ifstream in(input.c_str(), ios::in);\n\n if(in.is_open())\n {\n in >> NV >> NE;\n\n cout << \"Map contains \" << NV << \" verticies (cities) and \"\n << NE << \" edges\" << endl\n << \"Generating city coordinates...\" << endl;\n\n for( ; i < NV; ++i)\n {\n Vertex vtx;\n\n in >> vtx.p.idx;\n in >> vtx.p.x;\n in >> vtx.p.y;\n\n ss << vtx.p.idx;\n vtx.id = ss.str();\n ss.str(\"\"); ss.clear();\n\n g.add_vertex(vtx);\n }\n\n cout << \"Generated \" << cities.size() << \" city coordinates\" << endl\n << \"Connecting edges between cities in graph...\" << endl;\n\n for(i = 0; i < NE && ok; ++i)\n {\n in >> s;\n u = g.get_vertex(s);\n in >> s;\n v = g.get_vertex(s);\n\n if(u && v)\n {\n cout << u->id << \"->\" << v->id << \" | \" << u->distance(*v)\n << endl;\n g.add_edge(u, v, u->distance(*v));\n }\n else\n {\n cerr << \"Error: Could not locate verticies exiting...\" << endl;\n ok = false;\n }\n }\n\n if (ok) cout << \"Connected \" << g.esize() << \" edges\" << endl;\n\n in.close();\n }\n else cerr << \"Could not open: \" << input << \" for reading\" << endl;\n\n return ok;\n}\n\n#define extract_min(q, u) { u = q.top().v; q.pop(); }\n\n\/**\n *\n *\/\nvoid print_q(priority_queue, std::greater >& pq)\n{\n cout << \"Rendering Priority Queue...\" << endl;\n priority_queue, std::greater > c;\n c = pq;\n while(!c.empty())\n {\n VertexEntry* ve = (VertexEntry*) &c.top();\n Vertex* u = ve->v;\n cout << \"extract-min: \" << \"u[\" << u->id << \"]: \" << u->d << endl;\n c.pop();\n }\n}\n\n\/**\n *\n *\/\nmap< pair, double> DIJKSTRA(Graph & g, Vertex* & src, Vertex* & tgt, map< pair, double> pd)\n{\n Vertex *v, *u;\n Edge* e;\n set s;\n float w;\n\n g.init_single_src(src);\n priority_queue, std::greater > pq;\n\n cout << \"Dijkstra Initialized Using Min Priority Queue...\" << endl;\n\n for(VertexMapIt i = g.VE.begin(); i != g.VE.end(); ++i)\n {\n v = (Vertex*) &i->first;\n VertexEntry ve(v);\n pq.push(ve);\n }\n\n print_q(pq);\n\n while(!pq.empty())\n {\n \/\/extract_min(pq, u);\n \/\/s.insert(VertexEntry(u));\n VertexEntry* ve = (VertexEntry*) &pq.top();\n u = ve->v;\n s.insert(*ve);\n pq.pop();\n cout << \"extract-min: \" << u->id << \" : \" << u->d << endl;\n AdjListIt ait = u->adj->begin();\n for( ; ait != u->adj->end(); ++ait)\n {\n v = *ait;\n w = g.get_edge(u, v)->cap;\n cout << \"ud[\" << u->id << \"]: \" << u->d << \" vd[\" << v->id << \"]: \"\n << v->d << \" w: \" << w << endl;\n g.relax(u, v, w);\/*\n if(g.relax(*u, *v, e->cap))\n {\n pair k = make_pair(u->id, v->id);\n pd[k] = v->d;\n }*\/\n }\n cout << \"Vertex[\" << u->id << \"] processed\" << endl;\n }\n\n cout << \"All pairs shortest path\" << endl;\n\n for(set::iterator vei = s.begin(); vei != s.end(); ++vei)\n {\n VertexEntry ve = *vei;\n cout << \"v[\" << ve.v->id << \"]: \" << ve.v->d << endl;\n }\n\n cout << \"All pairs shortest path complete...rendering path\" << endl;\n\n Vertex* vtgt = g.get_vertex(*tgt);\n\n if(vtgt)\n {\n cout << vtgt->id << \" -> \";\n Vertex* rent = vtgt->pi;\n while(rent)\n {\n cout << rent->id ;\n rent = rent->pi;\n if(rent) cout << \" -> \";\n }\n cout << endl;\n\n VertexEntry ve(tgt);\n set::iterator sit = s.find(ve);\n if(sit != s.end())\n {\n VertexEntry ve = *sit;\n cout << \"Total Distance: \" << ve.v->d << endl;\n }\n }\n\n return pd;\n}\n\/**\n *\n *\/\nvoid PRINT_APSP(map< pair, double> & apsp)\n{\n cout << \"Rendering APSP...\\n\";\n\n if(apsp.size() < 1)\n {\n cout << \"None\\n\";\n }\n else\n {\n map< pair, double>::iterator i = apsp.begin(),\n e = apsp.end();\n\n while(i != e)\n {\n cout << i->first.first << \" -> \" << i->first.second << \" \"\n << i->second << endl;\n ++i;\n }\n }\n}\n\n\/**\n *\n *\/\nint main(int argc, char* argv[])\n{\n string mapfile;\n bool ok = true;\n\n if(argc == 2)\n {\n stringstream s;\n\n s << argv[1];\n s >> mapfile;\n ok = make_graph(mapfile);\n }\n else\n {\n ok = make_graph();\n }\n if(ok)\n {\n get_input();\n\/*\n Graph g(false, true);\n g.add_edge(\"0\", \"1\", 4);\n g.add_edge(\"0\", \"7\", 8);\n g.add_edge(\"1\", \"2\", 8);\n g.add_edge(\"1\", \"7\", 11);\n g.add_edge(\"2\", \"3\", 7);\n g.add_edge(\"2\", \"8\", 2);\n g.add_edge(\"2\", \"5\", 4);\n g.add_edge(\"3\", \"4\", 9);\n g.add_edge(\"3\", \"5\", 14);\n g.add_edge(\"4\", \"5\", 10);\n g.add_edge(\"5\", \"6\", 2);\n g.add_edge(\"6\", \"7\", 1);\n g.add_edge(\"6\", \"8\", 6);\n g.add_edge(\"7\", \"8\", 7);\n*\/\n \/\/cout << g << endl;\n Vertex *src = g.get_vertex(srcstr),\n *tgt = g.get_vertex(tgtstr);\n if(!src)\n cout << \"Error: Could not retrive source city \" << srcstr << endl;\n else if(!src)\n cout << \"Error: Could not retrive destination city \" << tgtstr << endl;\n else\n {\n map< pair, double> r;\n DIJKSTRA(g, src, tgt, r);\n }\n }\n\n return 0;\n}\nFixed opposite dir issue using make_heap to extract-min properly#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \/\/heapify\n\n#include \"Graph.h\"\n\nusing namespace std;\n\nclass VertexEntry\n{\n public:\n\n Vertex* v;\n \/\/static int idc;\n\n VertexEntry()\n {\n v = 0;\n }\n\n VertexEntry(const Vertex* pV)\n {\n v = (Vertex*) &(*pV);\n }\n\/*\n VertexEntry& operator=(const VertexEntry & rhs)\n {\n if(this != &rhs)\n {\n if(rhs.v){ v = new Vertex(*rhs.v); }\n \/\/v = (Vertex*) &(*rhs.v);\n }\n return *this;\n }\n*\/\n bool operator==(const VertexEntry & rhs)\n {\n return *v == *(rhs.v);\n }\n\n bool operator<(const VertexEntry & rhs)\n {\n return v->d < rhs.v->d;\n }\n\n bool operator>(const VertexEntry & rhs)\n {\n \/\/return !(*this < rhs);\n return v->d > rhs.v->d;\n }\n\n};\n\n\/\/int VertexEntry::idc = 0;\nbool operator==(VertexEntry lhs, VertexEntry rhs) { return *lhs.v == *rhs.v; };\nbool operator>(VertexEntry lhs, VertexEntry rhs) { return lhs.v->d > rhs.v->d; };\nbool operator<(VertexEntry lhs, VertexEntry rhs) { return lhs.v->d < rhs.v->d; };\n\nbool mcomp(VertexEntry lhs, VertexEntry rhs) { return lhs.v->d > rhs.v->d; };\n\/*\nvoid set_input()\n{\n src = 0; tgt = 5;\n cout << \"Input source city index: \" << src << endl;\n cout << \"Input destination city index: \" << tgt << endl;\n cout << \"Computing shortest path from: \" << src << \" to \"\n << tgt << endl;\n}\n*\/\n\nstring srcstr, tgtstr;\nGraph g(false, true);\nmap cities;\nint NV, NE;\n\n\/**\n *\n *\/\nvoid get_input()\n{\n cout << \"Input source city index: \";\n cin >> srcstr;\n cout << \"Input destination city index: \";\n cin >> tgtstr;\n cout << \"Computing shortest path from: \" << srcstr << \" to \"\n << tgtstr << endl;\n}\n\n\/**\n *\n *\/\nbool make_graph(string input = \".\/doc\/sample.txt\")\n{\n int i = 0;\n bool ok = true;\n Point p;\n string s;\n stringstream ss;\n Vertex *u,\n *v;\n\n cout << \"Generating graph from file: \" << input << endl;\n\n ifstream in(input.c_str(), ios::in);\n\n if(in.is_open())\n {\n in >> NV >> NE;\n\n cout << \"Map contains \" << NV << \" verticies (cities) and \"\n << NE << \" edges\" << endl\n << \"Generating city coordinates...\" << endl;\n\n for( ; i < NV; ++i)\n {\n Vertex vtx;\n\n in >> vtx.p.idx;\n in >> vtx.p.x;\n in >> vtx.p.y;\n\n ss << vtx.p.idx;\n vtx.id = ss.str();\n ss.str(\"\"); ss.clear();\n\n g.add_vertex(vtx);\n }\n\n cout << \"Generated \" << cities.size() << \" city coordinates\" << endl\n << \"Connecting edges between cities in graph...\" << endl;\n\n for(i = 0; i < NE && ok; ++i)\n {\n in >> s;\n u = g.get_vertex(s);\n in >> s;\n v = g.get_vertex(s);\n\n if(u && v)\n {\n cout << u->id << \"->\" << v->id << \" | \" << u->distance(*v)\n << endl;\n g.add_edge(u, v, u->distance(*v));\n }\n else\n {\n cerr << \"Error: Could not locate verticies exiting...\" << endl;\n ok = false;\n }\n }\n\n if (ok) cout << \"Connected \" << g.esize() << \" edges\" << endl;\n\n in.close();\n cout << g << endl;\n }\n else cerr << \"Could not open: \" << input << \" for reading\" << endl;\n\n return ok;\n}\n\n#define extract_min(q, u) { u = q.top().v; q.pop(); }\n\n\/**\n *\n *\/\nvoid print_q(priority_queue, std::greater >& pq)\n{\n cout << \"Rendering Priority Queue...\" << endl;\n priority_queue, std::greater > c;\n c = pq;\n while(!c.empty())\n {\n VertexEntry* ve = (VertexEntry*) &c.top();\n Vertex* u = ve->v;\n cout << \"extract-min: \" << \"u[\" << u->id << \"]: \" << u->d << endl;\n c.pop();\n }\n}\n\n\/**\n *\n *\/\nmap< pair, double> DIJKSTRA(Graph & g, Vertex* & src, Vertex* & tgt, map< pair, double> pd)\n{\n Vertex *v, *u;\n Edge* e;\n set s;\n float w;\n\n g.init_single_src(src);\n priority_queue, greater > pq;\n\n cout << \"Dijkstra Initialized Using Min Priority Queue...\" << endl;\n\n for(VertexMapIt i = g.VE.begin(); i != g.VE.end(); ++i)\n {\n v = (Vertex*) &i->first;\n VertexEntry ve(v);\n pq.push(ve);\n }\n\n\n while(!pq.empty())\n {\n \/\/extract_min(pq, u);\n \/\/s.insert(VertexEntry(u));\n print_q(pq);\n VertexEntry* ve = (VertexEntry*) &pq.top();\n u = ve->v;\n s.insert(*ve);\n pq.pop();\n cout << \"extract-min: \" << u->id << \" : \" << u->d << endl;\n AdjListIt ait = u->adj->begin();\n for( ; ait != u->adj->end(); ++ait)\n {\n v = *ait;\n w = g.get_edge(u, v)->cap;\n cout << \"ud[\" << u->id << \"]: \" << u->d << \" vd[\" << v->id << \"]: \"\n << v->d << \" w: \" << w << endl;\n if(g.relax(u, v, w))\n {\n cout << \"-------RELAX-------\" << endl;\n cout << \"ud[\" << u->id << \"]: \" << u->d << \" vd[\" << v->id << \"]: \"\n << v->d << \" w: \" << w << endl;\n cout << \"-------RELAX-------\" << endl;\n }\/*\n if(g.relax(*u, *v, e->cap))\n {\n pair k = make_pair(u->id, v->id);\n pd[k] = v->d;\n }*\/\n }\n cout << \"Vertex[\" << u->id << \"] processed\" << endl;\n make_heap(const_cast(&pq.top()), const_cast(&pq.top()) + pq.size(), mcomp);\n }\n\n cout << \"All pairs shortest path\" << endl;\n\n for(set::iterator vei = s.begin(); vei != s.end(); ++vei)\n {\n VertexEntry ve = *vei;\n cout << \"v[\" << ve.v->id << \"]: \" << ve.v->d << endl;\n }\n\n cout << \"All pairs shortest path complete...rendering path\" << endl;\n\n Vertex* vtgt = g.get_vertex(*tgt);\n\n if(vtgt)\n {\n cout << vtgt->id << \" -> \";\n Vertex* rent = vtgt->pi;\n while(rent)\n {\n cout << rent->id ;\n rent = rent->pi;\n if(rent) cout << \" -> \";\n }\n cout << endl;\n\n VertexEntry ve(tgt);\n set::iterator sit = s.find(ve);\n if(sit != s.end())\n {\n VertexEntry ve = *sit;\n cout << \"Total Distance: \" << ve.v->d << endl;\n }\n }\n\n return pd;\n}\n\/**\n *\n *\/\nvoid PRINT_APSP(map< pair, double> & apsp)\n{\n cout << \"Rendering APSP...\\n\";\n\n if(apsp.size() < 1)\n {\n cout << \"None\\n\";\n }\n else\n {\n map< pair, double>::iterator i = apsp.begin(),\n e = apsp.end();\n\n while(i != e)\n {\n cout << i->first.first << \" -> \" << i->first.second << \" \"\n << i->second << endl;\n ++i;\n }\n }\n}\n\n\/**\n *\n *\/\nint main(int argc, char* argv[])\n{\n string mapfile;\n bool ok = true;\n\n if(argc == 2)\n {\n stringstream s;\n\n s << argv[1];\n s >> mapfile;\n ok = make_graph(mapfile);\n }\n else\n {\n ok = make_graph();\n }\n if(ok)\n {\n get_input();\n\/*\n Graph g(false, true);\n g.add_edge(\"0\", \"1\", 4);\n g.add_edge(\"0\", \"7\", 8);\n g.add_edge(\"1\", \"2\", 8);\n g.add_edge(\"1\", \"7\", 11);\n g.add_edge(\"2\", \"3\", 7);\n g.add_edge(\"2\", \"8\", 2);\n g.add_edge(\"2\", \"5\", 4);\n g.add_edge(\"3\", \"4\", 9);\n g.add_edge(\"3\", \"5\", 14);\n g.add_edge(\"4\", \"5\", 10);\n g.add_edge(\"5\", \"6\", 2);\n g.add_edge(\"6\", \"7\", 1);\n g.add_edge(\"6\", \"8\", 6);\n g.add_edge(\"7\", \"8\", 7);\n*\/\n \/\/cout << g << endl;\n Vertex *src = g.get_vertex(srcstr),\n *tgt = g.get_vertex(tgtstr);\n if(!src)\n cout << \"Error: Could not retrive source city \" << srcstr << endl;\n else if(!src)\n cout << \"Error: Could not retrive destination city \" << tgtstr << endl;\n else\n {\n map< pair, double> r;\n DIJKSTRA(g, src, tgt, r);\n }\n }\n\n return 0;\n}\n<|endoftext|>"} {"text":"#ifndef BULL_CORE_FILESYSTEM_FILE_HPP\n#define BULL_CORE_FILESYSTEM_FILE_HPP\n\n#include \n\n#include \n#include \n#include \n#include \n#include \n#include \n\nnamespace Bull\n{\n namespace prv\n {\n class FileImpl;\n }\n\n class BULL_CORE_API File : public NonCopyable, public CursorAwareInStream, public OutStream\n {\n private:\n\n #if defined BULL_OS_WINDOWS\n static constexpr const char* EndOfLine = \"\\r\\n\";\n #else\n static constexpr char EndOfLine = '\\n';\n #endif\n\n public:\n\n \/*! \\brief Create a File\n *\n * \\param path The Path of the file to create\n *\n *\/\n static void create(const Path& path);\n\n \/*! \\brief Tell whether a File exists\n *\n * \\param path The Path of the File\n *\n * \\return True if the file exists\n *\n *\/\n static bool exists(const Path& path);\n\n \/*! \\brief Copy a File\n *\n * \\param path The Path of the file to copy\n * \\param newPath The new Path copied File\n *\n *\/\n static void copy(const Path& path, const Path& newPath);\n\n \/*! \\brief Rename a File\n *\n * \\param path The Path of the File to rename\n * \\param newPath The new Path of the File\n *\n *\/\n static void rename(const Path& path, const Path& newPath);\n\n \/*! \\brief Delete a File\n *\n * \\param path The Path of the File to delete\n *\n *\/\n static void remove(const Path& path);\n\n public:\n\n \/*! \\brief Default constructor\n *\n *\/\n File();\n\n \/*! \\brief Constructor\n *\n * \\param path The Path of the file to open\n * \\param mode The opening mode of the file (read, write or both)\n *\n *\/\n explicit File(const Path& path, Uint32 mode = FileOpeningMode_Read | FileOpeningMode_Write);\n\n \/*! \\brief Constructor by movement\n *\n * \\param file The File to move\n *\n *\/\n File(File&& file) noexcept = default;\n\n \/*! \\brief Destructor\n *\n *\/\n ~File();\n\n \/*! \\brief Basic assignment operator by movement\n *\n * \\param File The File to move\n *\n * \\return This\n *\n *\/\n File& operator=(File&& file) noexcept = default;\n\n \/*! \\brief Open the File\n *\n * \\param path The path of the file to open\n * \\param mode The opening mode of the file (read, write or both)\n *\n *\/\n void open(const Path& path, Uint32 mode);\n\n \/*! \\brief Read bytes from the File\n *\n * \\param length The length of data to read\n *\n * \\return Read bytes\n *\n *\/\n ByteArray read(std::size_t length) override;\n\n \/*! \\brief Write data into the File\n *\n * \\param bytes Bytes to write\n *\n * \\return Return the number of bytes written\n *\n *\/\n std::size_t write(const ByteArray& bytes) override;\n\n \/*! \\brief Flush the File\n *\n *\/\n void flush() override;\n\n \/*! \\brief Get the date of the creation of the file\n *\n * \\return Return the date of the creation of the file\n *\n *\/\n DateTime getCreationDate() const;\n\n \/*! \\brief Get the date of the creation of the file\n *\n * \\return Return the date of the last access of the file\n *\n *\/\n DateTime getLastAccessDate() const;\n\n \/*! \\brief Get the date of the creation of the file\n *\n * \\return Return the date of the last write of the file\n *\n *\/\n DateTime getLastWriteDate() const;\n\n \/*! \\brief Get the position of the cursor in the file\n *\n * \\return Return the position of the cursor in the file\n *\n *\/\n std::size_t getCursor() const override;\n\n \/*! \\brief Move the reading position in the file\n *\n * \\param offset The offset to move the cursor\n *\n * \\return Return the actual position of the cursor\n *\n *\/\n std::size_t moveCursor(Int64 offset);\n\n \/*! \\brief Set the reading position in the file\n *\n * \\param position The position to seek to\n *\n * \\return Return the actual position of the cursor\n *\n *\/\n std::size_t setCursor(std::size_t position) override;\n\n \/*! \\brief Get the path of the file\n *\n * \\return Return the path of the file\n *\n *\/\n inline const Path& getPath() const\n {\n return m_path;\n }\n\n \/*! \\brief Get the size of the file\n *\n * \\return Return the size of the file\n *\n *\/\n std::size_t getSize() const override;\n\n private:\n\n Path m_path;\n Uint32 m_mode;\n std::unique_ptr m_impl;\n };\n}\n\n#endif \/\/ BULL_CORE_FILESYSTEM_FILE_HPP\n[Core\/File] Add a default opening mode on method open#ifndef BULL_CORE_FILESYSTEM_FILE_HPP\n#define BULL_CORE_FILESYSTEM_FILE_HPP\n\n#include \n\n#include \n#include \n#include \n#include \n#include \n#include \n\nnamespace Bull\n{\n namespace prv\n {\n class FileImpl;\n }\n\n class BULL_CORE_API File : public NonCopyable, public CursorAwareInStream, public OutStream\n {\n private:\n\n #if defined BULL_OS_WINDOWS\n static constexpr const char* EndOfLine = \"\\r\\n\";\n #else\n static constexpr char EndOfLine = '\\n';\n #endif\n\n public:\n\n \/*! \\brief Create a File\n *\n * \\param path The Path of the file to create\n *\n *\/\n static void create(const Path& path);\n\n \/*! \\brief Tell whether a File exists\n *\n * \\param path The Path of the File\n *\n * \\return True if the file exists\n *\n *\/\n static bool exists(const Path& path);\n\n \/*! \\brief Copy a File\n *\n * \\param path The Path of the file to copy\n * \\param newPath The new Path copied File\n *\n *\/\n static void copy(const Path& path, const Path& newPath);\n\n \/*! \\brief Rename a File\n *\n * \\param path The Path of the File to rename\n * \\param newPath The new Path of the File\n *\n *\/\n static void rename(const Path& path, const Path& newPath);\n\n \/*! \\brief Delete a File\n *\n * \\param path The Path of the File to delete\n *\n *\/\n static void remove(const Path& path);\n\n public:\n\n \/*! \\brief Default constructor\n *\n *\/\n File();\n\n \/*! \\brief Constructor\n *\n * \\param path The Path of the file to open\n * \\param mode The opening mode of the file (read, write or both)\n *\n *\/\n explicit File(const Path& path, Uint32 mode = FileOpeningMode_Read | FileOpeningMode_Write);\n\n \/*! \\brief Constructor by movement\n *\n * \\param file The File to move\n *\n *\/\n File(File&& file) noexcept = default;\n\n \/*! \\brief Destructor\n *\n *\/\n ~File();\n\n \/*! \\brief Basic assignment operator by movement\n *\n * \\param File The File to move\n *\n * \\return This\n *\n *\/\n File& operator=(File&& file) noexcept = default;\n\n \/*! \\brief Open the File\n *\n * \\param path The path of the file to open\n * \\param mode The opening mode of the file\n *\n *\/\n void open(const Path& path, Uint32 mode = FileOpeningMode_Read | FileOpeningMode_Write);\n\n \/*! \\brief Read bytes from the File\n *\n * \\param length The length of data to read\n *\n * \\return Read bytes\n *\n *\/\n ByteArray read(std::size_t length) override;\n\n \/*! \\brief Write data into the File\n *\n * \\param bytes Bytes to write\n *\n * \\return Return the number of bytes written\n *\n *\/\n std::size_t write(const ByteArray& bytes) override;\n\n \/*! \\brief Flush the File\n *\n *\/\n void flush() override;\n\n \/*! \\brief Get the date of the creation of the file\n *\n * \\return Return the date of the creation of the file\n *\n *\/\n DateTime getCreationDate() const;\n\n \/*! \\brief Get the date of the creation of the file\n *\n * \\return Return the date of the last access of the file\n *\n *\/\n DateTime getLastAccessDate() const;\n\n \/*! \\brief Get the date of the creation of the file\n *\n * \\return Return the date of the last write of the file\n *\n *\/\n DateTime getLastWriteDate() const;\n\n \/*! \\brief Get the position of the cursor in the file\n *\n * \\return Return the position of the cursor in the file\n *\n *\/\n std::size_t getCursor() const override;\n\n \/*! \\brief Move the reading position in the file\n *\n * \\param offset The offset to move the cursor\n *\n * \\return Return the actual position of the cursor\n *\n *\/\n std::size_t moveCursor(Int64 offset);\n\n \/*! \\brief Set the reading position in the file\n *\n * \\param position The position to seek to\n *\n * \\return Return the actual position of the cursor\n *\n *\/\n std::size_t setCursor(std::size_t position) override;\n\n \/*! \\brief Get the path of the file\n *\n * \\return Return the path of the file\n *\n *\/\n inline const Path& getPath() const\n {\n return m_path;\n }\n\n \/*! \\brief Get the size of the file\n *\n * \\return Return the size of the file\n *\n *\/\n std::size_t getSize() const override;\n\n private:\n\n Path m_path;\n Uint32 m_mode;\n std::unique_ptr m_impl;\n };\n}\n\n#endif \/\/ BULL_CORE_FILESYSTEM_FILE_HPP\n<|endoftext|>"} {"text":"#ifndef ARABICA_XSLT_STYLESHEET_HPP\r\n#define ARABICA_XSLT_STYLESHEET_HPP\r\n\r\n#include \r\n#include \r\n#include \r\n#include \r\n\r\n#include \"xslt_execution_context.hpp\"\r\n#include \"xslt_template.hpp\"\r\n#include \"xslt_top_level_param.hpp\"\r\n\r\nnamespace Arabica\r\n{\r\nnamespace XSLT\r\n{\r\n\r\nclass Stylesheet\r\n{\r\n typedef Arabica::XPath::BoolValue > BoolValue;\r\n typedef Arabica::XPath::NumericValue > NumericValue;\r\n typedef Arabica::XPath::StringValue > StringValue;\r\n typedef Arabica::XPath::XPathValuePtr ValuePtr;\r\n\r\npublic:\r\n Stylesheet() :\r\n output_(new StreamSink(std::cout)),\r\n error_output_(&std::cerr)\r\n {\r\n push_import_precedence();\r\n } \/\/ Stylesheet\r\n\r\n ~Stylesheet()\r\n {\r\n } \/\/ ~Stylesheet\r\n\r\n void set_parameter(const std::string& name, bool value)\r\n {\r\n set_parameter(name, ValuePtr(new BoolValue(value)));\r\n } \/\/ set_parameter\r\n void set_parameter(const std::string& name, double value)\r\n {\r\n set_parameter(name, ValuePtr(new NumericValue(value)));\r\n } \/\/ set_parameter\r\n void set_parameter(const std::string& name, const char* value)\r\n {\r\n set_parameter(name, ValuePtr(new StringValue(value)));\r\n } \/\/ set_parameter\r\n void set_parameter(const std::string& name, const std::string& value)\r\n {\r\n set_parameter(name, ValuePtr(new StringValue(value)));\r\n } \/\/ set_parameter\r\n\r\n void set_output(Sink& sink)\r\n {\r\n output_.reset(sink);\r\n } \/\/ set_output\r\n\r\n void set_error_output(std::ostream& os)\r\n {\r\n error_output_ = &os;\r\n } \/\/ set_error_output\r\n\r\n void execute(DOM::Node& initialNode) const\r\n {\r\n Arabica::XPath::NodeSet ns;\r\n ns.push_back(initialNode);\r\n\r\n ExecutionContext context(*this, output_.get(), *error_output_);\r\n\r\n \/\/ set up variables and so forth\r\n for(boost::ptr_vector::const_iterator pi = params_.begin(), pe = params_.end(); pi != pe; ++pi)\r\n pi->declare(context);\r\n for(boost::ptr_vector::const_iterator ci = items_.begin(), ce = items_.end(); ci != ce; ++ci)\r\n ci->execute(initialNode, context);\r\n context.freezeTopLevel();\r\n\r\n \/\/ go!\r\n output_.get().asOutput().start_document(output_settings_);\r\n applyTemplates(ns, context, std::pair(\"\", \"\"));\r\n output_.get().asOutput().end_document();\r\n } \/\/ execute\r\n\r\n \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\r\n void add_template(Template* templat)\r\n {\r\n typedef std::vector > MatchExprList;\r\n typedef MatchExprList::const_iterator MatchIterator;\r\n\r\n all_templates_.push_back(templat);\r\n\r\n for(MatchIterator e = templat->compiled_matches().begin(), ee = templat->compiled_matches().end(); e != ee; ++e)\r\n templates_.back()[templat->mode()].push_back(MatchTemplate(*e, templat));\r\n\r\n if(!templat->has_name())\r\n return;\r\n\r\n if(named_templates_.find(templat->name()) != named_templates_.end())\r\n {\r\n std::cerr << \"Template named '\";\r\n if(!templat->name().first.empty())\r\n std::cerr << \"{\" << templat->name().first << \"}\";\r\n std::cerr << templat->name().second << \"' already defined\" << std::endl;\r\n return;\r\n }\r\n \r\n named_templates_[templat->name()] = templat;\r\n } \/\/ add_template\r\n\r\n void push_import_precedence()\r\n {\r\n templates_.push_back(ModeTemplates());\r\n } \/\/ push_import_precedence\r\n\r\n void add_item(Item* item)\r\n {\r\n items_.push_back(item);\r\n } \/\/ add_item\r\n\r\n void output_settings(const Output::Settings& settings)\r\n {\r\n output_settings_ = settings;\r\n } \/\/ output_settings\r\n\r\n void prepare() \r\n {\r\n for(TemplateStack::iterator ts = templates_.begin(), tse = templates_.end(); ts != tse; ++ts)\r\n for(ModeTemplates::iterator ms = ts->begin(), mse = ts->end(); ms != mse; ++ms)\r\n {\r\n MatchTemplates& matches = ms->second;\r\n std::reverse(matches.begin(), matches.end());\r\n std::stable_sort(matches.begin(), matches.end());\r\n } \/\/ for ...\r\n } \/\/ prepare\r\n\r\n \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\r\n void applyTemplates(const Arabica::XPath::NodeSet& nodes, ExecutionContext& context, const std::pair& mode) const \r\n {\r\n \/\/ entirely simple so far\r\n StackFrame frame(context);\r\n LastFrame last(context, nodes.size());\r\n int p = 1;\r\n for(Arabica::XPath::NodeSet::const_iterator n = nodes.begin(), ne = nodes.end(); n != ne; ++n)\r\n {\r\n context.setPosition(*n, p++);\r\n doApplyTemplates(*n, context, mode, 0);\r\n }\r\n } \/\/ applyTemplates\r\n\r\n void applyTemplates(const DOM::NodeList& nodes, ExecutionContext& context, const std::pair& mode) const \r\n {\r\n \/\/ entirely simple so far\r\n StackFrame frame(context);\r\n LastFrame last(context, (size_t)nodes.getLength());\r\n for(int i = 0, ie = nodes.getLength(); i != ie; ++i)\r\n {\r\n context.setPosition(nodes.item(i), i+1);\r\n doApplyTemplates(nodes.item(i), context, mode, 0);\r\n }\r\n } \/\/ applyTemplates\r\n\r\n void applyTemplates(const DOM::Node& node, ExecutionContext& context, const std::pair& mode) const\r\n {\r\n StackFrame frame(context);\r\n LastFrame last(context, -1);\r\n context.setPosition(node, 1);\r\n doApplyTemplates(node, context, mode, 0);\r\n } \/\/ applyTemplates\r\n\r\n void callTemplate(const std::pair& name, const DOM::Node& node, ExecutionContext& context) const\r\n {\r\n StackFrame frame(context);\r\n\r\n NamedTemplates::const_iterator t = named_templates_.find(name);\r\n if(t == named_templates_.end())\r\n {\r\n std::cerr << \"No template named '\"; \r\n if(!name.first.empty())\r\n std::cerr << \"{\" << name.first << \"}\";\r\n std::cerr << name.second << \"'. I should be a compile time-error!\" << std::endl;\r\n return;\r\n }\r\n \r\n t->second->execute(node, context);\r\n } \/\/ callTemplate\r\n\r\n void applyImports(const DOM::Node& node, ExecutionContext& context) const\r\n {\r\n StackFrame frame(context);\r\n\r\n doApplyTemplates(node, context, current_mode_, current_generation_+1);\r\n } \/\/ applyImports\r\n\r\nprivate:\r\n void doApplyTemplates(const DOM::Node& node, \r\n ExecutionContext& context, \r\n const std::pair& mode, \r\n int generation) const\r\n {\r\n current_mode_ = mode;\r\n current_generation_ = generation;\r\n\r\n for(TemplateStack::const_iterator ts = templates_.begin()+generation, tse = templates_.end(); ts != tse; ++ts)\r\n { \r\n ModeTemplates::const_iterator mt = ts->find(mode);\r\n if(mt != ts->end())\r\n {\r\n const MatchTemplates& templates = mt->second;\r\n\t for(MatchTemplates::const_iterator t = templates.begin(), te = templates.end(); t != te; ++t)\r\n\t if(t->match().evaluate(node, context.xpathContext()))\r\n\t {\r\n\t t->action()->execute(node, context);\r\n\t return;\r\n\t } \/\/ if ...\r\n } \/\/ if ...\r\n ++current_generation_;\r\n } \/\/ for ...\r\n defaultAction(node, context, mode);\r\n } \/\/ doApplyTemplates\r\n\r\n void defaultAction(const DOM::Node& node, \r\n ExecutionContext& context, \r\n const std::pair& mode) const\r\n {\r\n switch(node.getNodeType())\r\n {\r\n case DOM::Node::DOCUMENT_NODE:\r\n case DOM::Node::DOCUMENT_FRAGMENT_NODE:\r\n case DOM::Node::ELEMENT_NODE:\r\n applyTemplates(node.getChildNodes(), context, mode);\r\n break;\r\n case DOM::Node::ATTRIBUTE_NODE:\r\n case DOM::Node::TEXT_NODE:\r\n case DOM::Node::CDATA_SECTION_NODE:\r\n {\r\n const std::string& ch = node.getNodeValue();\r\n for(std::string::const_iterator i = ch.begin(), e = ch.end(); i != e; ++i)\r\n if(!Arabica::XML::is_space(*i))\r\n {\r\n context.sink().characters(ch);\r\n return;\r\n } \/\/ if ...\r\n } \r\n break;\r\n default:\r\n ;\/\/ nothing!\r\n } \/\/ switch\r\n } \/\/ defaultAction\r\n\r\n void set_parameter(const std::string& name, ValuePtr value)\r\n {\r\n params_.push_back(new TopLevelParam(\"\", name, value));\r\n } \/\/ set_parameter\r\n\r\n void set_parameter(const std::string& namespace_uri, const std::string& name, ValuePtr value)\r\n {\r\n params_.push_back(new TopLevelParam(namespace_uri, name, value));\r\n } \/\/ set_parameter\r\n\r\nprivate:\r\n class MatchTemplate\r\n {\r\n public:\r\n MatchTemplate(const Arabica::XPath::MatchExpr& matchExpr, Template* templat) :\r\n match_(matchExpr),\r\n template_(templat) \r\n { \r\n } \/\/ MatchTemplate\r\n MatchTemplate(const MatchTemplate& rhs) : \r\n match_(rhs.match_),\r\n template_(rhs.template_)\r\n {\r\n } \/\/ MatchTemplate\r\n\r\n const Arabica::XPath::MatchExpr& match() const { return match_; }\r\n Template* action() const { return template_; }\r\n\r\n bool operator<(const MatchTemplate& rhs) const\r\n {\r\n \/\/ high priority first!\r\n return match_.priority() > rhs.match_.priority();\r\n } \/\/ operator<\r\n private:\r\n Arabica::XPath::MatchExpr match_;\r\n Template* template_;\r\n }; \/\/ struct MatchTemplate\r\n\r\n typedef boost::ptr_vector