UA Server SDK C++ Bundle  1.4.1.271
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
UaNodeId Class Reference

Wrapper class for the UA stack structure OpcUa_NodeId. More...

#include <uanodeid.h>

Public Member Functions

 UaNodeId ()
 Creates an empty NodeId with NS=0, IdentifierType=Numeric, Identifier=0. More...
 
 UaNodeId (const UaNodeId &other)
 Constructs a copy of other. More...
 
 UaNodeId (const OpcUa_NodeId &other)
 Constructs a copy of the native OpcUa_NodeId structure. More...
 
 UaNodeId (OpcUa_UInt32 id, OpcUa_UInt16 NsIdx=0)
 Creates a new NodeId with a numeric identifier. More...
 
 UaNodeId (const UaString &sId, OpcUa_UInt16 NsIdx)
 Creates a new NodeId with a string identifier. More...
 
 UaNodeId (const UaGuid &guid, OpcUa_UInt16 NsIdx)
 Creates a new NodeId with a GUID identifier. More...
 
 UaNodeId (const UaByteString &data, OpcUa_UInt16 NsIdx)
 Creates a new NodeId with a ByteString identifier. More...
 
 ~UaNodeId ()
 Cleans up everything. More...
 
OpcUa_Boolean isNull () const
 Checks whether the NodeId is Null or not. More...
 
void clear ()
 Clears the current NodeId. More...
 
void attach (const OpcUa_NodeId *pOther)
 Attaches to the native NodeId structure. More...
 
OpcUa_NodeId * detach (OpcUa_NodeId *pDst)
 Detaches the internal NodeId structure from this class. More...
 
void setNamespaceIndex (OpcUa_UInt16 NsIdx)
 Assigns a new namespace index to the NodeId. More...
 
void setNodeId (OpcUa_UInt32 id, OpcUa_UInt16 NsIdx=0)
 Sets the currently used NodeId to a numeric identifier. More...
 
void setNodeId (const UaString &sId, OpcUa_UInt16 NsIdx=1)
 Sets the currently used NodeId to a string identifier. More...
 
void setNodeId (const UaGuid &id, OpcUa_UInt16 NsIdx)
 Sets the currently used NodeId to a GUID identifier. More...
 
void setNodeId (const UaByteString &id, OpcUa_UInt16 NsIdx)
 Sets the currently used NodeId to a ByteString identyfier. More...
 
 operator const OpcUa_NodeId * () const
 Returns the OpcUa_NodeId pointer to the internal data structure. More...
 
OpcUa_NodeId * copy () const
 Creates a copy of the internal NodeId. More...
 
void copyTo (OpcUa_NodeId *pDst) const
 Creates a copy of the internal NodeId. More...
 
UaNodeIdoperator= (const UaNodeId &other)
 Assigns another NodeId to the current instance. More...
 
bool operator< (const UaNodeId &other) const
 Is lower than operator for two NodeIds. More...
 
bool operator== (const UaNodeId &other) const
 Is equal operator for two NodeIds. More...
 
bool operator!= (const UaNodeId &other) const
 Is not equal operator for two NodeIds. More...
 
bool nodeIdCompare (OpcUa_NodeId *pNodeId) const
 Compares two nodeIds and returns true if they are equal. More...
 
UaString toString () const
 Converts the identifier of the NodeId to a UaString. More...
 
UaString toFullString () const
 Converts all elements of a NodeId to a human readable string. More...
 
UaString toXmlString () const
 Converts all elements of a NodeId to a string where the syntax is defined by the OPC UA XML Schema. More...
 
OpcUa_IdentifierType identifierType () const
 Gets the identifier type of a NodeId. More...
 
OpcUa_UInt16 namespaceIndex () const
 Gets the namespace index. More...
 
OpcUa_UInt32 identifierNumeric () const
 Gets the identifier of a node as numeric value. More...
 
const OpcUa_String * identifierString () const
 Get the identifier of a node as string value. More...
 

Static Public Member Functions

static OpcUa_NodeId * clone (const OpcUa_NodeId &source)
 Creates a copy of the source NodeId. More...
 
static void cloneTo (const OpcUa_NodeId &source, OpcUa_NodeId &copy)
 Creates a copy of the source NodeId. More...
 
static bool compare (const OpcUa_NodeId &, const OpcUa_NodeId &)
 Compares two nodeIds and returns true if they are equal. More...
 
static UaNodeId fromXmlString (UaString xmlString)
 Creates a NodeId to from a string where the syntax is defined by the OPC UA XML Schema. More...
 

Friends

UABASE_EXPORT UaDataStream & operator<< (UaDataStream &, const UaNodeId &)
 Writes a NodeId to the stream. More...
 
UABASE_EXPORT UaDataStream & operator>> (UaDataStream &, UaNodeId &)
 Reads a NodeId from the stream. More...
 

Detailed Description

Wrapper class for the UA stack structure OpcUa_NodeId.

Helper class for handling the OPC UA built-in data type NodeId. It provides conversion and comparison functions and handles memory allocation and cleanup.

The NodeId data type is a structure with the following elements

Name Type Description
namespaceIndex UInt16 The index for a namespace URI used in an OPC UA server
identifierType enum The format and data type of the identifier
identifier * The identifier for a node in the address space of an OPC UA server

The namespace is a URI that identifies the naming authority responsible for assigning the identifier element of the NodeId. Naming authorities include the local server, the underlying system, standards bodies, and consortia. It is expected that most nodes will use the URI of the server or of the underlying system.

Using a namespace URI allows multiple OPC UA servers attached to the same underlying system to use the same identifier to identify the same object. This enables clients that connect to those Servers to recognise Objects that they have in common. The namespace URI is case sensitive. Namespace URIs are identified by numeric values in OPC UA services to permit more efficient transfer and processing (e.g. table lookups). The numeric values used to identify namespaces correspond to the index into the NamespaceArray. The NamespaceArray is a variable that is part of the Server object in the address space.

The URI for the OPC UA namespace is “http://opcfoundation.org/UA/”. Its corresponding index in the namespace table is 0.

The following IdentifierTypes are available:

Value Description
OpcUa_IdentifierType_Numeric Numeric value
OpcUa_IdentifierType_String String value
OpcUa_IdentifierType_Guid Globally Unique Identifier
OpcUa_IdentifierType_Opaque Namespace specific format in a ByteString

Normally the scope of NodeIds is the server in which they are defined. For certain types of NodeIds, NodeIds can uniquely identify a Node within a system, or across systems (e.g. GUIDs). System-wide and globally-unique identifiers allow clients to track Nodes, such as work orders, as they move between OPC UA servers as they progress through the system.

String identifiers are case sensitive. That is, clients shall consider them case sensitive. Servers are allowed to provide alternative NodeIds and using this mechanism severs can handle NodeIds as case insensitive.

The identifier value element is used within the context of the first two elements to identify a node. Its data type and format is defined by the identifierType.

Identifier values of IdentifierType STRING are restricted to 4096 characters. Identifier values of IdentifierType OPAQUE are restricted to 4096 bytes.

A null NodeId has special meaning. For example, many services define special behaviour if a null NodeId is passed as a parameter. A node in the address space cannot have a null NodeId.

UaNodeId uses implicit sharing to avoid needless copying and to boost the performance. Only if you modify a shared NodeId it creates a copy for that (copy-on-write). So assigning another UaNodeId or passing it as parameter is as fast as assigning a pointer.

Constructor & Destructor Documentation

UaNodeId::UaNodeId ( )

Creates an empty NodeId with NS=0, IdentifierType=Numeric, Identifier=0.

UaNodeId::UaNodeId ( const UaNodeId other)

Constructs a copy of other.

This operation takes constant time, because UaNodeId is implicitly shared. This makes returning a UaNodeId from a function very fast. If a shared instance is modified, it will be copied (copy-on-write), and that takes linear time.

Parameters
otherthe UaNodeId.
UaNodeId::UaNodeId ( const OpcUa_NodeId &  other)

Constructs a copy of the native OpcUa_NodeId structure.

This creates a copy of the native data and doesn't modify other. You can also attach the native structure, so that no copying is needed.

Parameters
otherthe OpcUa_NodeId.
See Also
attach
UaNodeId::UaNodeId ( OpcUa_UInt32  id,
OpcUa_UInt16  NsIdx = 0 
)

Creates a new NodeId with a numeric identifier.

Parameters
idThe numeric identifier.
NsIdxThe namespace index. The default value for the namespace index is 0 to allow simple assignment of OPC UA defined numeric NodeIds.
UaNodeId::UaNodeId ( const UaString sId,
OpcUa_UInt16  NsIdx 
)

Creates a new NodeId with a string identifier.

Parameters
sIdThe string identifier.
NsIdxThe namespace index.
UaNodeId::UaNodeId ( const UaGuid guid,
OpcUa_UInt16  NsIdx 
)

Creates a new NodeId with a GUID identifier.

Parameters
guidThe GUID identifier.
NsIdxThe namespace index.
UaNodeId::UaNodeId ( const UaByteString data,
OpcUa_UInt16  NsIdx 
)

Creates a new NodeId with a ByteString identifier.

Parameters
dataThe ByteString identifier.
NsIdxThe namespace index.
UaNodeId::~UaNodeId ( )

Cleans up everything.

If you want to prevent deleting the internal OpcUa_NodeId structure, you can also detach it before deleting the UaNodeId instance.

See Also
detach

Member Function Documentation

void UaNodeId::attach ( const OpcUa_NodeId *  pOther)

Attaches to the native NodeId structure.

This means UaNodeId takes ownership of the NodeId data and automatically clears it in the destructor. It does not clear the OpcUa_NodeId structure itself.

Parameters
pOtherPointer to native OpcUa_NodeId structure.
void UaNodeId::clear ( )

Clears the current NodeId.

OpcUa_NodeId * UaNodeId::clone ( const OpcUa_NodeId &  source)
static

Creates a copy of the source NodeId.

This method creates a complete new OpcUa_NodeId structure. You have to call OpcUa_NodeId_Clear to clear the contents of the NodeId and you have to free the structure itself using OpcUa_Memory_Free.

Parameters
sourceSource NodeId to clone.
Returns
a new copy of source NodeId.
void UaNodeId::cloneTo ( const OpcUa_NodeId &  source,
OpcUa_NodeId &  copy 
)
static

Creates a copy of the source NodeId.

This method copies the NodeId data into an existing OpcUa_NodeId structure. You have to call OpcUa_NodeId_Clear to clear the contents of the NodeId.

Parameters
sourceSource NodeId to clone.
copyNew copy of source NodeId.
bool UaNodeId::compare ( const OpcUa_NodeId &  nodeId1,
const OpcUa_NodeId &  nodeId2 
)
static

Compares two nodeIds and returns true if they are equal.

Parameters
nodeId1The source to compare to.
nodeId2The destination to compare to.
Returns
true if the two nodeIds are equal.
See Also
operator==
OpcUa_NodeId * UaNodeId::copy ( ) const

Creates a copy of the internal NodeId.

This method creates a completely new OpcUa_NodeId structure. You have to call OpcUa_NodeId_Clear to clear the contents of the NodeId and you have to free the structure itself using OpcUa_Memory_Free.

Returns
a copy of this NodeId.
void UaNodeId::copyTo ( OpcUa_NodeId *  pDst) const

Creates a copy of the internal NodeId.

This method copies the NodeId data into an existing OpcUa_NodeId structure. You have to call OpcUa_NodeId_Clear to clear the contents of the NodeId.

Parameters
pDstThe destination of this copy operation.
Returns
a new copy.
OpcUa_NodeId * UaNodeId::detach ( OpcUa_NodeId *  pDst)

Detaches the internal NodeId structure from this class.

This way you take over the control of releasing the NodeId data. You can only detach the data if not more than one reference exists.

Parameters
pDstPointer to OpcUa_NodeId structure that receives the NodeId data.
Returns
If the functions succeeds, pDst is returned, otherwise 0 is returned.
UaNodeId UaNodeId::fromXmlString ( UaString  xmlString)
static

Creates a NodeId to from a string where the syntax is defined by the OPC UA XML Schema.

The reverse function is

See Also
toXmlString()

The format of the string is
ns=<namespaceindex>;<identifier type>=<identifier>

with the fields

<namespace index>
The namespace index formatted as a base 10 number. If the index is 0, then the entire 'ns=0;' clause is omitted.
<identifier type>
A flag that specifies the identifier type. The flag has the following values:
Flag Identifier Type
i NUMERIC (UInteger)
s STRING (String)
g GUID (Guid)
b OPAQUE (ByteString)
<identifier>
The identifier encoded as string. The identifier is formatted using the XML data type mapping for the identifier type. Note that the identifier may contain any non-null UTF8 character including whitespace.
UaNodeId myNodeId;
UaString sNodeId("ns=2;s=MyNode");
myNodeId = UaNodeId::fromXmlString(sNodeId);
OpcUa_UInt32 UaNodeId::identifierNumeric ( ) const

Gets the identifier of a node as numeric value.

Returns
the numeric identifier as numeric value.
const OpcUa_String * UaNodeId::identifierString ( ) const

Get the identifier of a node as string value.

Returns
the string identifier as string value.
OpcUa_IdentifierType UaNodeId::identifierType ( ) const

Gets the identifier type of a NodeId.

Possible values are

  • OpcUa_IdentifierType_Numeric = 0x00
  • OpcUa_IdentifierType_String = 0x01
  • OpcUa_IdentifierType_Guid = 0x02
  • OpcUa_IdentifierType_Opaque = 0x03
Returns
the identifier type of the NodeId
OpcUa_Boolean UaNodeId::isNull ( ) const

Checks whether the NodeId is Null or not.

Returns
true if Null, false if not.
OpcUa_UInt16 UaNodeId::namespaceIndex ( ) const

Gets the namespace index.

Returns
the namespace index as numeric value.
bool UaNodeId::nodeIdCompare ( OpcUa_NodeId *  pNodeId) const

Compares two nodeIds and returns true if they are equal.

Parameters
pNodeIdThe node id of the actual node.
Returns
true if the nodeIds are equal.
See Also
operator==
UaNodeId::operator const OpcUa_NodeId * ( ) const

Returns the OpcUa_NodeId pointer to the internal data structure.

Returns
OpcUa_NodeId pointer to the internal data structure.
bool UaNodeId::operator!= ( const UaNodeId other) const

Is not equal operator for two NodeIds.

See Also
operator==
Parameters
otherThe UaString to compare.
Returns
true if other is not equal to this.
bool UaNodeId::operator< ( const UaNodeId other) const

Is lower than operator for two NodeIds.

This is used to sort NodeIds, e.g. to use it as key in map.

Parameters
otherThe UaNodeId to compare.
Returns
true if lower, false if not.
UaNodeId & UaNodeId::operator= ( const UaNodeId other)

Assigns another NodeId to the current instance.

Parameters
otherThe UaNodeId to assign.
Returns
another NodeId for the current instance.
bool UaNodeId::operator== ( const UaNodeId other) const

Is equal operator for two NodeIds.

Parameters
otherThe UaNodeId to compare.
Returns
true if the two nodeIds are equal
void UaNodeId::setNamespaceIndex ( OpcUa_UInt16  NsIdx)

Assigns a new namespace index to the NodeId.

Parameters
NsIdxThe namespace index.
void UaNodeId::setNodeId ( OpcUa_UInt32  id,
OpcUa_UInt16  NsIdx = 0 
)

Sets the currently used NodeId to a numeric identifier.

Parameters
idThe numeric identifier.
NsIdxThe namespace index.
void UaNodeId::setNodeId ( const UaString sId,
OpcUa_UInt16  NsIdx = 1 
)

Sets the currently used NodeId to a string identifier.

Parameters
sIdThe string identifier.
NsIdxThe namespace index.
void UaNodeId::setNodeId ( const UaGuid id,
OpcUa_UInt16  NsIdx 
)

Sets the currently used NodeId to a GUID identifier.

Parameters
idThe GUID identifier.
NsIdxThe namespace index.
void UaNodeId::setNodeId ( const UaByteString id,
OpcUa_UInt16  NsIdx 
)

Sets the currently used NodeId to a ByteString identyfier.

Parameters
idThe ByteString identifier.
NsIdxThe namespace index.
UaString UaNodeId::toFullString ( ) const

Converts all elements of a NodeId to a human readable string.

The format of the string is
NS<namespace index>|<identifier type>|<identifier>s

with the fields

<namespace index>
is the namespace index in the NodeId as numeric value
<identifier type>
is Numeric, String, Guid or Opaque
<identifier>
is the string representation of the Identifier field of the NodeId

There is no reverse function available for toFullString. If you want to create a string that can be used later to create a UaNodeId from this string, toXmlString() must be used.

Examples are

'NS0|Numeric|13'
namespace index 0, numeric identifier
'NS10|Numeric|5001'
namespace index 10, numeric identifier
'NS10|String|Hello:World'
namespace index 10, string identifier
'NS1|Guid|{09087e75-8e5e-499b-954f-f2a9603db28a}'
namespace index 1, GUID identifier
'NS1|Opaque|0x61626364'
namespace index 1, Opaque/ByteString identifier
Returns
the converted NodeId.
UaString UaNodeId::toString ( ) const

Converts the identifier of the NodeId to a UaString.

Only the identifier part of the NodeId is returned as UaString. The namespace index and the identifier type is not contained. Use toFullString() or toXmlString() to get all information contained in the NodeId.

There is no reverse function available for toString. If you want to create a string that can be used later to create a UaNodeId from this string, toXmlString() must be used.

Returns
the converted NodeId
UaString UaNodeId::toXmlString ( ) const

Converts all elements of a NodeId to a string where the syntax is defined by the OPC UA XML Schema.

The reverse function is

See Also
fromXmlString()

The format of the string is
ns=<namespaceindex>;<identifier type>=<identifier>

with the fields

<namespace index>
The namespace index formatted as a base 10 number. If the index is 0, then the entire 'ns=0;' clause is omitted.
<identifier type>
A flag that specifies the identifier type. The flag has the following values:
Flag Identifier Type
i NUMERIC (UInteger)
s STRING (String)
g GUID (Guid)
b OPAQUE (ByteString)
<identifier>
The identifier encoded as string. The identifier is formatted using the XML data type mapping for the identifier type. Note that the identifier may contain any non-null UTF8 character including whitespace.

Examples are

'i=13'
namespace index 0, numeric identifier
'ns=10;i=5001'
namespace index 10, numeric identifier
'ns=10;s=Hello:World'
namespace index 10, string identifier
'ns=1;g=09087e75-8e5e-499b-954f-f2a9603db28a'
namespace index 1, GUID identifier
'ns=1;b=M/RbKBsRVkePCePcx24oRA=='
namespace index 1, Opaque/ByteString identifier
Returns
the converted NodeId.

Friends And Related Function Documentation

UABASE_EXPORT UaDataStream& operator<< ( UaDataStream &  ,
const UaNodeId  
)
friend

Writes a NodeId to the stream.

UABASE_EXPORT UaDataStream& operator>> ( UaDataStream &  ,
UaNodeId  
)
friend

Reads a NodeId from the stream.


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