From 8244efcc02b1aed06214bc58e5503ca5d68b4e63 Mon Sep 17 00:00:00 2001 From: NeoBrainX Date: Sat, 11 Jun 2011 19:37:21 +0000 Subject: Revert r7421 and r7422. Should fix issue 4413. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7592 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/LinearDiskCache.h | 45 ++++++++++++++++---------------- 1 file changed, 22 insertions(+), 23 deletions(-) (limited to 'Source/Core/Common') diff --git a/Source/Core/Common/Src/LinearDiskCache.h b/Source/Core/Common/Src/LinearDiskCache.h index 6ead5a8b7f..7a124aaa7b 100644 --- a/Source/Core/Common/Src/LinearDiskCache.h +++ b/Source/Core/Common/Src/LinearDiskCache.h @@ -20,7 +20,6 @@ #include "Common.h" #include -#include // Update this to the current SVN revision every time you change shader generation code. // We don't automatically get this from SVN_REV because that would mean regenerating the @@ -44,15 +43,12 @@ enum // value_type[value_size] value; //} -// Example reader: -// -//class LinearDiskCacheReader -//{ -//public: -// template -// void operator()(const K& key, u32 value_size, F get_data) const -// {...} -//}; +template +class LinearDiskCacheReader +{ +public: + virtual void Read(const K &key, const V *value, u32 value_size) = 0; +}; // Dead simple unsorted key-value store with append functionality. // No random read functionality, all reading is done in OpenAndRead. @@ -71,45 +67,48 @@ class LinearDiskCache { public: // return number of read entries - template - u32 OpenAndRead(const char* filename, LinearDiskCacheReader& reader) + u32 OpenAndRead(const char *filename, LinearDiskCacheReader &reader) { - using std::ios; + using std::ios_base; // close any currently opened file Close(); // try opening for reading/writing - m_file.open(filename, ios::in | ios::out | ios::binary | ios::app); + m_file.open(filename, ios_base::in | ios_base::out | ios_base::binary | ios_base::app); if (m_file.is_open() && ValidateHeader()) { // good header, read some key/value pairs u32 num_entries = 0; + K key; + V *value = NULL; u32 value_size; - K key; - while (Read(&value_size) && Read(&key)) - { - std::streamoff const pos = m_file.tellg(); - // pass key and value_size to reader with callback function to read the data - reader(key, value_size, [this, &value_size](V* data){ Read(data, value_size); }); + while (Read(&value_size)) + { + delete[] value; + value = new V[value_size]; - // seek past data (in case reader didn't read it for whatever reason) - m_file.seekg(pos + (value_size * sizeof(V)), ios::beg); + // read key/value and pass to reader + if (Read(&key) && Read(value, value_size)) + reader.Read(key, value, value_size); + else + break; ++num_entries; } m_file.clear(); + delete[] value; return num_entries; } // failed to open file for reading or bad header // close and recreate file Close(); - m_file.open(filename, ios::out | ios::trunc | ios::binary); + m_file.open(filename, ios_base::out | ios_base::trunc | ios_base::binary); WriteHeader(); return 0; } -- cgit v1.2.3