Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F98140243
lm_defaults.hh
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Jan 10, 05:34
Size
11 KB
Mime Type
text/x-c++
Expires
Sun, Jan 12, 05:34 (1 d, 19 h)
Engine
blob
Format
Raw Data
Handle
23514562
Attached To
rLIBMULTISCALE LibMultiScale
lm_defaults.hh
View Options
/**
* @file lm_defaults.hh
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @date Tue Oct 29 18:26:07 2013
*
* @brief Handles the defaults for the parsing system
*
* @section LICENSE
*
* Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne)
* Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
*
* LibMultiScale is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* LibMultiScale 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. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with LibMultiScale. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef __LIBMULTISCALE_LM_DEFAULTS_HH__
#define __LIBMULTISCALE_LM_DEFAULTS_HH__
/* -------------------------------------------------------------------------- */
#include <vector>
#include <map>
/* -------------------------------------------------------------------------- */
#include "quantity.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
/* -------------------------------------------------------------------------- */
// template <PhysicalQuantity q, UInt nb, typename T>
// class Quantity;
/* -------------------------------------------------------------------------- */
template
<
typename
T
>
class
default_val
{
public
:
default_val
(){
is_set
=
false
;
};
default_val
(
const
T
&
v
){
is_set
=
true
;
val
=
v
;
};
bool
setDefault
(
T
&
toSet
)
const
{
if
(
!
this
->
is_set
)
return
false
;
toSet
=
val
;
return
true
;
};
const
T
&
getVal
()
const
{
return
val
;};
private
:
bool
is_set
;
T
val
;
};
/* -------------------------------------------------------------------------- */
template
<
typename
T
,
typename
Tscalar
,
UInt
nb
>
class
default_val_static_vector
{
public
:
default_val_static_vector
(){
is_set
=
false
;
};
// default_val_static_vector(const std::initializer_list<Tscalar> def){
// if (def.size() < nb) LM_FATAL("internal error " << def.size() << " " << nb);
// typename std::initializer_list<Tscalar>::iterator it = def.begin();
// typename std::initializer_list<Tscalar>::iterator end = def.end();
// for (UInt i = 0; it != end && i < nb; ++i, ++it)
// val[i] = *it;
// is_set = true;
// };
default_val_static_vector
(
const
std
::
vector
<
Tscalar
>
def
){
if
(
def
.
size
()
<
nb
)
LM_FATAL
(
"internal error "
<<
def
.
size
()
<<
" "
<<
nb
);
typename
std
::
vector
<
Tscalar
>::
const_iterator
it
=
def
.
begin
();
typename
std
::
vector
<
Tscalar
>::
const_iterator
end
=
def
.
end
();
for
(
UInt
i
=
0
;
it
!=
end
&&
i
<
nb
;
++
i
,
++
it
)
val
[
i
]
=
*
it
;
is_set
=
true
;
};
default_val_static_vector
(
const
T
&
v
){
is_set
=
true
;
val
=
v
;
};
template
<
UInt
n
>
default_val_static_vector
(
const
Tscalar
(
&
v
)[
n
]){
is_set
=
true
;
if
(
n
<
nb
)
LM_FATAL
(
"internal error"
);
for
(
UInt
i
=
0
;
i
<
nb
;
++
i
)
{
val
[
i
]
=
v
[
i
];
}
};
bool
setDefault
(
T
&
toSet
)
const
{
if
(
!
this
->
is_set
)
return
false
;
for
(
UInt
i
=
0
;
i
<
nb
;
++
i
)
{
toSet
[
i
]
=
val
[
i
];
}
return
true
;
};
const
T
&
getVal
()
const
{
return
val
;};
bool
getIsSet
()
const
{
return
is_set
;};
protected
:
bool
is_set
;
T
val
;
};
/* -------------------------------------------------------------------------- */
template
<
typename
T
,
UInt
nb
>
class
default_val
<
T
[
nb
]
>
:
public
default_val_static_vector
<
T
[
nb
],
T
,
nb
>
{
public
:
default_val
(){};
// default_val(const std::initializer_list<T> def):
// default_val_static_vector<T[nb],T,nb>(def) {};
default_val
(
const
std
::
vector
<
T
>
def
)
:
default_val_static_vector
<
T
[
nb
],
T
,
nb
>
(
def
)
{};
default_val
(
const
T
(
&
v
)
[
nb
])
:
default_val_static_vector
<
T
[
nb
],
T
,
nb
>
(
v
)
{};
template
<
UInt
n
>
default_val
(
const
default_val
<
T
[
n
]
>
&
v
)
:
default_val_static_vector
<
T
[
nb
],
T
,
nb
>
(
v
.
getVal
())
{
this
->
is_set
=
v
.
getIsSet
();
};
};
/* -------------------------------------------------------------------------- */
template
<
PhysicalQuantity
q
,
UInt
nb
,
typename
T
>
class
default_val
<
Quantity
<
q
,
nb
,
T
>
>
:
public
default_val_static_vector
<
Quantity
<
q
,
nb
,
T
>
,
T
,
nb
>
{
public
:
default_val
(){};
// default_val(const std::initializer_list<T> def):
// default_val_static_vector<Quantity<q,nb,T>,T,nb>(def) {};
default_val
(
const
std
::
vector
<
T
>
def
)
:
default_val_static_vector
<
Quantity
<
q
,
nb
,
T
>
,
T
,
nb
>
(
def
)
{};
default_val
(
const
Quantity
<
q
,
nb
,
T
>
&
v
)
:
default_val_static_vector
<
Quantity
<
q
,
nb
,
T
>
,
T
,
nb
>
(
v
)
{};
template
<
UInt
n
>
default_val
(
const
default_val
<
Quantity
<
q
,
n
,
T
>
>
&
v
)
:
default_val_static_vector
<
Quantity
<
q
,
nb
,
T
>
,
T
,
nb
>
(
Quantity
<
q
,
nb
,
T
>
(
v
.
getVal
()))
{
this
->
is_set
=
v
.
getIsSet
();
};
};
/* -------------------------------------------------------------------------- */
template
<
typename
T
>
class
default_val
<
std
::
vector
<
T
>
>
{
public
:
public
:
default_val
(){
is_set
=
true
;
};
default_val
(
const
std
::
vector
<
T
>
&
v
){
is_set
=
true
;
val
=
v
;
};
bool
setDefault
(
std
::
vector
<
T
>
&
toSet
)
const
{
if
(
!
this
->
is_set
)
return
false
;
toSet
=
val
;
return
true
;
};
const
std
::
vector
<
T
>
&
getVal
()
const
{
return
val
;};
private
:
bool
is_set
;
std
::
vector
<
T
>
val
;
};
/* -------------------------------------------------------------------------- */
template
<
typename
T1
,
typename
T2
>
class
default_val
<
std
::
map
<
T1
,
T2
>
>
{
public
:
public
:
default_val
(){
is_set
=
true
;
};
default_val
(
const
std
::
map
<
T1
,
T2
>
&
v
){
is_set
=
true
;
val
=
v
;
};
bool
setDefault
(
std
::
map
<
T1
,
T2
>
&
toSet
)
const
{
if
(
!
this
->
is_set
)
return
false
;
toSet
=
val
;
return
true
;
};
const
std
::
map
<
T1
,
T2
>
&
getVal
()
const
{
return
val
;};
private
:
bool
is_set
;
std
::
map
<
T1
,
T2
>
val
;
};
/* -------------------------------------------------------------------------- */
// temp until intel compiler can compile c++11 with list initializer
template
<
typename
T
>
std
::
vector
<
T
>
VEC_DEFAULTS
(
const
T
&
t0
){
std
::
vector
<
T
>
tmp
(
1
);
tmp
[
0
]
=
t0
;
return
tmp
;
}
template
<
typename
T
>
std
::
vector
<
T
>
VEC_DEFAULTS
(
const
T
&
t0
,
const
T
&
t1
){
std
::
vector
<
T
>
tmp
(
2
);
tmp
[
0
]
=
t0
;
tmp
[
1
]
=
t1
;
return
tmp
;
}
template
<
typename
T
>
std
::
vector
<
T
>
VEC_DEFAULTS
(
const
T
&
t0
,
const
T
&
t1
,
const
T
&
t2
){
std
::
vector
<
T
>
tmp
(
3
);
tmp
[
0
]
=
t0
;
tmp
[
1
]
=
t1
;
tmp
[
2
]
=
t2
;
return
tmp
;
}
template
<
typename
T
>
std
::
vector
<
T
>
VEC_DEFAULTS
(
const
T
&
t0
,
const
T
&
t1
,
const
T
&
t2
,
const
T
&
t3
){
std
::
vector
<
T
>
tmp
(
4
);
tmp
[
0
]
=
t0
;
tmp
[
1
]
=
t1
;
tmp
[
2
]
=
t2
;
tmp
[
3
]
=
t3
;
return
tmp
;
}
template
<
typename
T
>
std
::
vector
<
T
>
VEC_DEFAULTS
(
const
T
&
t0
,
const
T
&
t1
,
const
T
&
t2
,
const
T
&
t3
,
const
T
&
t4
){
std
::
vector
<
T
>
tmp
(
5
);
tmp
[
0
]
=
t0
;
tmp
[
1
]
=
t1
;
tmp
[
2
]
=
t2
;
tmp
[
3
]
=
t3
;
tmp
[
4
]
=
t4
;
return
tmp
;
}
template
<
typename
T
>
std
::
vector
<
T
>
VEC_DEFAULTS
(
const
T
&
t0
,
const
T
&
t1
,
const
T
&
t2
,
const
T
&
t3
,
const
T
&
t4
,
const
T
&
t5
){
std
::
vector
<
T
>
tmp
(
6
);
tmp
[
0
]
=
t0
;
tmp
[
1
]
=
t1
;
tmp
[
2
]
=
t2
;
tmp
[
3
]
=
t3
;
tmp
[
4
]
=
t4
;
tmp
[
5
]
=
t5
;
return
tmp
;
}
template
<
typename
T
>
std
::
vector
<
T
>
VEC_DEFAULTS
(
const
T
&
t0
,
const
T
&
t1
,
const
T
&
t2
,
const
T
&
t3
,
const
T
&
t4
,
const
T
&
t5
,
const
T
&
t6
){
std
::
vector
<
T
>
tmp
(
7
);
tmp
[
0
]
=
t0
;
tmp
[
1
]
=
t1
;
tmp
[
2
]
=
t2
;
tmp
[
3
]
=
t3
;
tmp
[
4
]
=
t4
;
tmp
[
5
]
=
t5
;
tmp
[
6
]
=
t6
;
return
tmp
;
}
template
<
typename
T
>
std
::
vector
<
T
>
VEC_DEFAULTS
(
const
T
&
t0
,
const
T
&
t1
,
const
T
&
t2
,
const
T
&
t3
,
const
T
&
t4
,
const
T
&
t5
,
const
T
&
t6
,
const
T
&
t7
){
std
::
vector
<
T
>
tmp
(
8
);
tmp
[
0
]
=
t0
;
tmp
[
1
]
=
t1
;
tmp
[
2
]
=
t2
;
tmp
[
3
]
=
t3
;
tmp
[
4
]
=
t4
;
tmp
[
5
]
=
t5
;
tmp
[
6
]
=
t6
;
tmp
[
7
]
=
t7
;
return
tmp
;
}
template
<
typename
T
>
std
::
vector
<
T
>
VEC_DEFAULTS
(
const
T
&
t0
,
const
T
&
t1
,
const
T
&
t2
,
const
T
&
t3
,
const
T
&
t4
,
const
T
&
t5
,
const
T
&
t6
,
const
T
&
t7
,
const
T
&
t8
){
std
::
vector
<
T
>
tmp
(
9
);
tmp
[
0
]
=
t0
;
tmp
[
1
]
=
t1
;
tmp
[
2
]
=
t2
;
tmp
[
3
]
=
t3
;
tmp
[
4
]
=
t4
;
tmp
[
5
]
=
t5
;
tmp
[
6
]
=
t6
;
tmp
[
7
]
=
t7
;
tmp
[
8
]
=
t8
;
return
tmp
;
}
/****************************************************************/
template
<
UInt
nb
>
std
::
vector
<
std
::
string
>
VEC_DEFAULTS
(
const
char
(
&
t0
)
[
nb
]){
std
::
vector
<
std
::
string
>
tmp
(
1
);
tmp
[
0
]
=
t0
;
return
tmp
;
}
template
<
UInt
nb
>
std
::
vector
<
std
::
string
>
VEC_DEFAULTS
(
const
char
(
&
t0
)
[
nb
],
const
char
(
&
t1
)
[
nb
]){
std
::
vector
<
std
::
string
>
tmp
(
2
);
tmp
[
0
]
=
t0
;
tmp
[
1
]
=
t1
;
return
tmp
;
}
template
<
UInt
nb
>
std
::
vector
<
std
::
string
>
VEC_DEFAULTS
(
const
char
(
&
t0
)
[
nb
],
const
char
(
&
t1
)
[
nb
],
const
char
(
&
t2
)
[
nb
]){
std
::
vector
<
std
::
string
>
tmp
(
3
);
tmp
[
0
]
=
t0
;
tmp
[
1
]
=
t1
;
tmp
[
2
]
=
t2
;
return
tmp
;
}
template
<
UInt
nb
>
std
::
vector
<
std
::
string
>
VEC_DEFAULTS
(
const
char
(
&
t0
)
[
nb
],
const
char
(
&
t1
)
[
nb
],
const
char
(
&
t2
)
[
nb
],
const
char
(
&
t3
)
[
nb
]){
std
::
vector
<
std
::
string
>
tmp
(
4
);
tmp
[
0
]
=
t0
;
tmp
[
1
]
=
t1
;
tmp
[
2
]
=
t2
;
tmp
[
3
]
=
t3
;
return
tmp
;
}
template
<
UInt
nb
>
std
::
vector
<
std
::
string
>
VEC_DEFAULTS
(
const
char
(
&
t0
)
[
nb
],
const
char
(
&
t1
)
[
nb
],
const
char
(
&
t2
)
[
nb
],
const
char
(
&
t3
)
[
nb
],
const
char
(
&
t4
)
[
nb
]){
std
::
vector
<
std
::
string
>
tmp
(
5
);
tmp
[
0
]
=
t0
;
tmp
[
1
]
=
t1
;
tmp
[
2
]
=
t2
;
tmp
[
3
]
=
t3
;
tmp
[
4
]
=
t4
;
return
tmp
;
}
template
<
UInt
nb
>
std
::
vector
<
std
::
string
>
VEC_DEFAULTS
(
const
char
(
&
t0
)
[
nb
],
const
char
(
&
t1
)
[
nb
],
const
char
(
&
t2
)
[
nb
],
const
char
(
&
t3
)
[
nb
],
const
char
(
&
t4
)
[
nb
],
const
char
(
&
t5
)
[
nb
]){
std
::
vector
<
std
::
string
>
tmp
(
6
);
tmp
[
0
]
=
t0
;
tmp
[
1
]
=
t1
;
tmp
[
2
]
=
t2
;
tmp
[
3
]
=
t3
;
tmp
[
4
]
=
t4
;
tmp
[
5
]
=
t5
;
return
tmp
;
}
template
<
UInt
nb
>
std
::
vector
<
std
::
string
>
VEC_DEFAULTS
(
const
char
(
&
t0
)
[
nb
],
const
char
(
&
t1
)
[
nb
],
const
char
(
&
t2
)
[
nb
],
const
char
(
&
t3
)
[
nb
],
const
char
(
&
t4
)
[
nb
],
const
char
(
&
t5
)
[
nb
],
const
char
(
&
t6
)
[
nb
]){
std
::
vector
<
std
::
string
>
tmp
(
7
);
tmp
[
0
]
=
t0
;
tmp
[
1
]
=
t1
;
tmp
[
2
]
=
t2
;
tmp
[
3
]
=
t3
;
tmp
[
4
]
=
t4
;
tmp
[
5
]
=
t5
;
tmp
[
6
]
=
t6
;
return
tmp
;
}
template
<
UInt
nb
>
std
::
vector
<
std
::
string
>
VEC_DEFAULTS
(
const
char
(
&
t0
)
[
nb
],
const
char
(
&
t1
)
[
nb
],
const
char
(
&
t2
)
[
nb
],
const
char
(
&
t3
)
[
nb
],
const
char
(
&
t4
)
[
nb
],
const
char
(
&
t5
)
[
nb
],
const
char
(
&
t6
)
[
nb
],
const
char
(
&
t7
)
[
nb
]){
std
::
vector
<
std
::
string
>
tmp
(
8
);
tmp
[
0
]
=
t0
;
tmp
[
1
]
=
t1
;
tmp
[
2
]
=
t2
;
tmp
[
3
]
=
t3
;
tmp
[
4
]
=
t4
;
tmp
[
5
]
=
t5
;
tmp
[
6
]
=
t6
;
tmp
[
7
]
=
t7
;
return
tmp
;
}
template
<
UInt
nb
>
std
::
vector
<
std
::
string
>
VEC_DEFAULTS
(
const
char
(
&
t0
)
[
nb
],
const
char
(
&
t1
)
[
nb
],
const
char
(
&
t2
)
[
nb
],
const
char
(
&
t3
)
[
nb
],
const
char
(
&
t4
)
[
nb
],
const
char
(
&
t5
)
[
nb
],
const
char
(
&
t6
)
[
nb
],
const
char
(
&
t7
)
[
nb
],
const
char
(
&
t8
)
[
nb
]){
std
::
vector
<
std
::
string
>
tmp
(
9
);
tmp
[
0
]
=
t0
;
tmp
[
1
]
=
t1
;
tmp
[
2
]
=
t2
;
tmp
[
3
]
=
t3
;
tmp
[
4
]
=
t4
;
tmp
[
5
]
=
t5
;
tmp
[
6
]
=
t6
;
tmp
[
7
]
=
t7
;
tmp
[
8
]
=
t8
;
return
tmp
;
}
__END_LIBMULTISCALE__
#endif
/* __LIBMULTISCALE_LM_DEFAULTS_HH__ */
Event Timeline
Log In to Comment