A platform for high-performance distributed tool and library development written in C++. It can be deployed in two different cluster modes: standalone or distributed. API for v0.5.0, released on June 13, 2018.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
PDBString.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * *
3  * Copyright 2018 Rice University *
4  * *
5  * Licensed under the Apache License, Version 2.0 (the "License"); *
6  * you may not use this file except in compliance with the License. *
7  * You may obtain a copy of the License at *
8  * *
9  * http://www.apache.org/licenses/LICENSE-2.0 *
10  * *
11  * Unless required by applicable law or agreed to in writing, software *
12  * distributed under the License is distributed on an "AS IS" BASIS, *
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14  * See the License for the specific language governing permissions and *
15  * limitations under the License. *
16  * *
17  *****************************************************************************/
18 
19 #include "Handle.h"
20 #include "InterfaceFunctions.h"
21 
22 
23 #ifndef PDBSTRING_H
24 #define PDBSTRING_H
25 
26 #include <iostream>
27 #include <string>
28 
29 // the String class has a special type code value reserved for it... even though it is no
30 // longer a PDB Object. Now, whenever the PDBTemplateBase sees a type code of String_TYPECODE,
31 // it knows that it is pointing to a String, and acts accordingly. No VTable or VTable
32 // fixing is used. This has been done so as to optimize the storage for this classs,
33 // since it is so ubiquitous. Now, the total storage is a Handle (12B), plus the space
34 // for the counter associated with the target of the Handle (4B), for 16B. Previously,
35 // when this was a PDB Object, the total storage was 8B (VTable pointer) + the Handle (12B) +
36 // the two counters inside the Array class (which the String was built on; 8B) + the type
37 // code for the type inside the array (4B) + the VTble pointer for the Array (8B) + the
38 // counter associated with the target of the Handle (4B), for a total size of 44B. This
39 // means that the overhead for the non-PDB-Object string is 64% less than the old implementation.
40 
41 namespace pdb {
42 
43 class String {
44 
45  char storage[sizeof(Handle<char>)];
46  Handle<char>& data() const;
47 
48 public:
49  String();
50  ~String();
51  String& operator=(const char* toMe);
52  String& operator=(const std::string& s);
53  String& operator=(const String& s);
54  String(const char* fromMe);
55  String(const char* s, size_t n);
56  String(const std::string& s);
57  String(const String& s);
58  char& operator[](int whichOne);
59  operator std::string() const;
60  char* c_str() const;
61  size_t size() const;
62  size_t hash() const;
63  friend std::ostream& operator<<(std::ostream& stream, const String& printMe);
64  bool operator==(const String& toMe);
65  bool operator==(const char* toMe);
66  bool operator==(const std::string& toMe);
67  bool operator!=(const String& toMe);
68  bool operator!=(const std::string& toMe);
69  bool operator!=(const char* toMe);
70  bool endsWith(const std::string& suffix);
71 };
72 }
73 
74 #include "PDBString.cc"
75 
76 #endif
friend std::ostream & operator<<(std::ostream &stream, const String &printMe)
Definition: PDBString.cc:201
String & operator=(const char *toMe)
Definition: PDBString.cc:50
size_t size() const
Definition: PDBString.cc:193
Handle< char > & data() const
Definition: PDBString.cc:33
size_t hash() const
Definition: PDBString.cc:45
bool operator!=(const String &toMe)
Definition: PDBString.cc:219
bool endsWith(const std::string &suffix)
Definition: PDBString.cc:232
bool operator==(const String &toMe)
Definition: PDBString.cc:207
char & operator[](int whichOne)
Definition: PDBString.cc:176
char * c_str() const
Definition: PDBString.cc:184
char storage[sizeof(Handle< char >)]
Definition: PDBString.h:45