SafetyProfileStreams.cpp

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Distributed under the OpenDDS License.
00005  * See: http://www.opendds.org/license.html
00006  */
00007 #include "DCPS/DdsDcps_pch.h" //Only the _pch include should start with DCPS/
00008 
00009 #include "dds/DCPS/SafetyProfileStreams.h"
00010 
00011 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
00012 
00013 namespace OpenDDS {
00014 namespace DCPS {
00015 
00016 OPENDDS_STRING
00017 to_dds_string(::CORBA::UShort to_convert)
00018 {
00019   const char* fmt = "%hu";
00020   const int buff_size = 5 + 1; // note +1 for null terminator
00021   char buf[buff_size];
00022   ACE_OS::snprintf(&buf[0], buff_size, fmt, to_convert);
00023   return OPENDDS_STRING(buf);
00024 }
00025 
00026 OPENDDS_STRING
00027 to_dds_string(int to_convert)
00028 {
00029   const char* fmt = "%d";
00030   const int buff_size = 20 + 1; // note +1 for null terminator
00031   char buf[buff_size];
00032   ACE_OS::snprintf(&buf[0], buff_size, fmt, to_convert);
00033   return OPENDDS_STRING(buf);
00034 }
00035 
00036 OPENDDS_STRING
00037 to_dds_string(unsigned int to_convert, bool as_hex)
00038 {
00039   const char* fmt;
00040   if (as_hex) {
00041     fmt = "%02x";
00042     const int buff_size = 3; // note +1 for null terminator
00043     char buf[buff_size];
00044     ACE_OS::snprintf(&buf[0], buff_size, fmt, to_convert);
00045     return OPENDDS_STRING(buf);
00046   } else {
00047     fmt = "%u";
00048     const int buff_size = 20 + 1; // note +1 for null terminator
00049     char buf[buff_size];
00050     ACE_OS::snprintf(&buf[0], buff_size, fmt, to_convert);
00051     return OPENDDS_STRING(buf);
00052   }
00053 }
00054 
00055 OPENDDS_STRING
00056 to_dds_string(long to_convert)
00057 {
00058   const char* fmt = "%ld";
00059   const int buff_size = 20 + 1; // note +1 for null terminator
00060   char buf[buff_size];
00061   ACE_OS::snprintf(&buf[0], buff_size, fmt, to_convert);
00062   return OPENDDS_STRING(buf);
00063 }
00064 
00065 OPENDDS_STRING
00066 to_dds_string(long long to_convert)
00067 {
00068   const char* fmt = "%lld";
00069   const int buff_size = 20 + 1; // note +1 for null terminator
00070   char buf[buff_size];
00071   ACE_OS::snprintf(&buf[0], buff_size, fmt, to_convert);
00072   return OPENDDS_STRING(buf);
00073 }
00074 
00075 OPENDDS_STRING
00076 to_dds_string(unsigned long long to_convert, bool as_hex)
00077 {
00078   const char* fmt;
00079   if (as_hex) {
00080     fmt = "%0llx";
00081   } else {
00082     fmt = "%llu";
00083   }
00084   const int buff_size = 20 + 1; // note +1 for null terminator
00085   char buf[buff_size];
00086   ACE_OS::snprintf(&buf[0], buff_size, fmt, to_convert);
00087   return OPENDDS_STRING(buf);
00088 }
00089 
00090 OPENDDS_STRING
00091 to_dds_string(unsigned long to_convert, bool as_hex)
00092 {
00093   const char* fmt;
00094   if (as_hex) {
00095     fmt = "%0.8lx";
00096   } else {
00097     fmt = "%lu";
00098   }
00099   const int buff_size = 20 + 1; // note +1 for null terminator
00100   char buf[buff_size];
00101   ACE_OS::snprintf(&buf[0], buff_size, fmt, to_convert);
00102   return OPENDDS_STRING(buf);
00103 }
00104 
00105 } // namespace DCPS
00106 } // namespace OpenDDS
00107 
00108 OPENDDS_END_VERSIONED_NAMESPACE_DECL
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1