/[pcsx2_0.9.7]/trunk/pcsx2/GameDatabase.cpp
ViewVC logotype

Contents of /trunk/pcsx2/GameDatabase.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 62 - (show annotations) (download)
Tue Sep 7 11:08:22 2010 UTC (9 years, 9 months ago) by william
File size: 4063 byte(s)
Auto Commited Import of: pcsx2-0.9.7-r3738-debug in ./trunk
1 /* PCSX2 - PS2 Emulator for PCs
2 * Copyright (C) 2002-2010 PCSX2 Dev Team
3 *
4 * PCSX2 is free software: you can redistribute it and/or modify it under the terms
5 * of the GNU Lesser General Public License as published by the Free Software Found-
6 * ation, either version 3 of the License, or (at your option) any later version.
7 *
8 * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10 * PURPOSE. See the GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along with PCSX2.
13 * If not, see <http://www.gnu.org/licenses/>.
14 */
15
16 #include "PrecompiledHeader.h"
17 #include "GameDatabase.h"
18
19 BaseGameDatabaseImpl::BaseGameDatabaseImpl()
20 : gHash( 9400 )
21 , m_baseKey( L"Serial" )
22 {
23 m_BlockTable.reserve(48);
24
25 m_CurBlockWritePos = 0;
26 m_BlockTableWritePos = 0;
27
28 m_GamesPerBlock = 256;
29
30 m_BlockTable.push_back(NULL);
31 }
32
33 BaseGameDatabaseImpl::~BaseGameDatabaseImpl() throw()
34 {
35 for(uint blockidx=0; blockidx<=m_BlockTableWritePos; ++blockidx)
36 {
37 if( !m_BlockTable[blockidx] ) continue;
38
39 const uint endidx = (blockidx == m_BlockTableWritePos) ? m_CurBlockWritePos : m_GamesPerBlock;
40
41 for( uint gameidx=0; gameidx<endidx; ++gameidx )
42 m_BlockTable[blockidx][gameidx].~Game_Data();
43
44 safe_free( m_BlockTable[blockidx] );
45 }
46 }
47
48 // Sets the current game to the one matching the serial id given
49 // Returns true if game found, false if not found...
50 bool BaseGameDatabaseImpl::findGame(Game_Data& dest, const wxString& id) {
51
52 GameDataHash::const_iterator iter( gHash.find(id) );
53 if( iter == gHash.end() ) {
54 dest.clear();
55 return false;
56 }
57 dest = *iter->second;
58 return true;
59 }
60
61 Game_Data* BaseGameDatabaseImpl::createNewGame( const wxString& id )
62 {
63 if(!m_BlockTable[m_BlockTableWritePos])
64 m_BlockTable[m_BlockTableWritePos] = (Game_Data*)malloc(m_GamesPerBlock * sizeof(Game_Data));
65
66 Game_Data* block = m_BlockTable[m_BlockTableWritePos];
67 Game_Data* retval = &block[m_CurBlockWritePos];
68
69 gHash[id] = retval;
70
71 new (retval) Game_Data(id);
72
73 if( ++m_CurBlockWritePos >= m_GamesPerBlock )
74 {
75 ++m_BlockTableWritePos;
76 m_CurBlockWritePos = 0;
77 m_BlockTable.push_back(NULL);
78 }
79
80 return retval;
81 }
82
83 void BaseGameDatabaseImpl::updateGame(const Game_Data& game)
84 {
85 GameDataHash::const_iterator iter( gHash.find(game.id) );
86
87 if( iter == gHash.end() ) {
88 *(createNewGame( game.id )) = game;
89 }
90 else
91 {
92 // Re-assign existing vector/array entry!
93 *gHash[game.id] = game;
94 }
95 }
96
97 // Searches the current game's data to see if the given key exists
98 bool Game_Data::keyExists(const wxChar* key) const {
99 KeyPairArray::const_iterator it( kList.begin() );
100 for ( ; it != kList.end(); ++it) {
101 if (it->CompareKey(key)) {
102 return true;
103 }
104 }
105 return false;
106 }
107
108 // Totally Deletes the specified key/pair value from the current game's data
109 void Game_Data::deleteKey(const wxChar* key) {
110 KeyPairArray::iterator it( kList.begin() );
111 for ( ; it != kList.end(); ++it) {
112 if (it->CompareKey(key)) {
113 kList.erase(it);
114 return;
115 }
116 }
117 }
118
119 // Gets a string representation of the 'value' for the given key
120 wxString Game_Data::getString(const wxChar* key) const {
121 KeyPairArray::const_iterator it( kList.begin() );
122 for ( ; it != kList.end(); ++it) {
123 if (it->CompareKey(key)) {
124 return it->value;
125 }
126 }
127 return wxString();
128 }
129
130 void Game_Data::writeString(const wxString& key, const wxString& value) {
131 KeyPairArray::iterator it( kList.begin() );
132 for ( ; it != kList.end(); ++it) {
133 if (it->CompareKey(key)) {
134 if( value.IsEmpty() )
135 kList.erase(it);
136 else
137 it->value = value;
138 return;
139 }
140 }
141 if( !value.IsEmpty() ) {
142 kList.push_back(key_pair(key, value));
143 }
144 }
145
146 // Write a bool value to the specified key
147 void Game_Data::writeBool(const wxString& key, bool value) {
148 writeString(key, value ? L"1" : L"0");
149 }

  ViewVC Help
Powered by ViewVC 1.1.22