Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-xt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
ag-ohlberger
dune-community
dune-xt
Commits
ee8a24d3
Commit
ee8a24d3
authored
8 years ago
by
Dr. Felix Tobias Schindler
Browse files
Options
Downloads
Patches
Plain Diff
[parameter] add first draft of Parameter ParameterType
parent
b56201aa
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
dune/xt/common/exceptions.hh
+4
-0
4 additions, 0 deletions
dune/xt/common/exceptions.hh
dune/xt/common/parameter.cc
+235
-0
235 additions, 0 deletions
dune/xt/common/parameter.cc
dune/xt/common/parameter.hh
+96
-0
96 additions, 0 deletions
dune/xt/common/parameter.hh
with
335 additions
and
0 deletions
dune/xt/common/exceptions.hh
+
4
−
0
View file @
ee8a24d3
...
...
@@ -127,6 +127,10 @@ class reinterpretation_error : public Dune::Exception
{
};
class
parameter_error
:
public
Dune
::
Exception
{
};
class
spe10_data_file_missing
:
public
Dune
::
IOError
{
};
...
...
This diff is collapsed.
Click to expand it.
dune/xt/common/parameter.cc
0 → 100644
+
235
−
0
View file @
ee8a24d3
#include
"config.h"
#include
<type_traits>
#include
"exceptions.hh"
#include
"parameter.hh"
namespace
Dune
{
namespace
XT
{
namespace
Common
{
namespace
internal
{
// ========================
// ===== SimpleDict =====
// ========================
template
<
class
ValueType
>
SimpleDict
<
ValueType
>::
SimpleDict
()
{
}
template
<
class
ValueType
>
SimpleDict
<
ValueType
>::
SimpleDict
(
const
std
::
string
&
key
,
const
ValueType
&
value
)
:
dict_
({
std
::
make_pair
(
key
,
value
)})
{
}
template
<
class
ValueType
>
SimpleDict
<
ValueType
>::
SimpleDict
(
const
std
::
vector
<
std
::
pair
<
std
::
string
,
ValueType
>>&
key_value_pairs
)
{
for
(
const
auto
&
key_value_pair
:
key_value_pairs
)
dict_
.
emplace
(
key_value_pair
);
}
template
<
class
ValueType
>
bool
SimpleDict
<
ValueType
>::
empty
()
const
{
return
dict_
.
size
()
==
0
;
}
template
<
class
ValueType
>
bool
SimpleDict
<
ValueType
>::
has_key
(
const
std
::
string
&
key
)
const
{
return
dict_
.
find
(
key
)
!=
dict_
.
end
();
}
template
<
class
ValueType
>
void
SimpleDict
<
ValueType
>::
set
(
const
std
::
string
&
key
,
const
ValueType
&
value
,
const
bool
overwrite
)
{
if
(
!
overwrite
&&
has_key
(
key
))
DUNE_THROW
(
Exceptions
::
parameter_error
,
"You are trying to set a value ("
<<
/*value <<*/
") for the key '"
<<
key
<<
"', although a value is already set ("
// << dict_[key]
<<
") and overwrite is false!"
);
dict_
[
key
]
=
value
;
}
template
<
class
ValueType
>
const
ValueType
&
SimpleDict
<
ValueType
>::
get
(
const
std
::
string
&
key
)
const
{
const
auto
result
=
dict_
.
find
(
key
);
if
(
result
==
dict_
.
end
())
DUNE_THROW
(
Exceptions
::
parameter_error
,
"Key '"
<<
key
<<
"' does not exist!"
);
return
result
->
second
;
}
template
<
class
ValueType
>
bool
SimpleDict
<
ValueType
>::
operator
<
(
const
SimpleDict
<
ValueType
>&
other
)
const
{
return
dict_
<
other
.
dict_
;
}
template
<
class
ValueType
>
bool
SimpleDict
<
ValueType
>::
operator
==
(
const
SimpleDict
<
ValueType
>&
other
)
const
{
return
dict_
==
other
.
dict_
;
}
template
<
class
ValueType
>
bool
SimpleDict
<
ValueType
>::
operator
!=
(
const
SimpleDict
<
ValueType
>&
other
)
const
{
return
dict_
!=
other
.
dict_
;
}
template
<
class
ValueType
>
size_t
SimpleDict
<
ValueType
>::
size
()
const
{
return
dict_
.
size
();
}
template
class
SimpleDict
<
size_t
>;
template
class
SimpleDict
<
std
::
vector
<
double
>
>
;
}
// namespace internal
// =========================
// ===== ParameterType =====
// =========================
ParameterType
::
ParameterType
()
:
BaseType
()
{
}
ParameterType
::
ParameterType
(
const
std
::
string
&
key
,
const
size_t
&
sz
)
:
BaseType
(
key
,
sz
)
{
}
ParameterType
::
ParameterType
(
const
std
::
vector
<
std
::
pair
<
std
::
string
,
size_t
>>&
key_size_pairs
)
:
BaseType
(
key_size_pairs
)
{
}
// std::string ParameterType::report() const
//{
// std::ostringstream ret;
// ret << "(";
// if (dict_.size() == 1) {
// const auto element = dict_.begin();
// ret << "\"" << element->first << "\", " << element->second;
// } else if (dict_.size() > 1) {
// const auto& kk = keys();
// const auto& vv = values();
// ret << "{\"";
// for (size_t ii = 0; ii < (kk.size() - 1); ++ii)
// ret << kk[ii] << "\", \"";
// ret << kk[kk.size() - 1] << "\"}, {";
// for (size_t ii = 0; ii < (vv.size() - 1); ++ii)
// ret << vv[ii] << ", ";
// ret << vv[vv.size() - 1] << "}";
// }
// ret << ")";
// return ret.str();
//}
// std::ostream& operator<<(std::ostream& oo, const ParameterType& pp)
//{
// oo << pp.report();
// return oo;
//}
// =====================
// ===== Parameter =====
// =====================
Parameter
::
Parameter
(
const
double
&
value
)
:
BaseType
(
"None"
,
{
value
})
{
}
Parameter
::
Parameter
(
const
std
::
string
&
key
,
const
double
&
value
)
:
BaseType
(
key
,
{
value
})
{
}
Parameter
::
Parameter
(
const
std
::
string
&
key
,
const
ValueType
&
value
)
:
BaseType
(
key
,
value
)
{
}
Parameter
::
Parameter
(
const
std
::
vector
<
std
::
pair
<
std
::
string
,
ValueType
>>&
key_value_pairs
)
:
BaseType
(
key_value_pairs
)
{
}
ParameterType
Parameter
::
type
()
const
{
ParameterType
ret
;
for
(
const
auto
key_value_pairs
:
dict_
)
ret
.
set
(
key_value_pairs
.
first
,
key_value_pairs
.
second
.
size
());
return
ret
;
}
// std::string Parameter::report() const
//{
// std::ostringstream ret;
// ret << "(";
// if (dict_.size() == 1) {
// const auto element = dict_.begin();
// ret << "\"" << element->first << "\", ";
// const auto& second = element->second;
// if (second.size() == 1) {
// ret << second[0];
// } else {
// ret << "{";
// for (size_t ii = 0; ii < (second.size() - 1); ++ii)
// ret << second[ii] << ", ";
// ret << second[second.size() - 1] << "}";
// }
// } else if (dict_.size() > 1) {
// const auto& kk = keys();
// const auto& vv = values();
// ret << "{\"";
// for (size_t ii = 0; ii < (kk.size() - 1); ++ii)
// ret << kk[ii] << "\", \"";
// ret << kk[kk.size() - 1] << "\"}, {";
// for (size_t ii = 0; ii < (vv.size() - 1); ++ii) {
// if (vv[ii].size() == 1) {
// ret << vv[ii][0] << ", ";
// } else {
// ret << "{";
// for (size_t jj = 0; jj < (vv[ii].size() - 1); ++jj)
// ret << vv[ii][jj] << ", ";
// ret << vv[ii][vv[ii].size() - 1] << "}, ";
// }
// }
// if (vv[vv.size() - 1].size() == 1) {
// ret << vv[vv.size() - 1][0] << "}";
// } else {
// ret << "{";
// for (size_t jj = 0; jj < (vv[vv.size() - 1].size() - 1); ++jj)
// ret << vv[vv.size() - 1][jj] << ", ";
// ret << vv[vv.size() - 1][vv[vv.size() - 1].size() - 1] << "}";
// }
// }
// ret << ")";
// return ret.str();
//}
// std::ostream& operator<<(std::ostream& oo, const Parameter& pp)
//{
// oo << pp.report();
// return oo;
//}
}
// namespace Common
}
// namespace XT
}
// namespace Dune
This diff is collapsed.
Click to expand it.
dune/xt/common/parameter.hh
0 → 100644
+
96
−
0
View file @
ee8a24d3
#ifndef DUNE_XT_COMMON_PARAMETER_HH
#define DUNE_XT_COMMON_PARAMETER_HH
#include
<string>
#include
<map>
#include
<vector>
#include
<initializer_list>
#include
<sstream>
#include
<ostream>
namespace
Dune
{
namespace
XT
{
namespace
Common
{
namespace
internal
{
template
<
class
ValueType
>
class
SimpleDict
{
public:
SimpleDict
();
SimpleDict
(
const
std
::
string
&
key
,
const
ValueType
&
value
);
SimpleDict
(
const
std
::
vector
<
std
::
pair
<
std
::
string
,
ValueType
>>&
key_value_pairs
);
bool
empty
()
const
;
bool
has_key
(
const
std
::
string
&
key
)
const
;
void
set
(
const
std
::
string
&
key
,
const
ValueType
&
value
,
const
bool
overwrite
=
false
);
const
ValueType
&
get
(
const
std
::
string
&
key
)
const
;
bool
operator
<
(
const
SimpleDict
<
ValueType
>&
other
)
const
;
bool
operator
==
(
const
SimpleDict
<
ValueType
>&
other
)
const
;
bool
operator
!=
(
const
SimpleDict
<
ValueType
>&
other
)
const
;
size_t
size
()
const
;
// std::string report() const;
protected:
std
::
map
<
std
::
string
,
ValueType
>
dict_
;
};
// class SimpleDict
}
// namespace internal
class
ParameterType
:
public
internal
::
SimpleDict
<
size_t
>
{
typedef
internal
::
SimpleDict
<
size_t
>
BaseType
;
public:
ParameterType
();
ParameterType
(
const
std
::
string
&
key
,
const
size_t
&
sz
);
ParameterType
(
const
std
::
vector
<
std
::
pair
<
std
::
string
,
size_t
>>&
key_size_pairs
);
};
// class ParameterType
// std::ostream& operator<<(std::ostream& out, const ParameterType& param_type);
class
Parameter
:
public
internal
::
SimpleDict
<
std
::
vector
<
double
>>
{
typedef
SimpleDict
<
std
::
vector
<
double
>>
BaseType
;
typedef
std
::
vector
<
double
>
ValueType
;
public:
Parameter
(
const
std
::
vector
<
std
::
pair
<
std
::
string
,
ValueType
>>&
key_value_pairs
=
{});
Parameter
(
const
double
&
value
);
Parameter
(
const
std
::
string
&
key
,
const
double
&
value
);
Parameter
(
const
std
::
string
&
key
,
const
ValueType
&
value
);
// Parameter(const ParameterType& param_type, const std::vector<ValueType>& values);
ParameterType
type
()
const
;
};
// class Parameter
// std::ostream& operator<<(std::ostream& out, const Parameter& mu);
}
// namespace Common
}
// namespace XT
}
// namespace Dune
#endif // DUNE_XT_COMMON_PARAMETER_HH
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