Dobby  3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
ContainerId.h
1 /*
2 * If not stated otherwise in this file or this component's LICENSE file the
3 * following copyright and licenses apply:
4 *
5 * Copyright 2016 Sky UK
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19 /*
20  * File: ContainerId.h
21  *
22  */
23 #ifndef CONTAINERID_H
24 #define CONTAINERID_H
25 
26 #include <cstdint>
27 #include <string>
28 
29 // -----------------------------------------------------------------------------
41 {
42 public:
43  static ContainerId create(const std::string& s);
44  static ContainerId create(const char* s);
45  static ContainerId create(const char* s, size_t n);
46 
47 public:
48  ContainerId() = default;
49  ContainerId(ContainerId&&) = default;
50  ContainerId(const ContainerId&) = default;
51  ContainerId& operator=(const ContainerId&) = default;
52  ContainerId& operator=(ContainerId&&) = default;
53 
54 public:
55  ~ContainerId() = default;
56 
57  bool isValid() const
58  {
59  return !mId.empty();
60  }
61 
62  const std::string& str() const
63  {
64  return mId;
65  }
66 
67  const char* c_str() const
68  {
69  return mId.c_str();
70  }
71 
72 public:
73  bool operator==(const ContainerId& rhs) const
74  {
75  return mId == rhs.mId;
76  }
77 
78  bool operator!=(const ContainerId& rhs) const
79  {
80  return mId != rhs.mId;
81  }
82 
83  bool operator<(const ContainerId& rhs) const
84  {
85  return mId < rhs.mId;
86  }
87 
88  bool operator>(const ContainerId& rhs) const
89  {
90  return mId > rhs.mId;
91  }
92 
93 private:
94  std::string mId;
95 };
96 
97 
98 #endif // !defined(CONTAINERID_H)
A wrapper around a std::string, used to add some type definition to to an id and also to sanity check...
Definition: ContainerId.h:41