[llvm-commits] CVS: llvm/include/llvm/ADT/SmallString.h SmallVector.h
Chris Lattner
sabre at nondot.org
Sun Oct 29 19:39:34 PST 2006
Changes in directory llvm/include/llvm/ADT:
SmallString.h added (r1.1)
SmallVector.h updated: 1.20 -> 1.21
---
Log message:
Add SmallString a (currently) minimal class that adapts SmallVector to be
more string-like.
---
Diffs of the changes: (+58 -0)
SmallString.h | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
SmallVector.h | 1 +
2 files changed, 58 insertions(+)
Index: llvm/include/llvm/ADT/SmallString.h
diff -c /dev/null llvm/include/llvm/ADT/SmallString.h:1.1
*** /dev/null Sun Oct 29 21:39:30 2006
--- llvm/include/llvm/ADT/SmallString.h Sun Oct 29 21:39:20 2006
***************
*** 0 ****
--- 1,57 ----
+ //===- llvm/ADT/SmallString.h - 'Normally small' strings --------*- C++ -*-===//
+ //
+ // The LLVM Compiler Infrastructure
+ //
+ // This file was developed by Chris Lattner and is distributed under
+ // the University of Illinois Open Source License. See LICENSE.TXT for details.
+ //
+ //===----------------------------------------------------------------------===//
+ //
+ // This file defines the SmallString class.
+ //
+ //===----------------------------------------------------------------------===//
+
+ #ifndef LLVM_ADT_SMALLSTRING_H
+ #define LLVM_ADT_SMALLSTRING_H
+
+ #include "llvm/ADT/SmallVector.h"
+ #include <cstring>
+
+ namespace llvm {
+
+ /// SmallString - A SmallString is just a SmallVector with methods and accessors
+ /// that make it work better as a string (e.g. operator+ etc).
+ template<unsigned InternalLen>
+ class SmallString : public SmallVector<char, InternalLen> {
+ public:
+ // Default ctor - Initialize to empty.
+ SmallString() {}
+
+ // Initialize with a range.
+ template<typename ItTy>
+ SmallString(ItTy S, ItTy E) : SmallVector<char, InternalLen>(S, E) {}
+
+ // Copy ctor.
+ SmallString(const SmallString &RHS) : SmallVector<char, InternalLen>(RHS) {}
+
+
+ // Extra methods.
+ const char *c_str() const {
+ SmallString *This = const_cast<SmallString*>(this);
+ // Ensure that there is a \0 at the end of the string.
+ This->reserve(this->size()+1);
+ This->End[0] = 0;
+ return this->begin();
+ }
+
+ // Extra operators.
+ SmallString &operator+=(const char *RHS) {
+ this->append(RHS, RHS+strlen(RHS));
+ return *this;
+ }
+ };
+
+
+ }
+
+ #endif
Index: llvm/include/llvm/ADT/SmallVector.h
diff -u llvm/include/llvm/ADT/SmallVector.h:1.20 llvm/include/llvm/ADT/SmallVector.h:1.21
--- llvm/include/llvm/ADT/SmallVector.h:1.20 Mon Oct 9 14:05:44 2006
+++ llvm/include/llvm/ADT/SmallVector.h Sun Oct 29 21:39:20 2006
@@ -25,6 +25,7 @@
/// template parameter.
template <typename T>
class SmallVectorImpl {
+protected:
T *Begin, *End, *Capacity;
// Allocate raw space for N elements of type T. If T has a ctor or dtor, we
More information about the llvm-commits
mailing list