Fletchgen
The Fletcher Design Generator
schema.h
1 // Copyright 2018-2019 Delft University of Technology
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 // http://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 #pragma once
16 
17 #include <arrow/api.h>
18 #include <cerata/api.h>
19 
20 #include <memory>
21 #include <vector>
22 #include <optional>
23 #include <string>
24 
25 #include "fletchgen/bus.h"
26 #include "fletchgen/utils.h"
27 
28 namespace fletchgen {
29 
30 using fletcher::Mode;
31 
36  public:
38  explicit FletcherSchema(const std::shared_ptr<arrow::Schema> &arrow_schema, const std::string &schema_name = "");
39 
46  static std::shared_ptr<FletcherSchema> Make(const std::shared_ptr<arrow::Schema> &arrow_schema,
47  const std::string &schema_name = "");
48 
50  [[nodiscard]] std::shared_ptr<arrow::Schema> arrow_schema() const { return arrow_schema_; }
51 
53  [[nodiscard]] Mode mode() const { return mode_; }
55  [[nodiscard]] std::string name() const { return name_; }
56 
57  private:
59  std::shared_ptr<arrow::Schema> arrow_schema_;
61  Mode mode_;
63  std::string name_;
65  BusDim bus_dims_;
66 };
67 
71 class SchemaSet : public cerata::Named {
72  public:
74  explicit SchemaSet(std::string name);
76  static std::shared_ptr<SchemaSet> Make(const std::string &name);
78  [[nodiscard]] bool RequiresReading() const;
80  [[nodiscard]] bool RequiresWriting() const;
82  [[nodiscard]] bool HasSchemaWithName(const std::string &name) const;
84  [[nodiscard]] std::optional<std::shared_ptr<FletcherSchema>> GetSchema(const std::string &name) const;
86  void AppendSchema(const std::shared_ptr<arrow::Schema> &schema);
88  [[nodiscard]] std::vector<std::shared_ptr<FletcherSchema>> schemas() const { return schemas_; }
90  [[nodiscard]] std::vector<std::shared_ptr<FletcherSchema>> read_schemas() const;
92  [[nodiscard]] std::vector<std::shared_ptr<FletcherSchema>> write_schemas() const;
94  void Sort();
95 
96  private:
98  std::vector<std::shared_ptr<FletcherSchema>> schemas_;
99 };
100 
101 } // namespace fletchgen
FletcherSchema(const std::shared_ptr< arrow::Schema > &arrow_schema, const std::string &schema_name="")
Construct a new Fletcher schema.
Definition: schema.cc:140
static std::shared_ptr< FletcherSchema > Make(const std::shared_ptr< arrow::Schema > &arrow_schema, const std::string &schema_name="")
Make a new FletcherSchema, returning a shared pointer to it.
Definition: schema.cc:156
std::shared_ptr< arrow::Schema > arrow_schema() const
Return the Arrow schema that this FletcherSchema was based on.
Definition: schema.h:50
std::string name() const
Return the name of this FletcherSchema.
Definition: schema.h:55
Mode mode() const
Return the access mode of the RecordBatch this schema represents.
Definition: schema.h:53
A named set of schemas.
Definition: schema.h:71
std::vector< std::shared_ptr< FletcherSchema > > schemas() const
Return all schemas of this schemaset.
Definition: schema.h:88
std::vector< std::shared_ptr< FletcherSchema > > read_schemas() const
Return all schemas with read mode.
Definition: schema.cc:96
SchemaSet(std::string name)
SchemaSet constructor.
Definition: schema.cc:30
bool RequiresReading() const
Determine whether any schema in this set requires reading from memory.
Definition: schema.cc:36
std::vector< std::shared_ptr< FletcherSchema > > write_schemas() const
Return all schemas with write mode.
Definition: schema.cc:106
void Sort()
Sort the schemas by name, then by read/write mode.
Definition: schema.cc:116
static std::shared_ptr< SchemaSet > Make(const std::string &name)
Make a new, empty SchemaSet, and return a shared pointer to it.
Definition: schema.cc:32
bool HasSchemaWithName(const std::string &name) const
Return true if set contains schema with some name, false otherwise.
Definition: schema.cc:54
void AppendSchema(const std::shared_ptr< arrow::Schema > &schema)
Append a schema.
Definition: schema.cc:63
std::optional< std::shared_ptr< FletcherSchema > > GetSchema(const std::string &name) const
Optionally return a schema with name, if it exists.
Definition: schema.cc:87
bool RequiresWriting() const
Determine whether any schema in this set requires writing to memory.
Definition: schema.cc:45
Contains all classes and functions related to Fletchgen.
Definition: array.cc:29
Holds bus interface dimensions.
Definition: bus.h:48