File: PolygonHandle.h

package info (click to toggle)
pprepair 0.0~20170614-dd91a21-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 344 kB
  • sloc: cpp: 2,853; xml: 295; makefile: 16; sh: 11; ansic: 10
file content (144 lines) | stat: -rw-r--r-- 3,624 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
 Copyright (c) 2009-2013,
 Ken Arroyo Ohori    g.a.k.arroyoohori@tudelft.nl
 Hugo Ledoux         h.ledoux@tudelft.nl
 Martijn Meijers     b.m.meijers@tudelft.nl
 All rights reserved.
 
 This file is part of pprepair: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 Licensees holding a valid commercial license may use this file in
 accordance with the commercial license agreement provided with
 the software.
 
 This file is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */

#ifndef POLYGONHANDLE_H
#define POLYGONHANDLE_H

#include "definitions/definitions.h"

// Abstract class to store different types of attributes
class Field {
public:
  // Destructor
  virtual ~Field() = 0;
  
	// Find the type of field
	const virtual OGRFieldType getType() = 0;
	
	// Comparison
	bool operator<(Field &f);
	bool operator==(Field &f);
	
	// Getters
	virtual const char * getValueAsString();
	virtual double getValueAsDouble();
	virtual int getValueAsInt();
	
	// Setters
	virtual void setValueFromString(const char *v);
	virtual void setValueFromDouble(double v);
	virtual void setValueFromInt(int v);
};

// Specific classes
class StringField : public Field {
public:
	StringField(const char *v);
	~StringField();
	
	bool operator<(const StringField &f);
	bool operator==(const StringField &f);
	
	const OGRFieldType getType();
	const char * getValueAsString();
	void setValueFromString(const char *v);
private:
	char * contents;
};
class DoubleField : public Field {
public:
	DoubleField(double v);
	
	bool operator<(const DoubleField &f);
	bool operator==(const DoubleField &f);
	
	const OGRFieldType getType();
	double getValueAsDouble();
	void setValueFromDouble(double v);
private:
	double contents;
};
class IntField : public Field {
public:
	IntField(int v);
	
	bool operator<(const IntField &f);
	bool operator==(const IntField &f);
	
	const OGRFieldType getType();
	int getValueAsInt();
	void setValueFromInt(int v);
private:
	int contents;
};

// Store a tag
class PolygonHandle {
public:
	// Constructors and destructors
	PolygonHandle(unsigned int si = 0, char *of = NULL, unsigned int l = 0, long fid = 0);
	virtual ~PolygonHandle();
  
  // References
	char * getOriginalFile();
	unsigned int getLayer();
  
  // Field information
	void addField(Field *field);
  Field * getSchemaField();
  Field * getField(unsigned int i);
	unsigned int getNumberOfFields();
  
  // Checking whether it's a MultiPolygonHandle
	virtual const bool isMultiPolygonHandle();
protected:
	char *originalFile;
	unsigned int layer;
	//long featureID;
	
	// The field to use as schema
	// (could be changed to a set or regex to represent complex criteria)
	unsigned int schemaIndex;
	
	// Fields it contains
	std::vector<Field *> fields;
};

// Trick to save memory when multiple tags are not present
class MultiPolygonHandle : public PolygonHandle {
public:
	// Constructor. No need to start with less than two
  MultiPolygonHandle(PolygonHandle *ph);
	~MultiPolygonHandle();
	
  // Checking whether it's a MultiPolygonHandle
	virtual const bool isMultiPolygonHandle();
  
  // Access functions to the individual PolygonHandles
  bool hasHandle(PolygonHandle *handle);
  void addHandle(PolygonHandle *handle);
  const std::list<PolygonHandle *> *getHandles();
  unsigned int numberOfHandles();
private:
	std::list<PolygonHandle *> handles;
};

#endif