Line data Source code
1 : /*
2 : Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
3 :
4 : This file is part of libzmq, the ZeroMQ core engine in C++.
5 :
6 : libzmq is free software; you can redistribute it and/or modify it under
7 : the terms of the GNU Lesser General Public License (LGPL) as published
8 : by the Free Software Foundation; either version 3 of the License, or
9 : (at your option) any later version.
10 :
11 : As a special exception, the Contributors give you permission to link
12 : this library with independent modules to produce an executable,
13 : regardless of the license terms of these independent modules, and to
14 : copy and distribute the resulting executable under terms of your choice,
15 : provided that you also meet, for each linked independent module, the
16 : terms and conditions of the license of that module. An independent
17 : module is a module which is not derived from or based on this library.
18 : If you modify this library, you must extend this exception to your
19 : version of the library.
20 :
21 : libzmq is distributed in the hope that it will be useful, but WITHOUT
22 : ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
24 : License for more details.
25 :
26 : You should have received a copy of the GNU Lesser General Public License
27 : along with this program. If not, see <http://www.gnu.org/licenses/>.
28 : */
29 :
30 : #ifndef __ZMQ_BLOB_HPP_INCLUDED__
31 : #define __ZMQ_BLOB_HPP_INCLUDED__
32 :
33 : #include <string>
34 : #include <string.h>
35 :
36 : // Borrowed from id3lib_strings.h:
37 : // They seem to be doing something for MSC, but since I only have gcc, I'll just do that
38 : // Assuming this is uneccessary on GCC 4
39 : // #if (defined(__GNUC__) && (__GNUC__ >= 3) || (defined(_MSC_VER) && _MSC_VER > 1000))
40 : #if (defined(__GNUC__) && (__GNUC__ >= 3) && (__GNUC__ <= 4))
41 : namespace std
42 : {
43 : template<>
44 : struct char_traits<unsigned char>
45 : {
46 : typedef unsigned char char_type;
47 : // Unsigned as wint_t in unsigned.
48 : typedef unsigned long int_type;
49 : typedef streampos pos_type;
50 : typedef streamoff off_type;
51 : typedef mbstate_t state_type;
52 :
53 : static void
54 : assign(char_type& __c1, const char_type& __c2)
55 1843 : { __c1 = __c2; }
56 :
57 : static bool
58 : eq(const char_type& __c1, const char_type& __c2)
59 : { return __c1 == __c2; }
60 :
61 : static bool
62 : lt(const char_type& __c1, const char_type& __c2)
63 : { return __c1 < __c2; }
64 :
65 : static int
66 : compare(const char_type* __s1, const char_type* __s2, size_t __n)
67 : {
68 94056 : for (size_t __i = 0; __i < __n; ++__i)
69 91614 : if (!eq(__s1[__i], __s2[__i]))
70 9028 : return lt(__s1[__i], __s2[__i]) ? -1 : 1;
71 : return 0;
72 : }
73 :
74 : static size_t
75 : length(const char_type* __s)
76 : {
77 : const char_type* __p = __s;
78 : while (__p)
79 : ++__p;
80 : return (__p - __s);
81 : }
82 :
83 : static const char_type*
84 : find(const char_type* __s, size_t __n, const char_type& __a)
85 : {
86 : for (const char_type* __p = __s; size_t(__p - __s) < __n; ++__p)
87 : if (*__p == __a) return __p;
88 : return 0;
89 : }
90 :
91 : static char_type*
92 : move(char_type* __s1, const char_type* __s2, size_t __n)
93 : { return (char_type*) memmove(__s1, __s2, __n * sizeof(char_type)); }
94 :
95 : static char_type*
96 : copy(char_type* __s1, const char_type* __s2, size_t __n)
97 : { return (char_type*) memcpy(__s1, __s2, __n * sizeof(char_type)); }
98 :
99 : static char_type*
100 : assign(char_type* __s, size_t __n, char_type __a)
101 : {
102 72 : for (char_type* __p = __s; __p < __s + __n; ++__p)
103 72 : assign(*__p, __a);
104 : return __s;
105 : }
106 :
107 : static char_type
108 : to_char_type(const int_type& __c)
109 : { return char_type(__c); }
110 :
111 : static int_type
112 : to_int_type(const char_type& __c) { return int_type(__c); }
113 :
114 : static bool
115 : eq_int_type(const int_type& __c1, const int_type& __c2)
116 : { return __c1 == __c2; }
117 :
118 : static int_type
119 : eof() { return static_cast<int_type>(-1); }
120 :
121 : static int_type
122 : not_eof(const int_type& __c)
123 : { return eq_int_type(__c, eof()) ? int_type(0) : __c; }
124 : };
125 :
126 : } // namespace std
127 : #endif // GCC version 3
128 :
129 :
130 : namespace zmq
131 : {
132 :
133 : // Object to hold dynamically allocated opaque binary data.
134 : typedef std::basic_string <unsigned char> blob_t;
135 :
136 : }
137 :
138 : #endif
139 :
|