20 integer,
parameter,
public :: MAX_NAMESPACE_LEN = 128
24 character(len=MAX_NAMESPACE_LEN) :: name =
""
25 type(namespace_t),
pointer,
public :: parent => null()
29 generic ::
operator(==) => equal
36 procedure namespace_constructor
39 type(namespace_t) :: global_namespace
48 recursive type(namespace_t) function namespace_constructor(name, parent, delimiter)
49 character(len=*),
intent(in) :: name
50 type(namespace_t),
optional,
target,
intent(in) :: parent
51 character(len=1),
optional,
intent(in) :: delimiter
53 integer :: total_len, parent_len
54 character(len=1) :: delimiter_
56 if (
present(delimiter))
then
57 delimiter_ = delimiter
63 total_len = len_trim(name)
64 if (
present(parent))
then
65 parent_len = parent%len()
66 if (parent_len > 0)
then
67 total_len = total_len + parent_len + 1
72 if (total_len > max_namespace_len)
then
73 write(stderr,
'(a)')
'*** Fatal Error (description follows)'
74 write(stderr,
'(a)')
'Trying to create the following namespace:'
75 if (
present(parent))
then
76 if (parent%len() > 0)
then
77 write(stderr,
'(a)') trim(parent%get()) // delimiter_ // name
80 write(stderr,
'(a)') name
82 write(stderr,
'(a,i4,a)')
'but namespaces are limited to ', max_namespace_len,
' characters'
88 assert(len_trim(name) > 0)
90 namespace_constructor%name = name
91 if (
present(parent))
then
92 namespace_constructor%parent => parent
94 nullify(namespace_constructor%parent)
102 recursive function namespace_get(this, delimiter)
result(name)
103 class(namespace_t),
intent(in) :: this
104 character(len=1),
optional,
intent(in) :: delimiter
105 character(len=MAX_NAMESPACE_LEN) :: name
107 character(len=1) :: delimiter_
109 if (
present(delimiter))
then
110 delimiter_ = delimiter
116 if (
associated(this%parent))
then
117 if (len_trim(name) > 0 .and. this%parent%len() > 0)
then
118 name = trim(this%parent%get(delimiter_)) // delimiter_ // trim(name)
129 integer :: parent_len
132 if (
associated(this%parent))
then
133 parent_len = this%parent%len()
134 if (parent_len > 0)
then
155 logical :: found_ancestor
156 type(
namespace_t),
pointer :: this_ancestor, namespace_ancestor
159 found_ancestor = .false.
160 namespace_ancestor => namespace
161 do while (
associated(namespace_ancestor))
162 found_ancestor = namespace_ancestor == this
163 if (found_ancestor)
exit
164 namespace_ancestor => namespace_ancestor%parent
167 if (found_ancestor)
then
170 this_ancestor => this
171 do while (
associated(namespace_ancestor%parent) .and.
associated(this_ancestor%parent))
174 this_ancestor => this_ancestor%parent
175 namespace_ancestor => namespace_ancestor%parent
187 character(len=*),
intent(in) :: name
188 character(len=1),
optional,
intent(in) :: delimiter
191 character(len=1) :: delimiter_
195 if (
present(delimiter))
then
196 delimiter_ = delimiter
202 si = index(name, delimiter_, back=.
true.)
203 namespace%name = name(si+1:len(name))
207 si = index(name(:se-1), delimiter_, back=.
true.)
208 allocate(next%parent)
209 next%parent =
namespace_t(name(si+1:se-1), delimiter=delimiter)
214 is_contained = namespace%contains(this)
217 parent => namespace%parent
218 do while (
associated(parent))
219 next => parent%parent
type(mpi_grp_t), public mpi_world
logical function namespace_is_contained_in(this, name, delimiter)
elemental logical function namespace_equal(lhs, rhs)
recursive type(namespace_t) function namespace_constructor(name, parent, delimiter)
Create namespace from name. If parent is present, the new namespace will be a child of it....
logical function namespace_contains(this, namespace)
type(namespace_t), public global_namespace
pure recursive integer function namespace_len(this)
recursive character(len=max_namespace_len) function namespace_get(this, delimiter)
get full name, including parents