aboutsummaryrefslogtreecommitdiff
path: root/src/vkscript/datum_type.h
blob: b229e20f1c23ad44938e9a60e74242ed1c96aff5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright 2018 The Amber Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef SRC_VKSCRIPT_DATUM_TYPE_H_
#define SRC_VKSCRIPT_DATUM_TYPE_H_

#include <cstddef>
#include <cstdint>
#include <memory>

#include "src/format.h"

namespace amber {
namespace vkscript {

enum class DataType {
  kInt8 = 0,
  kInt16,
  kInt32,
  kInt64,
  kUint8,
  kUint16,
  kUint32,
  kUint64,
  kFloat,
  kDouble,
};

/// Stores information on a given type of data. This class should only be used
/// as a simple way to create format objects. DatumType should not appear as a
/// member of any classes.
class DatumType {
 public:
  DatumType();
  DatumType(const DatumType&);
  ~DatumType();

  bool IsInt8() const { return type_ == DataType::kInt8; }
  bool IsInt16() const { return type_ == DataType::kInt16; }
  bool IsInt32() const { return type_ == DataType::kInt32; }
  bool IsInt64() const { return type_ == DataType::kInt64; }
  bool IsUint8() const { return type_ == DataType::kUint8; }
  bool IsUint16() const { return type_ == DataType::kUint16; }
  bool IsUint32() const { return type_ == DataType::kUint32; }
  bool IsUint64() const { return type_ == DataType::kUint64; }
  bool IsFloat() const { return type_ == DataType::kFloat; }
  bool IsDouble() const { return type_ == DataType::kDouble; }

  void SetType(DataType type) { type_ = type; }
  DataType GetType() const { return type_; }

  void SetColumnCount(uint32_t count) { column_count_ = count; }
  uint32_t ColumnCount() const { return column_count_; }

  void SetRowCount(uint32_t count) { row_count_ = count; }
  uint32_t RowCount() const { return row_count_; }

  std::unique_ptr<Format> AsFormat() const;

 private:
  DataType type_ = DataType::kUint8;
  uint32_t column_count_ = 1;
  uint32_t row_count_ = 1;
  bool is_std140_ = true;
};

}  // namespace vkscript
}  // namespace amber

#endif  // SRC_VKSCRIPT_DATUM_TYPE_H_