NSVD Reader  0.0.1
imple.hpp
Go to the documentation of this file.
1 
5 /*
6  * These codes are licensed under CC0.
7  * http://creativecommons.org/publicdomain/zero/1.0/
8  */
9 
10 #ifndef __NODAMUSHIMPLE_SVD_VALUE_IMPLE_HPP__
11 #define __NODAMUSHIMPLE_SVD_VALUE_IMPLE_HPP__
12 
13 # include <vector>
14 # include <memory>
15 # include "nodamushi/box.hpp"
16 # include "nodamushi/boxvec.hpp"
17 # include "nodamushi/svd/value.hpp"
18 namespace nodamushi{
19 namespace svd{
20 
21 namespace details{//--------------------------------------
22 
23 template<char... name>
25 {
26  std::stringstream s;
27  s << "empty_value_access_error: ";
28  print_const_string<name...>(s)<<" has no value.";
29  std::string text = s.str();
30  return empty_value_access_error(text);
31 }
32 
33 
34 template<typename T>
35 inline void value_clear_T(T& t)
36 {
37  t = T();
38 }
39 
40 template<typename T>
41 inline void value_clear_T(std::vector<T>& t)
42 {
43  t.clear();
44 }
45 
46 template<typename T>
48 {
49  t.release();
50 }
51 
52 template<typename T,typename PTR>
54 {
55  t.clear();
56 }
57 
58 
59 template<typename T>
60 using value_type_t = typename ::nodamushi::svd::vattr_unwrap<T>::type;
61 
62 } // end namespace details -----------------------------
63 
64 
65 template<typename T,bool attribute,bool required,char... name>
67 {
68 # if __cplusplus >= 201703
69  return get_const_string<name...>();
70 # else
71  const char arr[] = {name...,'\0'};
72  return std::string(arr);
73 # endif
74 }
75 template<typename T,bool attribute,bool required,char... name>
77  if(!_has_value) throw details::no_value_error<name...>();
78  return _value;
79 }
80 template<typename T,bool attribute,bool required,char... name>
82  if(!_has_value) throw details::no_value_error<name...>();
83  return _value;
84 }
85 
86 template<typename T,bool attribute,bool required,char... name>
88 {
89  _has_value = false;
90  details::value_clear_T(_value);
91 }
92 
93 } // end namespace svd
94 }// end namespace nodamushi
95 
96 #endif // __NODAMUSHIMPLE_SVD_VALUE_IMPLE_HPP__
boxvec. vector<pointer<X>>
typename ::nodamushi::svd::vattr_unwrap< T >::type value_type_t
Definition: imple.hpp:60
std::ostream & print_const_string(std::ostream &o)
empty_value_access_error no_value_error()
Definition: imple.hpp:24
box.std::unique_ptr wrapper
constexpr const_string get_const_string()
T * release() noexcept
Definition: box.hpp:64
void value_clear_T(T &t)
Definition: imple.hpp:35
std::string get_name() const noexcept
Definition: imple.hpp:66
#define NODAMUSHI_CONSTEXPR_STRING
Definition: string_type.hpp:46
vector<pointer<T>>.
Definition: boxvec.hpp:75
void clear() noexcept
clear this object. After calling this method,this object status will be empty.
Definition: imple.hpp:87
access to the empty value object.
Definition: value.hpp:30
value class, empty_value_access_error class
const type & get() const
get value
Definition: imple.hpp:76