Smithy Qt 0.1.0-pre
Internal development documentation
Loading...
Searching...
No Matches
shape.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2013-2025 Paul Colby <git@colby.id.au>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
4/*!
5 * \file
6 * Declares the Shape class.
7 */
8
9#ifndef QTSMITHY_SHAPE_H
10#define QTSMITHY_SHAPE_H
11
12#include "shapeid.h"
13
14#include <QCoreApplication>
15#include <QJsonObject>
16#include <QJsonValue>
17
19
21
22class ShapePrivate;
23
25{
26Q_DECLARE_TR_FUNCTIONS(Shape);
27
28public:
29 enum class Error {
30 NoError = 0,
31 UndefinedShapeType = 1,
32 MissingRequiredProperty = 2,
33 InvalidPropertyValue = 3,
34 };
35
36 // https://awslabs.github.io/smithy/2.0/spec/model.html#shape-types
37 enum class Type {
38 Undefined = 0x000, ///< The shape is undefined, usually the result of an error condition.
39
40 // Simple Types
41 Blob = 0x101, ///< Uninterpreted binary data.
42 Boolean = 0x102, ///< Boolean value type.
43 String = 0x103, ///< UTF-8 encoded string.
44 Enum = 0x104, ///< A string with a fixed set of values.
45 Byte = 0x105, ///< 8-bit signed integer ranging from -128 to 127 (inclusive).
46 Short = 0x106, ///< 16-bit signed integer ranging from -32,768 to 32,767 (inclusive).
47 Integer = 0x107, ///< 32-bit signed integer ranging from -2^31 to (2^31)-1 (inclusive).
48 IntEnum = 0x108, ///< An integer with a fixed set of values.
49 Long = 0x109, ///< 64-bit signed integer ranging from -2^63 to (2^63)-1 (inclusive).
50 Float = 0x10A, ///< Single precision IEEE-754 floating point number.
51 Double = 0x10B, ///< Double precision IEEE-754 floating point number.
52 BigInteger = 0x10C, ///< Arbitrarily large signed integer.
53 BigDecimal = 0x10D, ///< Arbitrary precision signed decimal number.
54 Timestamp = 0x10E, ///< An instant in time with no UTC offset or timezone.
55 Document = 0x10F, ///< Open content that functions as a kind of "any" type.
56
57 // Aggregate Types
58 List = 0x201, ///< Ordered collection of homogeneous values.
59 Set = 0x201, ///< Deprecated; use a list with the uniqueItems trait instead.
60 Map = 0x202, ///< Map data structure that maps string keys to homogeneous values.
61 Structure = 0x203, ///< Fixed set of named heterogeneous members.
62 Union = 0x204, ///< Tagged union data structure that can take on one of several
63 ///< different, but fixed, types
64
65 // Service Types
66 Service = 0x301, ///< Entry point of an API that aggregates resources and operations together.
67 Operation = 0x302, ///< Represents the input, output, and errors of an API operation.
68 Resource = 0x303, ///< Entity with an identity that has a set of operations
69
70 // Special Types
71 Apply = 0x401, ///< Traits to be applied to shapes outside of their definition.
72 };
73
74 // Map of absolute shape ID of a trait shape to the value to assign to the trait.
75 typedef QHash<ShapeId, QJsonValue> TraitsMap;
76
77 // https://awslabs.github.io/smithy/2.0/spec/json-ast.html#ast-shape-reference
79 ShapeId target;
80 };
81 typedef QHash<QString, ShapeReference> StringShapeRefMap;
82 typedef QSet<ShapeReference> ShapeReferences;
83
84 // https://awslabs.github.io/smithy/2.0/spec/json-ast.html#ast-member
85 struct Member : public ShapeReference {
86 TraitsMap traits;
87 };
88 typedef QHash<QString, Member> StringMemberMap;
89
90 Shape();
91 Shape(const QJsonObject &ast, const ShapeId &id = ShapeId{});
92 Shape(Shape &&other);
93 Shape(const Shape &other);
94 Shape& operator=(const Shape &shape);
95 Shape& operator=(const Shape &&shape);
96 ~Shape();
97
98 Error error() const;
99 bool isValid() const;
100
101 ShapeId id() const;
102 Type type() const;
103 TraitsMap traits() const;
104
105 // List (and set) shape https://awslabs.github.io/smithy/2.0/spec/json-ast.html#list-shapes
106 Member member() const;
107
108 // Map shape https://awslabs.github.io/smithy/2.0/spec/json-ast.html#map-shape
109 Member key() const;
110 Member value() const;
111
112 // Structure, union, enum, and intEnum shapes
113 // https://awslabs.github.io/smithy/2.0/spec/json-ast.html#structure-union-enum-and-intenum-shapes
114 StringMemberMap members() const;
115
116 // Service shape https://awslabs.github.io/smithy/2.0/spec/json-ast.html#service-shape
117 QString version() const;
118 ShapeReferences operations() const; // And resource shape.
119 ShapeReferences resources() const; // And resource shape.
120 ShapeReferences errors() const; // And operation shape.
121 ShapeIdStringMap rename() const;
122
123 // Resource shape https://awslabs.github.io/smithy/2.0/spec/json-ast.html#resource-shape
124 StringShapeRefMap identifiers() const;
125 StringShapeRefMap properties() const;
126 ShapeReference create() const;
127 ShapeReference put() const;
128 ShapeReference read() const;
129 ShapeReference update() const;
130 ShapeReference Delete() const;
131 ShapeReference list() const;
132 //ShapeReferences operations() const; // And service shape.
133 ShapeReferences collectionOperations() const;
134 //ShapeReferences resources() const; // And service shape.
135
136 // Operation shape https://awslabs.github.io/smithy/2.0/spec/json-ast.html#operation-shape
137 ShapeReference input() const;
138 ShapeReference output() const;
139 //ShapeReferences errors() const; // And service shape.
140
141 // Mixins https://awslabs.github.io/smithy/2.0/spec/json-ast.html#mixins
142 ShapeReferences mixins() const;
143
144 QJsonObject rawAst() const;
145
146protected:
147 /// \cond internal
148 ShapePrivate * d_ptr; ///< Internal d-pointer.
149 /// \endcond
150
151private:
152 Q_DECLARE_PRIVATE(Shape)
154};
155
156#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
157QTSMITHY_EXPORT uint qHash(const Shape::ShapeReference &key, uint seed = 0);
158#else
159QTSMITHY_EXPORT size_t qHash(const Shape::ShapeReference &key, size_t seed = 0);
160#endif
161
162QTSMITHY_EXPORT bool operator==(const Shape::ShapeReference &lhs, const Shape::ShapeReference& rhs);
163
165
166#endif // QTSMITHY_SHAPE_H
The ShapeId class provides a Qt representation of a Smithy Shape ID.
Definition shapeid.h:29
The ShapePrivate class provides private implementation for Shape.
Definition shape_p.h:20
The Shape class provides a Qt representation of a Smithy semantic shape.
Definition shape.h:25
ShapePrivate * d_ptr
Definition shape.h:148
Type
Definition shape.h:37
@ IntEnum
An integer with a fixed set of values.
Definition shape.h:48
@ Document
Open content that functions as a kind of "any" type.
Definition shape.h:55
@ Float
Single precision IEEE-754 floating point number.
Definition shape.h:50
@ String
UTF-8 encoded string.
Definition shape.h:43
@ Boolean
Boolean value type.
Definition shape.h:42
@ Operation
Represents the input, output, and errors of an API operation.
Definition shape.h:67
@ Short
16-bit signed integer ranging from -32,768 to 32,767 (inclusive).
Definition shape.h:46
@ Map
Map data structure that maps string keys to homogeneous values.
Definition shape.h:60
@ List
Ordered collection of homogeneous values.
Definition shape.h:58
@ Set
Deprecated; use a list with the uniqueItems trait instead.
Definition shape.h:59
@ Long
64-bit signed integer ranging from -2^63 to (2^63)-1 (inclusive).
Definition shape.h:49
@ Apply
Traits to be applied to shapes outside of their definition.
Definition shape.h:71
@ Integer
32-bit signed integer ranging from -2^31 to (2^31)-1 (inclusive).
Definition shape.h:47
@ Byte
8-bit signed integer ranging from -128 to 127 (inclusive).
Definition shape.h:45
@ Timestamp
An instant in time with no UTC offset or timezone.
Definition shape.h:54
@ Resource
Entity with an identity that has a set of operations.
Definition shape.h:68
@ Service
Entry point of an API that aggregates resources and operations together.
Definition shape.h:66
@ Enum
A string with a fixed set of values.
Definition shape.h:44
@ BigInteger
Arbitrarily large signed integer.
Definition shape.h:52
@ Double
Double precision IEEE-754 floating point number.
Definition shape.h:51
@ Structure
Fixed set of named heterogeneous members.
Definition shape.h:61
@ Blob
Uninterpreted binary data.
Definition shape.h:41
@ BigDecimal
Arbitrary precision signed decimal number.
Definition shape.h:53
@ Undefined
The shape is undefined, usually the result of an error condition.
Definition shape.h:38
Shape()
Constructs a new, empty Smithy shape.
Definition shape.cpp:28
#define QTSMITHY_EXPORT
QtSmithy library export/import macro.
#define QTSMITHY_BEGIN_NAMESPACE
Macro for starting the QtSmithy library's top-most namespace (if one is defined).
#define QTSMITHY_DECLARE_TEST(Class)
Macro for forward-delcaring a related unit test class, but only when QT_TESTLIB_LIB is defined.
#define QTSMITHY_BEFRIEND_TEST(Class)
Macro for befriending a related unit test class, but only when QT_TESTLIB_LIB is defined.
#define QTSMITHY_END_NAMESPACE
Macro for ending the QtSmithy library's top-most namespace (if one is defined).
Declares the ShapeId class.