1/*
2 * PROGRAM: Client/Server Common Code
3 * MODULE: MetaName.h
4 * DESCRIPTION: metadata name holder
5 *
6 * The contents of this file are subject to the Initial
7 * Developer's Public License Version 1.0 (the "License");
8 * you may not use this file except in compliance with the
9 * License. You may obtain a copy of the License at
10 * http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
11 *
12 * Software distributed under the License is distributed AS IS,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied.
14 * See the License for the specific language governing rights
15 * and limitations under the License.
16 *
17 * The Original Code was created by Alexander Peshkov
18 * for the Firebird Open Source RDBMS project.
19 *
20 * Copyright (c) 2005 Alexander Peshkov <peshkoff@mail.ru>
21 * and all contributors signed below.
22 *
23 * All Rights Reserved.
24 * Contributor(s): ______________________________________.
25 *
26 *
27 */
28
29#ifndef METANAME_H
30#define METANAME_H
31
32#include "../common/classes/fb_string.h"
33#include "../common/classes/fb_pair.h"
34#include "../jrd/constants.h"
35
36#ifdef SFIO
37#include <stdio.h>
38#endif
39
40namespace Firebird {
41
42class MetaName
43{
44private:
45 char data[MAX_SQL_IDENTIFIER_SIZE];
46 unsigned int count;
47
48 void init()
49 {
50 memset(data, 0, MAX_SQL_IDENTIFIER_SIZE);
51 }
52 MetaName& set(const MetaName& m)
53 {
54 memcpy(data, m.data, MAX_SQL_IDENTIFIER_SIZE);
55 count = m.count;
56 return *this;
57 }
58
59public:
60 MetaName() { init(); count = 0; }
61 MetaName(const char* s) { assign(s); }
62 MetaName(const char* s, size_t l) { assign(s, l); }
63 MetaName(const MetaName& m) { set(m); }
64 MetaName(const AbstractString& s) { assign(s.c_str(), s.length()); }
65 explicit MetaName(MemoryPool&) { init(); count = 0; }
66 MetaName(MemoryPool&, const char* s) { assign(s); }
67 MetaName(MemoryPool&, const char* s, size_t l) { assign(s, l); }
68 MetaName(MemoryPool&, const MetaName& m) { set(m); }
69 MetaName(MemoryPool&, const AbstractString& s) { assign(s.c_str(), s.length()); }
70
71 MetaName& assign(const char* s, size_t l);
72 MetaName& assign(const char* s) { return assign(s, s ? strlen(s) : 0); }
73 MetaName& operator=(const char* s) { return assign(s); }
74 MetaName& operator=(const AbstractString& s) { return assign(s.c_str(), s.length()); }
75 MetaName& operator=(const MetaName& m) { return set(m); }
76 char* getBuffer(const size_t l);
77
78 size_t length() const { return count; }
79 const char* c_str() const { return data; }
80 const char* nullStr() const { return (count == 0 ? NULL : data); }
81 bool isEmpty() const { return count == 0; }
82 bool hasData() const { return count != 0; }
83
84 const char* begin() const { return data; }
85 const char* end() const { return data + count; }
86
87 int compare(const char* s, size_t l) const;
88 int compare(const char* s) const { return compare(s, s ? strlen(s) : 0); }
89 int compare(const AbstractString& s) const { return compare(s.c_str(), s.length()); }
90 int compare(const MetaName& m) const { return memcmp(data, m.data, MAX_SQL_IDENTIFIER_SIZE); }
91
92 bool operator==(const char* s) const { return compare(s) == 0; }
93 bool operator!=(const char* s) const { return compare(s) != 0; }
94 bool operator==(const AbstractString& s) const { return compare(s) == 0; }
95 bool operator!=(const AbstractString& s) const { return compare(s) != 0; }
96 bool operator==(const MetaName& m) const { return compare(m) == 0; }
97 bool operator!=(const MetaName& m) const { return compare(m) != 0; }
98 bool operator<=(const MetaName& m) const { return compare(m) <= 0; }
99 bool operator>=(const MetaName& m) const { return compare(m) >= 0; }
100 bool operator< (const MetaName& m) const { return compare(m) < 0; }
101 bool operator> (const MetaName& m) const { return compare(m) > 0; }
102
103 void upper7();
104 void lower7();
105 void printf(const char*, ...);
106 size_t copyTo(char* to, size_t toSize) const;
107
108protected:
109 static void adjustLength(const char* const s, size_t& l);
110};
111
112typedef Pair<Full<MetaName, MetaName> > MetaNamePair;
113
114} // namespace Firebird
115
116#endif // METANAME_H
117