Savarese Software Research Corporation
UUIDGenerator.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Savarese Software Research Corporation
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     https://www.savarese.com/software/ApacheLicense-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00022 #ifndef __SSRC_WSPR_UTILITY_UUID_GENERATOR_H
00023 #define __SSRC_WSPR_UTILITY_UUID_GENERATOR_H
00024 
00025 #include <ssrc/wispers/types.h>
00026 
00027 #include <boost/uuid/uuid.hpp>
00028 #include <boost/uuid/uuid_generators.hpp>
00029 
00030 __BEGIN_NS_SSRC_WSPR_UTILITY
00031 
00032 uuid_key_type uuid_to_uuid_key(const boost::uuids::uuid & uuid);
00033 
00034 inline uuid_key_type str_to_uuid_key(const std::string & str)
00035 // Thrown by string_generator for invalid uuid strings
00036   SSRC_DECL_THROW(std::runtime_error)
00037 {
00038   boost::uuids::string_generator uuid_str_gen;
00039   return uuid_to_uuid_key(uuid_str_gen(str));
00040 }
00041 
00042 class UUIDGenerator {
00043 
00044   mutable boost::uuids::random_generator _gen_uuid;
00045 
00046 public:
00047 
00048   UUIDGenerator() { }
00049 
00050   boost::uuids::uuid gen_uuid() const {
00051     return _gen_uuid();
00052   }
00053 
00054   uuid_key_type gen_uuid_key() const {
00055     return uuid_to_uuid_key(gen_uuid());
00056   }
00057 };
00058 
00059 __END_NS_SSRC_WSPR_UTILITY
00060 
00061 #endif

Savarese Software Research Corporation
Copyright © 2006-2011 Savarese Software Research Corporation. All rights reserved.