UUID.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00020 #include <coil/UUID.h>
00021 #include <iostream>
00022 #include <string.h>
00023 
00024 #ifdef COIL_OS_FREEBSD
00025 void error_code(uint32_t status)
00026 {
00027   if (status == uuid_s_ok)
00028     std::cout << "uuid_s_ok" << std::endl;
00029   else if (status == uuid_s_bad_version)
00030     std::cout << "uuid_s_bad_version" << std::endl;
00031   else if (status == uuid_s_invalid_string_uuid)
00032     std::cout << "uuid_s_invalid_string_uuid" << std::endl;
00033   else if (status == uuid_s_no_memory)
00034     std::cout << "uuid_s_no_memory" << std::endl;
00035   else
00036     std::cout << "other error" << std::endl;
00037 }
00038 
00039 void uuid_clear(uuid_t& uu)
00040 {
00041   uint32_t status;
00042   uuid_create_nil(&uu, &status);
00043 }
00044 void uuid_unparse(uuid_t& uu, char*& uuidstr)
00045 {
00046   uint32_t status;
00047   uuid_to_string(&uu, &uuidstr, &status);
00048 }
00049 void uuid_generate(uuid_t& out)
00050 {
00051   uint32_t status;
00052   uuid_create(&out, &status);
00053 }
00054 #endif
00055 
00056 namespace coil
00057 {
00058 
00059 #ifdef COIL_OS_FREEBSD
00060   UUID::UUID()
00061     : m_uuidstr(0)
00062   {
00063     ::uuid_clear(m_uuid);
00064   }
00065   UUID::UUID(const uuid_t& uuid)
00066     : m_uuid(uuid), m_uuidstr(0)
00067   {
00068   }
00069 
00070   UUID::~UUID()
00071   {
00072     free(m_uuidstr);
00073   }
00074 
00075   const char* UUID::to_string()
00076   {
00077     uuid_unparse(m_uuid, m_uuidstr);
00078     return m_uuidstr;
00079   }
00080     
00081 
00082   UUID_Generator::UUID_Generator()
00083   {
00084   }
00085 
00086   UUID_Generator::~UUID_Generator()
00087   {
00088   }
00089 
00090   void UUID_Generator::init()
00091   {
00092   }
00093 
00094   UUID* UUID_Generator::generateUUID(int n, int h)
00095   {
00096     uuid_t uuid;
00097     uuid_generate(uuid);
00098     return new UUID(uuid);
00099   }
00100 #endif
00101 
00102 #if defined(COIL_OS_LINUX) || defined(COIL_OS_DARWIN) || defined(COIL_OS_CYGWIN)
00103 
00104   UUID_Generator::UUID_Generator(){}
00105   
00106   void UUID_Generator::init(){}
00107   UUID* UUID_Generator::generateUUID(int varsion, int variant){
00108     uuid_t uuid;
00109     
00110     uuid_generate(uuid);
00111     return new UUID(&uuid);
00112   }
00113   
00114   UUID::UUID(){
00115     uuid_clear(this->_uuid);
00116   }
00117   
00118   UUID::UUID(uuid_t *uuid){
00119     strncpy((char *)this->_uuid, (char *)(*uuid), sizeof(this->_uuid));
00120   }
00121   
00122   const char* UUID::to_string(){
00123     uuid_unparse(this->_uuid, buf);
00124     return buf;
00125   }
00126 
00127 #endif
00128 };


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sun Mar 26 2017 03:37:17