| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,7 +39,6 @@ | |||
| 39 | 39 | ], | |
| 40 | 40 | 'node_protocol_files': [ | |
| 41 | 41 | '<(protocol_tool_path)/lib/Allocator_h.template', | |
| 42 | - '<(protocol_tool_path)/lib/Array_h.template', | ||
| 43 | 42 | '<(protocol_tool_path)/lib/base_string_adapter_cc.template', | |
| 44 | 43 | '<(protocol_tool_path)/lib/base_string_adapter_h.template', | |
| 45 | 44 | '<(protocol_tool_path)/lib/DispatcherBase_cpp.template', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -147,8 +147,8 @@ DispatchResponse TracingAgent::start( | |||
| 147 | 147 | std::set<std::string> categories_set; | |
| 148 | 148 | protocol::Array<std::string>* categories = | |
| 149 | 149 | traceConfig->getIncludedCategories(); | |
| 150 | - for (size_t i = 0; i < categories->length(); i++) | ||
| 151 | - categories_set.insert(categories->get(i)); | ||
| 150 | + for (size_t i = 0; i < categories->size(); i++) | ||
| 151 | + categories_set.insert((*categories)[i]); | ||
| 152 | 152 | ||
| 153 | 153 | if (categories_set.empty()) | |
| 154 | 154 | return DispatchResponse::Error("At least one category should be enabled"); | |
@@ -172,29 +172,29 @@ DispatchResponse TracingAgent::stop() { | |||
| 172 | 172 | ||
| 173 | 173 | DispatchResponse TracingAgent::getCategories( | |
| 174 | 174 | std::unique_ptr<protocol::Array<String>>* categories) { | |
| 175 | - *categories = Array<String>::create(); | ||
| 175 | + *categories = std::make_unique<Array<String>>(); | ||
| 176 | 176 | protocol::Array<String>* categories_list = categories->get(); | |
| 177 | 177 | // In alphabetical order | |
| 178 | - categories_list->addItem("node"); | ||
| 179 | - categories_list->addItem("node.async_hooks"); | ||
| 180 | - categories_list->addItem("node.bootstrap"); | ||
| 181 | - categories_list->addItem("node.console"); | ||
| 182 | - categories_list->addItem("node.dns.native"); | ||
| 183 | - categories_list->addItem("node.environment"); | ||
| 184 | - categories_list->addItem("node.fs.async"); | ||
| 185 | - categories_list->addItem("node.fs.sync"); | ||
| 186 | - categories_list->addItem("node.fs_dir.async"); | ||
| 187 | - categories_list->addItem("node.fs_dir.sync"); | ||
| 188 | - categories_list->addItem("node.http"); | ||
| 189 | - categories_list->addItem("node.net.native"); | ||
| 190 | - categories_list->addItem("node.perf"); | ||
| 191 | - categories_list->addItem("node.perf.timerify"); | ||
| 192 | - categories_list->addItem("node.perf.usertiming"); | ||
| 193 | - categories_list->addItem("node.promises.rejections"); | ||
| 194 | - categories_list->addItem("node.threadpoolwork.async"); | ||
| 195 | - categories_list->addItem("node.threadpoolwork.sync"); | ||
| 196 | - categories_list->addItem("node.vm.script"); | ||
| 197 | - categories_list->addItem("v8"); | ||
| 178 | + categories_list->emplace_back("node"); | ||
| 179 | + categories_list->emplace_back("node.async_hooks"); | ||
| 180 | + categories_list->emplace_back("node.bootstrap"); | ||
| 181 | + categories_list->emplace_back("node.console"); | ||
| 182 | + categories_list->emplace_back("node.dns.native"); | ||
| 183 | + categories_list->emplace_back("node.environment"); | ||
| 184 | + categories_list->emplace_back("node.fs.async"); | ||
| 185 | + categories_list->emplace_back("node.fs.sync"); | ||
| 186 | + categories_list->emplace_back("node.fs_dir.async"); | ||
| 187 | + categories_list->emplace_back("node.fs_dir.sync"); | ||
| 188 | + categories_list->emplace_back("node.http"); | ||
| 189 | + categories_list->emplace_back("node.net.native"); | ||
| 190 | + categories_list->emplace_back("node.perf"); | ||
| 191 | + categories_list->emplace_back("node.perf.timerify"); | ||
| 192 | + categories_list->emplace_back("node.perf.usertiming"); | ||
| 193 | + categories_list->emplace_back("node.promises.rejections"); | ||
| 194 | + categories_list->emplace_back("node.threadpoolwork.async"); | ||
| 195 | + categories_list->emplace_back("node.threadpoolwork.sync"); | ||
| 196 | + categories_list->emplace_back("node.vm.script"); | ||
| 197 | + categories_list->emplace_back("v8"); | ||
| 198 | 198 | return DispatchResponse::OK(); | |
| 199 | 199 | } | |
| 200 | 200 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -638,7 +638,6 @@ def main(): | |||
| 638 | 638 | "Object_h.template", | |
| 639 | 639 | "ValueConversions_h.template", | |
| 640 | 640 | "Maybe_h.template", | |
| 641 | - "Array_h.template", | ||
| 642 | 641 | "DispatcherBase_h.template", | |
| 643 | 642 | "Parser_h.template", | |
| 644 | 643 | "encoding_h.template", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,7 +36,6 @@ template("inspector_protocol_generate") { | |||
| 36 | 36 | "$inspector_protocol_dir/lib/encoding_h.template", | |
| 37 | 37 | "$inspector_protocol_dir/lib/encoding_cpp.template", | |
| 38 | 38 | "$inspector_protocol_dir/lib/Allocator_h.template", | |
| 39 | - "$inspector_protocol_dir/lib/Array_h.template", | ||
| 40 | 39 | "$inspector_protocol_dir/lib/DispatcherBase_cpp.template", | |
| 41 | 40 | "$inspector_protocol_dir/lib/DispatcherBase_h.template", | |
| 42 | 41 | "$inspector_protocol_dir/lib/ErrorSupport_cpp.template", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,6 @@ | |||
| 8 | 8 | 'lib/encoding_h.template', | |
| 9 | 9 | 'lib/encoding_cpp.template', | |
| 10 | 10 | 'lib/Allocator_h.template', | |
| 11 | - 'lib/Array_h.template', | ||
| 12 | 11 | 'lib/DispatcherBase_cpp.template', | |
| 13 | 12 | 'lib/DispatcherBase_h.template', | |
| 14 | 13 | 'lib/ErrorSupport_cpp.template', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,7 +22,6 @@ | |||
| 22 | 22 | namespace {{namespace}} { | |
| 23 | 23 | {% endfor %} | |
| 24 | 24 | ||
| 25 | - template<typename T> class Array; | ||
| 26 | 25 | class DictionaryValue; | |
| 27 | 26 | class DispatchResponse; | |
| 28 | 27 | class ErrorSupport; | |
@@ -35,6 +34,26 @@ class StringValue; | |||
| 35 | 34 | class UberDispatcher; | |
| 36 | 35 | class Value; | |
| 37 | 36 | ||
| 37 | + namespace detail { | ||
| 38 | + template <typename T> | ||
| 39 | + struct ArrayTypedef { typedef std::vector<std::unique_ptr<T>> type; }; | ||
| 40 | + | ||
| 41 | + template <> | ||
| 42 | + struct ArrayTypedef<String> { typedef std::vector<String> type; }; | ||
| 43 | + | ||
| 44 | + template <> | ||
| 45 | + struct ArrayTypedef<int> { typedef std::vector<int> type; }; | ||
| 46 | + | ||
| 47 | + template <> | ||
| 48 | + struct ArrayTypedef<double> { typedef std::vector<double> type; }; | ||
| 49 | + | ||
| 50 | + template <> | ||
| 51 | + struct ArrayTypedef<bool> { typedef std::vector<bool> type; }; | ||
| 52 | + } // namespace detail | ||
| 53 | + | ||
| 54 | + template <typename T> | ||
| 55 | + using Array = typename detail::ArrayTypedef<T>::type; | ||
| 56 | + | ||
| 38 | 57 | {% for namespace in config.protocol.namespace %} | |
| 39 | 58 | } // namespace {{namespace}} | |
| 40 | 59 | {% endfor %} | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -128,6 +128,72 @@ struct ValueConversions<Binary> { | |||
| 128 | 128 | } | |
| 129 | 129 | }; | |
| 130 | 130 | ||
| 131 | + template<typename T> | ||
| 132 | + struct ValueConversions<std::vector<std::unique_ptr<T>>> { | ||
| 133 | + static std::unique_ptr<std::vector<std::unique_ptr<T>>> fromValue(protocol::Value* value, ErrorSupport* errors) { | ||
| 134 | + protocol::ListValue* array = ListValue::cast(value); | ||
| 135 | + if (!array) { | ||
| 136 | + errors->addError("array expected"); | ||
| 137 | + return nullptr; | ||
| 138 | + } | ||
| 139 | + errors->push(); | ||
| 140 | + std::unique_ptr<std::vector<std::unique_ptr<T>>> result( | ||
| 141 | + new std::vector<std::unique_ptr<T>>()); | ||
| 142 | + result->reserve(array->size()); | ||
| 143 | + for (size_t i = 0; i < array->size(); ++i) { | ||
| 144 | + errors->setName(StringUtil::fromInteger(i)); | ||
| 145 | + auto item = ValueConversions<T>::fromValue(array->at(i), errors); | ||
| 146 | + result->emplace_back(std::move(item)); | ||
| 147 | + } | ||
| 148 | + errors->pop(); | ||
| 149 | + if (errors->hasErrors()) | ||
| 150 | + return nullptr; | ||
| 151 | + return result; | ||
| 152 | + } | ||
| 153 | + | ||
| 154 | + static std::unique_ptr<protocol::ListValue> toValue(std::vector<std::unique_ptr<T>>* v) | ||
| 155 | + { | ||
| 156 | + std::unique_ptr<protocol::ListValue> result = ListValue::create(); | ||
| 157 | + result->reserve(v->size()); | ||
| 158 | + for (auto& item : *v) | ||
| 159 | + result->pushValue(ValueConversions<T>::toValue(item.get())); | ||
| 160 | + return result; | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + }; | ||
| 164 | + | ||
| 165 | + template<typename T> | ||
| 166 | + struct ValueConversions<std::vector<T>> { | ||
| 167 | + static std::unique_ptr<std::vector<T>> fromValue(protocol::Value* value, ErrorSupport* errors) { | ||
| 168 | + protocol::ListValue* array = ListValue::cast(value); | ||
| 169 | + if (!array) { | ||
| 170 | + errors->addError("array expected"); | ||
| 171 | + return nullptr; | ||
| 172 | + } | ||
| 173 | + errors->push(); | ||
| 174 | + std::unique_ptr<std::vector<T>> result(new std::vector<T>()); | ||
| 175 | + result->reserve(array->size()); | ||
| 176 | + for (size_t i = 0; i < array->size(); ++i) { | ||
| 177 | + errors->setName(StringUtil::fromInteger(i)); | ||
| 178 | + auto item = ValueConversions<T>::fromValue(array->at(i), errors); | ||
| 179 | + result->emplace_back(std::move(item)); | ||
| 180 | + } | ||
| 181 | + errors->pop(); | ||
| 182 | + if (errors->hasErrors()) | ||
| 183 | + return nullptr; | ||
| 184 | + return result; | ||
| 185 | + } | ||
| 186 | + | ||
| 187 | + static std::unique_ptr<protocol::ListValue> toValue(std::vector<T>* v) | ||
| 188 | + { | ||
| 189 | + std::unique_ptr<protocol::ListValue> result = ListValue::create(); | ||
| 190 | + result->reserve(v->size()); | ||
| 191 | + for (auto& item : *v) | ||
| 192 | + result->pushValue(ValueConversions<T>::toValue(item)); | ||
| 193 | + return result; | ||
| 194 | + } | ||
| 195 | + }; | ||
| 196 | + | ||
| 131 | 197 | template<> | |
| 132 | 198 | struct ValueConversions<Value> { | |
| 133 | 199 | static std::unique_ptr<Value> fromValue(protocol::Value* value, ErrorSupport* errors) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -271,6 +271,7 @@ public: | |||
| 271 | 271 | ||
| 272 | 272 | Value* at(size_t index); | |
| 273 | 273 | size_t size() const { return m_data.size(); } | |
| 274 | + void reserve(size_t capacity) { m_data.reserve(capacity); } | ||
| 274 | 275 | ||
| 275 | 276 | private: | |
| 276 | 277 | ListValue(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments