(svn r7712) [cbh] - Fix: [YAPF] make those 3 files added in (r7708) compilable by g++
--- a/yapf/blob.hpp Sun Dec 31 23:48:04 2006 +0000
+++ b/yapf/blob.hpp Mon Jan 01 01:43:40 2007 +0000
@@ -74,7 +74,7 @@
AppendRaw(src);
}
/** move constructor - take ownership of blob data */
- FORCEINLINE CBlobBaseSimple(CHdr*& pHdr_1) {assert(pHdr_1 != NULL); ptr_u.m_pHdr_1 = pHdr_1; pHdr_1 = NULL;}
+ FORCEINLINE CBlobBaseSimple(CHdr * const & pHdr_1) {assert(pHdr_1 != NULL); ptr_u.m_pHdr_1 = pHdr_1; *(CHdr**)&pHdr_1 = NULL;}
/** destructor */
FORCEINLINE ~CBlobBaseSimple() { Free(); }
protected:
@@ -219,7 +219,7 @@
};
/** Blob - simple dynamic Titem_ array. Titem_ (template argument) is a placeholder for any type.
-* Titem_ can be any size_tegral type, posize_ter, or structure. Using Blob instead of just plain C array
+* Titem_ can be any integral type, pointer, or structure. Using Blob instead of just plain C array
* simplifies the resource management in several ways:
* 1. When adding new item(s) it automatically grows capacity if needed.
* 2. When variable of type Blob comes out of scope it automatically frees the data buffer.
@@ -231,12 +231,13 @@
public:
typedef Titem_ Titem;
typedef Tbase_ Tbase;
+ typedef typename Tbase::size_t size_t;
static const size_t Titem_size = sizeof(Titem);
struct OnTransfer {
typename Tbase_::CHdr *m_pHdr_1;
- OnTransfer(OnTransfer& src) : m_pHdr_1(src.m_pHdr_1) {assert(src.m_pHdr_1 != NULL); src.m_pHdr_1 = NULL;}
+ OnTransfer(const OnTransfer& src) : m_pHdr_1(src.m_pHdr_1) {assert(src.m_pHdr_1 != NULL); *(typename Tbase_::CHdr**)&src.m_pHdr_1 = NULL;}
OnTransfer(CBlobT& src) : m_pHdr_1(src.ptr_u.m_pHdr_1) {src.InitEmpty();}
~OnTransfer() {assert(m_pHdr_1 == NULL);}
};
@@ -246,31 +247,31 @@
/** Constructor - makes new Blob with data */
FORCEINLINE CBlobT(const Titem_ *p, size_t num_items) : Tbase((int8*)p, num_items * Titem_size) {}
/** Copy constructor - make new blob to become copy of the original (source) blob */
- FORCEINLINE CBlobT(const Tbase& src) : Tbase(src) {assert((RawSize() % Titem_size) == 0);}
+ FORCEINLINE CBlobT(const Tbase& src) : Tbase(src) {assert((Tbase::RawSize() % Titem_size) == 0);}
/** Take ownership constructor */
- FORCEINLINE CBlobT(OnTransfer& ot) : Tbase(ot.m_pHdr_1) {}
+ FORCEINLINE CBlobT(const OnTransfer& ot) : Tbase(ot.m_pHdr_1) {}
/** Destructor - ensures that allocated memory (if any) is freed */
FORCEINLINE ~CBlobT() { Free(); }
/** Check the validity of item index (only in debug mode) */
FORCEINLINE void CheckIdx(size_t idx) { assert(idx >= 0); assert(idx < Size()); }
/** Return posize_ter to the first data item - non-const version */
- FORCEINLINE Titem* Data() { return (Titem*)RawData(); }
+ FORCEINLINE Titem* Data() { return (Titem*)Tbase::RawData(); }
/** Return posize_ter to the first data item - const version */
- FORCEINLINE const Titem* Data() const { return (const Titem*)RawData(); }
+ FORCEINLINE const Titem* Data() const { return (const Titem*)Tbase::RawData(); }
/** Return posize_ter to the idx-th data item - non-const version */
FORCEINLINE Titem* Data(size_t idx) { CheckIdx(idx); return (Data() + idx); }
/** Return posize_ter to the idx-th data item - const version */
FORCEINLINE const Titem* Data(size_t idx) const { CheckIdx(idx); return (Data() + idx); }
/** Return number of items in the Blob */
- FORCEINLINE size_t Size() const { return (RawSize() / Titem_size); }
+ FORCEINLINE size_t Size() const { return (Tbase::RawSize() / Titem_size); }
/** Return total number of items that can fit in the Blob without buffer reallocation */
- FORCEINLINE size_t MaxSize() const { return (MaxRawSize() / Titem_size); }
+ FORCEINLINE size_t MaxSize() const { return (Tbase::MaxRawSize() / Titem_size); }
/** Return number of additional items that can fit in the Blob without buffer reallocation */
- FORCEINLINE size_t GetReserve() const { return ((MaxRawSize() - RawSize()) / Titem_size); }
+ FORCEINLINE size_t GetReserve() const { return ((Tbase::MaxRawSize() - Tbase::RawSize()) / Titem_size); }
/** Free the memory occupied by Blob destroying all items */
FORCEINLINE void Free()
{
- assert((RawSize() % Titem_size) == 0);
+ assert((Tbase::RawSize() % Titem_size) == 0);
size_t old_size = Size();
if (old_size > 0) {
// destroy removed items;
@@ -280,7 +281,7 @@
Tbase::Free();
}
/** Grow number of data items in Blob by given number - doesn't construct items */
- FORCEINLINE Titem* GrowSizeNC(size_t num_items) { return (Titem*)GrowRawSize(num_items * Titem_size); }
+ FORCEINLINE Titem* GrowSizeNC(size_t num_items) { return (Titem*)Tbase::GrowRawSize(num_items * Titem_size); }
/** Grow number of data items in Blob by given number - constructs new items (using Titem_'s default constructor) */
FORCEINLINE Titem* GrowSizeC(size_t num_items)
{
@@ -290,7 +291,7 @@
/** Destroy given number of items and reduce the Blob's data size */
FORCEINLINE void ReduceSize(size_t num_items)
{
- assert((RawSize() % Titem_size) == 0);
+ assert((Tbase::RawSize() % Titem_size) == 0);
size_t old_size = Size();
assert(num_items <= old_size);
size_t new_size = (num_items <= old_size) ? (old_size - num_items) : 0;
@@ -298,7 +299,7 @@
Titem* pI_last_to_destroy = Data(new_size);
for (Titem* pI = Data(old_size - 1); pI >= pI_last_to_destroy; pI--) pI->~Titem();
// remove them
- ReduceRawSize(num_items * Titem_size);
+ Tbase::ReduceRawSize(num_items * Titem_size);
}
/** Append one data item at the end (calls Titem_'s default constructor) */
FORCEINLINE Titem* AppendNew()
@@ -344,11 +345,11 @@
// destroy the last item
pLast->~Titem_();
// and reduce the raw blob size
- ReduceRawSize(Titem_size);
+ Tbase::ReduceRawSize(Titem_size);
}
/** Ensures that given number of items can be added to the end of Blob. Returns posize_ter to the
* first free (unused) item */
- FORCEINLINE Titem* MakeFreeSpace(size_t num_items) { return (Titem*)MakeRawFreeSpace(num_items * Titem_size); }
+ FORCEINLINE Titem* MakeFreeSpace(size_t num_items) { return (Titem*)Tbase::MakeRawFreeSpace(num_items * Titem_size); }
FORCEINLINE OnTransfer Transfer() {return OnTransfer(*this);};
};
--- a/yapf/str.hpp Sun Dec 31 23:48:04 2006 +0000
+++ b/yapf/str.hpp Mon Jan 01 01:43:40 2007 +0000
@@ -4,6 +4,7 @@
#define STR_HPP
#include <errno.h>
+#include <stdarg.h>
#include "blob.hpp"
#include "strapi.hpp"
@@ -15,17 +16,20 @@
{
typedef CBlobT<Tchar> base;
typedef CStrApiT<Tchar, TcaseInsensitive> Api;
+ typedef typename base::size_t size_t;
+ typedef typename base::OnTransfer OnTransfer;
+
FORCEINLINE CStrT(const Tchar* str = NULL) {AppendStr(str);}
- FORCEINLINE CStrT(const Tchar* str, size_t num_chars) : base(str, num_chars) {FixTail();}
- FORCEINLINE CStrT(const Tchar* str, const Tchar* end) : base(str, end - str) {FixTail();}
- FORCEINLINE CStrT(const CBlobBaseSimple& src) : base(src) {FixTail();}
+ FORCEINLINE CStrT(const Tchar* str, size_t num_chars) : base(str, num_chars) {base::FixTail();}
+ FORCEINLINE CStrT(const Tchar* str, const Tchar* end) : base(str, end - str) {base::FixTail();}
+ FORCEINLINE CStrT(const CBlobBaseSimple& src) : base(src) {base::FixTail();}
/** Take ownership constructor */
- FORCEINLINE CStrT(OnTransfer& ot) : base(ot) {}
- FORCEINLINE Titem* GrowSizeNC(size_t count) {Titem* ret = base::GrowSizeNC(count); FixTail(); return ret;}
- FORCEINLINE void AppendStr(const Tchar* str) {if (str != NULL && str[0] != '\0') base::Append(str, (size_t)Api::StrLen(str)); FixTail();}
- FORCEINLINE CStrT& operator = (const Tchar* src) {Clear(); Append(src); return *this;}
- FORCEINLINE bool operator < (const CStrT &other) const {return (Api::StrCmp(Data(), other.Data()) < 0);}
+ FORCEINLINE CStrT(const OnTransfer& ot) : base(ot) {}
+ FORCEINLINE Tchar* GrowSizeNC(size_t count) {Tchar* ret = base::GrowSizeNC(count); base::FixTail(); return ret;}
+ FORCEINLINE void AppendStr(const Tchar* str) {if (str != NULL && str[0] != '\0') base::Append(str, (size_t)Api::StrLen(str)); base::FixTail();}
+ FORCEINLINE CStrT& operator = (const Tchar* src) {base::Clear(); Append(src); return *this;}
+ FORCEINLINE bool operator < (const CStrT &other) const {return (Api::StrCmp(base::Data(), other.Data()) < 0);}
int FormatL(const Tchar *fmt, va_list args)
{
@@ -35,14 +39,14 @@
int ret;
do {
Tchar *buf = MakeFreeSpace(addSize);
- ret = Api::SPrintFL(buf, GetReserve(), fmt, args);
+ ret = Api::SPrintFL(buf, base::GetReserve(), fmt, args);
addSize *= 2;
} while(ret < 0 && (errno == ERANGE || errno == 0));
if (ret > 0) {
GrowSizeNC(ret);
} else {
- int err = errno;
- FixTail();
+// int err = errno;
+ base::FixTail();
}
return ret;
}
--- a/yapf/strapi.hpp Sun Dec 31 23:48:04 2006 +0000
+++ b/yapf/strapi.hpp Mon Jan 01 01:43:40 2007 +0000
@@ -4,6 +4,12 @@
#define STRAPI_HPP
#include <string.h>
+#include <wchar.h>
+
+#if !defined(_MSC_VER)
+#define _stricmp strcmp
+#define _wcsicmp wcscmp
+#endif //!_MSC_VER
/** String API mapper base - just mapping by character type, not by case sensitivity yet.
* Class template CStrApiBaseT declaration is general, but following inline method