Google Cloud C++ Client  2.7.0
C++ Client Library for Google Cloud Platform
project.h
Go to the documentation of this file.
1 // Copyright 2021 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PROJECT_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PROJECT_H
17 
18 #include "google/cloud/status_or.h"
19 #include "google/cloud/version.h"
20 #include <iosfwd>
21 #include <string>
22 
23 namespace google {
24 namespace cloud {
26 
27 /**
28  * This class identifies a Cloud Project.
29  *
30  * A Cloud project is identified by its `project_id`.
31  *
32  * @note This class makes no effort to validate the components of the
33  * project name. It is the application's responsibility to provide
34  * a valid project id. Passing invalid values will not be checked
35  * until the project name is used in an RPC.
36  *
37  * For more info about the `project_id` format, see
38  * https://cloud.google.com/resource-manager/docs/creating-managing-projects
39  */
40 class Project {
41  public:
42  /// Constructs a Project object identified by the given @p project_id.
43  explicit Project(std::string project_id);
44 
45  /// @name Copy and move
46  ///@{
47  Project(Project const&) = default;
48  Project& operator=(Project const&) = default;
49  Project(Project&&) = default;
50  Project& operator=(Project&&) = default;
51  ///@}
52 
53  /// Returns the Project ID
54  std::string const& project_id() const { return project_id_; }
55 
56  /**
57  * Returns the fully qualified project name as a string of the form:
58  * "projects/<project-id>"
59  */
60  std::string FullName() const;
61 
62  /// @name Equality operators
63  ///@{
64  friend bool operator==(Project const& a, Project const& b);
65  friend bool operator!=(Project const& a, Project const& b);
66  ///@}
67 
68  /// Output the `FullName()` format.
69  friend std::ostream& operator<<(std::ostream&, Project const&);
70 
71  private:
72  std::string project_id_;
73 };
74 
75 /**
76  * Constructs a `Project` from the given @p full_name.
77  * Returns a non-OK Status if `full_name` is improperly formed.
78  */
79 StatusOr<Project> MakeProject(std::string const& full_name);
80 
82 } // namespace cloud
83 } // namespace google
84 
85 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PROJECT_H