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