Turi Create  4.0
gl_gframe.hpp
1 /* Copyright © 2017 Apple Inc. All rights reserved.
2  *
3  * Use of this source code is governed by a BSD-3-clause license that can
4  * be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
5  */
6 #ifndef TURI_UNITY_GL_GFRAME_HPP
7 #define TURI_UNITY_GL_GFRAME_HPP
8 
9 #include "gl_sframe.hpp"
10 
11 namespace turi {
12 class gl_sframe;
13 class gl_sgraph;
14 class gl_sarray;
15 
16 // Possible types of gl_gframe
17 enum class gframe_type_enum:int {VERTEX_GFRAME, EDGE_GFRAME};
18 
19 /**
20  * \ingroup gl_sdk
21  *
22  * A proxy for the \ref gl_sframe for the vertex and edge data of the SGRaph
23  */
24 class gl_gframe : public gl_sframe {
25  public:
26  gl_gframe() = delete;
27  gl_gframe(const gl_gframe&) = default;
28  gl_gframe(gl_gframe&&) = default;
29  gl_gframe& operator=(const gl_gframe&) = default;
30  gl_gframe& operator=(gl_gframe&&) = default;
31 
32  /*
33  * Construct gl_gframe from sgraph, and sframe.
34  */
35  gl_gframe(gl_sgraph*, gframe_type_enum);
36 
37  /*
38  * Implicit converters
39  */
40  operator std::shared_ptr<unity_sframe>() const;
41  operator std::shared_ptr<unity_sframe_base>() const;
42 
43  /**
44  * Returns number of rows. If type is VERTEX_GFRAME, the value
45  * is also the number of vertices (or edges if type is EDGE_GFRAME)
46  * in the \ref gl_sgraph.
47  *
48  * \see gl_sgraph::num_vertices
49  * \see gl_sgraph::num_edges
50  */
51  size_t size() const override;
52 
53  /**
54  * Returns number of columns. If type is VERTEX_GFRAME, the value
55  * is also the number of vertex fields (or edge fields if type is EDGE_GFRAME)
56  * in the \ref gl_sgraph.
57  */
58  size_t num_columns() const override;
59 
60  /**
61  * Returns a list of column names. If type is VERTEX_GFRAME, the value
62  * is also the names of the vertex fields (or edge fields if type is EDGE_GFRAME)
63  * in the \ref gl_sgraph.
64  *
65  * \see gl_sgraph::get_vertex_fields
66  * \see gl_sgraph::get_edge_fields
67  */
68  std::vector<std::string> column_names() const override;
69 
70  /**
71  * Returns a list of column types. If type is VERTEX_GFRAME, the value
72  * is also the names of the vertex fields (or edge fields if type is EDGE_GFRAME)
73  * in the \ref gl_sgraph.
74  *
75  * \see gl_sgraph::get_vertex_field_types
76  * \see gl_sgraph::get_edge_field_types
77  */
78  std::vector<flex_type_enum> column_types() const override;
79 
80  /**
81  * Add a new column with constant value. If type is VERTEX_GFRAME, the column
82  * is added as a new vertex field (or edge field if type is EDGE_GFRAME)
83  * in the \ref gl_sgraph.
84  *
85  * \param data the constant value to fill the column
86  * \param name the name of the new column
87  *
88  * \see gl_sgraph::add_vertex_field(const flexible_type&, const std::string&)
89  * \see gl_sgraph::add_edge_field(const flexible_type&, const std::stirng&)
90  */
91  void add_column(const flexible_type& data, const std::string& name) override;
92 
93  /**
94  * Add a new column with given column name and data. If type is
95  * VERTEX_GFRAME, the column is added as a new vertex field (or edge field if
96  * type is EDGE_GFRAME) in the \ref gl_sgraph.
97  *
98  * \param data the constant value to fill the column
99  * \param name the name of the new column
100  *
101  * \see gl_sgraph::add_vertex_field(const gl_sarray&, const std::string&)
102  * \see gl_sgraph::add_edge_field(const gl_sarray&, const std::string&)
103  */
104  void add_column(const gl_sarray& data, const std::string& name) override;
105 
106  /**
107  * Batch version of \ref add_column.
108  *
109  * \param data a map from column name to column data
110  */
111  void add_columns(const gl_sframe& data) override;
112 
113  /**
114  * Remove a column with the given name. If type is
115  * VERTEX_GFRAME, the column is removed from vertex data (or edge data if
116  * type is EDGE_GFRAME) from the \ref gl_sgraph.
117  *
118  * \param name the column name to be removed
119  *
120  * \see gl_sgraph::remove_vertex_field
121  * \see gl_sgraph::remove_edge_field
122  */
123  void remove_column(const std::string& name) override;
124 
125  /**
126  * Rename columns.
127  *
128  * \param old_to_new_names map from old column name to new column name.
129  *
130  * \see gl_sgraph::rename_vertex_fields
131  * \see gl_sgraph::rename_edge_fields
132  */
133  void rename(const std::map<std::string, std::string>& old_to_new_names) override;
134 
135  /**
136  * Swap the order of two columns
137  */
138  void swap_columns(const std::string& column_1, const std::string& column_2) override;
139 
140  virtual std::shared_ptr<unity_sframe> get_proxy() const override;
141 
142  private:
143  gl_sgraph* m_sgraph;
144  gframe_type_enum m_gframe_type;
145 };
146 
147 }
148 
149 #endif