LiteralString.h

Go to the documentation of this file.
00001 // @(#)root/reflex:$Id: LiteralString.h 32414 2010-02-26 05:43:25Z axel $
00002 // Author: Axel Naumann, 2010
00003 
00004 // Copyright CERN, CH-1211 Geneva 23, 2004-2010, All rights reserved.
00005 //
00006 // Permission to use, copy, modify, and distribute this software for any
00007 // purpose is hereby granted without fee, provided that this copyright and
00008 // permissions notice appear in all copies and derivatives.
00009 //
00010 // This software is provided "as is" without express or implied warranty.
00011 
00012 #ifndef Reflex_LiteralString
00013 #define Reflex_LiteralString
00014 
00015 #include <set>
00016 #include <cstring>
00017 #include <string>
00018 #include "Reflex/Kernel.h"
00019 
00020 namespace Reflex {
00021    class RFLX_API LiteralString {
00022    public:
00023       LiteralString(): fLiteral(0), fAllocSize(0) {}
00024       LiteralString(const char* s);
00025       LiteralString(const LiteralString& other);
00026 
00027       ~LiteralString();
00028 
00029       static void Add(const char* s);
00030       static void Remove(const char* s);
00031 
00032       LiteralString& operator=(const LiteralString& other);
00033 
00034       const char* c_str() const { return fLiteral; }
00035       const char** key() const { return (const char**) &fLiteral; }
00036       size_t length() const { return strlen(fLiteral); }
00037       void erase(size_t i);
00038 
00039       void ToHeap();
00040       bool IsLiteral() const { return !fAllocSize; }
00041 
00042       bool operator<(const LiteralString& other) const {
00043          return strcmp(fLiteral, other.fLiteral) < 0; }
00044       bool operator>(const LiteralString& other) const {
00045          return strcmp(fLiteral, other.fLiteral) > 0; }
00046       bool operator==(const LiteralString& other) const {
00047          return strcmp(fLiteral, other.fLiteral) == 0; }
00048       bool operator!=(const LiteralString& other) const {
00049          return strcmp(fLiteral, other.fLiteral) != 0; }
00050 
00051       bool operator<(const char* other) const {
00052          return strcmp(fLiteral, other) < 0; }
00053       bool operator>(const char* other) const {
00054          return strcmp(fLiteral, other) > 0; }
00055       bool operator==(const char* other) const {
00056          return strcmp(fLiteral, other) == 0; }
00057       bool operator!=(const char* other) const {
00058          return strcmp(fLiteral, other) != 0; }
00059 
00060       bool operator<(const std::string& other) const {
00061          return other.compare(fLiteral) < 0; }
00062       bool operator>(const std::string& other) const {
00063          return other.compare(fLiteral) > 0; }
00064       bool operator==(const std::string& other) const {
00065          return other.compare(fLiteral) == 0; }
00066       bool operator!=(const std::string& other) const {
00067          return other.compare(fLiteral) != 0; }
00068       LiteralString& operator+=(const LiteralString& other);
00069       LiteralString& operator+=(const std::string& other);
00070       LiteralString& operator+=(const char* other);
00071       char operator[](size_t i) const { return fBuf[i]; }
00072 
00073       // operator const std::string&()
00074 
00075    private:
00076       void Reserve(size_t size);
00077       void StrDup(const char* s);
00078       void StrCat(const char* s);
00079 
00080       union {
00081          const char* fLiteral;
00082          char* fBuf;
00083       };
00084       size_t fAllocSize;
00085    };
00086 }
00087 
00088 #endif // Reflex_LiteralString

Generated on Tue Jul 5 14:25:52 2011 for ROOT_528-00b_version by  doxygen 1.5.1