Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ogs-feliks
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Feliks Kiszkurno
ogs-feliks
Commits
682e10f2
Commit
682e10f2
authored
7 years ago
by
Dmitri Naumov
Browse files
Options
Downloads
Patches
Plain Diff
[GL] XmlGmlIO; Use unique_ptr to avoid mem leaks.
Drop unnecessary args from delete functions.
parent
a6ff2c7a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
GeoLib/IO/XmlIO/Qt/XmlGmlInterface.cpp
+61
-60
61 additions, 60 deletions
GeoLib/IO/XmlIO/Qt/XmlGmlInterface.cpp
GeoLib/IO/XmlIO/Qt/XmlGmlInterface.h
+21
-24
21 additions, 24 deletions
GeoLib/IO/XmlIO/Qt/XmlGmlInterface.h
with
82 additions
and
84 deletions
GeoLib/IO/XmlIO/Qt/XmlGmlInterface.cpp
+
61
−
60
View file @
682e10f2
...
@@ -56,9 +56,10 @@ int XmlGmlInterface::readFile(const QString &fileName)
...
@@ -56,9 +56,10 @@ int XmlGmlInterface::readFile(const QString &fileName)
auto
surfaces
=
std
::
unique_ptr
<
std
::
vector
<
GeoLib
::
Surface
*>>
(
auto
surfaces
=
std
::
unique_ptr
<
std
::
vector
<
GeoLib
::
Surface
*>>
(
new
std
::
vector
<
GeoLib
::
Surface
*>
);
new
std
::
vector
<
GeoLib
::
Surface
*>
);
auto
*
pnt_names
=
new
std
::
map
<
std
::
string
,
std
::
size_t
>
;
using
MapNameId
=
std
::
map
<
std
::
string
,
std
::
size_t
>
;
auto
*
ply_names
=
new
std
::
map
<
std
::
string
,
std
::
size_t
>
;
std
::
unique_ptr
<
MapNameId
>
pnt_names
{
new
MapNameId
};
auto
*
sfc_names
=
new
std
::
map
<
std
::
string
,
std
::
size_t
>
;
std
::
unique_ptr
<
MapNameId
>
ply_names
{
new
MapNameId
};
std
::
unique_ptr
<
MapNameId
>
sfc_names
{
new
MapNameId
};
QDomNodeList
geoTypes
=
docElement
.
childNodes
();
QDomNodeList
geoTypes
=
docElement
.
childNodes
();
for
(
int
i
=
0
;
i
<
geoTypes
.
count
();
i
++
)
for
(
int
i
=
0
;
i
<
geoTypes
.
count
();
i
++
)
...
@@ -70,41 +71,66 @@ int XmlGmlInterface::readFile(const QString &fileName)
...
@@ -70,41 +71,66 @@ int XmlGmlInterface::readFile(const QString &fileName)
{
{
ERR
(
"XmlGmlInterface::readFile(): <name>-tag is empty."
)
ERR
(
"XmlGmlInterface::readFile(): <name>-tag is empty."
)
deleteGeometry
(
std
::
move
(
points
),
std
::
move
(
polylines
),
deleteGeometry
(
std
::
move
(
points
),
std
::
move
(
polylines
),
std
::
move
(
surfaces
),
pnt_names
,
ply_names
,
std
::
move
(
surfaces
));
sfc_names
);
return
0
;
return
0
;
}
}
else
else
gliName
=
type_node
.
toElement
().
text
().
toStdString
();
gliName
=
type_node
.
toElement
().
text
().
toStdString
();
else
if
(
nodeName
.
compare
(
"points"
)
==
0
)
else
if
(
nodeName
.
compare
(
"points"
)
==
0
)
{
{
readPoints
(
type_node
,
points
.
get
(),
pnt_names
);
readPoints
(
type_node
,
points
.
get
(),
pnt_names
.
get
());
_geo_objs
.
addPointVec
(
std
::
move
(
points
),
gliName
,
pnt_names
);
// if names-map is empty, set it to NULL because it is not needed
if
(
pnt_names
->
empty
())
{
pnt_names
.
reset
(
nullptr
);
}
_geo_objs
.
addPointVec
(
std
::
move
(
points
),
gliName
,
std
::
move
(
pnt_names
));
}
}
else
if
(
nodeName
.
compare
(
"polylines"
)
==
0
)
else
if
(
nodeName
.
compare
(
"polylines"
)
==
0
)
{
readPolylines
(
readPolylines
(
type_node
,
polylines
.
get
(),
*
_geo_objs
.
getPointVec
(
gliName
),
type_node
,
polylines
.
get
(),
*
_geo_objs
.
getPointVec
(
gliName
),
_geo_objs
.
getPointVecObj
(
gliName
)
->
getIDMap
(),
ply_names
);
_geo_objs
.
getPointVecObj
(
gliName
)
->
getIDMap
(),
ply_names
.
get
());
// if names-map is empty, set it to NULL because it is not needed
if
(
ply_names
->
empty
())
{
ply_names
.
reset
(
nullptr
);
}
}
else
if
(
nodeName
.
compare
(
"surfaces"
)
==
0
)
else
if
(
nodeName
.
compare
(
"surfaces"
)
==
0
)
{
readSurfaces
(
readSurfaces
(
type_node
,
surfaces
.
get
(),
*
_geo_objs
.
getPointVec
(
gliName
),
type_node
,
surfaces
.
get
(),
*
_geo_objs
.
getPointVec
(
gliName
),
_geo_objs
.
getPointVecObj
(
gliName
)
->
getIDMap
(),
sfc_names
);
_geo_objs
.
getPointVecObj
(
gliName
)
->
getIDMap
(),
sfc_names
.
get
());
// if names-map is empty, set it to NULL because it is not needed
if
(
sfc_names
->
empty
())
{
sfc_names
.
reset
(
nullptr
);
}
}
}
}
if
(
polylines
->
empty
())
if
(
polylines
->
empty
())
deletePolylines
(
std
::
move
(
polylines
)
,
ply_names
);
deletePolylines
(
std
::
move
(
polylines
));
else
else
_geo_objs
.
addPolylineVec
(
std
::
move
(
polylines
),
gliName
,
ply_names
);
_geo_objs
.
addPolylineVec
(
std
::
move
(
polylines
),
gliName
,
std
::
move
(
ply_names
));
if
(
surfaces
->
empty
())
if
(
surfaces
->
empty
())
deleteSurfaces
(
std
::
move
(
surfaces
)
,
sfc_names
);
deleteSurfaces
(
std
::
move
(
surfaces
));
else
else
_geo_objs
.
addSurfaceVec
(
std
::
move
(
surfaces
),
gliName
,
sfc_names
);
_geo_objs
.
addSurfaceVec
(
std
::
move
(
surfaces
),
gliName
,
std
::
move
(
sfc_names
));
return
1
;
return
1
;
}
}
void
XmlGmlInterface
::
readPoints
(
const
QDomNode
&
pointsRoot
,
std
::
vector
<
GeoLib
::
Point
*>*
points
,
void
XmlGmlInterface
::
readPoints
(
const
QDomNode
&
pointsRoot
,
std
::
map
<
std
::
string
,
std
::
size_t
>*
&
pnt_names
)
std
::
vector
<
GeoLib
::
Point
*>*
points
,
std
::
map
<
std
::
string
,
std
::
size_t
>*
pnt_names
)
{
{
char
*
pEnd
;
char
*
pEnd
;
QDomElement
point
=
pointsRoot
.
firstChildElement
();
QDomElement
point
=
pointsRoot
.
firstChildElement
();
...
@@ -123,20 +149,14 @@ void XmlGmlInterface::readPoints(const QDomNode &pointsRoot, std::vector<GeoLib:
...
@@ -123,20 +149,14 @@ void XmlGmlInterface::readPoints(const QDomNode &pointsRoot, std::vector<GeoLib:
points
->
push_back
(
p
);
points
->
push_back
(
p
);
point
=
point
.
nextSiblingElement
();
point
=
point
.
nextSiblingElement
();
}
}
// if names-map is empty, set it to nullptr because it is not needed
if
(
pnt_names
->
empty
())
{
delete
pnt_names
;
pnt_names
=
nullptr
;
}
}
}
void
XmlGmlInterface
::
readPolylines
(
const
QDomNode
&
polylinesRoot
,
void
XmlGmlInterface
::
readPolylines
(
std
::
vector
<
GeoLib
::
Polyline
*>*
polylines
,
const
QDomNode
&
polylinesRoot
,
std
::
vector
<
GeoLib
::
Point
*>
const
&
points
,
std
::
vector
<
GeoLib
::
Polyline
*>*
polylines
,
const
std
::
vector
<
std
::
size_t
>
&
pnt_id_map
,
std
::
vector
<
GeoLib
::
Point
*>
const
&
points
,
std
::
map
<
std
::
string
,
std
::
size_t
>*
&
ply_names
)
const
std
::
vector
<
std
::
size_t
>&
pnt_id_map
,
std
::
map
<
std
::
string
,
std
::
size_t
>*
ply_names
)
{
{
std
::
size_t
idx
(
0
);
std
::
size_t
idx
(
0
);
QDomElement
polyline
=
polylinesRoot
.
firstChildElement
();
QDomElement
polyline
=
polylinesRoot
.
firstChildElement
();
...
@@ -169,20 +189,14 @@ void XmlGmlInterface::readPolylines(const QDomNode &polylinesRoot,
...
@@ -169,20 +189,14 @@ void XmlGmlInterface::readPolylines(const QDomNode &polylinesRoot,
polyline
=
polyline
.
nextSiblingElement
();
polyline
=
polyline
.
nextSiblingElement
();
}
}
// if names-map is empty, set it to nullptr because it is not needed
if
(
ply_names
->
empty
())
{
delete
ply_names
;
ply_names
=
nullptr
;
}
}
}
void
XmlGmlInterface
::
readSurfaces
(
const
QDomNode
&
surfacesRoot
,
void
XmlGmlInterface
::
readSurfaces
(
std
::
vector
<
GeoLib
::
Surface
*>*
surfaces
,
const
QDomNode
&
surfacesRoot
,
std
::
vector
<
GeoLib
::
Point
*>
const
&
points
,
std
::
vector
<
GeoLib
::
Surface
*>*
surfaces
,
const
std
::
vector
<
std
::
size_t
>
&
pnt_id_map
,
std
::
vector
<
GeoLib
::
Point
*>
const
&
points
,
std
::
map
<
std
::
string
,
std
::
size_t
>*
&
sfc_names
)
const
std
::
vector
<
std
::
size_t
>&
pnt_id_map
,
std
::
map
<
std
::
string
,
std
::
size_t
>*
sfc_names
)
{
{
QDomElement
surface
=
surfacesRoot
.
firstChildElement
();
QDomElement
surface
=
surfacesRoot
.
firstChildElement
();
while
(
!
surface
.
isNull
())
while
(
!
surface
.
isNull
())
...
@@ -205,46 +219,33 @@ void XmlGmlInterface::readSurfaces(const QDomNode &surfacesRoot,
...
@@ -205,46 +219,33 @@ void XmlGmlInterface::readSurfaces(const QDomNode &surfacesRoot,
surface
=
surface
.
nextSiblingElement
();
surface
=
surface
.
nextSiblingElement
();
}
}
// if names-map is empty, set it to nullptr because it is not needed
if
(
sfc_names
->
empty
())
{
delete
sfc_names
;
sfc_names
=
nullptr
;
}
}
}
void
XmlGmlInterface
::
deleteGeometry
(
void
XmlGmlInterface
::
deleteGeometry
(
std
::
unique_ptr
<
std
::
vector
<
GeoLib
::
Point
*>>
points
,
std
::
unique_ptr
<
std
::
vector
<
GeoLib
::
Point
*>>
points
,
std
::
unique_ptr
<
std
::
vector
<
GeoLib
::
Polyline
*>>
polylines
,
std
::
unique_ptr
<
std
::
vector
<
GeoLib
::
Polyline
*>>
std
::
unique_ptr
<
std
::
vector
<
GeoLib
::
Surface
*>>
surfaces
,
polylines
,
std
::
map
<
std
::
string
,
std
::
size_t
>*
pnt_names
,
std
::
unique_ptr
<
std
::
vector
<
GeoLib
::
Surface
*>>
std
::
map
<
std
::
string
,
std
::
size_t
>*
ply_names
,
surfaces
)
const
std
::
map
<
std
::
string
,
std
::
size_t
>*
sfc_names
)
const
{
{
for
(
GeoLib
::
Point
*
point
:
*
points
)
for
(
GeoLib
::
Point
*
point
:
*
points
)
delete
point
;
delete
point
;
delete
pnt_names
;
deletePolylines
(
std
::
move
(
polylines
));
deletePolylines
(
std
::
move
(
polylines
),
ply_names
);
deleteSurfaces
(
std
::
move
(
surfaces
));
deleteSurfaces
(
std
::
move
(
surfaces
),
sfc_names
);
}
}
void
XmlGmlInterface
::
deletePolylines
(
void
XmlGmlInterface
::
deletePolylines
(
std
::
unique_ptr
<
std
::
vector
<
GeoLib
::
Polyline
*>>
polylines
,
std
::
unique_ptr
<
std
::
vector
<
GeoLib
::
Polyline
*>>
polylines
)
const
std
::
map
<
std
::
string
,
std
::
size_t
>*
ply_names
)
const
{
{
for
(
GeoLib
::
Polyline
*
line
:
*
polylines
)
for
(
GeoLib
::
Polyline
*
line
:
*
polylines
)
delete
line
;
delete
line
;
delete
ply_names
;
}
}
void
XmlGmlInterface
::
deleteSurfaces
(
void
XmlGmlInterface
::
deleteSurfaces
(
std
::
unique_ptr
<
std
::
vector
<
GeoLib
::
Surface
*>>
surfaces
,
std
::
unique_ptr
<
std
::
vector
<
GeoLib
::
Surface
*>>
surfaces
)
const
std
::
map
<
std
::
string
,
std
::
size_t
>*
sfc_names
)
const
{
{
for
(
GeoLib
::
Surface
*
line
:
*
surfaces
)
for
(
GeoLib
::
Surface
*
line
:
*
surfaces
)
delete
line
;
delete
line
;
delete
sfc_names
;
}
}
bool
XmlGmlInterface
::
write
()
bool
XmlGmlInterface
::
write
()
...
...
This diff is collapsed.
Click to expand it.
GeoLib/IO/XmlIO/Qt/XmlGmlInterface.h
+
21
−
24
View file @
682e10f2
...
@@ -50,41 +50,38 @@ protected:
...
@@ -50,41 +50,38 @@ protected:
private
:
private
:
/// Reads GeoLib::Point-objects from an xml-file
/// Reads GeoLib::Point-objects from an xml-file
void
readPoints
(
const
QDomNode
&
pointsRoot
,
void
readPoints
(
const
QDomNode
&
pointsRoot
,
std
::
vector
<
GeoLib
::
Point
*>*
points
,
std
::
vector
<
GeoLib
::
Point
*>*
points
,
std
::
map
<
std
::
string
,
std
::
size_t
>*
&
pnt_names
);
std
::
map
<
std
::
string
,
std
::
size_t
>*
pnt_names
);
/// Reads GeoLib::Polyline-objects from an xml-file
/// Reads GeoLib::Polyline-objects from an xml-file
void
readPolylines
(
const
QDomNode
&
polylinesRoot
,
void
readPolylines
(
const
QDomNode
&
polylinesRoot
,
std
::
vector
<
GeoLib
::
Polyline
*>*
polylines
,
std
::
vector
<
GeoLib
::
Polyline
*>*
polylines
,
std
::
vector
<
GeoLib
::
Point
*>
const
&
points
,
std
::
vector
<
GeoLib
::
Point
*>
const
&
points
,
const
std
::
vector
<
std
::
size_t
>
&
pnt_id_map
,
const
std
::
vector
<
std
::
size_t
>&
pnt_id_map
,
std
::
map
<
std
::
string
,
std
::
size_t
>*
&
ply_names
);
std
::
map
<
std
::
string
,
std
::
size_t
>*
ply_names
);
/// Reads GeoLib::Surface-objects from an xml-file
/// Reads GeoLib::Surface-objects from an xml-file
void
readSurfaces
(
const
QDomNode
&
surfacesRoot
,
void
readSurfaces
(
const
QDomNode
&
surfacesRoot
,
std
::
vector
<
GeoLib
::
Surface
*>*
surfaces
,
std
::
vector
<
GeoLib
::
Surface
*>*
surfaces
,
std
::
vector
<
GeoLib
::
Point
*>
const
&
points
,
std
::
vector
<
GeoLib
::
Point
*>
const
&
points
,
const
std
::
vector
<
std
::
size_t
>
&
pnt_id_map
,
const
std
::
vector
<
std
::
size_t
>&
pnt_id_map
,
std
::
map
<
std
::
string
,
std
::
size_t
>*
&
sfc_names
);
std
::
map
<
std
::
string
,
std
::
size_t
>*
sfc_names
);
/// Deletes all geometry data structures
/// Deletes all geometry data structures
void
deleteGeometry
(
void
deleteGeometry
(
std
::
unique_ptr
<
std
::
vector
<
GeoLib
::
Point
*>>
points
,
std
::
unique_ptr
<
std
::
vector
<
GeoLib
::
Point
*>>
points
,
std
::
unique_ptr
<
std
::
vector
<
GeoLib
::
Polyline
*>>
std
::
unique_ptr
<
std
::
vector
<
GeoLib
::
Polyline
*>>
polylines
,
polylines
,
std
::
unique_ptr
<
std
::
vector
<
GeoLib
::
Surface
*>>
surfaces
,
std
::
unique_ptr
<
std
::
vector
<
GeoLib
::
Surface
*>>
std
::
map
<
std
::
string
,
std
::
size_t
>*
pnt_names
,
surfaces
)
const
;
std
::
map
<
std
::
string
,
std
::
size_t
>*
ply_names
,
std
::
map
<
std
::
string
,
std
::
size_t
>*
sfc_names
)
const
;
/// Cleans up polylines-vector as well as its content if necessary
/// Cleans up polylines-vector as well as its content if necessary
void
deletePolylines
(
void
deletePolylines
(
std
::
unique_ptr
<
std
::
vector
<
GeoLib
::
Polyline
*>>
polylines
,
std
::
unique_ptr
<
std
::
vector
<
GeoLib
::
Polyline
*>>
polylines
)
const
;
std
::
map
<
std
::
string
,
std
::
size_t
>*
ply_names
)
const
;
/// Cleans up surfaces-vector as well as its content if necessary
/// Cleans up surfaces-vector as well as its content if necessary
void
deleteSurfaces
(
std
::
unique_ptr
<
std
::
vector
<
GeoLib
::
Surface
*>>
surfaces
,
void
deleteSurfaces
(
std
::
map
<
std
::
string
,
std
::
size_t
>*
sfc_nam
es
)
const
;
std
::
unique_ptr
<
std
::
vector
<
GeoLib
::
Surface
*>>
surfac
es
)
const
;
GeoLib
::
GEOObjects
&
_geo_objs
;
GeoLib
::
GEOObjects
&
_geo_objs
;
std
::
map
<
std
::
size_t
,
std
::
size_t
>
_idx_map
;
std
::
map
<
std
::
size_t
,
std
::
size_t
>
_idx_map
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment