Changeset 815 for trunk/includes/dbc.php


Ignore:
Timestamp:
Feb 22, 2015, 11:05:49 PM (9 years ago)
Author:
chronos
Message:
  • Remove: Trailing spaces from end of lines from all files.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/dbc.php

    r553 r815  
    2424  private $ColumnFormat; // Array (Index => Type)
    2525  private $EndOffset; // Calculated RecordSize according columns type
    26    
     26
    2727  private $RecordSize;
    2828  private $RecordCount;
    2929  private $StringBlockSize;
    3030  private $FieldCount;
    31      
     31
    3232  public function OpenFile($FileName, $ColumnFormat = array())
    3333  {
    3434    parent::OpenFile($FileName);
    35    
     35
    3636    $this->ColumnFormat = $ColumnFormat;
    3737    if($this->ReadUint() != DBC_SIGNATURE) die(NOT_DBC_FILE);
    38        
     38
    3939    $this->RecordCount = $this->ReadUint();
    4040    $this->FieldCount = $this->ReadUint();
    4141    $this->RecordSize = $this->ReadUint();
    4242    $this->StringBlockSize = $this->ReadUint();
    43      
     43
    4444    $this->GenerateOffsetTable();
    4545    if($this->EndOffset != $this->RecordSize)
    46     die(RECORD_SIZE_NOT_MATCH.$this->EndOffset.' <> '.$this->RecordSize); 
     46    die(RECORD_SIZE_NOT_MATCH.$this->EndOffset.' <> '.$this->RecordSize);
    4747  }
    4848
     
    5050  {
    5151    parent::CreateFile($FileName);
    52    
     52
    5353    $this->WriteUint(DBC_SIGNATURE);
    54        
     54
    5555    $this->StringList = array();
    5656    $this->StringOffset = 1;
     
    6565    $this->WriteUint($this->FieldCount);
    6666    $this->WriteUint($this->RecordSize);
    67     $this->WriteUint($this->StringBlockSize);         
    68   }
    69    
     67    $this->WriteUint($this->StringBlockSize);
     68  }
     69
    7070  private function GenerateOffsetTable()
    7171  {
    7272    // Preallocate array
    73     if($this->FieldCount > 0) $this->Offsets = array_fill(0, $this->FieldCount, 0); 
     73    if($this->FieldCount > 0) $this->Offsets = array_fill(0, $this->FieldCount, 0);
    7474      else $this->Offsets = array();
    75    
     75
    7676    $Offset = 0;
    7777    $I = 0;
     
    8383      switch($Format)
    8484      {
    85         case FORMAT_BYTE: 
    86           $Offset += 1; 
    87           break;
    88         case FORMAT_UINT32: 
    89         case FORMAT_SINT32: 
    90         case FORMAT_SINGLE: 
    91         case FORMAT_STRING: 
    92           $Offset += 4; 
    93           break;
    94       } 
     85        case FORMAT_BYTE:
     86          $Offset += 1;
     87          break;
     88        case FORMAT_UINT32:
     89        case FORMAT_SINT32:
     90        case FORMAT_SINGLE:
     91        case FORMAT_STRING:
     92          $Offset += 4;
     93          break;
     94      }
    9595      $I++;
    96     }   
     96    }
    9797    $this->EndOffset = $Offset;
    9898  }
    99  
     99
    100100  private function CellPos($Row, $Column)
    101101  {
    102102    return($this->HeaderSize + $Row * $this->RecordSize + $this->Offsets[$Column]);
    103103  }
    104    
     104
    105105  public function GetByte($Row, $Column)
    106106  {
    107     $this->SetPosition($this->CellPos($Row, $Column)); 
     107    $this->SetPosition($this->CellPos($Row, $Column));
    108108    return($this->ReadByte());
    109   }   
    110    
     109  }
     110
    111111  public function GetUInt($Row, $Column)
    112112  {
    113     $this->SetPosition($this->CellPos($Row, $Column)); 
     113    $this->SetPosition($this->CellPos($Row, $Column));
    114114    return($this->ReadUint());
    115115  }
    116    
     116
    117117  public function GetInt($Row, $Column)
    118118  {
    119     $this->SetPosition($this->CellPos($Row, $Column)); 
     119    $this->SetPosition($this->CellPos($Row, $Column));
    120120    return($this->ReadInt());
    121   } 
    122    
     121  }
     122
    123123  public function GetFloat($Row, $Column)
    124124  {
    125     $this->SetPosition($this->CellPos($Row, $Column)); 
     125    $this->SetPosition($this->CellPos($Row, $Column));
    126126    return($this->ReadFloat());
    127127  }
     
    129129  public function SetByte($Row, $Column, $Value)
    130130  {
    131     $this->SetPosition($this->CellPos($Row, $Column)); 
     131    $this->SetPosition($this->CellPos($Row, $Column));
    132132    $this->WriteByte($Value);
    133   }   
    134    
     133  }
     134
    135135  public function SetUint($Row, $Column, $Value)
    136136  {
    137     $this->SetPosition($this->CellPos($Row, $Column)); 
     137    $this->SetPosition($this->CellPos($Row, $Column));
    138138    $this->WriteUint($Value);
    139139  }
    140    
     140
    141141  public function SetInt($Row, $Column, $Value)
    142142  {
    143     $this->SetPosition($this->CellPos($Row, $Column)); 
     143    $this->SetPosition($this->CellPos($Row, $Column));
    144144    $this->WriteInt($Value);
    145   } 
    146    
     145  }
     146
    147147  public function SetFloat($Row, $Column, $Value)
    148148  {
    149     $this->SetPosition($this->CellPos($Row, $Column)); 
     149    $this->SetPosition($this->CellPos($Row, $Column));
    150150    $this->WriteFloat($Value);
    151151  }
    152  
     152
    153153  public function GetString($Row, $Column)
    154154  {
    155155    $Offset = $this->GetUint($Row, $Column);
    156    
     156
    157157    $Position = $this->HeaderSize + $this->RecordCount * $this->RecordSize + $Offset;
    158158    if($Position >= $this->GetSize()) return('');
    159159    $this->SetPosition($Position);
    160      
     160
    161161    $String = '';
    162162    while(($Char = $this->ReadChar()) != "\0")
     
    165165    }
    166166    return($String);
    167   }   
    168  
     167  }
     168
    169169  public function SetString($Row, $Column, $Value)
    170170  {
    171171    if(in_array($Value, $this->StringList))
    172     { 
     172    {
    173173      $this->SetUint($Row, $Column, $this->StringListOffset[array_search($Value, $this->StringList)]);
    174     } else 
     174    } else
    175175    {
    176176      $this->SetUint($Row, $Column, $this->StringOffset);
     
    189189    $this->WriteUint($this->FieldCount);
    190190    $this->WriteUint($this->RecordSize);
    191     $this->WriteUint($this->StringOffset);         
     191    $this->WriteUint($this->StringOffset);
    192192    $this->SetPosition($this->HeaderSize + $this->RecordCount * $this->RecordSize);
    193193    $this->WriteByte(0);
    194194    foreach($this->StringList as $Index => $Item)
    195     {   
     195    {
    196196      $this->WriteString($Item."\0");
    197197    }
    198   }   
    199    
     198  }
     199
    200200  public function GetLine($Row)
    201201  {
     
    204204    $this->SetPosition($this->CellPos($Row, 0));
    205205    $Record->Data = $this->ReadBlock($this->RecordSize);
    206    
     206
    207207    // Preallocate array
    208     if($this->FieldCount > 0) $Line = array_fill(0, $this->FieldCount, 0); 
     208    if($this->FieldCount > 0) $Line = array_fill(0, $this->FieldCount, 0);
    209209      else $Line = array();
    210210    for($I = 0; $I < $this->FieldCount; $I++)
     
    212212      if(array_key_exists($I, $this->ColumnFormat)) $Format = $this->ColumnFormat[$I];
    213213        else $Format = FORMAT_UINT32;
    214       $Record->SetPosition($this->Offsets[$I]); 
     214      $Record->SetPosition($this->Offsets[$I]);
    215215      switch($Format)
    216216      {
    217         case FORMAT_BYTE: 
    218           $Line[$I] = $Record->ReadByte(); 
    219           break;
    220         case FORMAT_UINT32: 
    221           $Line[$I] = $Record->ReadUInt(); 
    222           break;
    223         case FORMAT_SINT32: 
    224           $Line[$I] = $Record->ReadInt(); 
    225           break;
    226         case FORMAT_SINGLE: 
    227           $Line[$I] = $Record->ReadFloat(); 
    228           break;
    229         case FORMAT_STRING: 
     217        case FORMAT_BYTE:
     218          $Line[$I] = $Record->ReadByte();
     219          break;
     220        case FORMAT_UINT32:
     221          $Line[$I] = $Record->ReadUInt();
     222          break;
     223        case FORMAT_SINT32:
     224          $Line[$I] = $Record->ReadInt();
     225          break;
     226        case FORMAT_SINGLE:
     227          $Line[$I] = $Record->ReadFloat();
     228          break;
     229        case FORMAT_STRING:
    230230          $Offset = $Record->ReadUint();
    231              
     231
    232232          $Position = $this->HeaderSize + $this->RecordCount * $this->RecordSize + $Offset;
    233233          if($Position >= $this->GetSize()) $String = '';
    234           else 
     234          else
    235235          {
    236             $this->SetPosition($Position);     
     236            $this->SetPosition($Position);
    237237            $String = '';
    238238            while(($Char = $this->ReadChar()) != "\0")
     
    241241          $Line[$I] = $String;
    242242          break;
    243         default: 
     243        default:
    244244          break;
    245245      }
     
    252252    // Cache record data
    253253    $Record = new MemoryStream();
    254    
     254
    255255    for($I = 0; $I < $this->FieldCount; $I++)
    256256    {
    257257      if(array_key_exists($I, $this->ColumnFormat)) $Format = $this->ColumnFormat[$I];
    258258        else $Format = FORMAT_UINT32;
    259       $Record->SetPosition($this->Offsets[$I]); 
     259      $Record->SetPosition($this->Offsets[$I]);
    260260      switch($Format)
    261261      {
    262         case FORMAT_BYTE: 
    263           $Record->WriteByte($Line[$I]); 
    264           break;
    265         case FORMAT_UINT32: 
    266           $Record->WriteUint($Line[$I]); 
    267           break;
    268         case FORMAT_SINT32: 
    269           $Record->WriteInt($Line[$I]); 
    270           break;
    271         case FORMAT_SINGLE: 
    272           $Record->WriteFloat($Line[$I]); 
    273           break;
    274         case FORMAT_STRING: 
     262        case FORMAT_BYTE:
     263          $Record->WriteByte($Line[$I]);
     264          break;
     265        case FORMAT_UINT32:
     266          $Record->WriteUint($Line[$I]);
     267          break;
     268        case FORMAT_SINT32:
     269          $Record->WriteInt($Line[$I]);
     270          break;
     271        case FORMAT_SINGLE:
     272          $Record->WriteFloat($Line[$I]);
     273          break;
     274        case FORMAT_STRING:
    275275          if(in_array($Line[$I], $this->StringList))
    276           { 
     276          {
    277277            $Record->WriteUint($this->StringListOffset[array_search($Line[$I], $this->StringList)]);
    278           } else 
     278          } else
    279279          {
    280280            $Record->WriteUint($this->StringOffset);
     
    284284          }
    285285          break;
    286         default: 
     286        default:
    287287          break;
    288288      }
    289289    }
    290    
     290
    291291    $this->SetPosition($this->CellPos($Row, 0));
    292292    $this->WriteBlock($Record->Data, $this->RecordSize);
    293293    return($Line);
    294   } 
    295    
    296   public function GetRecordCount() 
    297   { 
    298     return($this->RecordCount); 
    299   }
    300 
    301   public function SetRecordCount($Value) 
    302   { 
     294  }
     295
     296  public function GetRecordCount()
     297  {
     298    return($this->RecordCount);
     299  }
     300
     301  public function SetRecordCount($Value)
     302  {
    303303    $this->RecordCount = $Value;
    304304  }
    305305
    306   public function GetFieldCount() 
    307   { 
    308     return($this->FieldCount); 
    309   }
    310 
    311   public function SetFieldCount($Value) 
    312   { 
     306  public function GetFieldCount()
     307  {
     308    return($this->FieldCount);
     309  }
     310
     311  public function SetFieldCount($Value)
     312  {
    313313    $this->FieldCount = $Value;
    314314    $this->GenerateOffsetTable();
Note: See TracChangeset for help on using the changeset viewer.