Browse Source

compare and print with const pointers

Julius Pfrommer 11 years ago
parent
commit
e10cc908d3
2 changed files with 23 additions and 23 deletions
  1. 11 11
      include/ua_basictypes.h
  2. 12 12
      src/ua_basictypes.c

+ 11 - 11
include/ua_basictypes.h

@@ -219,14 +219,14 @@ UA_String;
 UA_TYPE_METHOD_PROTOTYPES (UA_String)
 UA_Int32 UA_String_copy(UA_String const * src, UA_String* dst);
 UA_Int32 UA_String_copycstring(char const * src, UA_String* dst);
-UA_Int32 UA_String_compare(UA_String *string1, UA_String *string2);
-void UA_String_printf(char* label, UA_String* string);
-void UA_String_printx(char* label, UA_String* string);
-void UA_String_printx_hex(char* label, UA_String* string);
+UA_Int32 UA_String_compare(const UA_String *string1, const UA_String *string2);
+void UA_String_printf(char* label, const UA_String* string);
+void UA_String_printx(char* label, const UA_String* string);
+void UA_String_printx_hex(char* label, const UA_String* string);
 
 /* ByteString - Part: 6, Chapter: 5.2.2.7, Page: 17 */
 UA_TYPE_METHOD_PROTOTYPES (UA_ByteString)
-UA_Int32 UA_ByteString_compare(UA_ByteString *string1, UA_ByteString *string2);
+UA_Int32 UA_ByteString_compare(const UA_ByteString *string1, const UA_ByteString *string2);
 UA_Int32 UA_ByteString_copy(UA_ByteString const * src, UA_ByteString* dst);
 UA_Int32 UA_ByteString_newMembers(UA_ByteString* p, UA_Int32 length);
 extern UA_ByteString UA_ByteString_securityPoliceNone;
@@ -246,9 +246,9 @@ typedef struct T_UA_LocalizedText
 UA_LocalizedText;
 UA_TYPE_METHOD_PROTOTYPES (UA_LocalizedText)
 UA_Int32 UA_LocalizedText_copycstring(char const * src, UA_LocalizedText* dst);
-void UA_ByteString_printf(char* label, UA_ByteString* string);
-void UA_ByteString_printx(char* label, UA_ByteString* string);
-void UA_ByteString_printx_hex(char* label, UA_ByteString* string);
+void UA_ByteString_printf(char* label, const UA_ByteString* string);
+void UA_ByteString_printx(char* label, const UA_ByteString* string);
+void UA_ByteString_printx_hex(char* label, const UA_ByteString* string);
 
 /* GuidType - Part: 6, Chapter: 5.2.2.6 Page: 17 */
 typedef struct T_UA_Guid
@@ -259,7 +259,7 @@ typedef struct T_UA_Guid
 	UA_Byte data4[8];
 } UA_Guid;
 UA_TYPE_METHOD_PROTOTYPES (UA_Guid)
-UA_Int32 UA_Guid_compare(UA_Guid *g1, UA_Guid *g2);
+UA_Int32 UA_Guid_compare(const UA_Guid *g1, const UA_Guid *g2);
 
 /* DateTime - Part: 6, Chapter: 5.2.2.5, Page: 16 */
 typedef UA_Int64 UA_DateTime; //100 nanosecond resolution
@@ -296,8 +296,8 @@ typedef struct T_UA_NodeId
     identifier;
 } UA_NodeId;
 UA_TYPE_METHOD_PROTOTYPES (UA_NodeId)
-UA_Int32 UA_NodeId_compare(UA_NodeId *n1, UA_NodeId *n2);
-void UA_NodeId_printf(char* label, UA_NodeId* node);
+UA_Int32 UA_NodeId_compare(const UA_NodeId *n1, const UA_NodeId *n2);
+void UA_NodeId_printf(char* label, const UA_NodeId* node);
 
 /** XmlElement - Part: 6, Chapter: 5.2.2.8, Page: 17 */
 typedef struct T_UA_XmlElement

+ 12 - 12
src/ua_basictypes.c

@@ -465,7 +465,7 @@ UA_Int32 UA_String_init(UA_String* p){
 }
 
 
-UA_Int32 UA_String_compare(UA_String* string1, UA_String* string2) {
+UA_Int32 UA_String_compare(const UA_String* string1, const UA_String* string2) {
 	UA_Int32 retval;
 
 	if (string1->length == 0 && string2->length == 0) {
@@ -481,11 +481,11 @@ UA_Int32 UA_String_compare(UA_String* string1, UA_String* string2) {
 	}
 	return retval;
 }
-void UA_String_printf(char* label, UA_String* string) {
+void UA_String_printf(char* label, const UA_String* string) {
 	printf("%s {Length=%d, Data=%.*s}\n", label, string->length,
 			string->length, (char*)string->data);
 }
-void UA_String_printx(char* label, UA_String* string) {
+void UA_String_printx(char* label, const UA_String* string) {
 	int i;
 	if (string == UA_NULL) { printf("%s {NULL}\n", label); return; }
 	printf("%s {Length=%d, Data=", label, string->length);
@@ -499,7 +499,7 @@ void UA_String_printx(char* label, UA_String* string) {
 	}
 	printf("}}\n");
 }
-void UA_String_printx_hex(char* label, UA_String* string) {
+void UA_String_printx_hex(char* label, const UA_String* string) {
 	int i;
 	printf("%s {Length=%d, Data=", label, string->length);
 	if (string->length > 0) {
@@ -516,16 +516,16 @@ void UA_String_printx_hex(char* label, UA_String* string) {
 // TODO: should we really handle UA_String and UA_ByteString the same way?
 UA_TYPE_METHOD_PROTOTYPES_AS(UA_ByteString, UA_String)
 UA_TYPE_METHOD_NEW_DEFAULT(UA_ByteString)
-UA_Int32 UA_ByteString_compare(UA_ByteString *string1, UA_ByteString *string2) {
-	return UA_String_compare((UA_String*) string1, (UA_String*) string2);
+UA_Int32 UA_ByteString_compare(const UA_ByteString *string1, const UA_ByteString *string2) {
+	return UA_String_compare((const UA_String*) string1, (const UA_String*) string2);
 }
-void UA_ByteString_printf(char* label, UA_ByteString* string) {
+void UA_ByteString_printf(char* label, const UA_ByteString* string) {
 	UA_String_printf(label, (UA_String*) string);
 }
-void UA_ByteString_printx(char* label, UA_ByteString* string) {
+void UA_ByteString_printx(char* label, const UA_ByteString* string) {
 	UA_String_printx(label, (UA_String*) string);
 }
-void UA_ByteString_printx_hex(char* label, UA_ByteString* string) {
+void UA_ByteString_printx_hex(char* label, const UA_ByteString* string) {
 	UA_String_printx_hex(label, (UA_String*) string);
 }
 
@@ -579,7 +579,7 @@ UA_Int32 UA_Guid_decodeBinary(UA_ByteString const * src, UA_Int32* pos, UA_Guid
 }
 UA_TYPE_METHOD_DELETE_STRUCT(UA_Guid)
 UA_Int32 UA_Guid_deleteMembers(UA_Guid* p) { return UA_SUCCESS; }
-UA_Int32 UA_Guid_compare(UA_Guid *g1, UA_Guid *g2) {
+UA_Int32 UA_Guid_compare(const UA_Guid *g1, const UA_Guid *g2) {
 	return memcmp(g1, g2, sizeof(UA_Guid));
 }
 UA_Int32 UA_Guid_init(UA_Guid* p){
@@ -788,7 +788,7 @@ UA_Int32 UA_NodeId_deleteMembers(UA_NodeId* p) {
 	return retval;
 }
 
-void UA_NodeId_printf(char* label, UA_NodeId* node) {
+void UA_NodeId_printf(char* label, const UA_NodeId* node) {
 	int l;
 
 	printf("%s {encodingByte=%d, namespace=%d,", label,
@@ -828,7 +828,7 @@ void UA_NodeId_printf(char* label, UA_NodeId* node) {
 	printf("}\n");
 }
 
-UA_Int32 UA_NodeId_compare(UA_NodeId *n1, UA_NodeId *n2) {
+UA_Int32 UA_NodeId_compare(const UA_NodeId *n1, const UA_NodeId *n2) {
 	if (n1->encodingByte != n2->encodingByte || n1->namespace != n2->namespace)
 		return FALSE;