SigUtil  0.95
Utility modules for modern C++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
percent.hpp
Go to the documentation of this file.
1 /*
2 Copyright© 2014 Akihiro Nishimura
3 
4 This software is released under the MIT License.
5 http://opensource.org/licenses/mit-license.php
6 */
7 
8 #ifndef SIG_UTIL_PERCENT_HPP
9 #define SIG_UTIL_PERCENT_HPP
10 
11 #include "../sigutil.hpp"
12 
13 #if SIG_ENABLE_BOOST
14 #include <boost/serialization/serialization.hpp>
15 #endif
16 
17 
18 namespace sig
19 {
20 
22 
36 class Percent
37 {
38  int percent_;
39 
40 public:
41  explicit Percent(int percent) : percent_(percent){}
42 
43  int get_percent() const{ return percent_; }
44  double get_double() const{ return percent_ * 0.01; }
45 
46  static Percent const& unit(){ static const Percent unit(100); return unit; }
47 
48  Percent operator=(Percent src){ percent_ = src.percent_; return *this; }
49  Percent operator=(int src){ percent_ = src; return *this; }
50 
51  bool operator==(Percent obj) const{ return percent_ == obj.percent_; }
52 
53  bool operator!=(Percent obj) const{ return percent_ != obj.percent_; }
54 
55 #if SIG_ENABLE_BOOST
56 private:
58 
59  template <class Archive>
60  void serialize(Archive& ar, unsigned int version)
61  {
62  ar & percent_;
63  }
64 
65  template <class Archive>
66  friend void save_construct_data(Archive & ar, Percent const* p, unsigned int version){};
67 
68  template <class Archive>
69  friend void load_construct_data(Archive & ar, Percent* p, unsigned int version){
70  ::new(p) Percent(0);
71  }
72 #endif
73 };
74 
75 }
76 #endif
static Percent const & unit()
Definition: percent.hpp:46
bool operator!=(Percent obj) const
Definition: percent.hpp:53
double get_double() const
Definition: percent.hpp:44
パーセント型
Definition: percent.hpp:36
Percent(int percent)
Definition: percent.hpp:41
Percent operator=(Percent src)
Definition: percent.hpp:48
friend void save_construct_data(Archive &ar, Percent const *p, unsigned int version)
Definition: percent.hpp:66
friend void load_construct_data(Archive &ar, Percent *p, unsigned int version)
Definition: percent.hpp:69
bool operator==(Percent obj) const
Definition: percent.hpp:51
friend class boost::serialization::access
Definition: percent.hpp:57
int get_percent() const
Definition: percent.hpp:43
Definition: array.hpp:15
Percent operator=(int src)
Definition: percent.hpp:49