OLD | NEW |
(Empty) | |
| 1 #include "ContentType.h" |
| 2 |
| 3 // Based on impl from libadblockplus |
| 4 |
| 5 using AdblockPlus::FilterEngine; |
| 6 |
| 7 namespace |
| 8 { |
| 9 typedef std::map<FilterEngine::ContentType, std::string> ContentTypeMap; |
| 10 ContentTypeMap CreateContentTypeMap() |
| 11 { |
| 12 ContentTypeMap contentTypes; |
| 13 contentTypes[FilterEngine::CONTENT_TYPE_OTHER] = "OTHER"; |
| 14 contentTypes[FilterEngine::CONTENT_TYPE_SCRIPT] = "SCRIPT"; |
| 15 contentTypes[FilterEngine::CONTENT_TYPE_IMAGE] = "IMAGE"; |
| 16 contentTypes[FilterEngine::CONTENT_TYPE_STYLESHEET] = "STYLESHEET"; |
| 17 contentTypes[FilterEngine::CONTENT_TYPE_OBJECT] = "OBJECT"; |
| 18 contentTypes[FilterEngine::CONTENT_TYPE_SUBDOCUMENT] = "SUBDOCUMENT"; |
| 19 contentTypes[FilterEngine::CONTENT_TYPE_DOCUMENT] = "DOCUMENT"; |
| 20 contentTypes[FilterEngine::CONTENT_TYPE_XMLHTTPREQUEST] = "XMLHTTPREQUEST"; |
| 21 contentTypes[FilterEngine::CONTENT_TYPE_OBJECT_SUBREQUEST] = "OBJECT_SUBREQU
EST"; |
| 22 contentTypes[FilterEngine::CONTENT_TYPE_FONT] = "FONT"; |
| 23 contentTypes[FilterEngine::CONTENT_TYPE_MEDIA] = "MEDIA"; |
| 24 contentTypes[FilterEngine::CONTENT_TYPE_ELEMHIDE] = "ELEMHIDE"; |
| 25 return contentTypes; |
| 26 } |
| 27 const ContentTypeMap g_contentTypes = CreateContentTypeMap(); |
| 28 } |
| 29 |
| 30 std::string ContentTypeToString(AdblockPlus::FilterEngine::ContentType contentTy
pe) |
| 31 { |
| 32 ContentTypeMap::const_iterator it = g_contentTypes.find(contentType); |
| 33 if (it != g_contentTypes.end()) |
| 34 return it->second; |
| 35 throw std::invalid_argument("Argument is not a valid ContentType"); |
| 36 } |
| 37 |
| 38 #include "Communication.h" |
| 39 |
| 40 using Communication::InputBuffer; |
| 41 using Communication::OutputBuffer; |
| 42 |
| 43 InputBuffer& operator>>(InputBuffer& in, FilterEngine::ContentType& contentType) |
| 44 { |
| 45 int32_t type; |
| 46 in >> type; |
| 47 contentType = static_cast<FilterEngine::ContentType>(contentType); |
| 48 return in; |
| 49 } |
| 50 |
| 51 OutputBuffer& operator<<(OutputBuffer& out, FilterEngine::ContentType contentTyp
e) |
| 52 { |
| 53 return out << static_cast<int32_t>(contentType); |
| 54 } |
OLD | NEW |