diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 (patch) | |
tree | 67208f7c145782a7e90b123b982ca78d88cc2c87 /akregator/src/mk4storage/metakit/include | |
download | tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.tar.gz tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'akregator/src/mk4storage/metakit/include')
-rw-r--r-- | akregator/src/mk4storage/metakit/include/mk4.h | 1078 | ||||
-rw-r--r-- | akregator/src/mk4storage/metakit/include/mk4.inl | 874 | ||||
-rw-r--r-- | akregator/src/mk4storage/metakit/include/mk4dll.h | 112 | ||||
-rw-r--r-- | akregator/src/mk4storage/metakit/include/mk4io.h | 66 | ||||
-rw-r--r-- | akregator/src/mk4storage/metakit/include/mk4str.h | 181 | ||||
-rw-r--r-- | akregator/src/mk4storage/metakit/include/mk4str.inl | 299 |
6 files changed, 2610 insertions, 0 deletions
diff --git a/akregator/src/mk4storage/metakit/include/mk4.h b/akregator/src/mk4storage/metakit/include/mk4.h new file mode 100644 index 000000000..33016dba0 --- /dev/null +++ b/akregator/src/mk4storage/metakit/include/mk4.h @@ -0,0 +1,1078 @@ +// mk4.h -- +// $Id$ +// This is part of Metakit, see http://www.equi4.com/metakit/ + +/** @file + * Main Metakit library include file + */ + +#ifndef __MK4_H__ +#define __MK4_H__ + +//--------------------------------------------------------------------------- +// +// TITLE +// +// The Metakit Library, by Jean-Claude Wippler, Equi4 Software, NL. +// +// DESCRIPTION +// +// Structured data storage with commit / rollback and on-demand loading. +// +// ACKNOWLEDGEMENTS +// +// To Liesbeth and Myra, for making this possible. +// +//--------------------------------------------------------------------------- +// +// NAMING CONVENTIONS PREFIX REMARKS +// +// Compile time options q4_ Always defined as 1 or 0, capitalized +// Preprocessor defines d4_ Use with "#ifdef" or "#if defined()" +// Classes c4_ Classes, listed at start of headers +// Typedefs t4_ Type definitions, if outside classes +// Global functions f4_ Internal, these are rarely defined +// +// Member functions Start in uppercase +// Instance variables _ And start in lowercase +// Static members _ And start in uppercase +// +// Local variable names Start in lowercase +// Formal parameter names Start lowercase, end with underscore +// +//--------------------------------------------------------------------------- + + /// Current release = 100 * major + 10 * minor + maintenance +#define d4_MetakitLibraryVersion 249 // 2.4.9.3 release, Jan 26, 2004 +#define d4_MetaKitLibraryVersion d4_MetakitLibraryVersion // compat, yuck + +//--------------------------------------------------------------------------- +// Declarations in this file + + class c4_View; // a view on underlying data + class c4_Cursor; // an index into a view + class c4_RowRef; // a reference to a row + class c4_Row; // one row in a view + class c4_Bytes; // used to pass around generic data + class c4_Storage; // manages view persistence + class c4_CustomViewer; // used for customizable views + class c4_Stream; // abstract stream class + class c4_Strategy; // system and file interface + + class c4_Property; // for access inside rows + class c4_IntProp; + class c4_LongProp; + class c4_FloatProp; + class c4_DoubleProp; + class c4_StringProp; + class c4_BytesProp; + class c4_ViewProp; + + // Everything below is part of the implementation, not for public use + + class c4_Sequence; // a collection of rows + + class c4_Reference; // refers to the actual data values + class c4_IntRef; + class c4_LongRef; + class c4_FloatRef; + class c4_DoubleRef; + class c4_BytesRef; + class c4_StringRef; + class c4_ViewRef; + + class c4_Dependencies; // not defined here + class c4_Handler; // not defined here + class c4_Notifier; // not defined here + class c4_Persist; // not defined here + +//--------------------------------------------------------------------------- + + // determine whether we need to include "mk4dll.h" to link as DLL +#if defined (MKDLL_EXPORTS) && !defined (q4_KITDLL) +#define q4_KITDLL 1 +#endif + + // omit floats and doubles in small model 16-bit Intel builds +#if defined (_DOS) && defined (_M_I86SM) && !defined (q4_TINY) +#define q4_TINY 1 +#endif + + // and here's the other end of the scale... +#if !defined (_WIN32) && !defined (q4_LONG64) +#if (defined (_PA_RISC2_0) && defined(__hpux)) || defined (__powerpc64__) || defined(__sparcv9) || \ + defined (__x86_64__) || defined (__s390x__) || defined (__alpha) || defined (__mips64) || \ + (defined (__ia64) && (!defined (__HP_aCC) || defined(__LP64__))) +#define q4_LONG64 1 +#endif +#endif + + // default to inlining for maximum performance +#if !defined (q4_INLINE) +#define q4_INLINE 1 +#endif + +//--------------------------------------------------------------------------- + + // Borland C++ and C++ Builder +#if defined (__BORLANDC__) + // by default, if runtime is linked as a DLL, then so is Metakit +#if defined (_RTLDLL) && !defined (q4_KITDLL) +#define q4_KITDLL 1 +#endif + + // Borland 5.0 supports the bool datatype +#if __BORLANDC__ >= 0x500 +#define q4_BOOL 1 +#endif +#endif // __BORLANDC__ + + // IRIX supports the bool datatype + // define before gcc to cover both the gcc and MipsPRO compiler +#if defined (sgi) +#define q4_BOOL 1 +#undef bool +#undef true +#undef false +#endif + + // GNU gcc/egcs +#if defined (__GNUC__) +#ifndef q4_BOOL +#define q4_BOOL 1 +#endif +#ifndef HAVE_LONG_LONG +#define HAVE_LONG_LONG 1 +#endif +#endif + + // HP aCC +#if defined (__HP_aCC) +#ifndef HAVE_LONG_LONG +#define HAVE_LONG_LONG 1 +#endif +#endif + + // Metrowerks CodeWarrior +#if defined (__MWERKS__) +#if __option(bool) +#define q4_BOOL 1 // bool datatype is optionally supported + // undef, these conflict with c4_Storage::c4_Storage overloading +#undef bool +#undef true +#undef false +#endif +#endif + + // Microsoft Visual C++ +#if defined (_MSC_VER) + // MSVC 5.0 supports the bool datatype, MSVC 4.x has no namespaces +#if _MSC_VER >= 1100 +#define q4_BOOL 1 +#define LONG_LONG __int64 +#else +#define q4_NO_NS 1 +#endif + + // a kludge to avoid having to use ugly DLL exprt defs in this header +#pragma warning(disable: 4273) // inconsistent dll linkage +#endif // _MSC_VER + +//--------------------------------------------------------------------------- +// Other definitions needed by the public Metakit library header files + +#if !q4_BOOL && !q4_STD // define a bool datatype +#define false 0 +#define true 1 +#define bool int +#endif + +#if q4_KITDLL // add declaration specifiers +#include "mk4dll.h" +#endif + +#if q4_INLINE // enable inline expansion +#define d4_inline inline +#else +#define d4_inline +#endif + +typedef unsigned char t4_byte; // create typedefs for t4_byte, etc. + +#if q4_LONG64 +typedef int t4_i32; // if longs are 64b, then int must be 32b +#else +typedef long t4_i32; // if longs aren't 64b, then they are 32b +#endif + +#if q4_LONG64 // choose a way to represent 64b integers +typedef long t4_i64; +#elif defined (LONG_LONG) +typedef LONG_LONG t4_i64; +#elif HAVE_LONG_LONG +typedef long long t4_i64; +#else +struct t4_i64 { long l1; long l2; }; +bool operator== (const t4_i64 a_, const t4_i64 b_); +bool operator< (const t4_i64 a_, const t4_i64 b_); +#endif + +//--------------------------------------------------------------------------- + +class c4_View +{ +protected: + c4_Sequence* _seq; + +public: +/* Construction / destruction / assignment */ + c4_View (c4_Sequence* =0); + c4_View (c4_CustomViewer*); + c4_View (c4_Stream*); + c4_View (const c4_Property& property_); + c4_View (const c4_View&); + ~c4_View (); + + c4_View& operator= (const c4_View&); + c4_Persist* Persist() const; // added 16-11-2000 to simplify c4_Storage + +/* Getting / setting the number of rows */ + int GetSize() const; + void SetSize(int, int =-1); + + void RemoveAll(); + +/*: Getting / setting individual elements */ + c4_RowRef GetAt(int) const; + c4_RowRef operator[] (int) const; + + void SetAt(int, const c4_RowRef&); + c4_RowRef ElementAt(int); + + bool GetItem(int, int, c4_Bytes&) const; + void SetItem(int, int, const c4_Bytes&) const; + +/* These can increase the number of rows */ + void SetAtGrow(int, const c4_RowRef&); + int Add(const c4_RowRef&); + +/* Insertion / deletion of rows */ + void InsertAt(int, const c4_RowRef&, int =1); + void RemoveAt(int, int =1); + void InsertAt(int, const c4_View&); + + bool IsCompatibleWith(const c4_View&) const; + void RelocateRows(int, int, c4_View&, int); + +/* Dealing with the properties of this view */ + int NumProperties() const; + const c4_Property& NthProperty(int) const; + int FindProperty(int); + int FindPropIndexByName(const char*) const; + c4_View Duplicate() const; + c4_View Clone() const; + int AddProperty(const c4_Property&); + c4_View operator, (const c4_Property&) const; + + const char* Description() const; + +/* Derived views */ + c4_View Sort() const; + c4_View SortOn(const c4_View&) const; + c4_View SortOnReverse(const c4_View&, const c4_View&) const; + + c4_View Select(const c4_RowRef&) const; + c4_View SelectRange(const c4_RowRef&, const c4_RowRef&) const; + + c4_View Project(const c4_View&) const; + c4_View ProjectWithout(const c4_View&) const; + + int GetIndexOf(const c4_RowRef&) const; + int RestrictSearch(const c4_RowRef&, int&, int&); + +/* Custom views */ + c4_View Slice(int, int =-1, int =1) const; + c4_View Product(const c4_View&) const; + c4_View RemapWith(const c4_View&) const; + c4_View Pair(const c4_View&) const; + c4_View Concat(const c4_View&) const; + c4_View Rename(const c4_Property&, const c4_Property&) const; + + c4_View GroupBy(const c4_View&, const c4_ViewProp&) const; + c4_View Counts(const c4_View&, const c4_IntProp&) const; + c4_View Unique() const; + + c4_View Union(const c4_View&) const; + c4_View Intersect(const c4_View&) const; + c4_View Different(const c4_View&) const; + c4_View Minus(const c4_View&) const; + + c4_View JoinProp(const c4_ViewProp&, bool =false) const; + c4_View Join(const c4_View&, const c4_View&, bool =false) const; + + c4_View ReadOnly() const; + c4_View Hash(const c4_View&, int =1) const; + c4_View Blocked() const; + c4_View Ordered(int =1) const; + c4_View Indexed(const c4_View&, const c4_View&, bool =false) const; + +/* Searching */ + int Find(const c4_RowRef&, int =0) const; + int Search(const c4_RowRef&) const; + int Locate(const c4_RowRef&, int* =0) const; + +/* Comparing view contents */ + int Compare(const c4_View&) const; + + friend bool operator== (const c4_View&, const c4_View&); + friend bool operator!= (const c4_View&, const c4_View&); + friend bool operator< (const c4_View&, const c4_View&); + friend bool operator> (const c4_View&, const c4_View&); + friend bool operator<= (const c4_View&, const c4_View&); + friend bool operator>= (const c4_View&, const c4_View&); + +protected: + void _IncSeqRef(); + void _DecSeqRef(); + + /// View references are allowed to peek inside view objects + friend class c4_ViewRef; + + // DROPPED: Structure() const; + // DROPPED: Description(const c4_View& view_); +}; + +//--------------------------------------------------------------------------- + +#if defined(os_aix) && defined(compiler_ibmcxx) && (compiler_ibmcxx > 500) + bool operator== (const c4_RowRef& a_, const c4_RowRef& b_); + bool operator!= (const c4_RowRef& a_, const c4_RowRef& b_); + bool operator<= (const c4_RowRef& a_, const c4_RowRef& b_); + bool operator>= (const c4_RowRef& a_, const c4_RowRef& b_); + bool operator> (const c4_RowRef& a_, const c4_RowRef& b_); + bool operator< (const c4_RowRef& a_, const c4_RowRef& b_); +#endif + +class c4_Cursor +{ +public: + /// Pointer to the sequence + c4_Sequence* _seq; + /// Current index into the sequence + int _index; + +/* Construction / destruction / dereferencing */ + /// Construct a new cursor + c4_Cursor (c4_Sequence&, int); + + /// Dereference this cursor to "almost" a row + c4_RowRef operator* () const; + + /// This is the same as *(cursor + offset) + c4_RowRef operator[] (int) const; + +/* Stepping the iterator forwards / backwards */ + /// Pre-increment the cursor + c4_Cursor& operator++ (); + /// Post-increment the cursor + c4_Cursor operator++ (int); + /// Pre-decrement the cursor + c4_Cursor& operator-- (); + /// Post-decrement the cursor + c4_Cursor operator-- (int); + + /// Advance by a given offset + c4_Cursor& operator+= (int); + /// Back up by a given offset + c4_Cursor& operator-= (int); + + /// Subtract a specified offset + c4_Cursor operator- (int) const; + /// Return the distance between two cursors + int operator- (c4_Cursor) const; + + /// Add specified offset + friend c4_Cursor operator+ (c4_Cursor, int); + /// Add specified offset to cursor + friend c4_Cursor operator+ (int, c4_Cursor); + +/* Comparing row positions */ + /// Return true if both cursors are equal + friend bool operator== (c4_Cursor, c4_Cursor); + /// Return true if both cursors are not equal + friend bool operator!= (c4_Cursor, c4_Cursor); + /// True if first cursor is less than second cursor + friend bool operator< (c4_Cursor, c4_Cursor); + /// True if first cursor is greater than second cursor + friend bool operator> (c4_Cursor, c4_Cursor); + /// True if first cursor is less or equal to second cursor + friend bool operator<= (c4_Cursor, c4_Cursor); + /// True if first cursor is greater or equal to second cursor + friend bool operator>= (c4_Cursor, c4_Cursor); + +/* Comparing row contents */ + /// Return true if the contents of both rows are equal + friend bool operator== (const c4_RowRef&, const c4_RowRef&); + /// Return true if the contents of both rows are not equal + friend bool operator!= (const c4_RowRef&, const c4_RowRef&); + /// True if first row is less than second row + friend bool operator< (const c4_RowRef&, const c4_RowRef&); + /// True if first row is greater than second row + friend bool operator> (const c4_RowRef&, const c4_RowRef&); + /// True if first row is less or equal to second row + friend bool operator<= (const c4_RowRef&, const c4_RowRef&); + /// True if first row is greater or equal to second row + friend bool operator>= (const c4_RowRef&, const c4_RowRef&); +}; + +//--------------------------------------------------------------------------- + +class c4_RowRef +{ + /// A row reference is a cursor in disguise + c4_Cursor _cursor; + +public: +/* General operations */ + /// Assign the value of another row to this one + c4_RowRef operator= (const c4_RowRef&); + /// Return the cursor associated to this row + c4_Cursor operator& () const; + /// Return the underlying container view + c4_View Container() const; + +protected: + /// Constructor, not for general use + c4_RowRef (c4_Cursor); + + friend class c4_Cursor; + friend class c4_Row; +}; + +//--------------------------------------------------------------------------- +/// An entry in a collection with copy semantics. +// +// Rows can exist by themselves and as contents of views. Row assignment +// implies that a copy of the contents of the originating row is made. +// +// A row is implemented as an unattached view with exactly one element. + +class c4_Row : public c4_RowRef +{ +public: + /// Construct a row with no properties + c4_Row (); + /// Construct a row from another one + c4_Row (const c4_Row&); + /// Construct a row copy from a row reference + c4_Row (const c4_RowRef&); + /// Destructor + ~c4_Row (); + + /// Assign a copy of another row to this one + c4_Row& operator= (const c4_Row&); + /// Copy another row to this one + c4_Row& operator= (const c4_RowRef&); + + /// Add all properties and values into this row + void ConcatRow(const c4_RowRef&); + /// Return a new row which is the concatenation of two others + friend c4_Row operator+ (const c4_RowRef&, const c4_RowRef&); + +private: + static c4_Cursor Allocate(); + static void Release(c4_Cursor); +}; + +//--------------------------------------------------------------------------- + +class c4_Bytes +{ + union { + t4_byte _buffer [16]; + double _aligner; // on a Sparc, the int below wasn't enough... + }; + + t4_byte* _contents; + int _size; + bool _copy; + +public: + c4_Bytes (); + c4_Bytes (const void*, int); + c4_Bytes (const void*, int, bool); + c4_Bytes (const c4_Bytes&); + ~c4_Bytes (); + + c4_Bytes& operator= (const c4_Bytes&); + void Swap(c4_Bytes&); + + int Size() const; + const t4_byte* Contents() const; + + t4_byte* SetBuffer(int); + t4_byte* SetBufferClear(int); + + friend bool operator== (const c4_Bytes&, const c4_Bytes&); + friend bool operator!= (const c4_Bytes&, const c4_Bytes&); + +private: + void _MakeCopy(); + void _LoseCopy(); +}; + +//--------------------------------------------------------------------------- + +class c4_Storage : public c4_View +{ +public: + /// Construct streaming-only storage object + c4_Storage (); + /// Construct a storage using the specified strategy handler + c4_Storage (c4_Strategy&, bool =false, int =1); + /// Construct a storage object, keeping the current structure + c4_Storage (const char*, int); + /// Reconstruct a storage object from a suitable view + c4_Storage (const c4_View&); + /// Destructor, usually closes file, but does not commit by default + ~c4_Storage (); + + void SetStructure(const char*); + bool AutoCommit(bool =true); + c4_Strategy& Strategy() const; + const char* Description(const char* =0); + + bool SetAside(c4_Storage&); + c4_Storage* GetAside() const; + + bool Commit(bool =false); + bool Rollback(bool =false); + + c4_ViewRef View(const char*); + c4_View GetAs(const char*); + + bool LoadFrom(c4_Stream&); + void SaveTo(c4_Stream&); + + //DROPPED: c4_Storage (const char* filename_, const char* description_); + //DROPPED: c4_View Store(const char* name_, const c4_View& view_); + //DROPPED: c4_HandlerSeq& RootTable() const; + //DROPPED: c4_RowRef xContents() const; + +private: + void Initialize(c4_Strategy&, bool, int); +}; + +//--------------------------------------------------------------------------- + +class c4_Property +{ + short _id; + char _type; + +public: + /// Construct a new property with the give type and id + c4_Property (char, int); + /// Construct a new property with the give type and name + c4_Property (char, const char*); + ~c4_Property (); + + c4_Property (const c4_Property&); + void operator= (const c4_Property&); + + const char* Name() const; + char Type() const; + + int GetId() const; + + c4_Reference operator() (const c4_RowRef&) const; + + void Refs(int) const; + + c4_View operator, (const c4_Property&) const; + + static void CleanupInternalData(); +}; + + /// Integer properties. +class c4_IntProp : public c4_Property +{ +public: + /// Construct a new property + c4_IntProp (const char*); + /// Destructor + ~c4_IntProp (); + + /// Get or set an integer property in a row + c4_IntRef operator() (const c4_RowRef&) const; + /// Get an integer property in a row + t4_i32 Get(const c4_RowRef&) const; + /// Set an integer property in a row + void Set(const c4_RowRef&, t4_i32) const; + + /// Creates a row with one integer, shorthand for AsRow. + c4_Row operator[] (t4_i32) const; + /// Creates a row with one integer. + c4_Row AsRow(t4_i32) const; +}; + +#if !q4_TINY + + /// Long int properties. +class c4_LongProp : public c4_Property +{ +public: + /// Construct a new property + c4_LongProp (const char*); + /// Destructor + ~c4_LongProp (); + + /// Get or set a long int property in a row + c4_LongRef operator() (const c4_RowRef&) const; + /// Get a long int property in a row + t4_i64 Get(const c4_RowRef&) const; + /// Set a long int property in a row + void Set(const c4_RowRef&, t4_i64) const; + + /// Creates a row with one long int, shorthand for AsRow. + c4_Row operator[] (t4_i64) const; + /// Creates a row with one long int. + c4_Row AsRow(t4_i64) const; +}; + + /// Floating point properties. +class c4_FloatProp : public c4_Property +{ +public: + /// Construct a new property + c4_FloatProp (const char*); + /// Destructor + ~c4_FloatProp (); + + /// Get or set a floating point property in a row + c4_FloatRef operator() (const c4_RowRef&) const; + /// Get a floating point property in a row + double Get(const c4_RowRef&) const; + /// Set a floating point property in a row + void Set(const c4_RowRef&, double) const; + + /// Create a row with one floating point value, shorthand for AsRow + c4_Row operator[] (double) const; + /// Create a row with one floating point value + c4_Row AsRow(double) const; +}; + + /// Double precision properties. +class c4_DoubleProp : public c4_Property +{ +public: + /// Construct a new property. + c4_DoubleProp (const char*); + /// Destructor + ~c4_DoubleProp (); + + /// Get or set a double precision property in a row + c4_DoubleRef operator() (const c4_RowRef&) const; + /// Get a double precision property in a row + double Get(const c4_RowRef&) const; + /// Set a double precision property in a row + void Set(const c4_RowRef&, double) const; + + /// Create a row with one double precision value, shorthand for AsRow + c4_Row operator[] (double) const; + /// Create a row with one double precision value + c4_Row AsRow(double) const; +}; +#endif // !q4_TINY + + /// String properties. +class c4_StringProp : public c4_Property +{ +public: + /// Construct a new property + c4_StringProp (const char*); + /// Destructor + ~c4_StringProp (); + + /// Get or set a string property in a row + c4_StringRef operator() (const c4_RowRef&) const; + /// Get a string property in a row + const char* Get(const c4_RowRef&) const; + /// Set a string property in a row + void Set(const c4_RowRef&, const char*) const; + + /// Create a row with one string, shorthand for AsRow + c4_Row operator[] (const char*) const; + /// Create a row with one string + c4_Row AsRow(const char*) const; +}; + + /// Binary properties. +class c4_BytesProp : public c4_Property +{ +public: + /// Construct a new property + c4_BytesProp (const char*); + /// Destructor + ~c4_BytesProp (); + + /// Get or set a bytes property in a row + c4_BytesRef operator() (const c4_RowRef&) const; + /// Get a bytes property in a row + c4_Bytes Get(const c4_RowRef&) const; + /// Set a bytes property in a row + void Set(const c4_RowRef&, const c4_Bytes&) const; + + /// Create a row with one bytes object, shorthand for AsRow + c4_Row operator[] (const c4_Bytes&) const; + /// Create a row with one bytes object + c4_Row AsRow(const c4_Bytes&) const; +}; + + /// View properties. +class c4_ViewProp : public c4_Property +{ +public: + /// Construct a new property + c4_ViewProp (const char*); + /// Destructor + ~c4_ViewProp (); + + /// Get or set a view property in a row + c4_ViewRef operator() (const c4_RowRef&) const; + /// Get a view property in a row + c4_View Get(const c4_RowRef&) const; + /// Set a view property in a row + void Set(const c4_RowRef&, const c4_View&) const; + + /// Create a row with one view, shorthand for AsRow + c4_Row operator[] (const c4_View&) const; + /// Create a row with one view + c4_Row AsRow(const c4_View&) const; +}; + +//--------------------------------------------------------------------------- + +class c4_CustomViewer +{ +protected: + /// Constructor, must be overriden in derived class + c4_CustomViewer (); +public: + /// Destructor + virtual ~c4_CustomViewer (); + + /// Return the structure of this view (initialization, called once) + virtual c4_View GetTemplate() = 0; + /// Return the number of rows in this view + virtual int GetSize() = 0; + int Lookup(const c4_RowRef&, int&); + virtual int Lookup(c4_Cursor, int&); + /// Fetch one data item, return it as a generic data value + virtual bool GetItem(int, int, c4_Bytes&) = 0; + virtual bool SetItem(int, int, const c4_Bytes&); + bool InsertRows(int, const c4_RowRef&, int =1); + virtual bool InsertRows(int, c4_Cursor, int =1); + virtual bool RemoveRows(int, int =1); +}; + +//--------------------------------------------------------------------------- +/// A stream is a virtual helper class to serialize in binary form. + +class c4_Stream +{ +public: + virtual ~c4_Stream (); + + /// Fetch some bytes sequentially + virtual int Read(void*, int) = 0; + /// Store some bytes sequentially + virtual bool Write(const void*, int) = 0; +}; + +//--------------------------------------------------------------------------- +/// A strategy encapsulates code dealing with the I/O system interface. + +class c4_Strategy +{ +public: + c4_Strategy (); + virtual ~c4_Strategy (); + + virtual bool IsValid() const; + virtual int DataRead(t4_i32, void*, int); + virtual void DataWrite(t4_i32, const void*, int); + virtual void DataCommit(t4_i32); + virtual void ResetFileMapping(); + virtual t4_i32 FileSize(); + virtual t4_i32 FreshGeneration(); + + void SetBase(t4_i32); + t4_i32 EndOfData(t4_i32 =-1); + + /// True if the storage format is not native (default is false) + bool _bytesFlipped; + /// Error code of last failed I/O operation, zero if I/O was ok + int _failure; + /// First byte in file mapping, zero if not active + const t4_byte* _mapStart; + /// Number of bytes filled with active data + t4_i32 _dataSize; + /// All file positions are relative to this offset + t4_i32 _baseOffset; + /// The root position of the shallow tree walks + t4_i32 _rootPos; + /// The size of the root column + t4_i32 _rootLen; +}; + +//--------------------------------------------------------------------------- +/// A sequence is an abstract base class for views on ranges of records. +// +// Sequences represent arrays of rows (or indexed collections / tables). +// Insertion and removal of entries is allowed, but could take linear time. +// A reference count is maintained to decide when the object should go away. + +class c4_Sequence +{ + /// Reference count + int _refCount; + /// Pointer to dependency list, or null if nothing depends on this + c4_Dependencies* _dependencies; + +protected: + /// Optimization: cached property index + int _propertyLimit; + /// Optimization: property map for faster access + short* _propertyMap; // see c4_HandlerSeq::Reset() + /// allocated on first use by c4_Sequence::Buffer() + c4_Bytes* _tempBuf; + +public: +/* General */ + /// Abstract constructor + c4_Sequence (); + + virtual int Compare(int, c4_Cursor) const; + virtual bool RestrictSearch(c4_Cursor, int&, int&); + void SetAt(int, c4_Cursor); + virtual int RemapIndex(int, const c4_Sequence*) const; + +/* Reference counting */ + void IncRef(); + void DecRef(); + int NumRefs() const; + +/* Adding / removing rows */ + /// Return the current number of rows + virtual int NumRows() const = 0; + void Resize(int, int =-1); + + virtual void InsertAt(int, c4_Cursor, int =1); + virtual void RemoveAt(int, int =1); + virtual void Move(int, int); + +/* Properties */ + int NthPropId(int) const; + int PropIndex(int); + int PropIndex(const c4_Property&); + + /// Return the number of data handlers in this sequence + virtual int NumHandlers() const = 0; + /// Return a reference to the N-th handler in this sequence + virtual c4_Handler& NthHandler(int) const = 0; + /// Return the context of the N-th handler in this sequence + virtual const c4_Sequence* HandlerContext(int) const = 0; + /// Add the specified data handler to this sequence + virtual int AddHandler(c4_Handler*) = 0; + /// Create a handler of the appropriate type + virtual c4_Handler* CreateHandler(const c4_Property&) = 0; + + virtual const char* Description(); + +/* Element access */ + /// Return width of specified data item + virtual int ItemSize(int, int); + /// Retrieve one data item from this sequence + virtual bool Get(int, int, c4_Bytes&); + /// Store a data item into this sequence + virtual void Set(int, const c4_Property&, const c4_Bytes&); + +/* Dependency notification */ + void Attach(c4_Sequence*); + void Detach(c4_Sequence*); + /// Return a pointer to the dependencies, or null + c4_Dependencies* GetDependencies() const; + + virtual c4_Notifier* PreChange(c4_Notifier&); + virtual void PostChange(c4_Notifier&); + + const char* UseTempBuffer(const char*); + +protected: + virtual ~c4_Sequence (); + + void ClearCache(); + +public: //! for c4_Table::Sequence setup + virtual void SetNumRows(int) = 0; + virtual c4_Persist* Persist() const; + + c4_Bytes& Buffer(); + +private: + c4_Sequence (const c4_Sequence&); // not implemented + void operator= (const c4_Sequence&); // not implemented +}; + +//--------------------------------------------------------------------------- +/// A reference is used to get or set typed data, using derived classes. +// +// Objects of this class are only intended to be used as a temporary handle +// while getting and setting properties in a row. They are normally only +// constructed as result of function overload operators: "property (row)". + +class c4_Reference +{ +protected: + /// The cursor which points to the data + c4_Cursor _cursor; + /// The property associated to this reference + const c4_Property& _property; + +public: + /// Constructor + c4_Reference (const c4_RowRef&, const c4_Property&); + + /// Assignment of one data item + c4_Reference& operator= (const c4_Reference&); + + /// Return width of the referenced data item + int GetSize() const; + /// Retrieve the value of the referenced data item + bool GetData(c4_Bytes&) const; + /// Store a value into the referenced data item + void SetData(const c4_Bytes&) const; + + /// Return true if the contents of both references is equal + friend bool operator== (const c4_Reference&, const c4_Reference&); + /// Return true if the contents of both references is not equal + friend bool operator!= (const c4_Reference&, const c4_Reference&); + +private: + void operator& () const; // not implemented +}; + +//--------------------------------------------------------------------------- + + /// Used to get or set integer values. +class c4_IntRef : public c4_Reference +{ +public: + /// Constructor + c4_IntRef (const c4_Reference&); + /// Get the value as integer + operator t4_i32 () const; + /// Set the value to the specified integer + c4_IntRef& operator= (t4_i32); +}; + +#if !q4_TINY + + /// Used to get or set long int values. +class c4_LongRef : public c4_Reference +{ +public: + /// Constructor + c4_LongRef (const c4_Reference&); + /// Get the value as long int + operator t4_i64 () const; + /// Set the value to the specified long int + c4_LongRef& operator= (t4_i64); +}; + + /// Used to get or set floating point values. +class c4_FloatRef : public c4_Reference +{ +public: + /// Constructor + c4_FloatRef (const c4_Reference&); + /// Get the value as floating point + operator double () const; + /// Set the value to the specified floating point + c4_FloatRef& operator= (double); +}; + + /// Used to get or set double precision values. +class c4_DoubleRef : public c4_Reference +{ +public: + /// Constructor + c4_DoubleRef (const c4_Reference&); + /// Get the value as floating point + operator double () const; + /// Set the value to the specified floating point + c4_DoubleRef& operator= (double); +}; + +#endif // !q4_TINY + + /// Used to get or set binary object values. +class c4_BytesRef : public c4_Reference +{ +public: + /// Constructor + c4_BytesRef (const c4_Reference&); + /// Get the value as binary object + operator c4_Bytes () const; + /// Set the value to the specified binary object + c4_BytesRef& operator= (const c4_Bytes&); + + /// Fetch data from the memo field, up to end if length is zero + c4_Bytes Access(t4_i32, int =0) const; + /// Store data, resize by diff_ bytes, return true if successful + bool Modify(const c4_Bytes&, t4_i32, int =0) const; +}; + + /// Used to get or set string values. +class c4_StringRef : public c4_Reference +{ +public: + /// Constructor + c4_StringRef (const c4_Reference&); + /// Get the value as string + operator const char* () const; + /// Set the value to the specified string + c4_StringRef& operator= (const char*); +}; + + /// Used to get or set view values. +class c4_ViewRef : public c4_Reference +{ +public: + /// Constructor + c4_ViewRef (const c4_Reference&); + /// Get the value as view + operator c4_View () const; + /// Set the value to the specified view + c4_ViewRef& operator= (const c4_View&); +}; + +//--------------------------------------------------------------------------- +// Debug logging option, can generate log of changes for one/all properties + +#if q4_LOGPROPMODS +FILE* f4_LogPropMods(FILE* fp_, int propId_); +#else +#define f4_LogPropMods(a,b) 0 +#endif + +//--------------------------------------------------------------------------- + +#if q4_INLINE +#include "mk4.inl" +#endif + +//--------------------------------------------------------------------------- + +#endif // __MK4_H__ diff --git a/akregator/src/mk4storage/metakit/include/mk4.inl b/akregator/src/mk4storage/metakit/include/mk4.inl new file mode 100644 index 000000000..1c717a367 --- /dev/null +++ b/akregator/src/mk4storage/metakit/include/mk4.inl @@ -0,0 +1,874 @@ +// mk4.inl -- +// $Id$ +// This is part of Metakit, the homepage is http://www.equi4.com/metakit/ + +/** @file + * Public definitions which are usually inlined + */ + +///////////////////////////////////////////////////////////////////////////// +// Reordered inlines so they are always defined before their first use + +d4_inline c4_Cursor c4_RowRef::operator& () const +{ + return _cursor; +} + +/** Return a unique id for this property + * + * A property object in fact merely represents an entry in a globally + * maintained symbol table. Each property is assigned a unique id, + * which remains valid as long as some reference to that property + * exists. In general, property id's remain unique as long as the + * application runs. Do not store id's on file, since they are + * not guaranteed to remain the same across program invocations. + * All properties with the same name are given the same id. + */ +d4_inline int c4_Property::GetId() const +{ + return _id; +} + +////////////////////////////////////////////////////////////////////////////////// + +#if !q4_LONG64 && !defined (LONG_LONG) && !HAVE_LONG_LONG + +d4_inline bool operator== (const t4_i64 a_, const t4_i64 b_) +{ + return a_.l1 == b_.l1 && a_.l2 == b_.l2; +} + +d4_inline bool operator< (const t4_i64 a_, const t4_i64 b_) +{ + return a_.l2 < b_.l2 || a_.l2 == b_.l2 && a_.l2 < b_.l2; +} + +#endif + +////////////////////////////////////////////////////////////////////////////////// +// c4_View + +/// Returns the number of entries in this view. +d4_inline int c4_View::GetSize() const +{ + return _seq->NumRows(); +} + +/** Change the size of this view + * Since views act like dynamic arrays, you can quickly + * change their size. Increasing the size will append rows + * with zero/empty values, while decreasing it will delete + * the last rows. The growBy_ parameter is currently unused. + */ +d4_inline void c4_View::SetSize(int newSize_, int growBy_) +{ + _seq->Resize(newSize_, growBy_); +} + +/// Removes all entries (sets size to zero). +d4_inline void c4_View::RemoveAll() +{ + SetSize(0); +} + +/// Return a pointer to the persistence handler, or zero +d4_inline c4_Persist* c4_View::Persist() const +{ + return _seq->Persist(); +} + +/** + * Change the value of the specified entry. If the new value has + * other properties, these will be added to the underlying view. + * + * @param index_ the zero-based row index + * @param newElem_ the row to copy to this view + */ +d4_inline void c4_View::SetAt(int index_, const c4_RowRef& newElem_) +{ + _seq->SetAt(index_, &newElem_); +} + +/** + * Insert a copy of the contents of another view. This is identical to + * inserting the specified number of default entries and then setting + * each of them to the new element value passed as argument. + */ +d4_inline void c4_View::InsertAt( + int index_, ///< zero-based row index + const c4_RowRef& newElem_, ///< the value to insert + int count_ ///< number of copies to insert, must be > 0 + ) +{ + _seq->InsertAt(index_, &newElem_, count_); +} + +/** + * Remove entries starting at the given index. Entries which have + * other view references may cause these views to be deleted if their + * reference counts drop to zero because of this removal. + * + * @param index_ the zero-based row index + * @param count_ the number of entries to remove + */ +d4_inline void c4_View::RemoveAt(int index_, int count_) +{ + _seq->RemoveAt(index_, count_); +} + +/** Return the number of properties present in this view. + * @return A non-negative integer + */ +d4_inline int c4_View::NumProperties() const +{ + return _seq->NumHandlers(); +} + +/** Find the index of a property, given its id + * @param propId_ Unique id associated to a specific propoerty + * @return The index of the property, or -1 of it was not found + */ +d4_inline int c4_View::FindProperty(int propId_) +{ + return _seq->PropIndex(propId_); +} + + /// Return a decription if there is a fixed structure, else zero +d4_inline const char* c4_View::Description() const +{ + return _seq->Description(); +} + + /// Increase the reference count of the associated sequence +d4_inline void c4_View::_IncSeqRef() +{ + _seq->IncRef(); +} + + /// Decrease the reference count of the associated sequence +d4_inline void c4_View::_DecSeqRef() +{ + _seq->DecRef(); +} + +/// Destructor, decrements reference count +d4_inline c4_View::~c4_View () +{ + _DecSeqRef(); +} + + /// Return true if the contents of both views are equal +d4_inline bool operator== (const c4_View& a_, const c4_View& b_) +{ + return a_.GetSize() == b_.GetSize() && a_.Compare(b_) == 0; +} + + /// Return true if the contents of both views are not equal +d4_inline bool operator!= (const c4_View& a_, const c4_View& b_) +{ + return !(a_ == b_); +} + + /// True if first view is less than second view +d4_inline bool operator< (const c4_View& a_, const c4_View& b_) +{ + return a_.Compare(b_) < 0; +} + + /// True if first view is greater than second view +d4_inline bool operator> (const c4_View& a_, const c4_View& b_) +{ + return b_ < a_; +} + + /// True if first view is less or equal to second view +d4_inline bool operator<= (const c4_View& a_, const c4_View& b_) +{ + return !(b_ < a_); +} + + /// True if first view is greater or equal to second view +d4_inline bool operator>= (const c4_View& a_, const c4_View& b_) +{ + return !(a_ < b_); +} + +///////////////////////////////////////////////////////////////////////////// +// c4_Cursor + +/** Constructs a new cursor. + * + * Cursor cannot be created without an underlying view, but you could + * define a global "nullView" object and then initialize the cursor with + * "&nullView[0]". This works because cursors need not point to a valid row. + */ +d4_inline c4_Cursor::c4_Cursor (c4_Sequence& seq_, int index_) + : _seq (&seq_), _index (index_) +{ +} + +/// Pre-increments the cursor. +d4_inline c4_Cursor& c4_Cursor::operator++ () +{ + ++_index; + return *this; +} + +/// Post-increments the cursor. +d4_inline c4_Cursor c4_Cursor::operator++ (int) +{ + return c4_Cursor (*_seq, _index++); +} + +/// Pre-decrements the cursor. +d4_inline c4_Cursor& c4_Cursor::operator-- () +{ + --_index; + return *this; +} + +/// Post-decrements the cursor. +d4_inline c4_Cursor c4_Cursor::operator-- (int) +{ + return c4_Cursor (*_seq, _index--); +} + +/// Advances by a given offset. +d4_inline c4_Cursor& c4_Cursor::operator+= (int offset_) +{ + _index += offset_; + return *this; +} + +/// Backs up by a given offset. +d4_inline c4_Cursor& c4_Cursor::operator-= (int offset_) +{ + _index -= offset_; + return *this; +} + +/// Subtracts a specified offset. +d4_inline c4_Cursor c4_Cursor::operator- (int offset_) const +{ + return c4_Cursor (*_seq, _index - offset_); +} + +/// Returns the distance between two cursors. +d4_inline int c4_Cursor::operator- (c4_Cursor cursor_) const +{ + return _index - cursor_._index; +} + +/// Add a specified offset. +d4_inline c4_Cursor operator+ (c4_Cursor cursor_, int offset_) +{ + return c4_Cursor (*cursor_._seq, cursor_._index + offset_); +} + +/// Adds specified offset to cursor. +d4_inline c4_Cursor operator+ (int offset_, c4_Cursor cursor_) +{ + return cursor_ + offset_; +} + +d4_inline bool operator== (c4_Cursor a_, c4_Cursor b_) +{ + return a_._seq == b_._seq && a_._index == b_._index; +} + +d4_inline bool operator!= (c4_Cursor a_, c4_Cursor b_) +{ + return !(a_ == b_); +} + +d4_inline bool operator< (c4_Cursor a_, c4_Cursor b_) +{ + return a_._seq < b_._seq || + a_._seq == b_._seq && a_._index < b_._index; +} + +d4_inline bool operator> (c4_Cursor a_, c4_Cursor b_) +{ + return b_ < a_; +} + +d4_inline bool operator<= (c4_Cursor a_, c4_Cursor b_) +{ + return !(b_ < a_); +} + +d4_inline bool operator>= (c4_Cursor a_, c4_Cursor b_) +{ + return !(a_ < b_); +} + +///////////////////////////////////////////////////////////////////////////// +// c4_RowRef + +d4_inline c4_RowRef::c4_RowRef (c4_Cursor cursor_) + : _cursor (cursor_) +{ +} + +d4_inline c4_RowRef c4_RowRef::operator= (const c4_RowRef& rowRef_) +{ + if (_cursor != rowRef_._cursor) + _cursor._seq->SetAt(_cursor._index, &rowRef_); + + return *this; +} + +d4_inline c4_View c4_RowRef::Container() const +{ + return _cursor._seq; +} + +d4_inline bool operator== (const c4_RowRef& a_, const c4_RowRef& b_) +{ + return (&a_)._seq->Compare((&a_)._index, &b_) == 0; +} + +d4_inline bool operator!= (const c4_RowRef& a_, const c4_RowRef& b_) +{ + return !(a_ == b_); +} + +d4_inline bool operator< (const c4_RowRef& a_, const c4_RowRef& b_) +{ + // 25-5-1998: don't exchange a and b, this comparison is -not- symmetric + return (&a_)._seq->Compare((&a_)._index, &b_) < 0; +} + +d4_inline bool operator> (const c4_RowRef& a_, const c4_RowRef& b_) +{ + // 25-5-1998: don't exchange a and b, this comparison is -not- symmetric + return (&a_)._seq->Compare((&a_)._index, &b_) > 0; +} + +d4_inline bool operator<= (const c4_RowRef& a_, const c4_RowRef& b_) +{ + return !(a_ > b_); +} + +d4_inline bool operator>= (const c4_RowRef& a_, const c4_RowRef& b_) +{ + return !(a_ < b_); +} + +///////////////////////////////////////////////////////////////////////////// +// c4_Bytes + + /// Construct an empty binary object +d4_inline c4_Bytes::c4_Bytes () + : _size (0), _copy (false) +{ + _contents = 0; // moved out of intializers for DEC CXX 5.7 +} + + /// Construct an object with contents, no copy +d4_inline c4_Bytes::c4_Bytes (const void* buf_, int len_) + : _size (len_), _copy (false) +{ + _contents = (t4_byte*) buf_; // moved out of intializers for DEC CXX 5.7 +} + +/// Returns a pointer to the contents. +d4_inline const t4_byte* c4_Bytes::Contents() const +{ + return _contents; +} + +/// Returns the number of bytes of its contents. +d4_inline int c4_Bytes::Size() const +{ + return _size; +} + +d4_inline void c4_Bytes::_LoseCopy() +{ + if (_copy) + delete [] (char*) _contents; +} + +/// Returns true if the contents of both objects is not equal. +d4_inline bool operator!= (const c4_Bytes& a_, const c4_Bytes& b_) +{ + return !(a_ == b_); +} + +/// Destructor, if a copy was made, it will be released here. +d4_inline c4_Bytes::~c4_Bytes () +{ + _LoseCopy(); +} + +///////////////////////////////////////////////////////////////////////////// +// c4_Reference + +d4_inline c4_Reference::c4_Reference (const c4_RowRef& rowRef_, + const c4_Property& prop_) + : _cursor (&rowRef_), _property (prop_) +{ +} + +d4_inline int c4_Reference::GetSize() const +{ + return _cursor._seq->ItemSize(_cursor._index, _property.GetId()); +} + +d4_inline bool c4_Reference::GetData(c4_Bytes& buf_) const +{ + return _cursor._seq->Get(_cursor._index, _property.GetId(), buf_); +} + +d4_inline void c4_Reference::SetData(const c4_Bytes& buf_) const +{ + _cursor._seq->Set(_cursor._index, _property, buf_); +} + +d4_inline bool operator!= (const c4_Reference& a_, const c4_Reference& b_) +{ + return !(a_ == b_); +} + +///////////////////////////////////////////////////////////////////////////// +// c4_IntRef + +d4_inline c4_IntRef::c4_IntRef (const c4_Reference& value_) + : c4_Reference (value_) +{ +} + +///////////////////////////////////////////////////////////////////////////// +#if !q4_TINY +///////////////////////////////////////////////////////////////////////////// +// c4_LongRef + +d4_inline c4_LongRef::c4_LongRef (const c4_Reference& value_) + : c4_Reference (value_) +{ +} + +///////////////////////////////////////////////////////////////////////////// +// c4_FloatRef + +d4_inline c4_FloatRef::c4_FloatRef (const c4_Reference& value_) + : c4_Reference (value_) +{ +} + +///////////////////////////////////////////////////////////////////////////// +// c4_DoubleRef + +d4_inline c4_DoubleRef::c4_DoubleRef (const c4_Reference& value_) + : c4_Reference (value_) +{ +} + +///////////////////////////////////////////////////////////////////////////// +#endif // !q4_TINY +///////////////////////////////////////////////////////////////////////////// +// c4_BytesRef + +d4_inline c4_BytesRef::c4_BytesRef (const c4_Reference& value_) + : c4_Reference (value_) +{ +} + +///////////////////////////////////////////////////////////////////////////// +// c4_StringRef + +d4_inline c4_StringRef::c4_StringRef (const c4_Reference& value_) + : c4_Reference (value_) +{ +} + +///////////////////////////////////////////////////////////////////////////// +// c4_ViewRef + +d4_inline c4_ViewRef::c4_ViewRef (const c4_Reference& value_) + : c4_Reference (value_) +{ +} + +///////////////////////////////////////////////////////////////////////////// +// c4_Property + +d4_inline c4_Property::c4_Property (char type_, int id_) + : _id ((short) id_), _type (type_) +{ +} + + /// Get or set this untyped property in a row +d4_inline c4_Reference c4_Property::operator() (const c4_RowRef& rowRef_) const +{ + return c4_Reference (rowRef_, *this); +} + + /// Return a view like the first, with a property appended to it +d4_inline c4_View c4_Property::operator, (const c4_Property& prop_) const +{ + return c4_View (*this), prop_; +} + + /// Return the type of this property +d4_inline char c4_Property::Type() const +{ + return _type; +} + +///////////////////////////////////////////////////////////////////////////// +// c4_IntProp + +d4_inline c4_IntProp::c4_IntProp (const char* name_) + : c4_Property ('I', name_) +{ +} + +d4_inline c4_IntProp::~c4_IntProp () +{ +} + +d4_inline c4_IntRef c4_IntProp::operator() (const c4_RowRef& rowRef_) const +{ + return c4_Reference (rowRef_, *this); +} + +d4_inline t4_i32 c4_IntProp::Get(const c4_RowRef& rowRef_) const +{ + return operator() (rowRef_); +} + +d4_inline void c4_IntProp::Set(const c4_RowRef& rowRef_, t4_i32 value_) const +{ + operator() (rowRef_) = value_; +} + +d4_inline c4_Row c4_IntProp::AsRow(t4_i32 value_) const +{ + c4_Row row; + operator() (row) = value_; + return row; +} + +d4_inline c4_Row c4_IntProp::operator[] (t4_i32 value_) const +{ + return AsRow(value_); +} + +///////////////////////////////////////////////////////////////////////////// +#if !q4_TINY +///////////////////////////////////////////////////////////////////////////// +// c4_LongProp + +d4_inline c4_LongProp::c4_LongProp (const char* name_) + : c4_Property ('L', name_) +{ +} + +d4_inline c4_LongProp::~c4_LongProp () +{ +} + +d4_inline c4_LongRef c4_LongProp::operator() (const c4_RowRef& rowRef_) const +{ + return c4_Reference (rowRef_, *this); +} + +d4_inline t4_i64 c4_LongProp::Get(const c4_RowRef& rowRef_) const +{ + return operator() (rowRef_); +} + +d4_inline void c4_LongProp::Set(const c4_RowRef& rowRef_, t4_i64 value_) const +{ + operator() (rowRef_) = value_; +} + +d4_inline c4_Row c4_LongProp::AsRow(t4_i64 value_) const +{ + c4_Row row; + operator() (row) = value_; + return row; +} + +d4_inline c4_Row c4_LongProp::operator[] (t4_i64 value_) const +{ + return AsRow(value_); +} + +///////////////////////////////////////////////////////////////////////////// +// c4_FloatProp + +d4_inline c4_FloatProp::c4_FloatProp (const char* name_) + : c4_Property ('F', name_) +{ +} + +d4_inline c4_FloatProp::~c4_FloatProp () +{ +} + +d4_inline c4_FloatRef c4_FloatProp::operator() (const c4_RowRef& rowRef_) const +{ + return c4_Reference (rowRef_, *this); +} + +d4_inline double c4_FloatProp::Get(const c4_RowRef& rowRef_) const +{ + return operator() (rowRef_); +} + +d4_inline void c4_FloatProp::Set(const c4_RowRef& rowRef_, double value_) const +{ + operator() (rowRef_) = value_; +} + +d4_inline c4_Row c4_FloatProp::AsRow(double value_) const +{ + c4_Row row; + operator() (row) = value_; + return row; +} + +d4_inline c4_Row c4_FloatProp::operator[] (double value_) const +{ + return AsRow(value_); +} + +///////////////////////////////////////////////////////////////////////////// +// c4_DoubleProp + +d4_inline c4_DoubleProp::c4_DoubleProp (const char* name_) + : c4_Property ('D', name_) +{ +} + +d4_inline c4_DoubleProp::~c4_DoubleProp () +{ +} + +d4_inline c4_DoubleRef c4_DoubleProp::operator() (const c4_RowRef& rowRef_) const +{ + return c4_Reference (rowRef_, *this); +} + +d4_inline double c4_DoubleProp::Get(const c4_RowRef& rowRef_) const +{ + return operator() (rowRef_); +} + +d4_inline void c4_DoubleProp::Set(const c4_RowRef& rowRef_, double value_) const +{ + operator() (rowRef_) = value_; +} + +d4_inline c4_Row c4_DoubleProp::AsRow(double value_) const +{ + c4_Row row; + operator() (row) = value_; + return row; +} + +d4_inline c4_Row c4_DoubleProp::operator[] (double value_) const +{ + return AsRow(value_); +} + +///////////////////////////////////////////////////////////////////////////// +#endif // !q4_TINY +///////////////////////////////////////////////////////////////////////////// +// c4_BytesProp + +d4_inline c4_BytesProp::c4_BytesProp (const char* name_) + : c4_Property ('B', name_) +{ +} + +d4_inline c4_BytesProp::~c4_BytesProp () +{ +} + +d4_inline c4_BytesRef c4_BytesProp::operator() (const c4_RowRef& rowRef_) const +{ + return c4_Reference (rowRef_, *this); +} + +d4_inline c4_Bytes c4_BytesProp::Get(const c4_RowRef& rowRef_) const +{ + return operator() (rowRef_); +} + +d4_inline void c4_BytesProp::Set(const c4_RowRef& rowRef_, const c4_Bytes& value_) const +{ + operator() (rowRef_) = value_; +} + +d4_inline c4_Row c4_BytesProp::AsRow(const c4_Bytes& value_) const +{ + c4_Row row; + operator() (row) = value_; + return row; +} + +d4_inline c4_Row c4_BytesProp::operator[] (const c4_Bytes& value_) const +{ + return AsRow(value_); +} + +///////////////////////////////////////////////////////////////////////////// +// c4_StringProp + +d4_inline c4_StringProp::c4_StringProp (const char* name_) + : c4_Property ('S', name_) +{ +} + +d4_inline c4_StringProp::~c4_StringProp () +{ +} + +d4_inline c4_StringRef c4_StringProp::operator() (const c4_RowRef& rowRef_) const +{ + return c4_Reference (rowRef_, *this); +} + +d4_inline const char* c4_StringProp::Get(const c4_RowRef& rowRef_) const +{ + return operator() (rowRef_); +} + +d4_inline void c4_StringProp::Set(const c4_RowRef& rowRef_, const char* value_) const +{ + operator() (rowRef_) = value_; +} + +d4_inline c4_Row c4_StringProp::AsRow(const char* value_) const +{ + c4_Row row; + operator() (row) = value_; + return row; +} + +d4_inline c4_Row c4_StringProp::operator[] (const char* value_) const +{ + return AsRow(value_); +} + +///////////////////////////////////////////////////////////////////////////// +// c4_ViewProp + +d4_inline c4_ViewProp::c4_ViewProp (const char* name_) + : c4_Property ('V', name_) +{ +} + +d4_inline c4_ViewProp::~c4_ViewProp () +{ +} + +d4_inline c4_ViewRef c4_ViewProp::operator() (const c4_RowRef& rowRef_) const +{ + return c4_Reference (rowRef_, *this); +} + +d4_inline c4_View c4_ViewProp::Get(const c4_RowRef& rowRef_) const +{ + return operator() (rowRef_); +} + +d4_inline void c4_ViewProp::Set(const c4_RowRef& rowRef_, const c4_View& value_) const +{ + operator() (rowRef_) = value_; +} + +d4_inline c4_Row c4_ViewProp::AsRow(const c4_View& value_) const +{ + c4_Row row; + operator() (row) = value_; + return row; +} + +d4_inline c4_Row c4_ViewProp::operator[] (const c4_View& value_) const +{ + return AsRow(value_); +} + +///////////////////////////////////////////////////////////////////////////// +// c4_Strategy + + /// True if we can do I/O with this object +d4_inline bool c4_Strategy::IsValid() const +{ + return false; +} + +///////////////////////////////////////////////////////////////////////////// +// c4_CustomViewer + +d4_inline c4_CustomViewer::c4_CustomViewer() +{ +} + +d4_inline int c4_CustomViewer::Lookup(const c4_RowRef& r_, int& n_) +{ + return Lookup(&r_, n_); // c4_Cursor +} + +d4_inline bool c4_CustomViewer::InsertRows(int p_, const c4_RowRef& r_, int n_) +{ + return InsertRows(p_, &r_, n_); // c4_Cursor +} + +///////////////////////////////////////////////////////////////////////////// +// c4_Sequence + +d4_inline c4_Dependencies* c4_Sequence::GetDependencies() const +{ + return _dependencies; +} + +///////////////////////////////////////////////////////////////////////////// +// Reordered inlines so they are always used after their definition + +/// Dereferences this cursor to "almost" a row. +d4_inline c4_RowRef c4_Cursor::operator* () const +{ + return *(c4_Cursor*) this; // cast avoids a const problem with BCPP 4.52 +} + +/// This is the same as *(cursor + offset). +d4_inline c4_RowRef c4_Cursor::operator[] (int offset_) const +{ + return *(*this + offset_); +} + +/// Returns a reference to specified entry, for use as RHS or LHS +d4_inline c4_RowRef c4_View::GetAt(int index_) const +{ + return * c4_Cursor (*_seq, index_); +} + +/** Element access, shorthand for GetAt + * @return A reference to the specified row in the view. + * This reference can be used on either side of the assignment operator. + */ +d4_inline c4_RowRef c4_View::operator[] ( + int index_ ///< zero-based row index + ) const +{ + return GetAt(index_); +} + +/** Element access, shorthand for GetAt + * @return A reference to the specified row in the view. + * This reference can be used on either side of the assignment operator. + */ +d4_inline c4_RowRef c4_View::ElementAt( + int index_ ///< zero-based row index + ) +{ + return GetAt(index_); +} + +///////////////////////////////////////////////////////////////////////////// diff --git a/akregator/src/mk4storage/metakit/include/mk4dll.h b/akregator/src/mk4storage/metakit/include/mk4dll.h new file mode 100644 index 000000000..979971fac --- /dev/null +++ b/akregator/src/mk4storage/metakit/include/mk4dll.h @@ -0,0 +1,112 @@ +// mk4dll.h -- +// $Id$ +// This is part of Metakit, see http://www.equi4.com/metakit/ +// +// Import declarations for DLLs + +#ifndef __MK4_H__ +#error This file is included by "mk4.h", it cannot be used standalone +#endif + +#ifndef d4_DLL +#ifdef _WIN32 +#ifdef _USRDLL +#define d4_DLL __declspec(dllexport) +#else +#define d4_DLL __declspec(dllimport) +#endif +#else +#define d4_DLL +#endif +#endif + +#ifndef d4_DLLSPEC +#ifdef _MSC_VER +#define d4_DLLSPEC(t) d4_DLL t +#else +#define d4_DLLSPEC(t) t d4_DLL +#endif +#endif + +///////////////////////////////////////////////////////////////////////////// +// Declarations in this file + + class d4_DLL c4_Bytes; + class d4_DLL c4_BytesProp; + class d4_DLL c4_BytesRef; + class d4_DLL c4_Cursor; + class d4_DLL c4_CustomViewer; + class d4_DLL c4_DoubleProp; + class d4_DLL c4_DoubleRef; + class d4_DLL c4_FileStrategy; + class d4_DLL c4_FileStream; + class d4_DLL c4_FloatProp; + class d4_DLL c4_FloatRef; + class d4_DLL c4_IntProp; + class d4_DLL c4_IntRef; + class d4_DLL c4_LongRef; + class d4_DLL c4_Property; + class d4_DLL c4_Reference; + class d4_DLL c4_Row; + class d4_DLL c4_RowRef; + class d4_DLL c4_Sequence; + class d4_DLL c4_Storage; + class d4_DLL c4_Strategy; + class d4_DLL c4_Stream; + class d4_DLL c4_StringProp; + class d4_DLL c4_StringRef; + class d4_DLL c4_View; + class d4_DLL c4_ViewProp; + class d4_DLL c4_ViewRef; + +#if !q4_MFC + class d4_DLL c4_String; +#endif + +///////////////////////////////////////////////////////////////////////////// + + d4_DLLSPEC(bool) operator== (const c4_View& a_, const c4_View& b_); + d4_DLLSPEC(bool) operator!= (const c4_View& a_, const c4_View& b_); + d4_DLLSPEC(bool) operator< (const c4_View& a_, const c4_View& b_); + d4_DLLSPEC(bool) operator> (const c4_View& a_, const c4_View& b_); + d4_DLLSPEC(bool) operator<= (const c4_View& a_, const c4_View& b_); + d4_DLLSPEC(bool) operator>= (const c4_View& a_, const c4_View& b_); + + d4_DLLSPEC(bool) operator== (c4_Cursor a_, c4_Cursor b_); + d4_DLLSPEC(bool) operator!= (c4_Cursor a_, c4_Cursor b_); + d4_DLLSPEC(bool) operator< (c4_Cursor a_, c4_Cursor b_); + d4_DLLSPEC(bool) operator> (c4_Cursor a_, c4_Cursor b_); + d4_DLLSPEC(bool) operator<= (c4_Cursor a_, c4_Cursor b_); + d4_DLLSPEC(bool) operator>= (c4_Cursor a_, c4_Cursor b_); + d4_DLLSPEC(c4_Cursor) operator+ (c4_Cursor cursor_, int offset_); + d4_DLLSPEC(c4_Cursor) operator+ (int offset_, c4_Cursor cursor_); + + d4_DLLSPEC(bool) operator== (const c4_RowRef& a_, const c4_RowRef& b_); + d4_DLLSPEC(bool) operator!= (const c4_RowRef& a_, const c4_RowRef& b_); + d4_DLLSPEC(bool) operator< (const c4_RowRef& a_, const c4_RowRef& b_); + d4_DLLSPEC(bool) operator> (const c4_RowRef& a_, const c4_RowRef& b_); + d4_DLLSPEC(bool) operator<= (const c4_RowRef& a_, const c4_RowRef& b_); + d4_DLLSPEC(bool) operator>= (const c4_RowRef& a_, const c4_RowRef& b_); + d4_DLLSPEC(c4_Row) operator+ (const c4_RowRef& a_, const c4_RowRef& b_); + + d4_DLLSPEC(bool) operator== (const c4_Bytes& a_, const c4_Bytes& b_); + d4_DLLSPEC(bool) operator!= (const c4_Bytes& a_, const c4_Bytes& b_); + + d4_DLLSPEC(bool) operator== (const c4_Reference&, const c4_Reference&); + d4_DLLSPEC(bool) operator!= (const c4_Reference&, const c4_Reference&); + +#if !q4_MFC + d4_DLLSPEC(c4_String) operator+ (const c4_String&, const c4_String&); + d4_DLLSPEC(c4_String) operator+ (const c4_String&, const char*); + d4_DLLSPEC(c4_String) operator+ (const char*, const c4_String&); + + d4_DLLSPEC(bool) operator== (const c4_String&, const c4_String&); + d4_DLLSPEC(bool) operator!= (const c4_String&, const c4_String&); + d4_DLLSPEC(bool) operator== (const c4_String& s1, const char* s2); + d4_DLLSPEC(bool) operator== (const char* s1, const c4_String& s2); + d4_DLLSPEC(bool) operator!= (const c4_String& s1, const char* s2); + d4_DLLSPEC(bool) operator!= (const char* s1, const c4_String& s2); +#endif + +///////////////////////////////////////////////////////////////////////////// + diff --git a/akregator/src/mk4storage/metakit/include/mk4io.h b/akregator/src/mk4storage/metakit/include/mk4io.h new file mode 100644 index 000000000..d70db9c52 --- /dev/null +++ b/akregator/src/mk4storage/metakit/include/mk4io.h @@ -0,0 +1,66 @@ +// mk4io.h -- +// $Id$ +// This is part of Metakit, the homepage is http://www.equi4.com/metakit/ + +/** @file + * Declaration of the file stream and strategy classes. + */ + +#ifndef __MK4IO_H__ +#define __MK4IO_H__ + +#include <stdio.h> + +///////////////////////////////////////////////////////////////////////////// +/// A file stream can be used to serialize using the stdio library. + +class c4_FileStream : public c4_Stream +{ +public: + c4_FileStream (FILE* stream_, bool owned_ =false); + virtual ~c4_FileStream (); + + virtual int Read(void* buffer_, int length_); + virtual bool Write(const void* buffer_, int length_); + + FILE* _stream; + bool _owned; +}; + +///////////////////////////////////////////////////////////////////////////// +/// A file strategy encapsulates code dealing with all file I/O. + +class c4_FileStrategy : public c4_Strategy +{ +public: + /// Construct a new strategy object + c4_FileStrategy (FILE* file_ =0); + virtual ~c4_FileStrategy (); + + /// True if we can do I/O with this object + virtual bool IsValid() const; + /// Open a data file by name + virtual bool DataOpen(const char* fileName_, int mode_); + /// Read a number of bytes + virtual int DataRead(t4_i32 pos_, void* buffer_, int length_); + /// Write a number of bytes, return true if successful + virtual void DataWrite(t4_i32 pos_, const void* buffer_, int length_); + /// Flush and truncate file + virtual void DataCommit(t4_i32 newSize_); + /// Support for memory-mapped files + virtual void ResetFileMapping(); + /// Report total size of the datafile + virtual t4_i32 FileSize(); + /// Return a good value to use as fresh generation counter + virtual t4_i32 FreshGeneration(); + +protected: + /// Pointer to file object + FILE* _file; + /// Pointer to same file object, if it must be deleted at end + FILE* _cleanup; +}; + +///////////////////////////////////////////////////////////////////////////// + +#endif // __MK4IO_H__ diff --git a/akregator/src/mk4storage/metakit/include/mk4str.h b/akregator/src/mk4storage/metakit/include/mk4str.h new file mode 100644 index 000000000..7124a29ea --- /dev/null +++ b/akregator/src/mk4storage/metakit/include/mk4str.h @@ -0,0 +1,181 @@ +// mk4str.h -- +// $Id$ +// This is part of Metakit, see http://www.equi4.com/metakit/ + +/** @file + * Declarations of the string package. + */ + +#ifndef __MK4STR_H__ +#define __MK4STR_H__ + +///////////////////////////////////////////////////////////////////////////// + +#if q4_MFC // Microsoft Foundation Classes + +#ifdef _WINDOWS +#include <afxwin.h> +#else +#include <afxcoll.h> +#endif + +#if _MSC_VER == 800 +// MSVC 1.52 thinks a typedef has no constructor, use define instead +#define c4_String CString +#elif _MSC_VER >= 1300 +// VC 7.0 does not like "class" (6-2-2002, Zhang Dehua) +typedef CString c4_String; +#else +typedef class CString c4_String; +#endif + +#elif q4_STD // STL and standard strings + +#include <string> + +#if !defined (d4_std) // the default is to use namespaces +#define d4_std std +#endif + + /// STL-based string class, modeled after the MFC version +class c4_String : public d4_std::string +{ + typedef d4_std::string string; + +public: + c4_String (); + c4_String (char ch, int nDup =1); + c4_String (const char* str); + c4_String (const void* ptr, int len); + c4_String (const d4_std::string& s); + c4_String (const c4_String& s); + ~c4_String (); + + const c4_String& operator= (const c4_String&); + + operator const char* () const; + + char operator[] (int i) const; + + friend c4_String operator+ (const c4_String&, const c4_String&); + friend c4_String operator+ (const c4_String&, const char*); + friend c4_String operator+ (const char*, const c4_String&); + + const c4_String& operator+= (const c4_String& s); + const c4_String& operator+= (const char* s); + + int GetLength() const; + bool IsEmpty() const; + void Empty(); + + c4_String Mid(int nFirst, int nCount =25000) const; + c4_String Left(int nCount) const; + c4_String Right(int nCount) const; + + int Compare(const char* str) const; + int CompareNoCase(const char* str) const; + + bool operator< (const c4_String& str) const; + + int Find(char ch) const; + int ReverseFind(char ch) const; + int FindOneOf(const char* set) const; + + int Find(const char* sub) const; + + c4_String SpanIncluding(const char* set) const; + c4_String SpanExcluding(const char* set) const; +}; + +bool operator== (const c4_String&, const c4_String&); +bool operator!= (const c4_String&, const c4_String&); + +d4_inline bool operator== (const c4_String& s1, const char* s2); +d4_inline bool operator== (const char* s1, const c4_String& s2); + +d4_inline bool operator!= (const c4_String& s1, const char* s2); +d4_inline bool operator!= (const char* s1, const c4_String& s2); + +#else // Universal replacement classes + + /// An efficient string class, modeled after the MFC version +class c4_String +{ +public: + c4_String (); + c4_String (char ch, int nDup =1); + c4_String (const char* str); + c4_String (const unsigned char* str); + c4_String (const void* ptr, int len); + c4_String (const c4_String& s); + ~c4_String (); + + const c4_String& operator= (const c4_String&); + + operator const char* () const; + operator const unsigned char* () const; + + char operator[] (int i) const; + + friend c4_String operator+ (const c4_String&, const c4_String&); + friend c4_String operator+ (const c4_String&, const char*); + friend c4_String operator+ (const char*, const c4_String&); +// friend c4_String operator+ (const c4_String&, char); +// friend c4_String operator+ (char, const c4_String&); + + const c4_String& operator+= (const c4_String& s); + const c4_String& operator+= (const char* s); +// const c4_String& operator+= (char c); + + int GetLength() const; + bool IsEmpty() const; + void Empty(); // free up the data + + c4_String Mid(int nFirst, int nCount =25000) const; + c4_String Left(int nCount) const; // first nCount chars + c4_String Right(int nCount) const; // last nCount chars + + friend bool operator== (const c4_String&, const c4_String&); // memcmp + friend bool operator!= (const c4_String&, const c4_String&); // opposite + + // only defined for strings having no zero bytes inside them: + + int Compare(const char* str) const; // strcmp + int CompareNoCase(const char* str) const; // stricmp + + bool operator< (const c4_String& str) const; + + int Find(char ch) const; // strchr + int ReverseFind(char ch) const; // strrchr + int FindOneOf(const char* set) const; // strpbrk + + int Find(const char* sub) const; // strstr + + c4_String SpanIncluding(const char* set) const; // strspn + c4_String SpanExcluding(const char* set) const; // strcspn + +private: + void Init(const void* p, int n); + const char* Data() const; + int FullLength() const; + + unsigned char* _value; +}; + +bool operator== (const c4_String& s1, const char* s2); +bool operator== (const char* s1, const c4_String& s2); + +bool operator!= (const c4_String& s1, const char* s2); +bool operator!= (const char* s1, const c4_String& s2); + +#endif // q4_MFC elif q4_STD else q4_UNIV + +///////////////////////////////////////////////////////////////////////////// + +#if q4_INLINE +#include "mk4str.inl" +#endif + +///////////////////////////////////////////////////////////////////////////// + +#endif // __MK4STR_H__ diff --git a/akregator/src/mk4storage/metakit/include/mk4str.inl b/akregator/src/mk4storage/metakit/include/mk4str.inl new file mode 100644 index 000000000..4f95fa514 --- /dev/null +++ b/akregator/src/mk4storage/metakit/include/mk4str.inl @@ -0,0 +1,299 @@ +// mk4str.inl -- +// $Id$ +// This is part of Metakit, the homepage is http://www.equi4.com/metakit/ + +/** @file + * Members of the string package which are usually inlined + */ + +///////////////////////////////////////////////////////////////////////////// +// c4_String + +#if q4_MFC // Microsoft Foundation Classes + +#elif q4_STD // STL and standard strings + +/// Construct empty string +d4_inline c4_String::c4_String () +{ +} + +d4_inline c4_String::c4_String (char ch_, int nDup_) + : string (nDup_, ch_) +{ +} + +d4_inline c4_String::c4_String (const char* str_) + : string (str_) +{ +} + +d4_inline c4_String::c4_String (const void* ptr_, int len_) + : string ((const char*) ptr_, len_) +{ +} + +d4_inline c4_String::c4_String (const d4_std::string& s_) + : string (s_) +{ +} + +d4_inline c4_String::c4_String (const c4_String& s_) + : string (s_) +{ +} + +d4_inline c4_String::~c4_String () +{ +} + +d4_inline const c4_String& c4_String::operator= (const c4_String& s_) +{ + *(string*) this = s_; + return *this; +} + +d4_inline c4_String::operator const char* () const +{ + return c_str(); +} + +d4_inline char c4_String::operator[] (int i) const +{ + return at(i); +} + +d4_inline c4_String operator+ (const c4_String& a_, const c4_String& b_) +{ + return (d4_std::string) a_ + (d4_std::string) b_; +} + +d4_inline c4_String operator+ (const c4_String& a_, const char* b_) +{ + return (d4_std::string) a_ + (d4_std::string) b_; +} + +d4_inline c4_String operator+ (const char* a_, const c4_String& b_) +{ + return (d4_std::string) a_ + (d4_std::string) b_; +} + +d4_inline const c4_String& c4_String::operator+= (const c4_String& s_) +{ + *(string*) this += s_; + return *this; +} + +d4_inline const c4_String& c4_String::operator+= (const char* s_) +{ + *(string*) this += s_; + return *this; +} + +d4_inline int c4_String::GetLength() const +{ + return length(); +} + +d4_inline bool c4_String::IsEmpty() const +{ + return empty(); +} + +d4_inline void c4_String::Empty() +{ + erase(); +} + +d4_inline c4_String c4_String::Left(int nCount_) const +{ + if (nCount_ > length()) + nCount_ = length(); + return substr(0, nCount_); +} + +d4_inline c4_String c4_String::Right(int nCount_) const +{ + if (nCount_ > length()) + nCount_ = length(); + return substr(length() - nCount_, nCount_); +} + +d4_inline int c4_String::Compare(const char* str_) const +{ + return compare(str_); +} + +d4_inline bool c4_String::operator< (const c4_String& str_) const +{ + return compare(str_) < 0; +} + +d4_inline int c4_String::Find(char ch_) const +{ + return find(ch_); +} + +d4_inline int c4_String::ReverseFind(char ch_) const +{ + return rfind(ch_); +} + +d4_inline int c4_String::FindOneOf(const char* set_) const +{ + return find_first_of(set_); +} + +d4_inline int c4_String::Find(const char* sub_) const +{ + return find(sub_); +} + +d4_inline c4_String c4_String::SpanIncluding(const char* set_) const +{ + return substr(0, find_first_not_of(set_)); +} + +d4_inline c4_String c4_String::SpanExcluding(const char* set_) const +{ + return substr(0, find_first_of(set_)); +} + +d4_inline bool operator== (const c4_String& a_, const c4_String& b_) +{ + return (d4_std::string) a_ == (d4_std::string) b_; +} + +d4_inline bool operator!= (const c4_String& a_, const c4_String& b_) +{ + return (d4_std::string) a_ != (d4_std::string) b_; +} + +d4_inline bool operator== (const c4_String& a_, const char* b_) +{ + return (d4_std::string) a_ == (d4_std::string) b_; +} + +d4_inline bool operator== (const char* a_, const c4_String& b_) +{ + return (d4_std::string) a_ == (d4_std::string) b_; +} + +d4_inline bool operator!= (const c4_String& a_, const char* b_) +{ + return (d4_std::string) a_ != (d4_std::string) b_; +} + +d4_inline bool operator!= (const char* a_, const c4_String& b_) +{ + return (d4_std::string) a_ != (d4_std::string) b_; +} + +#else // Universal replacement classes + +/// Construct empty string +d4_inline c4_String::c4_String () +{ + Init(0, 0); +} + +/// Construct string from Pascal-style <count,chars...> data +d4_inline c4_String::c4_String (const unsigned char* ptr) +{ + Init(ptr + 1, ptr ? *ptr : 0); +} + +/// Construct string from a specified area in memory +d4_inline c4_String::c4_String (const void* ptr, int len) +{ + Init(ptr, len); +} + +d4_inline const c4_String& c4_String::operator+= (const c4_String& s) +{ + return *this = *this + s; +} + +d4_inline const c4_String& c4_String::operator+= (const char* s) +{ + return *this += (c4_String) s; +} + +d4_inline const char* c4_String::Data() const +{ + return (const char*) (_value + 2); +} + +d4_inline c4_String::operator const char* () const +{ + return Data(); +} + +d4_inline c4_String::operator const unsigned char* () const +{ + return (unsigned char*) Data() - 1; +} + +d4_inline char c4_String::operator[] (int i) const +{ + return Data()[i]; +} + +d4_inline int c4_String::GetLength() const +{ + return _value[1] != 255 ? _value[1] : FullLength(); +} + +d4_inline bool c4_String::IsEmpty() const +{ + return GetLength() == 0; +} + +d4_inline void c4_String::Empty() +{ + *this = ""; +} + +d4_inline bool c4_String::operator< (const c4_String& a) const +{ + return Compare(a) < 0; +} + +d4_inline c4_String operator+ (const char* a, const c4_String& b) +{ + return (c4_String) a + b; +} + +d4_inline c4_String operator+ (const c4_String& a, const char* b) +{ + return a + (c4_String) b; +} + +d4_inline bool operator== (const char* a, const c4_String& b) +{ + return b.Compare(a) == 0; +} + +d4_inline bool operator== (const c4_String& a, const char* b) +{ + return a.Compare(b) == 0; +} + +d4_inline bool operator!= (const c4_String& a, const c4_String& b) +{ + return !(a == b); +} + +d4_inline bool operator!= (const char* a, const c4_String& b) +{ + return b.Compare(a) != 0; +} + +d4_inline bool operator!= (const c4_String& a, const char* b) +{ + return a.Compare(b) != 0; +} + +#endif // q4_UNIV + +///////////////////////////////////////////////////////////////////////////// |