LCOV - code coverage report
Current view: top level - frmts/pcidsk/sdk/segment - cpcidskvectorsegment.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 2 3 66.7 %
Date: 2024-04-27 17:22:41 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Purpose:  Declaration of the CPCIDSKVectorSegment class.
       4             :  *
       5             :  ******************************************************************************
       6             :  * Copyright (c) 2009
       7             :  * PCI Geomatics, 90 Allstate Parkway, Markham, Ontario, Canada.
       8             :  *
       9             :  * Permission is hereby granted, free of charge, to any person obtaining a
      10             :  * copy of this software and associated documentation files (the "Software"),
      11             :  * to deal in the Software without restriction, including without limitation
      12             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      13             :  * and/or sell copies of the Software, and to permit persons to whom the
      14             :  * Software is furnished to do so, subject to the following conditions:
      15             :  *
      16             :  * The above copyright notice and this permission notice shall be included
      17             :  * in all copies or substantial portions of the Software.
      18             :  *
      19             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      20             :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      21             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      22             :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      23             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      24             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      25             :  * DEALINGS IN THE SOFTWARE.
      26             :  ****************************************************************************/
      27             : #ifndef INCLUDE_SEGMENT_PCIDSKVECTORSEGMENT_H
      28             : #define INCLUDE_SEGMENT_PCIDSKVECTORSEGMENT_H
      29             : 
      30             : #include "pcidsk_config.h"
      31             : #include "pcidsk_types.h"
      32             : #include "pcidsk_vectorsegment.h"
      33             : #include "pcidsk_buffer.h"
      34             : #include "segment/cpcidsksegment.h"
      35             : #include "segment/vecsegheader.h"
      36             : #include "segment/vecsegdataindex.h"
      37             : 
      38             : #include <string>
      39             : #include <map>
      40             : 
      41             : namespace PCIDSK
      42             : {
      43             :     class PCIDSKFile;
      44             : 
      45             :     const int     sec_vert = 0;
      46             :     const int     sec_record = 1;
      47             :     const int     sec_raw = 2;
      48             : 
      49             :     /************************************************************************/
      50             :     /*                        CPCIDSKVectorSegment                          */
      51             :     /************************************************************************/
      52             : 
      53             :     class CPCIDSKVectorSegment final: virtual public CPCIDSKSegment,
      54             :                                       public PCIDSKVectorSegment
      55             :     {
      56             :         friend class VecSegHeader;
      57             :         friend class VecSegDataIndex;
      58             : 
      59             :     public:
      60             :         CPCIDSKVectorSegment( PCIDSKFile *file, int segment,
      61             :                               const char *segment_pointer );
      62             : 
      63             :         virtual        ~CPCIDSKVectorSegment();
      64             : 
      65             :         void            Initialize() override;
      66             :         void            Synchronize() override;
      67             : 
      68           0 :         std::string     GetRst() override { return ""; }
      69             :         std::vector<double> GetProjection( std::string &geosys ) override;
      70             :         void            SetProjection(const std::string& geosys,
      71             :                                       const std::vector<double>& params) override;
      72             : 
      73             :         int             GetFieldCount() override;
      74             :         std::string     GetFieldName(int) override;
      75             :         std::string     GetFieldDescription(int) override;
      76             :         ShapeFieldType  GetFieldType(int) override;
      77             :         std::string     GetFieldFormat(int) override;
      78             :         ShapeField      GetFieldDefault(int) override;
      79             : 
      80          10 :         ShapeIterator   begin() override { return ShapeIterator(this); }
      81          20 :         ShapeIterator   end() override { return ShapeIterator(this,NullShapeId); }
      82             : 
      83             :         ShapeId         FindFirst() override;
      84             :         ShapeId         FindNext(ShapeId) override;
      85             : 
      86             :         int             GetShapeCount() override;
      87             : 
      88             :         void            GetVertices( ShapeId, std::vector<ShapeVertex>& ) override;
      89             :         void            GetFields( ShapeId, std::vector<ShapeField>& ) override;
      90             : 
      91             :         void            AddField( const std::string& name, ShapeFieldType type,
      92             :                                   const std::string& description,
      93             :                                   const std::string& format,
      94             :                                   ShapeField *default_value ) override;
      95             : 
      96             :         ShapeId         CreateShape( ShapeId id ) override;
      97             :         void            DeleteShape( ShapeId id ) override;
      98             :         void            SetVertices( ShapeId id,
      99             :                                      const std::vector<ShapeVertex>& list ) override;
     100             :         void            SetFields( ShapeId id,
     101             :                                    const std::vector<ShapeField>& list ) override;
     102             : 
     103             :         std::string     ConsistencyCheck() override;
     104             : 
     105             :         // Essentially internal stuff.
     106             :         char                *GetData( int section, uint32 offset,
     107             :                                       int *bytes_available = nullptr,
     108             :                                       int min_bytes = 0,
     109             :                                       bool update = false );
     110             :         uint32               ReadField( uint32 offset,
     111             :                                         ShapeField& field,
     112             :                                         ShapeFieldType field_type,
     113             :                                         int section = sec_record );
     114             : 
     115             :         uint32               WriteField( uint32 offset,
     116             :                                          const ShapeField& field,
     117             :                                          PCIDSKBuffer &buffer );
     118             :         void                 ReadSecFromFile( int section, char *buffer,
     119             :                                               int block_offset,
     120             :                                               int block_count );
     121             :         void                 WriteSecToFile( int section, char *buffer,
     122             :                                              int block_offset,
     123             :                                              int block_count );
     124             : 
     125             :      private:
     126             :         bool            base_initialized;
     127             :         bool            needs_swap;
     128             : 
     129             :         VecSegHeader    vh;
     130             :         VecSegDataIndex di[2];
     131             : 
     132             :         int32                total_shape_count;
     133             :         int32                valid_shape_count;
     134             :         ShapeId              highest_shapeid_used;
     135             :         //ShapeId              first_shape_id;
     136             :         //ShapeId              last_shape_id;
     137             : 
     138             :         int32                shape_index_start;       // index of first shape
     139             :         std::vector<int32>   shape_index_ids;         // loaded shape ids.
     140             :         std::vector<uint32>  shape_index_vertex_off;  // loaded vertex offsets
     141             :         std::vector<uint32>  shape_index_record_off;  // loaded record offsets.
     142             :         bool                 shape_index_page_dirty;
     143             : 
     144             :         ShapeId              last_shapes_id;
     145             :         int                  last_shapes_index;
     146             : 
     147             :         bool                 shapeid_map_active;
     148             :         std::map<ShapeId,int> shapeid_map;
     149             :         int                  shapeid_pages_certainly_mapped;
     150             : 
     151             :         void                 AccessShapeByIndex( int iIndex );
     152             :         int                  IndexFromShapeId( ShapeId id );
     153             :         void                 LoadShapeIdPage( int page );
     154             :         void                 FlushLoadedShapeIndex();
     155             :         void                 PushLoadedIndexIntoMap();
     156             :         void                 PopulateShapeIdMap();
     157             : 
     158             :         // Cached buffers for GetData();
     159             :         PCIDSKBuffer         raw_loaded_data;
     160             :         uint32               raw_loaded_data_offset;
     161             :         bool                 raw_loaded_data_dirty;
     162             : 
     163             :         PCIDSKBuffer         vert_loaded_data;
     164             :         uint32               vert_loaded_data_offset;
     165             :         bool                 vert_loaded_data_dirty;
     166             : 
     167             :         PCIDSKBuffer         record_loaded_data;
     168             :         uint32               record_loaded_data_offset;
     169             :         bool                 record_loaded_data_dirty;
     170             : 
     171             :         bool                 vh_dirty = false;
     172             : 
     173             :         void                 FlushDataBuffer( int section );
     174             :         void                 LoadHeader();
     175             :         void                 FlushSegHeaderIfNeeded();
     176             : 
     177             :         std::string          ConsistencyCheck_Header();
     178             :         std::string          ConsistencyCheck_DataIndices();
     179             :         std::string          ConsistencyCheck_ShapeIndices();
     180             : 
     181             :         ShapeId         FindNextValidByIndex(int nIndex);
     182             :     };
     183             : } // end namespace PCIDSK
     184             : 
     185             : #endif // INCLUDE_SEGMENT_VECTORSEGMENT_H

Generated by: LCOV version 1.14