00001 /****************************************************************************** 00002 * Copyright (C) 2013-2014 by Alexander Rykovanov * 00003 * rykovanov.as@gmail.com * 00004 * * 00005 * This library is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU Lesser General Public License as * 00007 * published by the Free Software Foundation; version 3 of the License. * 00008 * * 00009 * This library is distributed in the hope that it will be useful, * 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00012 * GNU Lesser General Public License for more details. * 00013 * * 00014 * You should have received a copy of the GNU Lesser General Public License * 00015 * along with this library; if not, write to the * 00016 * Free Software Foundation, Inc., * 00017 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00018 ******************************************************************************/ 00019 00020 #pragma once 00021 00022 #include <opc/ua/protocol/types.h> 00023 #include <opc/ua/protocol/view.h> 00024 #include <ostream> 00025 #include <limits> 00026 00027 namespace OpcUa 00028 { 00029 00030 std::string ToString(const NodeId& id); 00031 std::string ToString(const Guid& guid); 00032 std::string ToString(const DateTime& t); 00033 std::string ToString(const BrowseDirection& direction); 00034 std::string ToString(const StatusCode& code); 00035 std::string ToString(const LocalizedText& code); 00036 00037 Guid ToGuid(const std::string& str); 00038 NodeId ToNodeId(const std::string& str, uint32_t defaultNamespace=0); 00039 QualifiedName ToQualifiedName(const std::string& str, uint32_t default_ns=0); 00040 00041 inline std::ostream& operator<<(std::ostream& os, const OpcUa::NodeId& nodeid) 00042 { 00043 os << OpcUa::ToString(nodeid).c_str(); 00044 return os; 00045 } 00046 00047 inline std::ostream& operator<<(std::ostream& os, const OpcUa::LocalizedText& t) 00048 { 00049 os << OpcUa::ToString(t).c_str(); 00050 return os; 00051 } 00052 00053 inline std::ostream& operator<<(std::ostream& os, const OpcUa::QualifiedName& qn) 00054 { 00055 os << "QualifiedName(" << qn.NamespaceIndex << ":" << qn.Name.c_str() << ")"; 00056 return os; 00057 } 00058 00059 inline std::ostream& operator<<(std::ostream& os, const OpcUa::BrowseDirection& direction) 00060 { 00061 os << OpcUa::ToString(direction); 00062 return os; 00063 } 00064 00065 inline std::ostream& operator<<(std::ostream& os, const OpcUa::Guid& guid) 00066 { 00067 os << "{" << ToString(guid) << "}"; 00068 return os; 00069 } 00070 00071 inline std::ostream& operator<<(std::ostream& os, const OpcUa::ByteString& buf) 00072 { 00073 const std::size_t size = buf.Data.size(); 00074 unsigned pos = 0; 00075 os << "Data size: " << size << std::endl; 00076 while (pos < size) 00077 { 00078 if (pos) 00079 printf((pos % 16 == 0) ? "\n" : " "); 00080 00081 const char letter = buf.Data[pos]; 00082 printf("%02x", (unsigned)letter & 0x000000FF); 00083 00084 if (letter > ' ') 00085 os << "(" << letter << ")"; 00086 else 00087 os << " "; 00088 00089 ++pos; 00090 } 00091 00092 os << std::endl; 00093 return os; 00094 } 00095 } 00096