Changeset 447 for trunk/includes/dbc.php
- Timestamp:
- Apr 12, 2010, 8:42:44 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/dbc.php
r443 r447 1 1 <?php 2 2 3 include('stream.php'); 3 include_once('FileStream.php'); 4 include_once('MemoryStream.php'); 4 5 5 6 define('NOT_DBC_FILE', 'Není DBC soubor.'); … … 97 98 } 98 99 99 private function SeekPosi($Row, $Column) 100 { 101 $Position = $this->HeaderSize + $Row * $this->RecordSize + $this->Offsets[$Column]; 102 $this->Seek($Position); 100 private function CellPos($Row, $Column) 101 { 102 return($this->HeaderSize + $Row * $this->RecordSize + $this->Offsets[$Column]); 103 103 } 104 104 105 105 public function GetByte($Row, $Column) 106 106 { 107 $this->Se ekPosi($Row, $Column);107 $this->SetPosition($this->CellPos($Row, $Column)); 108 108 return($this->ReadByte()); 109 109 } … … 111 111 public function GetUInt($Row, $Column) 112 112 { 113 $this->Se ekPosi($Row, $Column);113 $this->SetPosition($this->CellPos($Row, $Column)); 114 114 return($this->ReadUint()); 115 115 } … … 117 117 public function GetInt($Row, $Column) 118 118 { 119 $this->Se ekPosi($Row, $Column);119 $this->SetPosition($this->CellPos($Row, $Column)); 120 120 return($this->ReadInt()); 121 121 } … … 123 123 public function GetFloat($Row, $Column) 124 124 { 125 $this->Se ekPosi($Row, $Column);125 $this->SetPosition($this->CellPos($Row, $Column)); 126 126 return($this->ReadFloat()); 127 127 } … … 129 129 public function SetByte($Row, $Column, $Value) 130 130 { 131 $this->Se ekPosi($Row, $Column);131 $this->SetPosition($this->CellPos($Row, $Column)); 132 132 $this->WriteByte($Value); 133 133 } … … 135 135 public function SetUint($Row, $Column, $Value) 136 136 { 137 $this->Se ekPosi($Row, $Column);137 $this->SetPosition($this->CellPos($Row, $Column)); 138 138 $this->WriteUint($Value); 139 139 } … … 141 141 public function SetInt($Row, $Column, $Value) 142 142 { 143 $this->Se ekPosi($Row, $Column);143 $this->SetPosition($this->CellPos($Row, $Column)); 144 144 $this->WriteInt($Value); 145 145 } … … 147 147 public function SetFloat($Row, $Column, $Value) 148 148 { 149 $this->Se ekPosi($Row, $Column);149 $this->SetPosition($this->CellPos($Row, $Column)); 150 150 $this->WriteFloat($Value); 151 151 } … … 157 157 $Position = $this->HeaderSize + $this->RecordCount * $this->RecordSize + $Offset; 158 158 if($Position >= $this->GetSize()) return(''); 159 $this->Se ek($Position);159 $this->SetPosition($Position); 160 160 161 161 $String = ''; … … 184 184 { 185 185 $this->SetSize($this->HeaderSize + $this->RecordSize * $this->RecordCount); // Preallocate file 186 $this->Se ek(0);186 $this->SetPosition(0); 187 187 $this->WriteUint(DBC_SIGNATURE); 188 188 $this->WriteUint($this->RecordCount); … … 190 190 $this->WriteUint($this->RecordSize); 191 191 $this->WriteUint($this->StringOffset); 192 $this->Se ek($this->HeaderSize + $this->RecordCount * $this->RecordSize);192 $this->SetPosition($this->HeaderSize + $this->RecordCount * $this->RecordSize); 193 193 $this->WriteByte(0); 194 194 foreach($this->StringList as $Index => $Item) … … 200 200 public function GetLine($Row) 201 201 { 202 // Cache record data 203 $Record = new MemoryStream(); 204 $this->SetPosition($this->CellPos($Row, 0)); 205 $Record->Data = $this->ReadBlock($this->RecordSize); 206 202 207 // Preallocate array 203 208 if($this->FieldCount > 0) $Line = array_fill(0, $this->FieldCount, 0); … … 207 212 if(array_key_exists($I, $this->ColumnFormat)) $Format = $this->ColumnFormat[$I]; 208 213 else $Format = FORMAT_UINT32; 214 $Record->SetPosition($this->Offsets[$I]); 209 215 switch($Format) 210 216 { 211 217 case FORMAT_BYTE: 212 $Line[$I] = $ this->GetByte($Row, $I);218 $Line[$I] = $Record->ReadByte(); 213 219 break; 214 220 case FORMAT_UINT32: 215 $Line[$I] = $ this->GetUInt($Row, $I);221 $Line[$I] = $Record->ReadUInt(); 216 222 break; 217 223 case FORMAT_SINT32: 218 $Line[$I] = $ this->GetInt($Row, $I);224 $Line[$I] = $Record->ReadInt(); 219 225 break; 220 226 case FORMAT_SINGLE: 221 $Line[$ i] = $this->GetFloat($Row, $I);227 $Line[$I] = $Record->ReadFloat(); 222 228 break; 223 229 case FORMAT_STRING: 224 $Line[$I] = $this->GetString($Row, $I); 230 $Offset = $Record->ReadUint(); 231 232 $Position = $this->HeaderSize + $this->RecordCount * $this->RecordSize + $Offset; 233 if($Position >= $this->GetSize()) $String = ''; 234 else 235 { 236 $this->SetPosition($Position); 237 $String = ''; 238 while(($Char = $this->ReadChar()) != "\0") 239 $String .= $Char; 240 } 241 $Line[$I] = $String; 225 242 break; 226 243 default: … … 233 250 public function SetLine($Row, $Line) 234 251 { 252 // Cache record data 253 $Record = new MemoryStream(); 254 235 255 for($I = 0; $I < $this->FieldCount; $I++) 236 256 { 237 257 if(array_key_exists($I, $this->ColumnFormat)) $Format = $this->ColumnFormat[$I]; 238 258 else $Format = FORMAT_UINT32; 259 $Record->SetPosition($this->Offsets[$I]); 239 260 switch($Format) 240 261 { 241 262 case FORMAT_BYTE: 242 $ this->SetByte($Row, $I,$Line[$I]);263 $Record->WriteByte($Line[$I]); 243 264 break; 244 265 case FORMAT_UINT32: 245 $ this->SetUint($Row, $I,$Line[$I]);266 $Record->WriteUint($Line[$I]); 246 267 break; 247 268 case FORMAT_SINT32: 248 $ this->SetInt($Row, $I,$Line[$I]);269 $Record->WriteInt($Line[$I]); 249 270 break; 250 271 case FORMAT_SINGLE: 251 $ this->SetFloat($Row, $I, $Line[$i]);272 $Record->WriteFloat($Line[$I]); 252 273 break; 253 274 case FORMAT_STRING: 254 $this->SetString($Row, $I, $Line[$I]); 275 if(in_array($Line[$I], $this->StringList)) 276 { 277 $Record->WriteUint($this->StringListOffset[array_search($Line[$I], $this->StringList)]); 278 } else 279 { 280 $Record->WriteUint($this->StringOffset); 281 $this->StringList[] = $Line[$I]; 282 $this->StringListOffset[] = $this->StringOffset; 283 $this->StringOffset += strlen($Line[$I]) + 1; 284 } 255 285 break; 256 286 default: … … 258 288 } 259 289 } 290 291 $this->SetPosition($this->CellPos($Row, 0)); 292 $this->WriteBlock($Record->Data, $this->RecordSize); 260 293 return($Line); 261 } 262 263 public function GetLineCols($Row, $Columns) 264 { 265 // Preallocate array 266 if(count($Columns) > 0) $Line = array_fill(0, count($Columns), 0); 267 else $Line = array(); 268 for($I = 0; $I < count($Columns); $I++) 269 { 270 if(array_key_exists($I, $this->ColumnFormat)) $Format = $this->ColumnFormat[$I]; 271 else $Format = FORMAT_UINT32; 272 switch($Format) 273 { 274 case FORMAT_BYTE: 275 $Line[$I] = $this->GetByte($Row, $Columns[$I]); 276 break; 277 case FORMAT_UINT32: 278 $Line[$I] = $this->GetUint($Row, $Columns[$I]); 279 break; 280 case FORMAT_SINT32: 281 $Line[$I] = $this->GetInt($Row, $Columns[$I]); 282 break; 283 case FORMAT_SINGLE: 284 $Line[$i] = $this->GetFloat($Row, $Columns[$I]); 285 break; 286 case FORMAT_STRING: 287 $Line[$I] = $this->GetString($Row, $Columns[$I]); 288 break; 289 default: 290 break; 291 } 292 } 293 return($Line); 294 } 294 } 295 295 296 296 public function GetRecordCount()
Note:
See TracChangeset
for help on using the changeset viewer.