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
David Youssefi
otb
Commits
1d78ab93
Commit
1d78ab93
authored
13 years ago
by
Julien Malik
Browse files
Options
Downloads
Patches
Plain Diff
ENH: add GetParameterByKey to ParameterGroup (missing files)
parent
411eaac3
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Code/Core/otbWrapperChoiceParameter.cxx
+124
-0
124 additions, 0 deletions
Code/Core/otbWrapperChoiceParameter.cxx
Code/Core/otbWrapperParameterGroup.cxx
+153
-0
153 additions, 0 deletions
Code/Core/otbWrapperParameterGroup.cxx
with
277 additions
and
0 deletions
Code/Core/otbWrapperChoiceParameter.cxx
0 → 100644
+
124
−
0
View file @
1d78ab93
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include
"otbWrapperChoiceParameter.h"
namespace
otb
{
namespace
Wrapper
{
ChoiceParameter
::
ChoiceParameter
()
:
m_CurrentChoice
(
0
)
{
}
ChoiceParameter
::~
ChoiceParameter
()
{
}
void
ChoiceParameter
::
AddChoice
(
std
::
string
key
,
std
::
string
name
,
Parameter
*
param
)
{
ParameterGroup
*
paramAsGroup
=
dynamic_cast
<
ParameterGroup
*>
(
param
);
if
(
paramAsGroup
!=
0
)
{
Choice
choice
;
choice
.
m_Key
=
key
;
choice
.
m_Name
=
name
;
choice
.
m_AssociatedParameter
=
paramAsGroup
;
m_ChoiceList
.
push_back
(
choice
);
}
else
{
// wrap in group first
ParameterGroup
::
Pointer
group
=
ParameterGroup
::
New
();
group
->
AddParameter
(
param
);
AddChoice
(
key
,
name
,
group
.
GetPointer
());
}
}
std
::
string
ChoiceParameter
::
GetChoiceKey
(
int
i
)
{
return
m_ChoiceList
[
i
].
m_Key
;
}
std
::
string
ChoiceParameter
::
GetChoiceName
(
int
i
)
{
return
m_ChoiceList
[
i
].
m_Name
;
}
ParameterGroup
::
Pointer
ChoiceParameter
::
GetChoiceAssociatedParameter
(
int
i
)
{
return
m_ChoiceList
[
i
].
m_AssociatedParameter
;
}
unsigned
int
ChoiceParameter
::
GetNbChoices
(
void
)
{
return
m_ChoiceList
.
size
();
}
/** Set any value */
void
ChoiceParameter
::
SetValue
(
unsigned
int
v
)
{
// Perform any cast
m_CurrentChoice
=
v
;
// Call Modified();
this
->
Modified
();
}
/** Return any value */
unsigned
int
ChoiceParameter
::
GetValue
()
{
return
m_CurrentChoice
;
}
/** Set any value */
void
ChoiceParameter
::
SetAnyValue
(
boost
::
any
v
)
{
// Perform any cast
unsigned
int
val
=
boost
::
any_cast
<
unsigned
int
>
(
v
);
if
(
val
>=
GetNbChoices
()
)
{
itkExceptionMacro
(
<<
"Invalid choice value : "
<<
val
)
}
m_CurrentChoice
=
val
;
// Call Modified();
this
->
Modified
();
}
/** Return any value */
boost
::
any
ChoiceParameter
::
GetAnyValue
()
{
return
boost
::
any
(
m_CurrentChoice
);
}
}
}
This diff is collapsed.
Click to expand it.
Code/Core/otbWrapperParameterGroup.cxx
0 → 100644
+
153
−
0
View file @
1d78ab93
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include
"otbWrapperParameterGroup.h"
#include
"otbWrapperChoiceParameter.h"
#include
<boost/algorithm/string.hpp>
namespace
otb
{
namespace
Wrapper
{
ParameterGroup
::
ParameterGroup
()
{
}
ParameterGroup
::~
ParameterGroup
()
{
}
void
ParameterGroup
::
AddParameter
(
Parameter
::
Pointer
p
)
{
m_ParameterList
.
push_back
(
p
);
}
Parameter
::
Pointer
ParameterGroup
::
GetParameterByIndex
(
unsigned
int
i
)
{
return
m_ParameterList
[
i
];
}
Parameter
::
Pointer
ParameterGroup
::
GetParameterByKey
(
std
::
string
name
)
{
// Split the parameter name
std
::
vector
<
std
::
string
>
splittedName
;
boost
::
algorithm
::
split
(
splittedName
,
name
,
boost
::
is_any_of
(
"."
),
boost
::
token_compress_on
);
// Get the first parameter key
std
::
string
parentName
=
splittedName
[
0
];
// Look for parentName in the current group
Parameter
::
Pointer
parentParam
;
ParameterListType
::
iterator
it
;
for
(
it
=
m_ParameterList
.
begin
();
it
!=
m_ParameterList
.
end
();
++
it
)
{
Parameter
::
Pointer
param
=
*
it
;
if
(
param
->
GetKey
()
==
parentName
)
{
parentParam
=
param
;
break
;
}
}
if
(
parentParam
.
IsNull
())
{
itkExceptionMacro
(
<<
"Could not find parameter "
<<
name
)
}
// If the name contains a child, make a recursive call
if
(
splittedName
.
size
()
>
1
)
{
// Handle ParameterGroup case
ParameterGroup
*
parentAsGroup
=
dynamic_cast
<
ParameterGroup
*>
(
parentParam
.
GetPointer
());
if
(
parentAsGroup
)
{
// Remove the parent from the param name
std
::
ostringstream
childNameOss
;
std
::
vector
<
std
::
string
>::
const_iterator
it
=
splittedName
.
begin
()
+
1
;
while
(
it
!=
splittedName
.
end
())
{
childNameOss
<<
*
it
;
++
it
;
if
(
it
!=
splittedName
.
end
())
{
childNameOss
<<
"."
<<
std
::
endl
;
}
}
std
::
string
childName
=
childNameOss
.
str
();
return
parentAsGroup
->
GetParameterByKey
(
childName
);
}
// Handle ChoiceParameter case
ChoiceParameter
*
parentAsChoice
=
dynamic_cast
<
ChoiceParameter
*>
(
parentParam
.
GetPointer
());
if
(
parentAsChoice
)
{
// Check that splittedName[1] is one of the choice
ParameterGroup
::
Pointer
associatedParam
;
unsigned
int
nbChoices
=
parentAsChoice
->
GetNbChoices
();
for
(
int
i
=
0
;
i
<
nbChoices
;
++
i
)
{
if
(
parentAsChoice
->
GetChoiceKey
(
i
)
==
splittedName
[
1
]
)
{
associatedParam
=
parentAsChoice
->
GetChoiceAssociatedParameter
(
i
);
break
;
}
}
if
(
splittedName
.
size
()
>
2
)
{
if
(
associatedParam
.
IsNull
())
{
itkExceptionMacro
(
<<
"Parameter "
<<
splittedName
[
1
]
<<
"has no child named "
<<
splittedName
[
2
])
}
// Remove the parent and the choice value from the param name
std
::
ostringstream
childNameOss
;
std
::
vector
<
std
::
string
>::
const_iterator
it
=
splittedName
.
begin
()
+
2
;
while
(
it
!=
splittedName
.
end
())
{
childNameOss
<<
*
it
;
++
it
;
if
(
it
!=
splittedName
.
end
())
{
childNameOss
<<
"."
<<
std
::
endl
;
}
}
std
::
string
childName
=
childNameOss
.
str
();
return
associatedParam
->
GetParameterByKey
(
childName
);
}
return
associatedParam
.
GetPointer
();
}
// Neither ParameterGroup, neither ChoiceParameter
itkExceptionMacro
(
<<
"No parameter with key "
<<
name
);
}
return
parentParam
.
GetPointer
();
}
unsigned
int
ParameterGroup
::
GetNumberOfParameters
()
{
m_ParameterList
.
size
();
}
}
}
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