Panda3D
Loading...
Searching...
No Matches
windowsGuid.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file windowsGuid.cxx
10 * @author drose
11 * @date 2004-10-03
12 */
13
14#include "windowsGuid.h"
15#include "pnotify.h"
16
17#include <stdio.h> // for sscanf, sprintf
18
19using std::string;
20
21/**
22 * Parses the hex representation in the indicated string and stores it in the
23 * WindowsGuid object. Returns true if successful, false if the string
24 * representation is malformed.
25 */
27parse_string(const string &str) {
28 unsigned long data1;
29 unsigned int data2, data3;
30 unsigned int b1, b2, b3, b4, b5, b6, b7, b8;
31 int result = sscanf(str.c_str(),
32 "%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
33 &data1, &data2, &data3,
34 &b1, &b2, &b3, &b4, &b5, &b6, &b7, &b8);
35 if (result != 11) {
36 return false;
37 }
38
39 _data1 = data1;
40 _data2 = data2;
41 _data3 = data3;
42 _b1 = b1;
43 _b2 = b2;
44 _b3 = b3;
45 _b4 = b4;
46 _b5 = b5;
47 _b6 = b6;
48 _b7 = b7;
49 _b8 = b8;
50
51 return true;
52}
53
54/**
55 * Returns a hex representation of the GUID.
56 */
58format_string() const {
59 static const int buf_length = 128; // Actually, we only need 36 + 1 == 37.
60 char buffer[buf_length];
61 sprintf(buffer,
62 "%08lx-%04hx-%04hx-%02x%02x-%02x%02x%02x%02x%02x%02x",
63 _data1, _data2, _data3,
64 _b1, _b2, _b3, _b4, _b5, _b6, _b7, _b8);
65 nassertr((int)strlen(buffer) < buf_length, string());
66
67 return string(buffer);
68}
69
70/**
71 * Outputs a hex representation of the GUID.
72 */
74output(std::ostream &out) const {
75 out << format_string();
76}
std::string format_string() const
Returns a hex representation of the GUID.
bool parse_string(const std::string &str)
Parses the hex representation in the indicated string and stores it in the WindowsGuid object.
void output(std::ostream &out) const
Outputs a hex representation of the GUID.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.