Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
otb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Julien Cabieces
otb
Commits
e4cf686b
Commit
e4cf686b
authored
9 years ago
by
Julien Michel
Browse files
Options
Downloads
Patches
Plain Diff
ENH: Replace several if statements with a switch
parent
e35facc5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Modules/Core/VectorDataBase/src/otbVectorDataKeywordlist.cxx
+37
-19
37 additions, 19 deletions
Modules/Core/VectorDataBase/src/otbVectorDataKeywordlist.cxx
with
37 additions
and
19 deletions
Modules/Core/VectorDataBase/src/otbVectorDataKeywordlist.cxx
+
37
−
19
View file @
e4cf686b
...
@@ -90,33 +90,39 @@ VectorDataKeywordlist
...
@@ -90,33 +90,39 @@ VectorDataKeywordlist
{
{
if
(
key
.
compare
(
m_FieldList
[
i
].
first
->
GetNameRef
())
==
0
)
if
(
key
.
compare
(
m_FieldList
[
i
].
first
->
GetNameRef
())
==
0
)
{
{
if
(
m_FieldList
[
i
].
first
->
GetType
()
==
OFTString
)
switch
(
m_FieldList
[
i
].
first
->
GetType
())
{
case
OFTString
:
{
{
return
m_FieldList
[
i
].
second
.
String
;
return
m_FieldList
[
i
].
second
.
String
;
}
}
if
(
m_FieldList
[
i
].
first
->
GetType
()
==
OFTInteger
)
case
OFTInteger
:
{
{
std
::
ostringstream
ss
;
std
::
ostringstream
ss
;
ss
<<
std
::
setprecision
(
15
)
<<
m_FieldList
[
i
].
second
.
Integer
;
ss
<<
std
::
setprecision
(
15
)
<<
m_FieldList
[
i
].
second
.
Integer
;
return
ss
.
str
();
return
ss
.
str
();
}
}
#ifdef OTB_USE_GDAL_20
#ifdef OTB_USE_GDAL_20
if
(
m_FieldList
[
i
].
first
->
GetType
()
==
OFTInteger64
)
case
OFTInteger64
:
{
{
std
::
ostringstream
ss
;
std
::
ostringstream
ss
;
ss
<<
std
::
setprecision
(
15
)
<<
m_FieldList
[
i
].
second
.
Integer64
;
ss
<<
std
::
setprecision
(
15
)
<<
m_FieldList
[
i
].
second
.
Integer64
;
return
ss
.
str
();
return
ss
.
str
();
}
}
#endif
#endif
if
(
m_FieldList
[
i
].
first
->
GetType
()
==
OFTReal
)
case
OFTReal
:
{
{
std
::
ostringstream
ss
;
std
::
ostringstream
ss
;
ss
<<
std
::
setprecision
(
15
)
<<
m_FieldList
[
i
].
second
.
Real
;
ss
<<
std
::
setprecision
(
15
)
<<
m_FieldList
[
i
].
second
.
Real
;
return
ss
.
str
();
return
ss
.
str
();
}
}
itkExceptionMacro
(
default
:
<<
"This type ("
<<
m_FieldList
[
i
].
first
->
GetType
()
<<
{
") is not handled (yet) by GetFieldAsString(), please request for it"
);
itkExceptionMacro
(
<<
"This type ("
<<
m_FieldList
[
i
].
first
->
GetType
()
<<
") is not handled (yet) by GetFieldAsString(), please request for it"
);
}
}
}
}
}
}
return
""
;
return
""
;
...
@@ -130,24 +136,30 @@ VectorDataKeywordlist
...
@@ -130,24 +136,30 @@ VectorDataKeywordlist
{
{
if
(
key
.
compare
(
m_FieldList
[
i
].
first
->
GetNameRef
())
==
0
)
if
(
key
.
compare
(
m_FieldList
[
i
].
first
->
GetNameRef
())
==
0
)
{
{
if
(
m_FieldList
[
i
].
first
->
GetType
()
==
OFTInteger
)
switch
(
m_FieldList
[
i
].
first
->
GetType
())
{
case
OFTInteger
:
{
{
return
(
double
)(
m_FieldList
[
i
].
second
.
Integer
);
return
(
double
)(
m_FieldList
[
i
].
second
.
Integer
);
}
}
if
(
m_FieldList
[
i
].
first
->
GetType
()
==
OFTReal
)
case
OFTReal
:
{
{
return
(
double
)(
m_FieldList
[
i
].
second
.
Real
);
return
(
double
)(
m_FieldList
[
i
].
second
.
Real
);
}
}
if
(
m_FieldList
[
i
].
first
->
GetType
()
==
OFTString
)
case
OFTString
:
{
{
std
::
istringstream
is
(
m_FieldList
[
i
].
second
.
String
);
std
::
istringstream
is
(
m_FieldList
[
i
].
second
.
String
);
double
value
;
double
value
;
is
>>
value
;
is
>>
value
;
return
value
;
return
value
;
}
}
itkExceptionMacro
(
default
:
<<
"This type ("
<<
m_FieldList
[
i
].
first
->
GetType
()
<<
{
") is not handled (yet) by GetFieldAsDouble(), please request for it"
);
itkExceptionMacro
(
<<
"This type ("
<<
m_FieldList
[
i
].
first
->
GetType
()
<<
") is not handled (yet) by GetFieldAsDouble(), please request for it"
);
}
}
}
}
}
}
return
0.
;
return
0.
;
...
@@ -161,16 +173,18 @@ VectorDataKeywordlist
...
@@ -161,16 +173,18 @@ VectorDataKeywordlist
{
{
if
(
key
.
compare
(
m_FieldList
[
i
].
first
->
GetNameRef
())
==
0
)
if
(
key
.
compare
(
m_FieldList
[
i
].
first
->
GetNameRef
())
==
0
)
{
{
if
(
m_FieldList
[
i
].
first
->
GetType
()
==
OFTInteger
)
switch
(
m_FieldList
[
i
].
first
->
GetType
())
{
{
return
(
int
)(
m_FieldList
[
i
].
second
.
Integer
);
case
OFTInteger
:
}
{
return
(
int
)(
m_FieldList
[
i
].
second
.
Integer
);
}
#ifdef OTB_USE_GDAL_20
#ifdef OTB_USE_GDAL_20
// Some fields that were OFTInteger with gdal 1.x are now
// Some fields that were OFTInteger with gdal 1.x are now
// exposed as OFTInteger64. So as to make the old code still
// exposed as OFTInteger64. So as to make the old code still
// work with the same data, here we downcast to Integer (if
// work with the same data, here we downcast to Integer (if
// and only if no overflow occur).
// and only if no overflow occur).
if
(
m_FieldList
[
i
].
first
->
GetType
()
==
OFTInteger64
)
case
OFTInteger64
:
{
{
if
(
m_FieldList
[
i
].
second
.
Integer64
>
itk
::
NumericTraits
<
int
>::
max
())
if
(
m_FieldList
[
i
].
second
.
Integer64
>
itk
::
NumericTraits
<
int
>::
max
())
{
{
...
@@ -180,7 +194,7 @@ VectorDataKeywordlist
...
@@ -180,7 +194,7 @@ VectorDataKeywordlist
return
static_cast
<
int
>
(
m_FieldList
[
i
].
second
.
Integer64
);
return
static_cast
<
int
>
(
m_FieldList
[
i
].
second
.
Integer64
);
}
}
#endif
#endif
if
(
m_FieldList
[
i
].
first
->
GetType
()
==
OFTReal
)
case
OFTReal
:
{
{
return
(
int
)(
m_FieldList
[
i
].
second
.
Real
);
return
(
int
)(
m_FieldList
[
i
].
second
.
Real
);
}
}
...
@@ -191,11 +205,15 @@ VectorDataKeywordlist
...
@@ -191,11 +205,15 @@ VectorDataKeywordlist
is
>>
value
;
is
>>
value
;
return
value
;
return
value
;
}
}
default
:
{
itkExceptionMacro
(
itkExceptionMacro
(
<<
"This type ("
<<
m_FieldList
[
i
].
first
->
GetType
()
<<
<<
"This type ("
<<
m_FieldList
[
i
].
first
->
GetType
()
<<
") is not handled (yet) by GetFieldAsInt(), please request for it"
);
") is not handled (yet) by GetFieldAsInt(), please request for it"
);
}
}
}
}
}
}
return
0.
;
return
0.
;
}
}
...
...
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