| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef TOOLS_IPC_FUZZER_MESSAGE_LIB_MESSAGE_NAMES_H_ |
| 6 #define TOOLS_IPC_FUZZER_MESSAGE_LIB_MESSAGE_NAMES_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 #include "base/basictypes.h" |
| 11 #include "base/logging.h" |
| 12 |
| 13 namespace ipc_fuzzer { |
| 14 |
| 15 class MessageNames { |
| 16 public: |
| 17 MessageNames(); |
| 18 ~MessageNames(); |
| 19 static MessageNames* GetInstance(); |
| 20 |
| 21 void Add(uint32 type, const std::string& name) { |
| 22 name_map_[type] = name; |
| 23 type_map_[name] = type; |
| 24 } |
| 25 |
| 26 bool TypeExists(uint32 type) { |
| 27 return name_map_.find(type) != name_map_.end(); |
| 28 } |
| 29 |
| 30 bool NameExists(const std::string& name) { |
| 31 return type_map_.find(name) != type_map_.end(); |
| 32 } |
| 33 |
| 34 const std::string& TypeToName(uint32 type) { |
| 35 TypeToNameMap::iterator it = name_map_.find(type); |
| 36 CHECK(it != name_map_.end()); |
| 37 return it->second; |
| 38 } |
| 39 |
| 40 uint32 NameToType(const std::string& name) { |
| 41 NameToTypeMap::iterator it = type_map_.find(name); |
| 42 CHECK(it != type_map_.end()); |
| 43 return it->second; |
| 44 } |
| 45 |
| 46 private: |
| 47 typedef std::map<uint32, std::string> TypeToNameMap; |
| 48 typedef std::map<std::string, uint32> NameToTypeMap; |
| 49 TypeToNameMap name_map_; |
| 50 NameToTypeMap type_map_; |
| 51 |
| 52 static MessageNames* all_names_; |
| 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(MessageNames); |
| 55 }; |
| 56 |
| 57 } // namespace ipc_fuzzer |
| 58 |
| 59 #endif // TOOLS_IPC_FUZZER_MESSAGE_LIB_MESSAGE_NAMES_H_ |
| OLD | NEW |