GreenCloud Simulator
resource.cc
Go to the documentation of this file.
1 /*
2  * resource.cc
3  *
4  * @date Mar 8, 2013
5  * @author Guzek:Mateusz
6  */
7 
8 #include "resource.h"
9 
10 
11  Capacity::Capacity() : value(0.0) {
12 
13  }
14 
16 
17  }
18 
19  Capacity::Capacity(double d) : value(d){
20 
21  }
22 
23 Capacity& Capacity::operator=(const double& val){
24  this->value = val;
25  return *this; // Return ref for multiple assignment
26 }
27 
29  if (this != &c) { // make sure it is not the same object
30  this->value = c.value;
31  this->virtual_capacities.clear();
33  }
34  return *this; // Return ref for multiple assignment
35 }
36 
37 Capacity::operator double(){
38  return value;
39 }
40 
42  this->value += rhs.value;
43  return *this;
44 }
46  this->value -= rhs.value;
47  return *this;
48 }
49 
50 Capacity& Capacity::operator+=(const double& rhs){
51  this->value += rhs;
52  return *this;
53 }
54 Capacity& Capacity::operator-=(const double& rhs){
55  this->value -= rhs;
56  return *this;
57 }
58 
60  double result = value;
61  std::vector<Capacity*>::iterator iter;
62  if(!virtual_capacities.empty()){
63  for(iter = virtual_capacities.begin(); iter!=virtual_capacities.end(); iter ++){
64  result += (*iter)->getValueRecursive();
65  }
66  }
67  return result;
68 }
69 
71 
72 }
73 
74 Resource::Resource(res_type t,double a ,std::vector <Capacity> cap){
75  type = t;
76  arch = a;
77  this->setCapacity(cap);
78 }
79 
81 
82 }
83 
84 /*Computing, Memory, Storage, Networking, extend according to needs.*/
86  res_type type;
87  if(strcmp(t, "Computing") == 0){
88  type=Computing;
89  } else if(strcmp(t, "Memory") == 0){
90  type=Memory;
91  } else if(strcmp(t, "Storage") == 0){
92  type=Storage;
93  } else if(strcmp(t, "Networking") == 0){
94  type=Networking;
95  } else {
96  std::cerr << "Unknown resource type" << t;
97  abort();
98 
99  }
100  return type;
101 }
102 
103 int Resource::setType(const char* t){
104  type = translateType(t);
105  return 0;
106 }
107 
108 
109 
110 int Resource::setCapacity(std::vector <Capacity> cap){
111  capacity = cap;
112  return 0;
113 }
114 
116  std::sort(capacity.begin(),capacity.end());
117 }
118 
120  if (this != &r) { // make sure it is not the same object
121  capacity.clear();
122  capacity = r.capacity;
123  arch = r.arch;
124  type = r.type;
125  }
126  return *this; // Return ref for multiple assignment
127 }
128 
130  std::cerr << "Type:\t"<< type;
131  std::cerr << "\n";
132  std::cerr << "Architecture:\t"<< arch;
133  std::cerr << "\n";
134  std::cerr << "Capacities:\t";
135  std::vector <Capacity>::iterator iter;
136  for (iter = capacity.begin(); iter!=capacity.end(); iter++)
137  {
138  std::cerr << (*iter) << ",";
139  }
140 
141 }
Capacity()
Definition: resource.cc:11
Resource()
Definition: resource.cc:70
std::vector< Capacity > capacity
Definition: resource.h:87
std::vector< Capacity * > virtual_capacities
Definition: resource.h:34
res_type type
Definition: resource.h:95
virtual ~Resource()
Definition: resource.cc:80
int setType(const char *t)
Definition: resource.cc:103
res_type
Definition: resource.h:19
int setCapacity(std::vector< Capacity > cap)
Definition: resource.cc:110
static res_type translateType(const char *t)
Definition: resource.cc:85
double getValueRecursive()
Definition: resource.cc:59
double arch
Definition: resource.h:99
void print()
Definition: resource.cc:129
Resource & operator=(const Resource &r)
Definition: resource.cc:119
Capacity & operator=(const double &val)
Definition: resource.cc:23
Capacity & operator+=(const Capacity &rhs)
Definition: resource.cc:41
double value
Definition: resource.h:33
void sortCapacity()
Definition: resource.cc:115
Capacity & operator-=(const Capacity &rhs)
Definition: resource.cc:45