SC2API
An API for AI for StarCraft II
sc2_types.h
Go to the documentation of this file.
1 
7 #pragma once
8 
9 #include <stdint.h>
10 #include <string>
11 
12 namespace sc2 {
13 
18 template<class T>
19 class SC2Type {
20 public:
22  SC2Type() :
23  type_id_(0) {
24  }
26  SC2Type(uint32_t type_id) :
27  type_id_(type_id) {
28  }
30  SC2Type(T type_id) :
31  type_id_(static_cast<uint32_t>(type_id)) {
32  }
33 
36  bool operator ==(SC2Type<T> type_id) const { return type_id_ == type_id.type_id_; }
37  bool operator ==(T type_id) const { return type_id_ == static_cast<uint32_t>(type_id); }
38  bool operator ==(uint32_t type_id) const { return type_id_ == type_id; }
39  bool operator ==(int type_id) const { return static_cast<uint32_t>(type_id_) == type_id; }
40 
43  bool operator !=(SC2Type<T> type_id) const { return type_id_ != type_id.type_id_; }
44  bool operator !=(T type_id) const { return type_id_ != static_cast<uint32_t>(type_id); }
45  bool operator !=(uint32_t type_id) const { return type_id_ != type_id; }
46  bool operator !=(int type_id) const { return static_cast<uint32_t>(type_id_) != type_id; }
47 
49  bool operator<(const SC2Type<T>& other) const { return type_id_ < other.type_id_; }
50 
52  operator uint32_t() const { return type_id_; }
54  operator T() const { return static_cast<T>(type_id_); }
55 
58  bool IsValid() const { return type_id_ != 0; }
59 
62  std::string to_string() const { return std::to_string(type_id_); }
63 
66  T ToType() const { return static_cast<T>(type_id_); }
67 
68 private:
69  uint32_t type_id_;
70 };
71 
72 }
bool operator!=(SC2Type< T > type_id) const
Definition: sc2_types.h:43
std::string to_string() const
Definition: sc2_types.h:62
SC2Type(uint32_t type_id)
Construct from an integer, corresponds to the enum value.
Definition: sc2_types.h:26
bool operator==(SC2Type< T > type_id) const
Definition: sc2_types.h:36
Definition: sc2_action.h:9
SC2Type(T type_id)
Construct from the enum.
Definition: sc2_types.h:30
SC2Type()
Default constructor.
Definition: sc2_types.h:22
Definition: sc2_types.h:19
bool IsValid() const
Definition: sc2_types.h:58
T ToType() const
Definition: sc2_types.h:66