Apache Mesos
attributes.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef __MESOS_V1_ATTRIBUTES_HPP__
18 #define __MESOS_V1_ATTRIBUTES_HPP__
19 
20 #include <iterator>
21 #include <string>
22 
23 #include <mesos/v1/mesos.hpp>
24 
25 #include <stout/option.hpp>
26 
27 namespace mesos {
28 namespace v1 {
29 
30 std::ostream& operator<<(std::ostream& stream, const Attribute& attribute);
31 
32 
34 {
35 public:
37 
38  /*implicit*/
39  Attributes(const google::protobuf::RepeatedPtrField<Attribute>& _attributes)
40  {
41  attributes.MergeFrom(_attributes);
42  }
43 
44  /*implicit*/
45  Attributes(const Attributes& that)
46  {
47  attributes.MergeFrom(that.attributes);
48  }
49 
51  {
52  if (this != &that) {
53  attributes.Clear();
54  attributes.MergeFrom(that.attributes);
55  }
56 
57  return *this;
58  }
59 
60  bool operator==(const Attributes& that) const;
61 
62 
63  bool operator!=(const Attributes& that) const
64  {
65  return !(*this == that);
66  }
67 
68  size_t size() const
69  {
70  return attributes.size();
71  }
72 
73  // Using this operator makes it easy to copy an attributes object into
74  // a protocol buffer field.
75  operator const google::protobuf::RepeatedPtrField<Attribute>&() const
76  {
77  return attributes;
78  }
79 
80  void add(const Attribute& attribute)
81  {
82  attributes.Add()->MergeFrom(attribute);
83  }
84 
85  const Attribute get(int index) const
86  {
87  return attributes.Get(index);
88  }
89 
90  // Gets an attribute with the same name and type as the given
91  // attribute.
92  const Option<Attribute> get(const Attribute& thatAttribute) const;
93 
94  template <typename T>
95  T get(const std::string& name, const T& t) const;
96 
97  // Checks if these Attributes contain an attribute with the same
98  // name, type and value as the given attribute.
99  bool contains(const Attribute& attribute) const;
100 
101  typedef google::protobuf::RepeatedPtrField<Attribute>::iterator
103 
104  typedef google::protobuf::RepeatedPtrField<Attribute>::const_iterator
106 
107  iterator begin() { return attributes.begin(); }
108  iterator end() { return attributes.end(); }
109 
110  const_iterator begin() const { return attributes.begin(); }
111  const_iterator end() const { return attributes.end(); }
112 
113  static Attribute parse(const std::string& name, const std::string& value);
114  static Attributes parse(const std::string& s);
115 
116  static bool isValid(const Attribute& attribute);
117 
118 private:
119  google::protobuf::RepeatedPtrField<Attribute> attributes;
120 };
121 
122 } // namespace v1 {
123 } // namespace mesos {
124 
125 #endif // __MESOS_V1_ATTRIBUTES_HPP__
Definition: option.hpp:29
Attributes()
Definition: attributes.hpp:36
Attributes & operator=(const Attributes &that)
Definition: attributes.hpp:50
void add(const Attribute &attribute)
Definition: attributes.hpp:80
iterator end()
Definition: attributes.hpp:108
google::protobuf::RepeatedPtrField< Attribute >::const_iterator const_iterator
Definition: attributes.hpp:105
bool contains(const Attribute &attribute) const
google::protobuf::RepeatedPtrField< Attribute >::iterator iterator
Definition: attributes.hpp:102
size_t size() const
Definition: attributes.hpp:68
const_iterator end() const
Definition: attributes.hpp:111
Definition: agent.hpp:25
static bool isValid(const Attribute &attribute)
bool operator==(const Attributes &that) const
Attributes(const Attributes &that)
Definition: attributes.hpp:45
static Attribute parse(const std::string &name, const std::string &value)
const_iterator begin() const
Definition: attributes.hpp:110
iterator begin()
Definition: attributes.hpp:107
Attributes(const google::protobuf::RepeatedPtrField< Attribute > &_attributes)
Definition: attributes.hpp:39
bool operator!=(const Attributes &that) const
Definition: attributes.hpp:63
std::ostream & operator<<(std::ostream &stream, const Attribute &attribute)
constexpr const char * name
Definition: shell.hpp:41
Definition: attributes.hpp:33