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

The ShapeId class provides a Qt representation of a Smithy Shape ID. More...

Collaboration diagram for ShapeId:
[legend]

Public Member Functions

 ShapeId ()
 Constructs an empty ShapeId object.
 
 ShapeId (ShapeId &&other)
 Constructs a ShapeId object by moving resources from other.
 
 ShapeId (const ShapeId &other)
 Constructs a ShapeId object by copying other.
 
 ShapeId (const QString &shapeId)
 Constructs a ShapeId object by parsing the Smithy Shape ID given by shapeId.
 
ShapeIdoperator= (const ShapeId &shapeId)
 Assigns the specified shapeId to this object.
 
ShapeIdoperator= (const ShapeId &&shapeId)
 Moves the specified shapeId to this object.
 
ShapeIdoperator= (const QString &shapeId)
 Assigns the specified shapeId to this object.
 
 ~ShapeId ()
 Destroys this ShapeId object.
 
QString memberName () const
 Returns the Shape ID's member name, if it has one, otherwise a null string.
 
QString nameSpace () const
 Returns the Shape ID's namespace, if it has one, otherwise a null string.
 
QString shapeName () const
 Returns the Shape ID's shape name, if it has one, otherwise a null string.
 
void setMemberName (const QString &name)
 Set the Shape ID's member name to name, which may be an empty or null string.
 
void setNameSpace (const QString &name)
 Set the Shape ID's namespace to name, which may be an empty or null string.
 
void setShapeName (const QString &name)
 Set the Shape ID's shape name to name.
 
QString absoluteShapeId () const
 Returns this object as an absolute Smithy Shape ID if this object has a namespace, otherwise a null string.
 
QString relativeShapeId () const
 Returns this object as a relative Smithy Shape ID, that one without a leading namespace.
 
QString toString () const
 Returns this object as an absolute Smithy Shape ID if this object has a namespace, otherwise a relative Smithy Shape ID.
 
bool hasNameSpace () const
 Returns true if this Shape ID has a non-empty namespace, otherwise false otherwise.
 
bool hasMemberName () const
 Returns true if this Shape ID has a non-empty member name, otherwise false otherwise.
 
bool isAbsoluteRootShapeId () const
 Returns true if this Shape ID is a root Shape ID, and has a namespace, false otherwise.
 
bool isRootShapeId () const
 Returns true if this Shape ID is a root Shape ID, false otherwise.
 
bool isRelativeShapeId () const
 Returns true if this Shape ID is a relative Shape ID, false otherwise.
 
bool isValid () const
 Returns true if this object represents a valid, non-empty Smithy Shape ID.
 
bool operator== (const ShapeId &other) const
 

Private Member Functions

 Q_DECLARE_TR_FUNCTIONS (ShapeId)
 

Private Attributes

ShapeIdPrivated_ptr
 

Detailed Description

The ShapeId class provides a Qt representation of a Smithy Shape ID.

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

Definition at line 28 of file shapeid.h.

Constructor & Destructor Documentation

◆ ShapeId() [1/4]

ShapeId::ShapeId ( )

Constructs an empty ShapeId object.

Definition at line 27 of file shapeid.cpp.

27 : d_ptr(new ShapeIdPrivate(this))
28{
29
30}
ShapeIdPrivate * d_ptr
Definition shapeid.h:65

References d_ptr.

Referenced by isValid(), memberName(), nameSpace(), operator=(), operator=(), operator=(), setMemberName(), setNameSpace(), setShapeName(), ShapeId(), ShapeId(), ShapeId(), and shapeName().

Here is the caller graph for this function:

◆ ShapeId() [2/4]

ShapeId::ShapeId ( ShapeId && other)

Constructs a ShapeId object by moving resources from other.

Definition at line 35 of file shapeid.cpp.

35 : d_ptr(new ShapeIdPrivate(this))
36{
37 Q_D(ShapeId);
38 d->memberName = std::move(other.d_ptr->memberName);
39 d->nameSpace = std::move(other.d_ptr->nameSpace);
40 d->shapeName = std::move(other.d_ptr->shapeName);
41}
ShapeId()
Constructs an empty ShapeId object.
Definition shapeid.cpp:27

References d_ptr, and ShapeId().

Here is the call graph for this function:

◆ ShapeId() [3/4]

ShapeId::ShapeId ( const ShapeId & other)

Constructs a ShapeId object by copying other.

Definition at line 46 of file shapeid.cpp.

46 : d_ptr(new ShapeIdPrivate(this))
47{
48 Q_D(ShapeId);
49 d->memberName = other.d_ptr->memberName;
50 d->nameSpace = other.d_ptr->nameSpace;
51 d->shapeName = other.d_ptr->shapeName;
52}

References d_ptr, and ShapeId().

Here is the call graph for this function:

◆ ShapeId() [4/4]

ShapeId::ShapeId ( const QString & shapeId)

Constructs a ShapeId object by parsing the Smithy Shape ID given by shapeId.

To be considered valid, shapeId must contain at least a valid shape name, but may also contain optional namespace and member name components. Use isValid() to verify shapeId's validity.

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

Definition at line 63 of file shapeid.cpp.

63 : d_ptr(new ShapeIdPrivate(this))
64{
65 Q_D(ShapeId);
66 d->setShapeId(shapeId);
67}

References d_ptr, and ShapeId().

Here is the call graph for this function:

◆ ~ShapeId()

ShapeId::~ShapeId ( )

Destroys this ShapeId object.

Definition at line 106 of file shapeid.cpp.

107{
108 delete d_ptr;
109}

References d_ptr.

Member Function Documentation

◆ absoluteShapeId()

QString ShapeId::absoluteShapeId ( ) const

Returns this object as an absolute Smithy Shape ID if this object has a namespace, otherwise a null string.

Note
, Smithy defines an absolute Shape ID as one that begins with a namespace, therefore it is not possible to return an absolute Shape ID if no namespace has been set.
, if the Shape ID is invalid (ie isValid() returns false) it still safe to invoke this method, but the result is undefined.
See also
setNameSpace
isValid

Definition at line 185 of file shapeid.cpp.

186{
187 return hasNameSpace() ? QStringLiteral("%1#%2").arg(nameSpace(), relativeShapeId()) : QString();
188}
QString nameSpace() const
Returns the Shape ID's namespace, if it has one, otherwise a null string.
Definition shapeid.cpp:123
QString relativeShapeId() const
Returns this object as a relative Smithy Shape ID, that one without a leading namespace.
Definition shapeid.cpp:198
bool hasNameSpace() const
Returns true if this Shape ID has a non-empty namespace, otherwise false otherwise.
Definition shapeid.cpp:225

References hasNameSpace(), nameSpace(), and relativeShapeId().

Referenced by toString().

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

◆ hasMemberName()

bool ShapeId::hasMemberName ( ) const

Returns true if this Shape ID has a non-empty member name, otherwise false otherwise.

See also
memberName.
setMemberName.

Definition at line 236 of file shapeid.cpp.

237{
238 return !memberName().isEmpty();
239}
QString memberName() const
Returns the Shape ID's member name, if it has one, otherwise a null string.
Definition shapeid.cpp:114

References memberName().

Referenced by isRootShapeId(), and relativeShapeId().

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

◆ hasNameSpace()

bool ShapeId::hasNameSpace ( ) const

Returns true if this Shape ID has a non-empty namespace, otherwise false otherwise.

See also
nameSpace.
setNameSpace.

Definition at line 225 of file shapeid.cpp.

226{
227 return !nameSpace().isEmpty();
228}

References nameSpace().

Referenced by absoluteShapeId(), Model::insert(), isAbsoluteRootShapeId(), isRelativeShapeId(), and toString().

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

◆ isAbsoluteRootShapeId()

bool ShapeId::isAbsoluteRootShapeId ( ) const

Returns true if this Shape ID is a root Shape ID, and has a namespace, false otherwise.

See also
isRootShapeId.
hasNameSpace.

Definition at line 247 of file shapeid.cpp.

248{
249 return isRootShapeId() && hasNameSpace();
250}
bool isRootShapeId() const
Returns true if this Shape ID is a root Shape ID, false otherwise.
Definition shapeid.cpp:259

References hasNameSpace(), and isRootShapeId().

Here is the call graph for this function:

◆ isRelativeShapeId()

bool ShapeId::isRelativeShapeId ( ) const

Returns true if this Shape ID is a relative Shape ID, false otherwise.

Note
, Smithy defines a relative Shape ID as one that does not have a namespace.
See also
hasNameSpace.

Definition at line 271 of file shapeid.cpp.

272{
273 return !hasNameSpace();
274}

References hasNameSpace().

Here is the call graph for this function:

◆ isRootShapeId()

bool ShapeId::isRootShapeId ( ) const

Returns true if this Shape ID is a root Shape ID, false otherwise.

Note
, Smithy defines a root Shape ID as one that does not have a member name.
See also
hasMemberName.

Definition at line 259 of file shapeid.cpp.

260{
261 return !hasMemberName();
262}
bool hasMemberName() const
Returns true if this Shape ID has a non-empty member name, otherwise false otherwise.
Definition shapeid.cpp:236

References hasMemberName().

Referenced by isAbsoluteRootShapeId().

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

◆ isValid()

bool ShapeId::isValid ( ) const

Returns true if this object represents a valid, non-empty Smithy Shape ID.

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

Definition at line 281 of file shapeid.cpp.

282{
283 Q_D(const ShapeId);
284 // Validate the (optional) namespace.
285 if (!d->nameSpace.isEmpty()) {
286 static QRegularExpression namespacePattern(QStringLiteral("^(_*[a-zA-Z]\\w*\\.?)+(?<!\\.)$"));
287 Q_ASSERT(namespacePattern.isValid());
288 if (!namespacePattern.match(d->nameSpace).hasMatch()) {
289 return false;
290 }
291 }
292
293 // Validate the (required) shape name.
294 static QRegularExpression identifierPattern(QStringLiteral("^_*[a-zA-Z]\\w*$"));
295 Q_ASSERT(identifierPattern.isValid());
296 if ((d->shapeName.isEmpty()) || (!identifierPattern.match(d->shapeName).hasMatch())) {
297 return false;
298 }
299
300 // Validate the (optional) member name.
301 if ((!d->memberName.isEmpty()) && (!identifierPattern.match(d->memberName).hasMatch())) {
302 return false;
303 }
304 return true; // Valid.
305}

References ShapeId().

Referenced by Model::insert().

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

◆ memberName()

QString ShapeId::memberName ( ) const

Returns the Shape ID's member name, if it has one, otherwise a null string.

Definition at line 114 of file shapeid.cpp.

115{
116 Q_D(const ShapeId);
117 return d->memberName;
118}

References ShapeId().

Referenced by hasMemberName(), and relativeShapeId().

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

◆ nameSpace()

QString ShapeId::nameSpace ( ) const

Returns the Shape ID's namespace, if it has one, otherwise a null string.

Definition at line 123 of file shapeid.cpp.

124{
125 Q_D(const ShapeId);
126 return d->nameSpace;
127}

References ShapeId().

Referenced by absoluteShapeId(), and hasNameSpace().

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

◆ operator=() [1/3]

ShapeId & ShapeId::operator= ( const QString & shapeId)

Assigns the specified shapeId to this object.

Definition at line 96 of file shapeid.cpp.

97{
98 Q_D(ShapeId);
99 d->setShapeId(shapeId);
100 return *this;
101}

References ShapeId().

Here is the call graph for this function:

◆ operator=() [2/3]

ShapeId & ShapeId::operator= ( const ShapeId && shapeId)

Moves the specified shapeId to this object.

Definition at line 84 of file shapeid.cpp.

85{
86 Q_D(ShapeId);
87 d->memberName = std::move(shapeId.d_ptr->memberName);
88 d->nameSpace = std::move(shapeId.d_ptr->nameSpace);
89 d->shapeName = std::move(shapeId.d_ptr->shapeName);
90 return *this;
91}

References ShapeId().

Here is the call graph for this function:

◆ operator=() [3/3]

ShapeId & ShapeId::operator= ( const ShapeId & shapeId)

Assigns the specified shapeId to this object.

Definition at line 72 of file shapeid.cpp.

73{
74 Q_D(ShapeId);
75 d->memberName = shapeId.d_ptr->memberName;
76 d->nameSpace = shapeId.d_ptr->nameSpace;
77 d->shapeName = shapeId.d_ptr->shapeName;
78 return *this;
79}

References d_ptr, and ShapeId().

Here is the call graph for this function:

◆ operator==()

bool ShapeId::operator== ( const ShapeId & other) const

Definition at line 307 of file shapeid.cpp.

308{
309 Q_D(const ShapeId);
310 return (d->memberName == other.d_ptr->memberName) &&
311 (d->nameSpace == other.d_ptr->nameSpace) &&
312 (d->shapeName == other.d_ptr->shapeName);
313}

◆ relativeShapeId()

QString ShapeId::relativeShapeId ( ) const

Returns this object as a relative Smithy Shape ID, that one without a leading namespace.

Note
, if the Shape ID is invalid (ie isValid() returns false) it still safe to invoke this method, but the result is undefined.
See also
isValid

Definition at line 198 of file shapeid.cpp.

199{
200 return hasMemberName() ? QStringLiteral("%1$%2").arg(shapeName(), memberName()) : shapeName();
201}
QString shapeName() const
Returns the Shape ID's shape name, if it has one, otherwise a null string.
Definition shapeid.cpp:136

References hasMemberName(), memberName(), and shapeName().

Referenced by absoluteShapeId(), and toString().

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

◆ setMemberName()

void ShapeId::setMemberName ( const QString & name)

Set the Shape ID's member name to name, which may be an empty or null string.

Definition at line 145 of file shapeid.cpp.

146{
147 Q_D(ShapeId);
148 d->memberName = name;
149}

References ShapeId().

Here is the call graph for this function:

◆ setNameSpace()

void ShapeId::setNameSpace ( const QString & name)

Set the Shape ID's namespace to name, which may be an empty or null string.

Definition at line 154 of file shapeid.cpp.

155{
156 Q_D(ShapeId);
157 d->nameSpace = name;
158}

References ShapeId().

Here is the call graph for this function:

◆ setShapeName()

void ShapeId::setShapeName ( const QString & name)

Set the Shape ID's shape name to name.

Note, a Shape ID is considered invalid if it has no shape name, so name should typically be non-empty.

Definition at line 166 of file shapeid.cpp.

167{
168 Q_D(ShapeId);
169 d->shapeName = name;
170}

References ShapeId().

Here is the call graph for this function:

◆ shapeName()

QString ShapeId::shapeName ( ) const

Returns the Shape ID's shape name, if it has one, otherwise a null string.

Note, a Shape ID is considered invalid if it has no shape name.

See also
isValid

Definition at line 136 of file shapeid.cpp.

137{
138 Q_D(const ShapeId);
139 return d->shapeName;
140}

References ShapeId().

Referenced by relativeShapeId().

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

◆ toString()

QString ShapeId::toString ( ) const

Returns this object as an absolute Smithy Shape ID if this object has a namespace, otherwise a relative Smithy Shape ID.

Note
, if the Shape ID is invalid (ie isValid() returns false) it still safe to invoke this method, but the result is undefined.
See also
absoluteShapeId
relativeShapeId
isValid

Definition at line 214 of file shapeid.cpp.

215{
217}
QString absoluteShapeId() const
Returns this object as an absolute Smithy Shape ID if this object has a namespace,...
Definition shapeid.cpp:185

References absoluteShapeId(), hasNameSpace(), and relativeShapeId().

Referenced by Model::insert().

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

Member Data Documentation

◆ d_ptr

ShapeIdPrivate* ShapeId::d_ptr
private

Internal d-pointer.

Definition at line 65 of file shapeid.h.

Referenced by operator=(), ShapeId(), ShapeId(), ShapeId(), ShapeId(), and ~ShapeId().


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