40 lines
1.4 KiB
C++
40 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include "bts_export.h"
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
#include <stdint.h>
|
|
|
|
namespace bts {
|
|
namespace utils {
|
|
|
|
typedef std::string Puid;
|
|
|
|
// because posix file lock semantics are per process (not per thread)
|
|
// this interface must be static see:
|
|
// http://www.boost.org/doc/libs/1_49_0/doc/html/interprocess/synchronization_mechanisms.html
|
|
|
|
// generate Probably Unique Ids. The ids are constructed using the
|
|
// machine's ip, the unix time (seconds since 1970) and a machine
|
|
// unique counter. id's are 20 bytes long and can contain [a-z], [A-Z]
|
|
// [0-9] and -
|
|
BTS_EXPORT std::vector<Puid> gen_puids (std::string const &scope, int n_puids);
|
|
BTS_EXPORT Puid gen_puid (std::string const &scope);
|
|
|
|
// generate machine unique ids (no guarantees of uniqueness across
|
|
// machines)
|
|
BTS_EXPORT std::vector<uint64_t> gen_ids (std::string const &scope, int n_ids);
|
|
// Similar to the above but instead of copying the ids to a vector
|
|
// this simply returns the first free id (x) and skips ahead by n_ids
|
|
// so that the next gen_id call will will be x+n_ids
|
|
BTS_EXPORT uint64_t reserve_ids (std::string const &scope, int n_ids);
|
|
// generate a single id
|
|
BTS_EXPORT uint64_t gen_id (std::string const &scope);
|
|
|
|
// convert a uint32 to a 6 byte human readeable string containing only
|
|
// alpha numerical characters.
|
|
BTS_EXPORT std::string to_base_62 (uint32_t id);
|
|
BTS_EXPORT void to_base_62 (std::vector<uint32_t> const &ids, std::vector<char> *out);
|
|
}}
|