Bond 0.9
C++ Bond Runtime Library API Documentation
Loading...
Searching...
No Matches
Bond::QualifiedName Class Reference

An immutable wrapper around a constant array of C-style strings to represent the fully qualified name of a symbol in compiled Bond bytecode. More...

#include <bond/types/qualifiedname.h>

Public Member Functions

 QualifiedName ()
 Constructs an empty QualifiedName. After construction, GetElement(0) returns nullptr. More...
 
 QualifiedName (const char *const *elements)
 Constructs a QualifiedName with the given array of C-style strings. More...
 
const char * GetElement (size_t i) const
 Returns the string at the given index in the array of qualified name elements. More...
 
void PrintTo (OutputStream &stream) const
 Writes the qualified name to the provided output stream with the elements separated by a '.' character. More...
 
int Compare (const QualifiedName &other) const
 Does an element-wise lexicographic comparison of this QualifiedName with another one. More...
 
int Compare (const char *other) const
 Does an element-wise lexicographic comparison of this QualifiedName with a string. More...
 
bool operator== (const QualifiedName &other) const
 Does an element-wise lexicographic comparison of this QualifiedName with another one and returns whether they are equal. More...
 
bool operator== (const char *other) const
 Does an element-wise lexicographic comparison of this QualifiedName with a string. and returns whether they are equal. More...
 
bool operator< (const QualifiedName &other) const
 Does an element-wise lexicographic comparison of this QualifiedName with another one and returns whether this one is less. More...
 
bool operator< (const char *other) const
 Does an element-wise lexicographic comparison of this QualifiedName with a string. and returns whether this one is less. More...
 

Detailed Description

An immutable wrapper around a constant array of C-style strings to represent the fully qualified name of a symbol in compiled Bond bytecode.

The number of elements in the wrapped array is not stored; instead, the array must be terminated with a nullptr. QualifiedName does not perform any allocations; it contains a pointer to an existing array of strings whose lifetime must supersede that of the QualifiedName.

Constructor & Destructor Documentation

◆ QualifiedName() [1/2]

Bond::QualifiedName::QualifiedName ( )
inline

Constructs an empty QualifiedName. After construction, GetElement(0) returns nullptr.

◆ QualifiedName() [2/2]

Bond::QualifiedName::QualifiedName ( const char *const *  elements)
inlineexplicit

Constructs a QualifiedName with the given array of C-style strings.

Parameters
elementsPointer to an array of string which are the elements of the qualified name. The last element of the array must be nullptr.

Member Function Documentation

◆ Compare() [1/2]

int Bond::QualifiedName::Compare ( const char *  other) const

Does an element-wise lexicographic comparison of this QualifiedName with a string.

This function returns the same value that the other overload of this function would return if the string passed in were to be treated as a QualifiedName whose elements are separated by the '.' character.

Parameters
otherThe string against which this QualifiedName is compared.
Returns
A negative value, positive value or 0 if this QualifiedName is lexicographically less than greater than or equal to the other one.

◆ Compare() [2/2]

int Bond::QualifiedName::Compare ( const QualifiedName other) const

Does an element-wise lexicographic comparison of this QualifiedName with another one.

The algorithm iterates over each element of both QualifiedNames and calls strcmp() for each pair of elements. If strcmp() returns a non-zero value, that value is returned immediately. If the end of this QualifiedName is reached first, a negative value is returned. If the end of the other QualifiedName is reached first, a positive value is returned. If the end of both is reached at the same time, the value 0 is returned.

Parameters
otherThe QualifiedName against which this one is compared.
Returns
A negative value, positive value or 0 if this QualifiedName is lexicographically less than greater than or equal to the other one.

◆ GetElement()

const char * Bond::QualifiedName::GetElement ( size_t  i) const
inline

Returns the string at the given index in the array of qualified name elements.

It it safe to call this function with the values in the range [0-n] where n is the first value for which this function returns nullptr.

Parameters
iThe index of the element to be retrieved.

◆ operator<() [1/2]

bool Bond::QualifiedName::operator< ( const char *  other) const
inline

Does an element-wise lexicographic comparison of this QualifiedName with a string. and returns whether this one is less.

Parameters
otherThe string against which this QualifiedName is compared.
Returns
The result of the expression: Compare(other) < 0.

◆ operator<() [2/2]

bool Bond::QualifiedName::operator< ( const QualifiedName other) const
inline

Does an element-wise lexicographic comparison of this QualifiedName with another one and returns whether this one is less.

Parameters
otherThe QualifiedName against which this one is compared.
Returns
The result of the expression: Compare(other) < 0.

◆ operator==() [1/2]

bool Bond::QualifiedName::operator== ( const char *  other) const
inline

Does an element-wise lexicographic comparison of this QualifiedName with a string. and returns whether they are equal.

Parameters
otherThe string against which this QualifiedName is compared.
Returns
The result of the expression: Compare(other) == 0.

◆ operator==() [2/2]

bool Bond::QualifiedName::operator== ( const QualifiedName other) const
inline

Does an element-wise lexicographic comparison of this QualifiedName with another one and returns whether they are equal.

Parameters
otherThe QualifiedName against which this one is compared.
Returns
The result of the expression: Compare(other) == 0.

◆ PrintTo()

void Bond::QualifiedName::PrintTo ( OutputStream stream) const

Writes the qualified name to the provided output stream with the elements separated by a '.' character.

Parameters
streamThe stream to which the characters are written.

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