Smithy Qt 0.1.0-pre
Internal development documentation
Loading...
Searching...
No Matches
Shape Class Reference

The Shape class provides a Qt representation of a Smithy semantic shape. More...

Collaboration diagram for Shape:
[legend]

Classes

struct  Member
 
struct  ShapeReference
 

Public Types

enum class  Error { NoError = 0 , UndefinedShapeType = 1 , MissingRequiredProperty = 2 , InvalidPropertyValue = 3 }
 
enum class  Type {
  Undefined = 0x000 , Blob = 0x101 , Boolean = 0x102 , String = 0x103 ,
  Enum = 0x104 , Byte = 0x105 , Short = 0x106 , Integer = 0x107 ,
  IntEnum = 0x108 , Long = 0x109 , Float = 0x10A , Double = 0x10B ,
  BigInteger = 0x10C , BigDecimal = 0x10D , Timestamp = 0x10E , Document = 0x10F ,
  List = 0x201 , Set = 0x201 , Map = 0x202 , Structure = 0x203 ,
  Union = 0x204 , Service = 0x301 , Operation = 0x302 , Resource = 0x303 ,
  Apply = 0x401
}
 
typedef QHash< ShapeId, QJsonValue > TraitsMap
 
typedef QHash< QString, ShapeReferenceStringShapeRefMap
 
typedef QSet< ShapeReferenceShapeReferences
 
typedef QHash< QString, MemberStringMemberMap
 

Public Member Functions

 Shape ()
 Constructs a new, empty Smithy shape.
 
 Shape (const QJsonObject &ast, const ShapeId &id=ShapeId{})
 
 Shape (Shape &&other)
 
 Shape (const Shape &other)
 
Shapeoperator= (const Shape &shape)
 
Shapeoperator= (const Shape &&shape)
 
 ~Shape ()
 Destroys this Shape object.
 
Error error () const
 
bool isValid () const
 
ShapeId id () const
 
Type type () const
 
TraitsMap traits () const
 
Member member () const
 
Member key () const
 
Member value () const
 
StringMemberMap members () const
 
QString version () const
 
ShapeReferences operations () const
 
ShapeReferences resources () const
 
ShapeReferences errors () const
 
ShapeIdStringMap rename () const
 
StringShapeRefMap identifiers () const
 
StringShapeRefMap properties () const
 
ShapeReference create () const
 
ShapeReference put () const
 
ShapeReference read () const
 
ShapeReference update () const
 
ShapeReference Delete () const
 
ShapeReference list () const
 
ShapeReferences collectionOperations () const
 
ShapeReference input () const
 
ShapeReference output () const
 
ShapeReferences mixins () const
 
QJsonObject rawAst () const
 

Protected Attributes

ShapePrivated_ptr
 

Private Member Functions

 Q_DECLARE_TR_FUNCTIONS (Shape)
 

Detailed Description

The Shape class provides a Qt representation of a Smithy semantic shape.

That is, essentially a tagged union or variant class, with some specialised conversions for native Qt types.

See also
https://awslabs.github.io/smithy/2.0/spec/shape.html#semantic-shape

Definition at line 24 of file shape.h.

Member Typedef Documentation

◆ ShapeReferences

typedef QSet<ShapeReference> Shape::ShapeReferences

Definition at line 82 of file shape.h.

◆ StringMemberMap

typedef QHash<QString, Member> Shape::StringMemberMap

Definition at line 88 of file shape.h.

◆ StringShapeRefMap

typedef QHash<QString, ShapeReference> Shape::StringShapeRefMap

Definition at line 81 of file shape.h.

◆ TraitsMap

typedef QHash<ShapeId, QJsonValue> Shape::TraitsMap

Definition at line 75 of file shape.h.

Member Enumeration Documentation

◆ Error

enum class Shape::Error
strong

Definition at line 29 of file shape.h.

29 {
30 NoError = 0,
31 UndefinedShapeType = 1,
32 MissingRequiredProperty = 2,
33 InvalidPropertyValue = 3,
34 };

◆ Type

enum class Shape::Type
strong
Enumerator
Undefined 0x000 

The shape is undefined, usually the result of an error condition.

Blob 0x101 

Uninterpreted binary data.

Boolean 0x102 

Boolean value type.

String 0x103 

UTF-8 encoded string.

Enum 0x104 

A string with a fixed set of values.

Byte 0x105 

8-bit signed integer ranging from -128 to 127 (inclusive).

Short 0x106 

16-bit signed integer ranging from -32,768 to 32,767 (inclusive).

Integer 0x107 

32-bit signed integer ranging from -2^31 to (2^31)-1 (inclusive).

IntEnum 0x108 

An integer with a fixed set of values.

Long 0x109 

64-bit signed integer ranging from -2^63 to (2^63)-1 (inclusive).

Float 0x10A 

Single precision IEEE-754 floating point number.

Double 0x10B 

Double precision IEEE-754 floating point number.

BigInteger 0x10C 

Arbitrarily large signed integer.

BigDecimal 0x10D 

Arbitrary precision signed decimal number.

Timestamp 0x10E 

An instant in time with no UTC offset or timezone.

Document 0x10F 

Open content that functions as a kind of "any" type.

List 0x201 

Ordered collection of homogeneous values.

Set 0x201 

Deprecated; use a list with the uniqueItems trait instead.

Map 0x202 

Map data structure that maps string keys to homogeneous values.

Structure 0x203 

Fixed set of named heterogeneous members.

Union 0x204 

Tagged union data structure that can take on one of several different, but fixed, types

Service 0x301 

Entry point of an API that aggregates resources and operations together.

Operation 0x302 

Represents the input, output, and errors of an API operation.

Resource 0x303 

Entity with an identity that has a set of operations.

Apply 0x401 

Traits to be applied to shapes outside of their definition.

Definition at line 37 of file shape.h.

37 {
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 };

Constructor & Destructor Documentation

◆ Shape() [1/4]

Shape::Shape ( )

Constructs a new, empty Smithy shape.

Definition at line 28 of file shape.cpp.

28 : d_ptr(new ShapePrivate(this))
29{
30 Q_D(Shape);
31 d->error = Error::NoError;
32 d->type = Type::Undefined;
33}
ShapePrivate * d_ptr
Definition shape.h:148
@ 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

References d_ptr, Shape(), and Undefined.

Referenced by Shape().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Shape() [2/4]

Shape::Shape ( const QJsonObject & ast,
const ShapeId & id = ShapeId{} )

Definition at line 35 of file shape.cpp.

35 : d_ptr(new ShapePrivate(this))
36{
37 Q_D(Shape);
38 d->ast = ast;
39 d->error = Error::NoError;
40 d->id = id;
41 d->type = ShapePrivate::getType(ast);
42 if (d->type == Type::Undefined) {
43 d->error = Error::UndefinedShapeType;
44 }
45
46 // Warn on any unsupported properties.
47 const QStringList supportedProperties = ShapePrivate::supportedProperties(d->type);
48 const QStringList keys = ast.keys();
49 for (const QString &key: keys) {
50 if (!supportedProperties.contains(key)) {
51 qCWarning(d->lc).noquote() << tr("Ignoring unsupported Shape property: %1").arg(key);
52 }
53 }
54
55 // Error on any missing required properties.
56 const QStringList requiredProperties = ShapePrivate::requiredProperties(d->type);
57 for (const QString &key: requiredProperties) {
58 if (!keys.contains(key)) {
59 qCritical(d->lc).noquote() << tr("Missing required Shape property: %1").arg(key);
60 d->error = Error::MissingRequiredProperty;
61 }
62 }
63
64 // Validate all present properties.
65 for (auto iter = ast.constBegin(); iter != ast.constEnd(); ++iter) {
66 if (!supportedProperties.contains(iter.key())) {
67 continue;
68 }
69 if (!ShapePrivate::validateProperty(iter.key(), iter.value())) {
70 if (d->error == Error::NoError) {
71 d->error = Error::InvalidPropertyValue;
72 }
73 }
74 }
75}

◆ Shape() [3/4]

Shape::Shape ( Shape && other)

Definition at line 77 of file shape.cpp.

77 : d_ptr(new ShapePrivate(this))
78{
79 Q_D(Shape);
80 d->ast = std::move(other.d_ptr->ast);
81 d->error = std::move(other.d_ptr->error);
82 d->id = std::move(other.d_ptr->id);
83 d->type = std::move(other.d_ptr->type);
84}

◆ Shape() [4/4]

Shape::Shape ( const Shape & other)

Definition at line 86 of file shape.cpp.

86 : d_ptr(new ShapePrivate(this))
87{
88 Q_D(Shape);
89 d->ast = other.d_ptr->ast;
90 d->error = other.d_ptr->error;
91 d->id = other.d_ptr->id;
92 d->type = other.d_ptr->type;
93}

◆ ~Shape()

Shape::~Shape ( )

Destroys this Shape object.

Definition at line 118 of file shape.cpp.

119{
120 delete d_ptr;
121}

References d_ptr.

Member Function Documentation

◆ collectionOperations()

Shape::ShapeReferences Shape::collectionOperations ( ) const

Definition at line 254 of file shape.cpp.

255{
256 Q_D(const Shape);
257 return ShapePrivate::getShapeRefs(d->ast, QStringLiteral("collectionOperations"));
258}

◆ create()

Shape::ShapeReference Shape::create ( ) const

Definition at line 218 of file shape.cpp.

219{
220 Q_D(const Shape);
221 return ShapePrivate::getShapeRef(d->ast, QStringLiteral("create"));
222}

◆ Delete()

Shape::ShapeReference Shape::Delete ( ) const

Definition at line 242 of file shape.cpp.

243{
244 Q_D(const Shape);
245 return ShapePrivate::getShapeRef(d->ast, QStringLiteral("delete"));
246}

◆ error()

Shape::Error Shape::error ( ) const

Definition at line 123 of file shape.cpp.

124{
125 Q_D(const Shape);
126 return d->error;
127}

◆ errors()

Shape::ShapeReferences Shape::errors ( ) const

Definition at line 195 of file shape.cpp.

195 {
196 Q_D(const Shape);
197 return ShapePrivate::getShapeRefs(d->ast, QStringLiteral("errors"));
198}

◆ id()

ShapeId Shape::id ( ) const

Definition at line 136 of file shape.cpp.

137{
138 Q_D(const Shape);
139 return d->id;
140}

◆ identifiers()

Shape::StringShapeRefMap Shape::identifiers ( ) const

Definition at line 206 of file shape.cpp.

207{
208 Q_D(const Shape);
209 return ShapePrivate::getStrShapeRefMap(d->ast, QStringLiteral("identifiers"));
210}

◆ input()

Shape::ShapeReference Shape::input ( ) const

Definition at line 260 of file shape.cpp.

261{
262 Q_D(const Shape);
263 return ShapePrivate::getShapeRef(d->ast, QStringLiteral("input"));
264}

◆ isValid()

bool Shape::isValid ( ) const

Definition at line 129 of file shape.cpp.

130{
131 Q_D(const Shape);
132 return ((d->error == Error::NoError) && (d->type != Type::Undefined));
133}

◆ key()

Shape::Member Shape::key ( ) const

Definition at line 160 of file shape.cpp.

161{
162 Q_D(const Shape);
163 return ShapePrivate::getMember(d->ast, QStringLiteral("key"));
164}

◆ list()

Shape::ShapeReference Shape::list ( ) const

Definition at line 248 of file shape.cpp.

249{
250 Q_D(const Shape);
251 return ShapePrivate::getShapeRef(d->ast, QStringLiteral("list"));
252}

◆ member()

Shape::Member Shape::member ( ) const

Definition at line 154 of file shape.cpp.

155{
156 Q_D(const Shape);
157 return ShapePrivate::getMember(d->ast, QStringLiteral("member"));
158}

◆ members()

Shape::StringMemberMap Shape::members ( ) const

Definition at line 172 of file shape.cpp.

173{
174 Q_D(const Shape);
175 return ShapePrivate::getStrMemberMap(d->ast, QStringLiteral("members"));
176}

◆ mixins()

Shape::ShapeReferences Shape::mixins ( ) const

Definition at line 272 of file shape.cpp.

273{
274 Q_D(const Shape);
275 return ShapePrivate::getShapeRefs(d->ast, QStringLiteral("mixins"));
276}

◆ operations()

Shape::ShapeReferences Shape::operations ( ) const

Definition at line 184 of file shape.cpp.

185{
186 Q_D(const Shape);
187 return ShapePrivate::getShapeRefs(d->ast, QStringLiteral("operations"));
188}

◆ operator=() [1/2]

Shape & Shape::operator= ( const Shape && shape)

Definition at line 105 of file shape.cpp.

106{
107 Q_D(Shape);
108 d->ast = std::move(shape.d_ptr->ast);
109 d->error = std::move(shape.d_ptr->error);
110 d->id = std::move(shape.d_ptr->id);
111 d->type = std::move(shape.d_ptr->type);
112 return *this;
113}

◆ operator=() [2/2]

Shape & Shape::operator= ( const Shape & shape)

Definition at line 95 of file shape.cpp.

96{
97 Q_D(Shape);
98 d->ast = shape.d_ptr->ast;
99 d->error = shape.d_ptr->error;
100 d->id = shape.d_ptr->id;
101 d->type = shape.d_ptr->type;
102 return *this;
103}

◆ output()

Shape::ShapeReference Shape::output ( ) const

Definition at line 266 of file shape.cpp.

267{
268 Q_D(const Shape);
269 return ShapePrivate::getShapeRef(d->ast, QStringLiteral("output"));
270}

◆ properties()

Shape::StringShapeRefMap Shape::properties ( ) const

Definition at line 212 of file shape.cpp.

213{
214 Q_D(const Shape);
215 return ShapePrivate::getStrShapeRefMap(d->ast, QStringLiteral("properties"));
216}

◆ put()

Shape::ShapeReference Shape::put ( ) const

Definition at line 224 of file shape.cpp.

225{
226 Q_D(const Shape);
227 return ShapePrivate::getShapeRef(d->ast, QStringLiteral("put"));
228}

◆ rawAst()

QJsonObject Shape::rawAst ( ) const

Definition at line 278 of file shape.cpp.

279{
280 Q_D(const Shape);
281 return d->ast;
282}

◆ read()

Shape::ShapeReference Shape::read ( ) const

Definition at line 230 of file shape.cpp.

231{
232 Q_D(const Shape);
233 return ShapePrivate::getShapeRef(d->ast, QStringLiteral("read"));
234}

◆ rename()

ShapeIdStringMap Shape::rename ( ) const

Definition at line 200 of file shape.cpp.

201{
202 Q_D(const Shape);
203 return ShapePrivate::getShapeIdStrMap(d->ast, QStringLiteral("rename"));
204}

◆ resources()

Shape::ShapeReferences Shape::resources ( ) const

Definition at line 190 of file shape.cpp.

190 {
191 Q_D(const Shape);
192 return ShapePrivate::getShapeRefs(d->ast, QStringLiteral("resources"));
193}

◆ traits()

Shape::TraitsMap Shape::traits ( ) const

Definition at line 148 of file shape.cpp.

149{
150 Q_D(const Shape);
151 return ShapePrivate::getTraitsMap(d->ast, QStringLiteral("traits"));
152}

◆ type()

Shape::Type Shape::type ( ) const

Definition at line 142 of file shape.cpp.

143{
144 Q_D(const Shape);
145 return d->type;
146}

◆ update()

Shape::ShapeReference Shape::update ( ) const

Definition at line 236 of file shape.cpp.

237{
238 Q_D(const Shape);
239 return ShapePrivate::getShapeRef(d->ast, QStringLiteral("update"));
240}

◆ value()

Shape::Member Shape::value ( ) const

Definition at line 166 of file shape.cpp.

167{
168 Q_D(const Shape);
169 return ShapePrivate::getMember(d->ast, QStringLiteral("value"));
170}

◆ version()

QString Shape::version ( ) const

Definition at line 178 of file shape.cpp.

179{
180 Q_D(const Shape);
181 return ShapePrivate::getString(d->ast, QStringLiteral("version"));
182}

Member Data Documentation

◆ d_ptr

ShapePrivate* Shape::d_ptr
protected

Internal d-pointer.

Definition at line 148 of file shape.h.

Referenced by Shape(), and ~Shape().


The documentation for this class was generated from the following files: