feisty meow concerns codebase
2.140
create_guid.cpp
Go to the documentation of this file.
1
/*****************************************************************************\
2
* *
3
* Name : create_guid *
4
* Author : Chris Koeritz *
5
* *
6
* Purpose: *
7
* *
8
* This program generates a globally unique identifier using the operating *
9
* system's support. The resulting id can be used to tag items that must be *
10
* uniquely named. *
11
* *
12
*******************************************************************************
13
* Copyright (c) 2006-$now By Author. This program is free software; you can *
14
* redistribute it and/or modify it under the terms of the GNU General Public *
15
* License as published by the Free Software Foundation; either version 2 of *
16
* the License or (at your option) any later version. This is online at: *
17
* http://www.fsf.org/copyleft/gpl.html *
18
* Please send any updates to: fred@gruntose.com *
19
\*****************************************************************************/
20
21
#include <
application/application_shell.h
>
22
#include <
application/hoople_main.h
>
23
#include <
application/windoze_helper.h
>
24
#include <
basis/astring.h
>
25
#include <
loggers/console_logger.h
>
26
#include <
mathematics/chaos.h
>
27
#include <
structures/static_memory_gremlin.h
>
28
#include <
textual/string_manipulation.h
>
29
30
#ifdef __WIN32__
31
// #define DO_GUIDS
32
//hmmm: currently disabled due to problems compiling in cygwin using this header; complains about new.h being missing.
33
#endif
34
35
#ifdef DO_GUIDS
36
#include <comdef.h>
37
#endif
38
39
using namespace
application
;
40
using namespace
basis
;
41
using namespace
loggers
;
42
using namespace
mathematics
;
43
using namespace
structures
;
44
using namespace
textual
;
45
46
#define BASE_LOG(to_print) program_wide_logger::get().log(to_print, ALWAYS_PRINT)
47
48
// this is an example GUID in the DCE format:
49
//
50
// {12345678-1234-1234-1234-123456789012}
51
//
52
// each position can be a hexadecimal digit, ranging from 0 to F.
53
// the full size is measured as 32 nibbles or 16 bytes or 128 bits.
54
55
class
create_guid :
public
application_shell
56
{
57
public
:
58
create_guid() :
application_shell
() {}
59
DEFINE_CLASS_NAME
(
"create_guid"
);
60
int
execute();
61
};
62
63
int
create_guid::execute()
64
{
65
FUNCDEF
(
"execute"
);
66
SETUP_CONSOLE_LOGGER
;
67
#ifndef DO_GUIDS
68
// this is completely bogus for the time being. it just produces a random
69
// number rather than a guid.
70
#define add_random \
71
faux_guid += astring(string_manipulation::hex_to_char \
72
(randomizer().inclusive(0, 0xf)), 1)
73
74
astring
faux_guid(
"{"
);
75
for
(
int
i = 0; i < 8; i++)
add_random
;
76
faux_guid +=
"-"
;
77
for
(
int
j = 0; j < 3; j++) {
78
for
(
int
i = 0; i < 4; i++)
add_random
;
79
faux_guid +=
"-"
;
80
}
81
for
(
int
i = 0; i < 8; i++)
add_random
;
82
faux_guid +=
"}"
;
83
BASE_LOG
(faux_guid.lower());
84
#elif defined (DO_GUIDS)
85
GUID guid;
86
CoCreateGuid(&guid);
87
const
int
BUFFER_SIZE
= 1024;
88
LPOLESTR wide_buffer =
new
WCHAR[
BUFFER_SIZE
+ 4];
89
StringFromGUID2(guid, wide_buffer,
BUFFER_SIZE
);
90
const
int
BYTE_BUFFER_SIZE =
BUFFER_SIZE
* 2 + 4;
91
char
buffer[BYTE_BUFFER_SIZE];
92
WideCharToMultiByte(CP_UTF8, 0, wide_buffer, -1, buffer, BYTE_BUFFER_SIZE,
93
NULL, NULL);
94
astring
guid_text = buffer;
95
delete
[] wide_buffer;
96
BASE_LOG
(guid_text);
97
#else
98
#error unknown operating system; no support for guids.
99
#endif
100
101
return
0;
102
}
103
104
HOOPLE_MAIN
(create_guid, )
105
106
#ifdef __BUILD_STATIC_APPLICATION__
107
// static dependencies found by buildor_gen_deps.sh:
108
#include <
application/application_shell.cpp
>
109
#include <
application/command_line.cpp
>
110
#include <
application/windoze_helper.cpp
>
111
#include <
basis/astring.cpp
>
112
#include <
basis/common_outcomes.cpp
>
113
#include <
basis/environment.cpp
>
114
#include <
basis/guards.cpp
>
115
#include <
basis/mutex.cpp
>
116
#include <
basis/utf_conversion.cpp
>
117
#include <
configuration/application_configuration.cpp
>
118
#include <
configuration/configurator.cpp
>
119
#include <
configuration/ini_configurator.cpp
>
120
#include <
configuration/ini_parser.cpp
>
121
#include <
configuration/table_configurator.cpp
>
122
#include <
configuration/variable_tokenizer.cpp
>
123
#include <
filesystem/byte_filer.cpp
>
124
#include <
filesystem/directory.cpp
>
125
#include <
filesystem/filename.cpp
>
126
#include <
loggers/combo_logger.cpp
>
127
#include <
loggers/console_logger.cpp
>
128
#include <
loggers/critical_events.cpp
>
129
#include <
loggers/file_logger.cpp
>
130
#include <
loggers/program_wide_logger.cpp
>
131
#include <
structures/bit_vector.cpp
>
132
#include <
structures/checksums.cpp
>
133
#include <
structures/object_packers.cpp
>
134
#include <
structures/static_memory_gremlin.cpp
>
135
#include <
structures/string_hasher.cpp
>
136
#include <
structures/string_table.cpp
>
137
#include <
structures/version_record.cpp
>
138
#include <
textual/byte_formatter.cpp
>
139
#include <
textual/parser_bits.cpp
>
140
#include <
textual/string_manipulation.cpp
>
141
#include <
timely/earth_time.cpp
>
142
#include <
timely/time_stamp.cpp
>
143
#endif
// __BUILD_STATIC_APPLICATION__
144
application_configuration.cpp
application_shell.cpp
application_shell.h
astring.cpp
astring.h
bit_vector.cpp
byte_filer.cpp
byte_formatter.cpp
chaos.h
checksums.cpp
application::application_shell
The application_shell is a base object for console programs.
Definition:
application_shell.h:33
basis::astring
Provides a dynamically resizable ASCII character string.
Definition:
astring.h:35
combo_logger.cpp
command_line.cpp
common_outcomes.cpp
configurator.cpp
console_logger.cpp
console_logger.h
SETUP_CONSOLE_LOGGER
#define SETUP_CONSOLE_LOGGER
< a macro that retasks the program-wide logger as a console_logger.
Definition:
console_logger.h:69
add_random
#define add_random
BASE_LOG
#define BASE_LOG(to_print)
Definition:
create_guid.cpp:46
critical_events.cpp
directory.cpp
earth_time.cpp
DEFINE_CLASS_NAME
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
Definition:
enhance_cpp.h:45
FUNCDEF
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Definition:
enhance_cpp.h:57
environment.cpp
file_logger.cpp
filename.cpp
guards.cpp
hoople_main.h
Provides macros that implement the 'main' program of an application.
HOOPLE_MAIN
#define HOOPLE_MAIN(obj_name, obj_args)
options that should work for most unix and linux apps.
Definition:
hoople_main.h:61
ini_configurator.cpp
ini_parser.cpp
mutex.cpp
application
Implements an application lock to ensure only one is running at once.
Definition:
application_shell.cpp:40
application::BUFFER_SIZE
const int BUFFER_SIZE
Definition:
redirecter.cpp:46
basis
The guards collection helps in testing preconditions and reporting errors.
Definition:
array.h:30
loggers
A logger that sends to the console screen using the standard output device.
Definition:
combo_logger.cpp:36
mathematics
An extension to floating point primitives providing approximate equality.
Definition:
averager.h:21
structures
A dynamic container class that holds any kind of object via pointers.
Definition:
amorph.h:55
textual
Definition:
byte_formatter.cpp:38
object_packers.cpp
parser_bits.cpp
program_wide_logger.cpp
static_memory_gremlin.cpp
static_memory_gremlin.h
string_hasher.cpp
string_manipulation.cpp
string_manipulation.h
string_table.cpp
table_configurator.cpp
time_stamp.cpp
utf_conversion.cpp
variable_tokenizer.cpp
version_record.cpp
windoze_helper.cpp
windoze_helper.h
Aids in achievement of platform independence.
nucleus
tools
simple_utilities
create_guid.cpp
Generated by
1.9.1