patch 1073385

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30791 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Ryan Norton
2004-11-25 20:37:44 +00:00
parent b494e2b008
commit f44eaed650
6 changed files with 56 additions and 54 deletions

View File

@@ -67,6 +67,7 @@ public:
protected: protected:
wxArchiveEntry() : m_notifier(NULL) { } wxArchiveEntry() : m_notifier(NULL) { }
wxArchiveEntry(const wxArchiveEntry& e) : wxObject(e), m_notifier(NULL) { }
virtual void SetOffset(wxFileOffset offset) = 0; virtual void SetOffset(wxFileOffset offset) = 0;
virtual wxArchiveEntry* DoClone() const = 0; virtual wxArchiveEntry* DoClone() const = 0;
@@ -211,14 +212,14 @@ private:
#include <iterator> #include <iterator>
#include <utility> #include <utility>
template <class X, class Y> template <class X, class Y> inline
void WXDLLIMPEXP_BASE _wxSetArchiveIteratorValue( void _wxSetArchiveIteratorValue(
X& val, Y entry, void *WXUNUSED(d)) X& val, Y entry, void *WXUNUSED(d))
{ {
val = X(entry); val = X(entry);
} }
template <class X, class Y, class Z> template <class X, class Y, class Z> inline
void WXDLLIMPEXP_BASE _wxSetArchiveIteratorValue( void _wxSetArchiveIteratorValue(
std::pair<X, Y>& val, Z entry, Z WXUNUSED(d)) std::pair<X, Y>& val, Z entry, Z WXUNUSED(d))
{ {
val = std::make_pair(X(entry->GetInternalName()), Y(entry)); val = std::make_pair(X(entry->GetInternalName()), Y(entry));
@@ -229,7 +230,7 @@ template <class Arc, class T = Arc::entry_type*>
#else #else
template <class Arc, class T = typename Arc::entry_type*> template <class Arc, class T = typename Arc::entry_type*>
#endif #endif
class WXDLLIMPEXP_BASE wxArchiveIterator class wxArchiveIterator
{ {
public: public:
typedef std::input_iterator_tag iterator_category; typedef std::input_iterator_tag iterator_category;
@@ -283,11 +284,11 @@ public:
return it; return it;
} }
bool operator ==(const wxArchiveIterator& j) { bool operator ==(const wxArchiveIterator& j) const {
return (*this).m_rep == j.m_rep; return m_rep == j.m_rep;
} }
bool operator !=(const wxArchiveIterator& j) { bool operator !=(const wxArchiveIterator& j) const {
return !(*this == j); return !(*this == j);
} }

View File

@@ -455,29 +455,29 @@ private:
#if wxUSE_STL || defined WX_TEST_ARCHIVE_ITERATOR #if wxUSE_STL || defined WX_TEST_ARCHIVE_ITERATOR
typedef wxArchiveIterator<wxZipInputStream> wxZipIter; typedef wxArchiveIterator<wxZipInputStream> wxZipIter;
typedef wxArchiveIterator<wxZipInputStream, typedef wxArchiveIterator<wxZipInputStream,
std::pair<wxString, wxZipEntry*> > wxZipPairIter; std::pair<wxString, wxZipEntry*> > wxZipPairIter;
#endif #endif
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// wxZipEntry inlines // wxZipEntry inlines
bool wxZipEntry::IsText() const inline bool wxZipEntry::IsText() const
{ {
return (m_InternalAttributes & TEXT_ATTR) != 0; return (m_InternalAttributes & TEXT_ATTR) != 0;
} }
bool wxZipEntry::IsDir() const inline bool wxZipEntry::IsDir() const
{ {
return (m_ExternalAttributes & wxZIP_A_SUBDIR) != 0; return (m_ExternalAttributes & wxZIP_A_SUBDIR) != 0;
} }
bool wxZipEntry::IsReadOnly() const inline bool wxZipEntry::IsReadOnly() const
{ {
return (m_ExternalAttributes & wxZIP_A_RDONLY) != 0; return (m_ExternalAttributes & wxZIP_A_RDONLY) != 0;
} }
bool wxZipEntry::IsMadeByUnix() const inline bool wxZipEntry::IsMadeByUnix() const
{ {
const int pattern = const int pattern =
(1 << wxZIP_SYSTEM_OPENVMS) | (1 << wxZIP_SYSTEM_OPENVMS) |
@@ -492,7 +492,7 @@ bool wxZipEntry::IsMadeByUnix() const
|| ((pattern >> m_SystemMadeBy) & 1); || ((pattern >> m_SystemMadeBy) & 1);
} }
void wxZipEntry::SetIsText(bool isText) inline void wxZipEntry::SetIsText(bool isText)
{ {
if (isText) if (isText)
m_InternalAttributes |= TEXT_ATTR; m_InternalAttributes |= TEXT_ATTR;
@@ -500,7 +500,7 @@ void wxZipEntry::SetIsText(bool isText)
m_InternalAttributes &= ~TEXT_ATTR; m_InternalAttributes &= ~TEXT_ATTR;
} }
void wxZipEntry::SetIsReadOnly(bool isReadOnly) inline void wxZipEntry::SetIsReadOnly(bool isReadOnly)
{ {
if (isReadOnly) if (isReadOnly)
SetMode(GetMode() & ~0222); SetMode(GetMode() & ~0222);
@@ -508,8 +508,8 @@ void wxZipEntry::SetIsReadOnly(bool isReadOnly)
SetMode(GetMode() | 0200); SetMode(GetMode() | 0200);
} }
void wxZipEntry::SetName(const wxString& name, inline void wxZipEntry::SetName(const wxString& name,
wxPathFormat format /*=wxPATH_NATIVE*/) wxPathFormat format /*=wxPATH_NATIVE*/)
{ {
bool isDir; bool isDir;
m_Name = GetInternalName(name, format, &isDir); m_Name = GetInternalName(name, format, &isDir);

View File

@@ -65,9 +65,9 @@ void wxArchiveEntry::SetNotifier(wxArchiveNotifier& notifier)
m_notifier->OnEntryUpdated(*this); m_notifier->OnEntryUpdated(*this);
} }
wxArchiveEntry& wxArchiveEntry::operator=(const wxArchiveEntry& entry) wxArchiveEntry& wxArchiveEntry::operator=(const wxArchiveEntry& WXUNUSED(e))
{ {
m_notifier = entry.m_notifier; m_notifier = NULL;
return *this; return *this;
} }

View File

@@ -622,7 +622,8 @@ wxZipEntry::~wxZipEntry()
} }
wxZipEntry::wxZipEntry(const wxZipEntry& e) wxZipEntry::wxZipEntry(const wxZipEntry& e)
: m_SystemMadeBy(e.m_SystemMadeBy), : wxArchiveEntry(e),
m_SystemMadeBy(e.m_SystemMadeBy),
m_VersionMadeBy(e.m_VersionMadeBy), m_VersionMadeBy(e.m_VersionMadeBy),
m_VersionNeeded(e.m_VersionNeeded), m_VersionNeeded(e.m_VersionNeeded),
m_Flags(e.m_Flags), m_Flags(e.m_Flags),
@@ -640,7 +641,7 @@ wxZipEntry::wxZipEntry(const wxZipEntry& e)
m_ExternalAttributes(e.m_ExternalAttributes), m_ExternalAttributes(e.m_ExternalAttributes),
m_Extra(AddRef(e.m_Extra)), m_Extra(AddRef(e.m_Extra)),
m_LocalExtra(AddRef(e.m_LocalExtra)), m_LocalExtra(AddRef(e.m_LocalExtra)),
m_zipnotifier(e.m_zipnotifier), m_zipnotifier(NULL),
m_backlink(NULL) m_backlink(NULL)
{ {
} }
@@ -666,7 +667,7 @@ wxZipEntry& wxZipEntry::operator=(const wxZipEntry& e)
m_ExternalAttributes = e.m_ExternalAttributes; m_ExternalAttributes = e.m_ExternalAttributes;
Copy(m_Extra, e.m_Extra); Copy(m_Extra, e.m_Extra);
Copy(m_LocalExtra, e.m_LocalExtra); Copy(m_LocalExtra, e.m_LocalExtra);
m_zipnotifier = e.m_zipnotifier; m_zipnotifier = NULL;
if (m_backlink) { if (m_backlink) {
m_backlink->Release(m_Key); m_backlink->Release(m_Key);
m_backlink = NULL; m_backlink = NULL;

View File

@@ -21,9 +21,9 @@
#define WX_TEST_ARCHIVE_ITERATOR #define WX_TEST_ARCHIVE_ITERATOR
// This sample uses some advanced typedef syntax that messes // VC++ 6 warns that the list iterator's '->' operator will not work whenever
// up MSVC 6 - turn off its warning about it // std::list is used with a non-pointer, so switch it off.
#if defined _MSC_VER #if defined _MSC_VER && _MSC_VER < 1300
#pragma warning (disable:4284) #pragma warning (disable:4284)
#endif #endif
@@ -114,7 +114,7 @@ class TestEntry
{ {
public: public:
TestEntry(const wxDateTime& dt, int len, const char *data); TestEntry(const wxDateTime& dt, int len, const char *data);
~TestEntry() { delete [] (char*) m_data; } ~TestEntry() { delete [] m_data; }
wxDateTime GetDateTime() const { return m_dt; } wxDateTime GetDateTime() const { return m_dt; }
wxFileOffset GetLength() const { return m_len; } wxFileOffset GetLength() const { return m_len; }
@@ -129,7 +129,7 @@ public:
private: private:
wxDateTime m_dt; wxDateTime m_dt;
size_t m_len; size_t m_len;
const char *m_data; char *m_data;
wxString m_comment; wxString m_comment;
bool m_isText; bool m_isText;
}; };
@@ -139,9 +139,8 @@ TestEntry::TestEntry(const wxDateTime& dt, int len, const char *data)
m_len(len), m_len(len),
m_isText(len > 0) m_isText(len > 0)
{ {
char *d = new char[len]; m_data = new char[len];
memcpy(d, data, len); memcpy(m_data, data, len);
m_data = d;
for (int i = 0; i < len && m_isText; i++) for (int i = 0; i < len && m_isText; i++)
m_isText = (signed char)m_data[i] > 0; m_isText = (signed char)m_data[i] > 0;
@@ -163,7 +162,7 @@ public:
wxFileOffset GetLength() const { return m_size; } wxFileOffset GetLength() const { return m_size; }
// gives away the data, this stream is then empty, and can be reused // gives away the data, this stream is then empty, and can be reused
void GetData(const char*& data, size_t& size); void GetData(char*& data, size_t& size);
enum { STUB_SIZE = 2048, INITIAL_SIZE = 0x18000, SEEK_LIMIT = 0x100000 }; enum { STUB_SIZE = 2048, INITIAL_SIZE = 0x18000, SEEK_LIMIT = 0x100000 };
@@ -256,7 +255,7 @@ size_t TestOutputStream::OnSysWrite(const void *buffer, size_t size)
return size; return size;
} }
void TestOutputStream::GetData(const char*& data, size_t& size) void TestOutputStream::GetData(char*& data, size_t& size)
{ {
data = m_data; data = m_data;
size = m_size; size = m_size;
@@ -289,7 +288,7 @@ public:
TestInputStream(TestOutputStream& out) : m_data(NULL) { SetData(out); } TestInputStream(TestOutputStream& out) : m_data(NULL) { SetData(out); }
// this ctor 'dups' // this ctor 'dups'
TestInputStream(const TestInputStream& in); TestInputStream(const TestInputStream& in);
~TestInputStream() { delete [] (char*) m_data; } ~TestInputStream() { delete [] m_data; }
void Rewind(); void Rewind();
wxFileOffset GetLength() const { return m_size; } wxFileOffset GetLength() const { return m_size; }
@@ -303,7 +302,7 @@ private:
int m_options; int m_options;
size_t m_pos; size_t m_pos;
size_t m_size; size_t m_size;
const char *m_data; char *m_data;
}; };
TestInputStream::TestInputStream(const TestInputStream& in) TestInputStream::TestInputStream(const TestInputStream& in)
@@ -311,9 +310,8 @@ TestInputStream::TestInputStream(const TestInputStream& in)
m_pos(in.m_pos), m_pos(in.m_pos),
m_size(in.m_size) m_size(in.m_size)
{ {
char *p = new char[m_size]; m_data = new char[m_size];
memcpy(p, in.m_data, m_size); memcpy(m_data, in.m_data, m_size);
m_data = p;
} }
void TestInputStream::Rewind() void TestInputStream::Rewind()
@@ -333,7 +331,7 @@ void TestInputStream::Rewind()
void TestInputStream::SetData(TestOutputStream& out) void TestInputStream::SetData(TestOutputStream& out)
{ {
delete [] (char*) m_data; delete [] m_data;
m_options = out.GetOptions(); m_options = out.GetOptions();
out.GetData(m_data, m_size); out.GetData(m_data, m_size);
Rewind(); Rewind();
@@ -734,7 +732,7 @@ TestEntry& ArchiveTestCase<Classes>::Add(const char *name,
{ {
wxCharBuffer buf(len); wxCharBuffer buf(len);
for (int i = 0; i < len; i++) for (int i = 0; i < len; i++)
buf.data()[i] = value == EOF ? rand() : value; buf.data()[i] = (char)(value == EOF ? rand() : value);
return Add(name, buf, len); return Add(name, buf, len);
} }
@@ -884,7 +882,7 @@ void ArchiveTestCase<Classes>::ModifyArchive(wxInputStream& in,
{ {
auto_ptr<InputStreamT> arcIn(m_factory->NewStream(in)); auto_ptr<InputStreamT> arcIn(m_factory->NewStream(in));
auto_ptr<OutputStreamT> arcOut(m_factory->NewStream(out)); auto_ptr<OutputStreamT> arcOut(m_factory->NewStream(out));
; EntryT *pEntry;
const wxString deleteName = _T("bin/bin1000"); const wxString deleteName = _T("bin/bin1000");
const wxString renameFrom = _T("zero/zero1024"); const wxString renameFrom = _T("zero/zero1024");
@@ -894,14 +892,10 @@ void ArchiveTestCase<Classes>::ModifyArchive(wxInputStream& in,
arcOut->CopyArchiveMetaData(*arcIn); arcOut->CopyArchiveMetaData(*arcIn);
auto_ptr<EntryT>* pEntry; while ((pEntry = arcIn->GetNextEntry()) != NULL) {
auto_ptr<EntryT> entry(pEntry);
for (pEntry = new auto_ptr<EntryT>(arcIn->GetNextEntry()) ; OnSetNotifier(*entry);
pEntry->get() != NULL ; wxString name = entry->GetName(wxPATH_UNIX);
delete pEntry, pEntry = new auto_ptr<EntryT>(arcIn->GetNextEntry()))
{
OnSetNotifier(**pEntry);
wxString name = (*pEntry)->GetName(wxPATH_UNIX);
// provide some context for the error message so that we know which // provide some context for the error message so that we know which
// iteration of the loop we were on // iteration of the loop we were on
@@ -919,7 +913,7 @@ void ArchiveTestCase<Classes>::ModifyArchive(wxInputStream& in,
} }
else { else {
if (name == renameFrom) { if (name == renameFrom) {
(*pEntry)->SetName(renameTo); entry->SetName(renameTo);
TestEntries::iterator it = m_testEntries.find(renameFrom); TestEntries::iterator it = m_testEntries.find(renameFrom);
CPPUNIT_ASSERT_MESSAGE( CPPUNIT_ASSERT_MESSAGE(
"rename failed (already renamed?) for" + error_entry, "rename failed (already renamed?) for" + error_entry,
@@ -930,12 +924,10 @@ void ArchiveTestCase<Classes>::ModifyArchive(wxInputStream& in,
} }
CPPUNIT_ASSERT_MESSAGE("CopyEntry" + error_context, CPPUNIT_ASSERT_MESSAGE("CopyEntry" + error_context,
arcOut->CopyEntry(pEntry->release(), *arcIn)); arcOut->CopyEntry(entry.release(), *arcIn));
} }
} }
delete pEntry;
// check that the deletion and rename were done // check that the deletion and rename were done
CPPUNIT_ASSERT(m_testEntries.count(deleteName) == 0); CPPUNIT_ASSERT(m_testEntries.count(deleteName) == 0);
CPPUNIT_ASSERT(m_testEntries.count(renameFrom) == 0); CPPUNIT_ASSERT(m_testEntries.count(renameFrom) == 0);
@@ -1141,7 +1133,7 @@ void ArchiveTestCase<Classes>::VerifyDir(wxString& path, size_t rootlen /*=0*/)
CPPUNIT_ASSERT_MESSAGE( CPPUNIT_ASSERT_MESSAGE(
"entry not found in archive" + error_entry, in.Ok()); "entry not found in archive" + error_entry, in.Ok());
size_t size = in.GetLength(); size_t size = (size_t)in.GetLength();
wxCharBuffer buf(size); wxCharBuffer buf(size);
CPPUNIT_ASSERT_MESSAGE("Read" + error_context, CPPUNIT_ASSERT_MESSAGE("Read" + error_context,
in.Read(buf.data(), size).LastRead() == size); in.Read(buf.data(), size).LastRead() == size);
@@ -1248,6 +1240,11 @@ void ArchiveTestCase<Classes>::TestSmartIterator(wxInputStream& in)
template <class Classes> template <class Classes>
void ArchiveTestCase<Classes>::TestSmartPairIterator(wxInputStream& in) void ArchiveTestCase<Classes>::TestSmartPairIterator(wxInputStream& in)
{ {
#if defined _MSC_VER && defined _MSC_VER < 1200
// With VC++ 5.0 the '=' operator of std::pair breaks when the second
// type is Ptr<EntryT>, so this iterator can't be made to work.
(void)in;
#else
typedef std::map<wxString, Ptr<EntryT> > ArchiveCatalog; typedef std::map<wxString, Ptr<EntryT> > ArchiveCatalog;
typedef typename ArchiveCatalog::iterator CatalogIter; typedef typename ArchiveCatalog::iterator CatalogIter;
typedef wxArchiveIterator<InputStreamT, typedef wxArchiveIterator<InputStreamT,
@@ -1267,6 +1264,7 @@ void ArchiveTestCase<Classes>::TestSmartPairIterator(wxInputStream& in)
for (CatalogIter it = cat.begin(); it != cat.end(); ++it) for (CatalogIter it = cat.begin(); it != cat.end(); ++it)
CPPUNIT_ASSERT(m_testEntries.count(it->second->GetName(wxPATH_UNIX))); CPPUNIT_ASSERT(m_testEntries.count(it->second->GetName(wxPATH_UNIX)));
#endif
} }
// try reading two entries at the same time // try reading two entries at the same time

View File

@@ -155,7 +155,9 @@ void TestApp::List(Test *test, const string& parent /*=""*/) const
// take the last component of the name and append to the parent // take the last component of the name and append to the parent
name = test->getName(); name = test->getName();
string::size_type i = name.find_last_of(".:"); string::size_type i = name.find_last_of(".:");
name = parent + "." + (i != string::npos ? name.substr(i + 1) : name); if (i != string::npos)
name = name.substr(i + 1);
name = parent + "." + name;
// drop the 1st component from the display and indent // drop the 1st component from the display and indent
if (parent != "") { if (parent != "") {