Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
libcifpp
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
libcifpp
Commits
a5d43998
Unverified
Commit
a5d43998
authored
Jan 23, 2024
by
Maarten L. Hekkelman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
replace tag with item or item_name
parent
2792caec
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
290 additions
and
281 deletions
+290
-281
include/cif++/category.hpp
+17
-9
include/cif++/condition.hpp
+64
-64
include/cif++/datablock.hpp
+12
-3
include/cif++/parser.hpp
+9
-9
include/cif++/text.hpp
+14
-2
include/cif++/validate.hpp
+7
-7
src/category.cpp
+50
-50
src/condition.cpp
+3
-3
src/datablock.cpp
+9
-9
src/dictionary_parser.cpp
+27
-27
src/model.cpp
+4
-4
src/parser.cpp
+32
-32
src/pdb/reconstruct.cpp
+19
-19
src/text.cpp
+9
-9
src/validate.cpp
+14
-34
No files found.
include/cif++/category.hpp
View file @
a5d43998
...
...
@@ -957,32 +957,32 @@ class category
{
return
prefix
+
std
::
to_string
(
nr
+
1
);
});
}
/// @brief Generate a new, unique value for a item named @a
tag
/// @param
tag
The name of the item
/// @brief Generate a new, unique value for a item named @a
item_name
/// @param
item_name
The name of the item
/// @return a new unique value
std
::
string
get_unique_value
(
std
::
string_view
tag
);
std
::
string
get_unique_value
(
std
::
string_view
item_name
);
// --------------------------------------------------------------------
/// \brief Update a single item named @a
tag
in the rows that match \a cond to value \a value
/// \brief Update a single item named @a
item_name
in the rows that match \a cond to value \a value
/// making sure the linked categories are updated according to the link.
/// That means, child categories are updated if the links are absolute
/// and unique. If they are not, the child category rows are split.
void
update_value
(
condition
&&
cond
,
std
::
string_view
tag
,
std
::
string_view
value
)
void
update_value
(
condition
&&
cond
,
std
::
string_view
item_name
,
std
::
string_view
value
)
{
auto
rs
=
find
(
std
::
move
(
cond
));
std
::
vector
<
row_handle
>
rows
;
std
::
copy
(
rs
.
begin
(),
rs
.
end
(),
std
::
back_inserter
(
rows
));
update_value
(
rows
,
tag
,
value
);
update_value
(
rows
,
item_name
,
value
);
}
/// \brief Update a single item named @a
tag
in @a rows to value \a value
/// \brief Update a single item named @a
item_name
in @a rows to value \a value
/// making sure the linked categories are updated according to the link.
/// That means, child categories are updated if the links are absolute
/// and unique. If they are not, the child category rows are split.
void
update_value
(
const
std
::
vector
<
row_handle
>
&
rows
,
std
::
string_view
tag
,
std
::
string_view
value
);
void
update_value
(
const
std
::
vector
<
row_handle
>
&
rows
,
std
::
string_view
item_name
,
std
::
string_view
value
);
// --------------------------------------------------------------------
// Naming used to be very inconsistent. For backward compatibility,
...
...
@@ -1140,7 +1140,15 @@ class category
/// This function returns effectively the list of fully qualified item
/// names, that is category_name + '.' + item_name for each item
std
::
vector
<
std
::
string
>
get_tag_order
()
const
;
[[
deprecated
(
"use get_item_order instead"
)]]
std
::
vector
<
std
::
string
>
get_tag_order
()
const
{
return
get_item_order
();
}
/// This function returns effectively the list of fully qualified item
/// names, that is category_name + '.' + item_name for each item
std
::
vector
<
std
::
string
>
get_item_order
()
const
;
/// Write the contents of the category to the std::ostream @a os
void
write
(
std
::
ostream
&
os
)
const
;
...
...
include/cif++/condition.hpp
View file @
a5d43998
...
...
@@ -314,14 +314,14 @@ namespace detail
{
struct
key_is_empty_condition_impl
:
public
condition_impl
{
key_is_empty_condition_impl
(
const
std
::
string
&
item_
tag
)
:
m_item_
tag
(
item_tag
)
key_is_empty_condition_impl
(
const
std
::
string
&
item_
name
)
:
m_item_
name
(
item_name
)
{
}
condition_impl
*
prepare
(
const
category
&
c
)
override
{
m_item_ix
=
get_item_ix
(
c
,
m_item_
tag
);
m_item_ix
=
get_item_ix
(
c
,
m_item_
name
);
return
this
;
}
...
...
@@ -332,23 +332,23 @@ namespace detail
void
str
(
std
::
ostream
&
os
)
const
override
{
os
<<
m_item_
tag
<<
" IS NULL"
;
os
<<
m_item_
name
<<
" IS NULL"
;
}
std
::
string
m_item_
tag
;
std
::
string
m_item_
name
;
uint16_t
m_item_ix
=
0
;
};
struct
key_is_not_empty_condition_impl
:
public
condition_impl
{
key_is_not_empty_condition_impl
(
const
std
::
string
&
item_
tag
)
:
m_item_
tag
(
item_tag
)
key_is_not_empty_condition_impl
(
const
std
::
string
&
item_
name
)
:
m_item_
name
(
item_name
)
{
}
condition_impl
*
prepare
(
const
category
&
c
)
override
{
m_item_ix
=
get_item_ix
(
c
,
m_item_
tag
);
m_item_ix
=
get_item_ix
(
c
,
m_item_
name
);
return
this
;
}
...
...
@@ -359,17 +359,17 @@ namespace detail
void
str
(
std
::
ostream
&
os
)
const
override
{
os
<<
m_item_
tag
<<
" IS NOT NULL"
;
os
<<
m_item_
name
<<
" IS NOT NULL"
;
}
std
::
string
m_item_
tag
;
std
::
string
m_item_
name
;
uint16_t
m_item_ix
=
0
;
};
struct
key_equals_condition_impl
:
public
condition_impl
{
key_equals_condition_impl
(
item
&&
i
)
:
m_item_
tag
(
i
.
name
())
:
m_item_
name
(
i
.
name
())
,
m_value
(
i
.
value
())
{
}
...
...
@@ -383,7 +383,7 @@ namespace detail
void
str
(
std
::
ostream
&
os
)
const
override
{
os
<<
m_item_
tag
<<
(
m_icase
?
"^ "
:
" "
)
<<
" == "
<<
m_value
;
os
<<
m_item_
name
<<
(
m_icase
?
"^ "
:
" "
)
<<
" == "
<<
m_value
;
}
virtual
std
::
optional
<
row_handle
>
single
()
const
override
...
...
@@ -399,13 +399,13 @@ namespace detail
if
(
m_single_hit
.
has_value
()
or
ri
->
m_single_hit
.
has_value
())
return
m_single_hit
==
ri
->
m_single_hit
;
else
// watch out, both m_item_ix might be the same while
tag
s might be diffent (in case they both do not exist in the category)
return
m_item_ix
==
ri
->
m_item_ix
and
m_value
==
ri
->
m_value
and
m_item_
tag
==
ri
->
m_item_tag
;
// watch out, both m_item_ix might be the same while
item_name
s might be diffent (in case they both do not exist in the category)
return
m_item_ix
==
ri
->
m_item_ix
and
m_value
==
ri
->
m_value
and
m_item_
name
==
ri
->
m_item_name
;
}
return
this
==
rhs
;
}
std
::
string
m_item_
tag
;
std
::
string
m_item_
name
;
uint16_t
m_item_ix
=
0
;
bool
m_icase
=
false
;
std
::
string
m_value
;
...
...
@@ -415,7 +415,7 @@ namespace detail
struct
key_equals_or_empty_condition_impl
:
public
condition_impl
{
key_equals_or_empty_condition_impl
(
key_equals_condition_impl
*
equals
)
:
m_item_
tag
(
equals
->
m_item_tag
)
:
m_item_
name
(
equals
->
m_item_name
)
,
m_value
(
equals
->
m_value
)
,
m_icase
(
equals
->
m_icase
)
,
m_single_hit
(
equals
->
m_single_hit
)
...
...
@@ -424,8 +424,8 @@ namespace detail
condition_impl
*
prepare
(
const
category
&
c
)
override
{
m_item_ix
=
get_item_ix
(
c
,
m_item_
tag
);
m_icase
=
is_item_type_uchar
(
c
,
m_item_
tag
);
m_item_ix
=
get_item_ix
(
c
,
m_item_
name
);
m_icase
=
is_item_type_uchar
(
c
,
m_item_
name
);
return
this
;
}
...
...
@@ -441,7 +441,7 @@ namespace detail
void
str
(
std
::
ostream
&
os
)
const
override
{
os
<<
'('
<<
m_item_
tag
<<
(
m_icase
?
"^ "
:
" "
)
<<
" == "
<<
m_value
<<
" OR "
<<
m_item_tag
<<
" IS NULL)"
;
os
<<
'('
<<
m_item_
name
<<
(
m_icase
?
"^ "
:
" "
)
<<
" == "
<<
m_value
<<
" OR "
<<
m_item_name
<<
" IS NULL)"
;
}
virtual
std
::
optional
<
row_handle
>
single
()
const
override
...
...
@@ -457,13 +457,13 @@ namespace detail
if
(
m_single_hit
.
has_value
()
or
ri
->
m_single_hit
.
has_value
())
return
m_single_hit
==
ri
->
m_single_hit
;
else
// watch out, both m_item_ix might be the same while
tag
s might be diffent (in case they both do not exist in the category)
return
m_item_ix
==
ri
->
m_item_ix
and
m_value
==
ri
->
m_value
and
m_item_
tag
==
ri
->
m_item_tag
;
// watch out, both m_item_ix might be the same while
item_name
s might be diffent (in case they both do not exist in the category)
return
m_item_ix
==
ri
->
m_item_ix
and
m_value
==
ri
->
m_value
and
m_item_
name
==
ri
->
m_item_name
;
}
return
this
==
rhs
;
}
std
::
string
m_item_
tag
;
std
::
string
m_item_
name
;
uint16_t
m_item_ix
=
0
;
std
::
string
m_value
;
bool
m_icase
=
false
;
...
...
@@ -473,8 +473,8 @@ namespace detail
struct
key_compare_condition_impl
:
public
condition_impl
{
template
<
typename
COMP
>
key_compare_condition_impl
(
const
std
::
string
&
item_
tag
,
COMP
&&
comp
,
const
std
::
string
&
s
)
:
m_item_
tag
(
item_tag
)
key_compare_condition_impl
(
const
std
::
string
&
item_
name
,
COMP
&&
comp
,
const
std
::
string
&
s
)
:
m_item_
name
(
item_name
)
,
m_compare
(
std
::
move
(
comp
))
,
m_str
(
s
)
{
...
...
@@ -482,8 +482,8 @@ namespace detail
condition_impl
*
prepare
(
const
category
&
c
)
override
{
m_item_ix
=
get_item_ix
(
c
,
m_item_
tag
);
m_icase
=
is_item_type_uchar
(
c
,
m_item_
tag
);
m_item_ix
=
get_item_ix
(
c
,
m_item_
name
);
m_icase
=
is_item_type_uchar
(
c
,
m_item_
name
);
return
this
;
}
...
...
@@ -494,10 +494,10 @@ namespace detail
void
str
(
std
::
ostream
&
os
)
const
override
{
os
<<
m_item_
tag
<<
(
m_icase
?
"^ "
:
" "
)
<<
m_str
;
os
<<
m_item_
name
<<
(
m_icase
?
"^ "
:
" "
)
<<
m_str
;
}
std
::
string
m_item_
tag
;
std
::
string
m_item_
name
;
uint16_t
m_item_ix
=
0
;
bool
m_icase
=
false
;
std
::
function
<
bool
(
row_handle
,
bool
)
>
m_compare
;
...
...
@@ -506,8 +506,8 @@ namespace detail
struct
key_matches_condition_impl
:
public
condition_impl
{
key_matches_condition_impl
(
const
std
::
string
&
item_
tag
,
const
std
::
regex
&
rx
)
:
m_item_
tag
(
item_tag
)
key_matches_condition_impl
(
const
std
::
string
&
item_
name
,
const
std
::
regex
&
rx
)
:
m_item_
name
(
item_name
)
,
m_item_ix
(
0
)
,
mRx
(
rx
)
{
...
...
@@ -515,7 +515,7 @@ namespace detail
condition_impl
*
prepare
(
const
category
&
c
)
override
{
m_item_ix
=
get_item_ix
(
c
,
m_item_
tag
);
m_item_ix
=
get_item_ix
(
c
,
m_item_
name
);
return
this
;
}
...
...
@@ -527,10 +527,10 @@ namespace detail
void
str
(
std
::
ostream
&
os
)
const
override
{
os
<<
m_item_
tag
<<
" =~ expression"
;
os
<<
m_item_
name
<<
" =~ expression"
;
}
std
::
string
m_item_
tag
;
std
::
string
m_item_
name
;
uint16_t
m_item_ix
;
std
::
regex
mRx
;
};
...
...
@@ -873,7 +873,7 @@ inline condition operator or(condition &&a, condition &&b)
auto
ci
=
static_cast
<
detail
::
key_equals_condition_impl
*>
(
a
.
m_impl
);
auto
ce
=
static_cast
<
detail
::
key_is_empty_condition_impl
*>
(
b
.
m_impl
);
if
(
ci
->
m_item_
tag
==
ce
->
m_item_tag
)
if
(
ci
->
m_item_
name
==
ce
->
m_item_name
)
return
condition
(
new
detail
::
key_equals_or_empty_condition_impl
(
ci
));
}
else
if
(
typeid
(
*
b
.
m_impl
)
==
typeid
(
detail
::
key_equals_condition_impl
)
and
...
...
@@ -882,7 +882,7 @@ inline condition operator or(condition &&a, condition &&b)
auto
ci
=
static_cast
<
detail
::
key_equals_condition_impl
*>
(
b
.
m_impl
);
auto
ce
=
static_cast
<
detail
::
key_is_empty_condition_impl
*>
(
a
.
m_impl
);
if
(
ci
->
m_item_
tag
==
ce
->
m_item_tag
)
if
(
ci
->
m_item_
name
==
ce
->
m_item_name
)
return
condition
(
new
detail
::
key_equals_or_empty_condition_impl
(
ci
));
}
...
...
@@ -924,39 +924,39 @@ inline constexpr empty_type null = empty_type();
struct
key
{
/**
* @brief Construct a new key object using @a item
Tag
as name
* @brief Construct a new key object using @a item
_name
as name
*
* @param item
Tag
* @param item
_name
*/
explicit
key
(
const
std
::
string
&
item
Tag
)
:
m_item_
tag
(
itemTag
)
explicit
key
(
const
std
::
string
&
item
_name
)
:
m_item_
name
(
item_name
)
{
}
/**
* @brief Construct a new key object using @a item
Tag
as name
* @brief Construct a new key object using @a item
_name
as name
*
* @param item
Tag
* @param item
_name
*/
explicit
key
(
const
char
*
item
Tag
)
:
m_item_
tag
(
itemTag
)
explicit
key
(
const
char
*
item
_name
)
:
m_item_
name
(
item_name
)
{
}
/**
* @brief Construct a new key object using @a item
Tag
as name
* @brief Construct a new key object using @a item
_name
as name
*
* @param item
Tag
* @param item
_name
*/
explicit
key
(
std
::
string_view
item
Tag
)
:
m_item_
tag
(
itemTag
)
explicit
key
(
std
::
string_view
item
_name
)
:
m_item_
name
(
item_name
)
{
}
key
(
const
key
&
)
=
delete
;
key
&
operator
=
(
const
key
&
)
=
delete
;
std
::
string
m_item_
tag
;
///< The item name
std
::
string
m_item_
name
;
///< The item name
};
/**
...
...
@@ -965,7 +965,7 @@ struct key
template
<
typename
T
>
condition
operator
==
(
const
key
&
key
,
const
T
&
v
)
{
return
condition
(
new
detail
::
key_equals_condition_impl
({
key
.
m_item_
tag
,
v
}));
return
condition
(
new
detail
::
key_equals_condition_impl
({
key
.
m_item_
name
,
v
}));
}
/**
...
...
@@ -974,9 +974,9 @@ condition operator==(const key &key, const T &v)
inline
condition
operator
==
(
const
key
&
key
,
std
::
string_view
value
)
{
if
(
not
value
.
empty
())
return
condition
(
new
detail
::
key_equals_condition_impl
({
key
.
m_item_
tag
,
value
}));
return
condition
(
new
detail
::
key_equals_condition_impl
({
key
.
m_item_
name
,
value
}));
else
return
condition
(
new
detail
::
key_is_empty_condition_impl
(
key
.
m_item_
tag
));
return
condition
(
new
detail
::
key_is_empty_condition_impl
(
key
.
m_item_
name
));
}
/**
...
...
@@ -1006,8 +1006,8 @@ condition operator>(const key &key, const T &v)
s
<<
" > "
<<
v
;
return
condition
(
new
detail
::
key_compare_condition_impl
(
key
.
m_item_
tag
,
[
tag
=
key
.
m_item_tag
,
v
](
row_handle
r
,
bool
icase
)
{
return
r
[
tag
].
template
compare
<
T
>
(
v
,
icase
)
>
0
;
},
key
.
m_item_
name
,
[
item_name
=
key
.
m_item_name
,
v
](
row_handle
r
,
bool
icase
)
{
return
r
[
item_name
].
template
compare
<
T
>
(
v
,
icase
)
>
0
;
},
s
.
str
()));
}
...
...
@@ -1021,8 +1021,8 @@ condition operator>=(const key &key, const T &v)
s
<<
" >= "
<<
v
;
return
condition
(
new
detail
::
key_compare_condition_impl
(
key
.
m_item_
tag
,
[
tag
=
key
.
m_item_tag
,
v
](
row_handle
r
,
bool
icase
)
{
return
r
[
tag
].
template
compare
<
T
>
(
v
,
icase
)
>=
0
;
},
key
.
m_item_
name
,
[
item_name
=
key
.
m_item_name
,
v
](
row_handle
r
,
bool
icase
)
{
return
r
[
item_name
].
template
compare
<
T
>
(
v
,
icase
)
>=
0
;
},
s
.
str
()));
}
...
...
@@ -1036,8 +1036,8 @@ condition operator<(const key &key, const T &v)
s
<<
" < "
<<
v
;
return
condition
(
new
detail
::
key_compare_condition_impl
(
key
.
m_item_
tag
,
[
tag
=
key
.
m_item_tag
,
v
](
row_handle
r
,
bool
icase
)
{
return
r
[
tag
].
template
compare
<
T
>
(
v
,
icase
)
<
0
;
},
key
.
m_item_
name
,
[
item_name
=
key
.
m_item_name
,
v
](
row_handle
r
,
bool
icase
)
{
return
r
[
item_name
].
template
compare
<
T
>
(
v
,
icase
)
<
0
;
},
s
.
str
()));
}
...
...
@@ -1051,8 +1051,8 @@ condition operator<=(const key &key, const T &v)
s
<<
" <= "
<<
v
;
return
condition
(
new
detail
::
key_compare_condition_impl
(
key
.
m_item_
tag
,
[
tag
=
key
.
m_item_tag
,
v
](
row_handle
r
,
bool
icase
)
{
return
r
[
tag
].
template
compare
<
T
>
(
v
,
icase
)
<=
0
;
},
key
.
m_item_
name
,
[
item_name
=
key
.
m_item_name
,
v
](
row_handle
r
,
bool
icase
)
{
return
r
[
item_name
].
template
compare
<
T
>
(
v
,
icase
)
<=
0
;
},
s
.
str
()));
}
...
...
@@ -1061,7 +1061,7 @@ condition operator<=(const key &key, const T &v)
*/
inline
condition
operator
==
(
const
key
&
key
,
const
std
::
regex
&
rx
)
{
return
condition
(
new
detail
::
key_matches_condition_impl
(
key
.
m_item_
tag
,
rx
));
return
condition
(
new
detail
::
key_matches_condition_impl
(
key
.
m_item_
name
,
rx
));
}
/**
...
...
@@ -1069,7 +1069,7 @@ inline condition operator==(const key &key, const std::regex &rx)
*/
inline
condition
operator
==
(
const
key
&
key
,
const
empty_type
&
)
{
return
condition
(
new
detail
::
key_is_empty_condition_impl
(
key
.
m_item_
tag
));
return
condition
(
new
detail
::
key_is_empty_condition_impl
(
key
.
m_item_
name
));
}
/**
...
...
@@ -1077,7 +1077,7 @@ inline condition operator==(const key &key, const empty_type &)
*/
inline
condition
operator
!=
(
const
key
&
key
,
const
empty_type
&
)
{
return
condition
(
new
detail
::
key_is_not_empty_condition_impl
(
key
.
m_item_
tag
));
return
condition
(
new
detail
::
key_is_not_empty_condition_impl
(
key
.
m_item_
name
));
}
/**
...
...
@@ -1088,9 +1088,9 @@ template <typename T>
condition
operator
==
(
const
key
&
key
,
const
std
::
optional
<
T
>
&
v
)
{
if
(
v
.
has_value
())
return
condition
(
new
detail
::
key_equals_condition_impl
({
key
.
m_item_
tag
,
*
v
}));
return
condition
(
new
detail
::
key_equals_condition_impl
({
key
.
m_item_
name
,
*
v
}));
else
return
condition
(
new
detail
::
key_is_empty_condition_impl
(
key
.
m_item_
tag
));
return
condition
(
new
detail
::
key_is_empty_condition_impl
(
key
.
m_item_
name
));
}
/**
...
...
include/cif++/datablock.hpp
View file @
a5d43998
...
...
@@ -169,7 +169,16 @@ class datablock : public std::list<category>
/**
* @brief Get the preferred order of the categories when writing them
*/
std
::
vector
<
std
::
string
>
get_tag_order
()
const
;
[[
deprecated
(
"use get_item_order instead"
)]]
std
::
vector
<
std
::
string
>
get_tag_order
()
const
{
return
get_item_order
();
}
/**
* @brief Get the preferred order of the categories when writing them
*/
std
::
vector
<
std
::
string
>
get_item_order
()
const
;
/**
* @brief Write out the contents to @a os
...
...
@@ -177,9 +186,9 @@ class datablock : public std::list<category>
void
write
(
std
::
ostream
&
os
)
const
;
/**
* @brief Write out the contents to @a os using the order defined in @a
tag
_order
* @brief Write out the contents to @a os using the order defined in @a
item_name
_order
*/
void
write
(
std
::
ostream
&
os
,
const
std
::
vector
<
std
::
string
>
&
tag
_order
);
void
write
(
std
::
ostream
&
os
,
const
std
::
vector
<
std
::
string
>
&
item_name
_order
);
/**
* @brief Friend operator<< to write datablock @a db to std::ostream @a os
...
...
include/cif++/parser.hpp
View file @
a5d43998
...
...
@@ -143,9 +143,9 @@ class sac_parser
enum
class
CIFToken
{
U
nknown
,
U
NKNOWN
,
E
of
,
E
ND_OF_FILE
,
DATA
,
LOOP
,
...
...
@@ -153,24 +153,24 @@ class sac_parser
SAVE_
,
SAVE_NAME
,
STOP
,
Tag
,
V
alue
ITEM_NAME
,
V
ALUE
};
static
constexpr
const
char
*
get_token_name
(
CIFToken
token
)
{
switch
(
token
)
{
case
CIFToken
:
:
U
nknown
:
return
"Unknown"
;
case
CIFToken
:
:
E
of
:
return
"Eof"
;
case
CIFToken
:
:
U
NKNOWN
:
return
"Unknown"
;
case
CIFToken
:
:
E
ND_OF_FILE
:
return
"Eof"
;
case
CIFToken
:
:
DATA
:
return
"DATA"
;
case
CIFToken
:
:
LOOP
:
return
"LOOP"
;
case
CIFToken
:
:
GLOBAL
:
return
"GLOBAL"
;
case
CIFToken
:
:
SAVE_
:
return
"SAVE"
;
case
CIFToken
:
:
SAVE_NAME
:
return
"SAVE+name"
;
case
CIFToken
:
:
STOP
:
return
"STOP"
;
case
CIFToken
:
:
Tag
:
return
"Tag"
;
case
CIFToken
:
:
V
alue
:
return
"Value"
;
case
CIFToken
:
:
ITEM_NAME
:
return
"Tag"
;
case
CIFToken
:
:
V
ALUE
:
return
"Value"
;
default:
return
"Invalid token parameter"
;
}
}
...
...
@@ -267,7 +267,7 @@ class sac_parser
QuotedString
,
QuotedStringQuote
,
UnquotedString
,
Tag
,
ItemName
,
TextItem
,
TextItemNL
,
Reserved
,
...
...
include/cif++/text.hpp
View file @
a5d43998
...
...
@@ -317,7 +317,7 @@ inline char tolower(int ch)
// --------------------------------------------------------------------
/** \brief return a tuple consisting of the category and item name for @a
tag
/** \brief return a tuple consisting of the category and item name for @a
item_name
*
* The category name is stripped of its leading underscore character.
*
...
...
@@ -325,7 +325,19 @@ inline char tolower(int ch)
* cif 1.0 formatted data.
*/
std
::
tuple
<
std
::
string
,
std
::
string
>
split_tag_name
(
std
::
string_view
tag
);
[[
deprecated
(
"use split_item_name instead"
)]]
std
::
tuple
<
std
::
string
,
std
::
string
>
split_tag_name
(
std
::
string_view
item_name
);
/** \brief return a tuple consisting of the category and item name for @a item_name
*
* The category name is stripped of its leading underscore character.
*
* If no dot character was found, the category name is empty. That's for
* cif 1.0 formatted data.
*/
std
::
tuple
<
std
::
string
,
std
::
string
>
split_item_name
(
std
::
string_view
item_name
);
// --------------------------------------------------------------------
...
...
include/cif++/validate.hpp
View file @
a5d43998
...
...
@@ -266,7 +266,7 @@ struct item_alias
*/
struct
item_validator
{
std
::
string
m_
tag
;
///< The item name
std
::
string
m_
item_name
;
///< The item name
bool
m_mandatory
;
///< Flag indicating this item is mandatory
const
type_validator
*
m_type
;
///< The type for this item
cif
::
iset
m_enums
;
///< If filled, the set of allowed values
...
...
@@ -277,13 +277,13 @@ struct item_validator
/// @brief Compare based on the name
bool
operator
<
(
const
item_validator
&
rhs
)
const
{
return
icompare
(
m_
tag
,
rhs
.
m_tag
)
<
0
;
return
icompare
(
m_
item_name
,
rhs
.
m_item_name
)
<
0
;
}
/// @brief Compare based on the name
bool
operator
==
(
const
item_validator
&
rhs
)
const
{
return
iequals
(
m_
tag
,
rhs
.
m_tag
);
return
iequals
(
m_
item_name
,
rhs
.
m_item_name
);
}
/// @brief Validate the value in @a value for this item
...
...
@@ -317,11 +317,11 @@ struct category_validator
/// @brief Add item_validator @a v to the list of item validators
void
add_item_validator
(
item_validator
&&
v
);
/// @brief Return the item_validator for item @a
tag
, may return nullptr
const
item_validator
*
get_validator_for_item
(
std
::
string_view
tag
)
const
;
/// @brief Return the item_validator for item @a
item_name
, may return nullptr
const
item_validator
*
get_validator_for_item
(
std
::
string_view
item_name
)
const
;
/// @brief Return the item_validator for an item that has as alias name @a
tag
, may return nullptr
const
item_validator
*
get_validator_for_aliased_item
(
std
::
string_view
tag
)
const
;
/// @brief Return the item_validator for an item that has as alias name @a
item_name
, may return nullptr
const
item_validator
*
get_validator_for_aliased_item
(
std
::
string_view
item_name
)
const
;
};
/**
...
...
src/category.cpp
View file @
a5d43998
...
...
@@ -648,7 +648,7 @@ iset category::key_items() const
iset
result
;
for
(
auto
&
iv
:
m_cat_validator
->
m_item_validators
)
result
.
insert
(
iv
.
m_
tag
);
result
.
insert
(
iv
.
m_
item_name
);
return
result
;
}
...
...
@@ -1280,17 +1280,17 @@ std::string category::get_unique_id(std::function<std::string(int)> generator)
std
::
string
result
=
generator
(
static_cast
<
int
>
(
m_last_unique_num
++
));
std
::
string
id_
tag
=
"id"
;
std
::
string
id_
name
=
"id"
;
if
(
m_cat_validator
!=
nullptr
and
m_cat_validator
->
m_keys
.
size
()
==
1
)
{
id_
tag
=
m_cat_validator
->
m_keys
.
front
();
id_
name
=
m_cat_validator
->
m_keys
.
front
();
if
(
m_index
==
nullptr
and
m_cat_validator
!=
nullptr
)
m_index
=
new
category_index
(
*
this
);
for
(;;)
{
if
(
m_index
->
find_by_value
(
*
this
,
{
{
id_
tag
,
result
}
})
==
nullptr
)
if
(
m_index
->
find_by_value
(
*
this
,
{
{
id_
name
,
result
}
})
==
nullptr
)
break
;
result
=
generator
(
static_cast
<
int
>
(
m_last_unique_num
++
));
}
...
...
@@ -1299,7 +1299,7 @@ std::string category::get_unique_id(std::function<std::string(int)> generator)
{
for
(;;)
{
if
(
not
contains
(
key
(
id_
tag
)
==
result
))
if
(
not
contains
(
key
(
id_
name
)
==
result
))
break
;
result
=
generator
(
static_cast
<
int
>
(
m_last_unique_num
++
));
...
...
@@ -1309,17 +1309,17 @@ std::string category::get_unique_id(std::function<std::string(int)> generator)
return
result
;
}
std
::
string
category
::
get_unique_value
(
std
::
string_view
tag
)
std
::
string
category
::
get_unique_value
(
std
::
string_view
item_name
)
{
std
::
string
result
;
if
(
m_validator
and
m_cat_validator
)
{
auto
iv
=
m_cat_validator
->
get_validator_for_item
(
tag
);
auto
iv
=
m_cat_validator
->
get_validator_for_item
(
item_name
);
if
(
iv
and
iv
->
m_type
and
iv
->
m_type
->
m_primitive_type
==
DDL_PrimitiveType
::
Numb
)
{
uint64_t
v
=
find_max
<
uint64_t
>
(
tag
);
uint64_t
v
=
find_max
<
uint64_t
>
(
item_name
);
result
=
std
::
to_string
(
v
+
1
);
}
}
...
...
@@ -1331,7 +1331,7 @@ std::string category::get_unique_value(std::string_view tag)
{
// result = m_name + "-" + std::to_string(ix);
result
=
cif_id_for_number
(
ix
);
if
(
not
contains
(
key
(
tag
)
==
result
))
if
(
not
contains
(
key
(
item_name
)
==
result
))
break
;
}
}
...
...
@@ -1339,14 +1339,14 @@ std::string category::get_unique_value(std::string_view tag)
return
result
;
}
void
category
::
update_value
(
const
std
::
vector
<
row_handle
>
&
rows
,
std
::
string_view
tag
,
std
::
string_view
value
)
void
category
::
update_value
(
const
std
::
vector
<
row_handle
>
&
rows
,
std
::
string_view
item_name
,
std
::
string_view
value
)
{
using
namespace
std
::
literals
;
if
(
rows
.
empty
())
return
;
auto
colIx
=
get_item_ix
(
tag
);
auto
colIx
=
get_item_ix
(
item_name
);
if
(
colIx
>=
m_items
.
size
())
throw
std
::
runtime_error
(
"Invalid item "
+
std
::
string
{
value
}
+
" for "
+
m_name
);
...
...
@@ -1357,10 +1357,10 @@ void category::update_value(const std::vector<row_handle> &rows, std::string_vie
(
*
col
.
m_validator
)(
value
);
// first some sanity checks, what was the old value and is it the same for all rows?
std
::
string
oldValue
{
rows
.
front
()[
tag
].
text
()
};
std
::
string
oldValue
{
rows
.
front
()[
item_name
].
text
()
};
for
(
auto
row
:
rows
)
{
if
(
oldValue
!=
row
[
tag
].
text
())
if
(
oldValue
!=
row
[
item_name
].
text
())
throw
std
::
runtime_error
(
"Inconsistent old values in update_value"
);
}
...
...
@@ -1376,20 +1376,20 @@ void category::update_value(const std::vector<row_handle> &rows, std::string_vie
{
for
(
auto
&&
[
childCat
,
linked
]
:
m_child_links
)
{
if
(
std
::
find
(
linked
->
m_parent_keys
.
begin
(),
linked
->
m_parent_keys
.
end
(),
tag
)
==
linked
->
m_parent_keys
.
end
())
if
(
std
::
find
(
linked
->
m_parent_keys
.
begin
(),
linked
->
m_parent_keys
.
end
(),
item_name
)
==
linked
->
m_parent_keys
.
end
())
continue
;
condition
cond
;
std
::
string
child
Tag
;
std
::
string
child
ItemName
;
for
(
size_t
ix
=
0
;
ix
<
linked
->
m_parent_keys
.
size
();
++
ix
)
{
std
::
string
pk
=
linked
->
m_parent_keys
[
ix
];
std
::
string
ck
=
linked
->
m_child_keys
[
ix
];
if
(
pk
==
tag
)
if
(
pk
==
item_name
)
{
child
Tag
=
ck
;
child
ItemName
=
ck
;
cond
=
std
::
move
(
cond
)
&&
key
(
ck
)
==
oldValue
;
}
else
...
...
@@ -1436,7 +1436,7 @@ void category::update_value(const std::vector<row_handle> &rows, std::string_vie
std
::
string
pk
=
linked
->
m_parent_keys
[
ix
];
std
::
string
ck
=
linked
->
m_child_keys
[
ix
];
if
(
pk
==
tag
)
if
(
pk
==
item_name
)
check
=
std
::
move
(
check
)
&&
key
(
ck
)
==
value
;
else
check
=
std
::
move
(
check
)
&&
key
(
ck
)
==
parent
[
pk
].
text
();
...
...
@@ -1458,12 +1458,12 @@ void category::update_value(const std::vector<row_handle> &rows, std::string_vie
// cannot update this...
if
(
cif
::
VERBOSE
>
0
)
std
::
cerr
<<
"Cannot update child "
<<
childCat
->
m_name
<<
"."
<<
child
Tag
<<
" with value "
<<
value
<<
'\n'
;
std
::
cerr
<<
"Cannot update child "
<<
childCat
->
m_name
<<
"."
<<
child
ItemName
<<
" with value "
<<
value
<<
'\n'
;
}
// finally, update the children
if
(
not
process
.
empty
())
childCat
->
update_value
(
process
,
child
Tag
,
value
);
childCat
->
update_value
(
process
,
child
ItemName
,
value
);
}
}
}
...
...
@@ -1521,11 +1521,11 @@ void category::update_value(row *row, uint16_t item, std::string_view value, boo
for
(
auto
&&
[
childCat
,
linked
]
:
m_child_links
)
{
if
(
std
::
find
(
linked
->
m_parent_keys
.
begin
(),
linked
->
m_parent_keys
.
end
(),
iv
->
m_
tag
)
==
linked
->
m_parent_keys
.
end
())
if
(
std
::
find
(
linked
->
m_parent_keys
.
begin
(),
linked
->
m_parent_keys
.
end
(),
iv
->
m_
item_name
)
==
linked
->
m_parent_keys
.
end
())
continue
;
condition
cond
;
std
::
string
child
Tag
;
std
::
string
child
ItemName
;
for
(
size_t
ix
=
0
;
ix
<
linked
->
m_parent_keys
.
size
();
++
ix
)
{
...
...
@@ -1534,9 +1534,9 @@ void category::update_value(row *row, uint16_t item, std::string_view value, boo
// TODO: add code to *NOT* test mandatory items for Empty
if
(
pk
==
iv
->
m_
tag
)
if
(
pk
==
iv
->
m_
item_name
)
{
child
Tag
=
ck
;
child
ItemName
=
ck
;
cond
=
std
::
move
(
cond
)
and
key
(
ck
)
==
oldStrValue
;
}
else
...
...
@@ -1569,7 +1569,7 @@ void category::update_value(row *row, uint16_t item, std::string_view value, boo
std
::
string
pk
=
linked
->
m_parent_keys
[
ix
];
std
::
string
ck
=
linked
->
m_child_keys
[
ix
];
if
(
pk
==
iv
->
m_
tag
)
if
(
pk
==
iv
->
m_
item_name
)
cond_n
=
std
::
move
(
cond_n
)
and
key
(
ck
)
==
value
;
else
{
...
...
@@ -1591,7 +1591,7 @@ void category::update_value(row *row, uint16_t item, std::string_view value, boo
}
for
(
auto
cr
:
rows
)
cr
.
assign
(
child
Tag
,
value
,
false
);
cr
.
assign
(
child
ItemName
,
value
,
false
);
}
}
}
...
...
@@ -1884,7 +1884,7 @@ namespace detail
}
// namespace detail
std
::
vector
<
std
::
string
>
category
::
get_
tag
_order
()
const
std
::
vector
<
std
::
string
>
category
::
get_
item
_order
()
const
{
std
::
vector
<
std
::
string
>
result
;
for
(
auto
&
c
:
m_items
)
...
...
@@ -2032,10 +2032,10 @@ void category::write(std::ostream &os, const std::vector<uint16_t> &order, bool
for
(
auto
&
col
:
m_items
)
{
std
::
string
tag
=
'_'
+
m_name
+
'.'
+
col
.
m_name
;
std
::
string
item_name
=
'_'
+
m_name
+
'.'
+
col
.
m_name
;
if
(
l
<
tag
.
length
())
l
=
tag
.
length
();
if
(
l
<
item_name
.
length
())
l
=
item_name
.
length
();
}
l
+=
3
;
...
...
@@ -2107,9 +2107,9 @@ bool category::operator==(const category &rhs) const
using
namespace
std
::
placeholders
;
// set<std::string>
tagsA(a.items()), tag
sB(b.items());
// set<std::string>
item_namesA(a.items()), item_name
sB(b.items());
//
// if (
tagsA != tag
sB)
// if (
item_namesA != item_name
sB)
// std::cout << "Unequal number of items\n";
const
category_validator
*
catValidator
=
nullptr
;
...
...
@@ -2119,40 +2119,40 @@ bool category::operator==(const category &rhs) const
catValidator
=
validator
->
get_validator_for_category
(
a
.
name
());
typedef
std
::
function
<
int
(
std
::
string_view
,
std
::
string_view
)
>
compType
;
std
::
vector
<
std
::
tuple
<
std
::
string
,
compType
>>
tag
s
;
std
::
vector
<
std
::
tuple
<
std
::
string
,
compType
>>
item_name
s
;
std
::
vector
<
std
::
string
>
keys
;
std
::
vector
<
size_t
>
keyIx
;
if
(
catValidator
==
nullptr
)
{
for
(
auto
&
tag
:
a
.
get_items
())
for
(
auto
&
item_name
:
a
.
get_items
())
{
tags
.
push_back
(
std
::
make_tuple
(
tag
,
[](
std
::
string_view
va
,
std
::
string_view
vb
)
item_names
.
push_back
(
std
::
make_tuple
(
item_name
,
[](
std
::
string_view
va
,
std
::
string_view
vb
)
{
return
va
.
compare
(
vb
);
}));
keyIx
.
push_back
(
keys
.
size
());
keys
.
push_back
(
tag
);
keys
.
push_back
(
item_name
);
}
}
else
{
keys
=
catValidator
->
m_keys
;
for
(
auto
&
tag
:
a
.
key_items
())
for
(
auto
&
item_name
:
a
.
key_items
())
{
auto
iv
=
catValidator
->
get_validator_for_item
(
tag
);
auto
iv
=
catValidator
->
get_validator_for_item
(
item_name
);
if
(
iv
==
nullptr
)
throw
std
::
runtime_error
(
"missing item validator"
);
auto
tv
=
iv
->
m_type
;
if
(
tv
==
nullptr
)
throw
std
::
runtime_error
(
"missing type validator"
);
tags
.
push_back
(
std
::
make_tuple
(
tag
,
std
::
bind
(
&
cif
::
type_validator
::
compare
,
tv
,
std
::
placeholders
::
_1
,
std
::
placeholders
::
_2
)));
item_names
.
push_back
(
std
::
make_tuple
(
item_name
,
std
::
bind
(
&
cif
::
type_validator
::
compare
,
tv
,
std
::
placeholders
::
_1
,
std
::
placeholders
::
_2
)));
auto
pred
=
[
tag
](
const
std
::
string
&
s
)
->
bool
auto
pred
=
[
item_name
](
const
std
::
string
&
s
)
->
bool
{
return
cif
::
iequals
(
tag
,
s
)
==
0
;
return
cif
::
iequals
(
item_name
,
s
)
==
0
;
};
if
(
find_if
(
keys
.
begin
(),
keys
.
end
(),
pred
)
==
keys
.
end
())
keyIx
.
push_back
(
tag
s
.
size
()
-
1
);
keyIx
.
push_back
(
item_name
s
.
size
()
-
1
);
}
}
...
...
@@ -2165,12 +2165,12 @@ bool category::operator==(const category &rhs) const
for
(
auto
kix
:
keyIx
)
{
std
::
string
tag
;
std
::
string
item_name
;
compType
compare
;
std
::
tie
(
tag
,
compare
)
=
tag
s
[
kix
];
std
::
tie
(
item_name
,
compare
)
=
item_name
s
[
kix
];
d
=
compare
(
a
[
tag
].
text
(),
b
[
tag
].
text
());
d
=
compare
(
a
[
item_name
].
text
(),
b
[
item_name
].
text
());
if
(
d
!=
0
)
break
;
...
...
@@ -2192,19 +2192,19 @@ bool category::operator==(const category &rhs) const
std
::
vector
<
std
::
string
>
missingA
,
missingB
,
different
;
for
(
auto
&
tt
:
tag
s
)
for
(
auto
&
tt
:
item_name
s
)
{
std
::
string
tag
;
std
::
string
item_name
;
compType
compare
;
std
::
tie
(
tag
,
compare
)
=
tt
;
std
::
tie
(
item_name
,
compare
)
=
tt
;
// make it an option to compare unapplicable to empty or something
auto
ta
=
ra
[
tag
].
text
();
auto
ta
=
ra
[
item_name
].
text
();
if
(
ta
==
"."
or
ta
==
"?"
)
ta
=
""
;
auto
tb
=
rb
[
tag
].
text
();
auto
tb
=
rb
[
item_name
].
text
();
if
(
tb
==
"."
or
tb
==
"?"
)
tb
=
""
;
...
...
src/condition.cpp
View file @
a5d43998
...
...
@@ -63,14 +63,14 @@ namespace detail
condition_impl
*
key_equals_condition_impl
::
prepare
(
const
category
&
c
)
{
m_item_ix
=
c
.
get_item_ix
(
m_item_
tag
);
m_icase
=
is_item_type_uchar
(
c
,
m_item_
tag
);
m_item_ix
=
c
.
get_item_ix
(
m_item_
name
);
m_icase
=
is_item_type_uchar
(
c
,
m_item_
name
);
if
(
c
.
get_cat_validator
()
!=
nullptr
and
c
.
key_item_indices
().
contains
(
m_item_ix
)
and
c
.
key_item_indices
().
size
()
==
1
)
{
m_single_hit
=
c
[{
{
m_item_
tag
,
m_value
}
}];
m_single_hit
=
c
[{
{
m_item_
name
,
m_value
}
}];
}
return
this
;
...
...
src/datablock.cpp
View file @
a5d43998
...
...
@@ -159,7 +159,7 @@ std::tuple<datablock::iterator, bool> datablock::emplace(std::string_view name)
return
std
::
make_tuple
(
i
,
is_new
);
}
std
::
vector
<
std
::
string
>
datablock
::
get_
tag
_order
()
const
std
::
vector
<
std
::
string
>
datablock
::
get_
item
_order
()
const
{
std
::
vector
<
std
::
string
>
result
;
...
...
@@ -168,7 +168,7 @@ std::vector<std::string> datablock::get_tag_order() const
{
return
cat
.
name
()
==
"entry"
;
});
if
(
ci
!=
end
())
{
auto
cto
=
ci
->
get_
tag
_order
();
auto
cto
=
ci
->
get_
item
_order
();
result
.
insert
(
result
.
end
(),
cto
.
begin
(),
cto
.
end
());
}
...
...
@@ -176,7 +176,7 @@ std::vector<std::string> datablock::get_tag_order() const
{
return
cat
.
name
()
==
"audit_conform"
;
});
if
(
ci
!=
end
())
{
auto
cto
=
ci
->
get_
tag
_order
();
auto
cto
=
ci
->
get_
item
_order
();
result
.
insert
(
result
.
end
(),
cto
.
begin
(),
cto
.
end
());
}
...
...
@@ -184,7 +184,7 @@ std::vector<std::string> datablock::get_tag_order() const
{
if
(
cat
.
name
()
==
"entry"
or
cat
.
name
()
==
"audit_conform"
)
continue
;
auto
cto
=
cat
.
get_
tag
_order
();
auto
cto
=
cat
.
get_
item
_order
();
result
.
insert
(
result
.
end
(),
cto
.
begin
(),
cto
.
end
());
}
...
...
@@ -338,16 +338,16 @@ void datablock::write(std::ostream &os) const
}
}
void
datablock
::
write
(
std
::
ostream
&
os
,
const
std
::
vector
<
std
::
string
>
&
tag
_order
)
void
datablock
::
write
(
std
::
ostream
&
os
,
const
std
::
vector
<
std
::
string
>
&
item_name
_order
)
{
os
<<
"data_"
<<
m_name
<<
'\n'
<<
"#
\n
"
;
std
::
vector
<
std
::
string
>
cat_order
;
for
(
auto
&
o
:
tag
_order
)
for
(
auto
&
o
:
item_name
_order
)
{
std
::
string
cat_name
,
item_name
;
std
::
tie
(
cat_name
,
item_name
)
=
split_
tag
_name
(
o
);
std
::
tie
(
cat_name
,
item_name
)
=
split_
item
_name
(
o
);
if
(
find_if
(
cat_order
.
rbegin
(),
cat_order
.
rend
(),
[
cat_name
](
const
std
::
string
&
s
)
->
bool
{
return
iequals
(
cat_name
,
s
);
})
==
cat_order
.
rend
())
cat_order
.
push_back
(
cat_name
);
...
...
@@ -360,10 +360,10 @@ void datablock::write(std::ostream &os, const std::vector<std::string> &tag_orde
continue
;
std
::
vector
<
std
::
string
>
items
;
for
(
auto
&
o
:
tag
_order
)
for
(
auto
&
o
:
item_name
_order
)
{
std
::
string
cat_name
,
item_name
;
std
::
tie
(
cat_name
,
item_name
)
=
split_
tag
_name
(
o
);
std
::
tie
(
cat_name
,
item_name
)
=
split_
item
_name
(
o
);
if
(
cat_name
==
c
)
items
.
push_back
(
item_name
);
...
...
src/dictionary_parser.cpp
View file @
a5d43998
...
...
@@ -50,7 +50,7 @@ class dictionary_parser : public parser
try
{
while
(
m_lookahead
!=
CIFToken
::
E
of
)
while
(
m_lookahead
!=
CIFToken
::
E
ND_OF_FILE
)
{
switch
(
m_lookahead
)
{
...
...
@@ -128,7 +128,7 @@ class dictionary_parser : public parser
datablock
::
iterator
cat
=
dict
.
end
();
match
(
CIFToken
::
SAVE_NAME
);
while
(
m_lookahead
==
CIFToken
::
LOOP
or
m_lookahead
==
CIFToken
::
Tag
)
while
(
m_lookahead
==
CIFToken
::
LOOP
or
m_lookahead
==
CIFToken
::
ITEM_NAME
)
{
if
(
m_lookahead
==
CIFToken
::
LOOP
)
{
...
...
@@ -136,30 +136,30 @@ class dictionary_parser : public parser
match
(
CIFToken
::
LOOP
);
std
::
vector
<
std
::
string
>
tag
s
;
while
(
m_lookahead
==
CIFToken
::
Tag
)
std
::
vector
<
std
::
string
>
item_name
s
;
while
(
m_lookahead
==
CIFToken
::
ITEM_NAME
)
{
std
::
string
catName
,
item_name
;
std
::
tie
(
catName
,
item_name
)
=
split_
tag
_name
(
m_token_value
);
std
::
tie
(
catName
,
item_name
)
=
split_
item
_name
(
m_token_value
);
if
(
cat
==
dict
.
end
())
std
::
tie
(
cat
,
std
::
ignore
)
=
dict
.
emplace
(
catName
);
else
if
(
not
iequals
(
cat
->
name
(),
catName
))
error
(
"inconsistent categories in loop_"
);
tag
s
.
push_back
(
item_name
);
match
(
CIFToken
::
Tag
);
item_name
s
.
push_back
(
item_name
);
match
(
CIFToken
::
ITEM_NAME
);
}
while
(
m_lookahead
==
CIFToken
::
V
alue
)
while
(
m_lookahead
==
CIFToken
::
V
ALUE
)
{
cat
->
emplace
({});
auto
row
=
cat
->
back
();
for
(
auto
tag
:
tag
s
)
for
(
auto
item_name
:
item_name
s
)
{
row
[
tag
]
=
m_token_value
;
match
(
CIFToken
::
V
alue
);
row
[
item_name
]
=
m_token_value
;
match
(
CIFToken
::
V
ALUE
);
}
}
...
...
@@ -168,18 +168,18 @@ class dictionary_parser : public parser
else
{
std
::
string
catName
,
item_name
;
std
::
tie
(
catName
,
item_name
)
=
split_
tag
_name
(
m_token_value
);
std
::
tie
(
catName
,
item_name
)
=
split_
item
_name
(
m_token_value
);
if
(
cat
==
dict
.
end
()
or
not
iequals
(
cat
->
name
(),
catName
))
std
::
tie
(
cat
,
std
::
ignore
)
=
dict
.
emplace
(
catName
);
match
(
CIFToken
::
Tag
);
match
(
CIFToken
::
ITEM_NAME
);
if
(
cat
->
empty
())
cat
->
emplace
({});
cat
->
back
()[
item_name
]
=
m_token_value
;
match
(
CIFToken
::
V
alue
);
match
(
CIFToken
::
V
ALUE
);
}
}
...
...
@@ -191,7 +191,7 @@ class dictionary_parser : public parser
std
::
vector
<
std
::
string
>
keys
;
for
(
auto
k
:
dict
[
"category_key"
])
keys
.
push_back
(
std
::
get
<
1
>
(
split_
tag
_name
(
k
[
"name"
].
as
<
std
::
string
>
())));
keys
.
push_back
(
std
::
get
<
1
>
(
split_
item
_name
(
k
[
"name"
].
as
<
std
::
string
>
())));
iset
groups
;
for
(
auto
g
:
dict
[
"category_group"
])
...
...
@@ -234,17 +234,17 @@ class dictionary_parser : public parser
// collect the dict from our dataBlock and construct validators
for
(
auto
i
:
dict
[
"item"
])
{
std
::
string
tagName
,
category
,
mandatory
;
cif
::
tie
(
tagName
,
category
,
mandatory
)
=
i
.
get
(
"name"
,
"category_id"
,
"mandatory_code"
);
std
::
string
item
,
category
,
mandatory
;
cif
::
tie
(
item
,
category
,
mandatory
)
=
i
.
get
(
"name"
,
"category_id"
,
"mandatory_code"
);
std
::
string
cat_name
,
item_name
;
std
::
tie
(
cat_name
,
item_name
)
=
split_
tag_name
(
tagName
);
std
::
tie
(
cat_name
,
item_name
)
=
split_
item_name
(
item
);
if
(
cat_name
.
empty
()
or
item_name
.
empty
())
error
(
"Invalid
tag name in _item.name "
+
tagName
);
error
(
"Invalid
item name in _item.name "
+
item
);
if
(
not
iequals
(
category
,
cat_name
)
and
not
(
category
.
empty
()
or
category
==
"?"
))
error
(
"specified category id does match the implicit category name for
tag '"
+
tagName
+
'\''
);
error
(
"specified category id does match the implicit category name for
item '"
+
item
+
'\''
);
else
category
=
cat_name
;
...
...
@@ -260,22 +260,22 @@ class dictionary_parser : public parser
{
if
(
VERBOSE
>
2
)
{
std
::
cerr
<<
"inconsistent mandatory value for "
<<
tagName
<<
" in dictionary
\n
"
;
std
::
cerr
<<
"inconsistent mandatory value for "
<<
item
<<
" in dictionary
\n
"
;
if
(
iequals
(
tagName
,
saveFrameName
))
if
(
iequals
(
item
,
saveFrameName
))
std
::
cerr
<<
"choosing "
<<
mandatory
<<
'\n'
;
else
std
::
cerr
<<
"choosing "
<<
(
vi
->
m_mandatory
?
"Y"
:
"N"
)
<<
'\n'
;
}
if
(
iequals
(
tagName
,
saveFrameName
))
if
(
iequals
(
item
,
saveFrameName
))
vi
->
m_mandatory
=
(
iequals
(
mandatory
,
"yes"
));
}
if
(
vi
->
m_type
!=
nullptr
and
tv
!=
nullptr
and
vi
->
m_type
!=
tv
)
{
if
(
VERBOSE
>
1
)
std
::
cerr
<<
"inconsistent type for "
<<
tagName
<<
" in dictionary
\n
"
;
std
::
cerr
<<
"inconsistent type for "
<<
item
<<
" in dictionary
\n
"
;
}
// vi->mMandatory = (iequals(mandatory, "yes"));
...
...
@@ -358,7 +358,7 @@ class dictionary_parser : public parser
}
size_t
ix
=
linkIndex
.
at
(
key
);
addLink
(
ix
,
piv
->
m_
tag
,
civ
->
m_tag
);
addLink
(
ix
,
piv
->
m_
item_name
,
civ
->
m_item_name
);
}
// Only process inline linked items if the linked group list is absent
...
...
@@ -386,7 +386,7 @@ class dictionary_parser : public parser
}
size_t
ix
=
linkIndex
.
at
(
key
);
addLink
(
ix
,
piv
->
m_
tag
,
civ
->
m_tag
);
addLink
(
ix
,
piv
->
m_
item_name
,
civ
->
m_item_name
);
}
}
...
...
@@ -417,7 +417,7 @@ class dictionary_parser : public parser
for
(
auto
&
iv
:
cv
.
m_item_validators
)
{
if
(
iv
.
m_type
==
nullptr
and
cif
::
VERBOSE
>=
0
)
std
::
cerr
<<
"Missing item_type for "
<<
iv
.
m_
tag
<<
'\n'
;
std
::
cerr
<<
"Missing item_type for "
<<
iv
.
m_
item_name
<<
'\n'
;
}
}
}
...
...
src/model.cpp
View file @
a5d43998
...
...
@@ -163,9 +163,9 @@ int atom::atom_impl::get_charge() const
// const std::string atom::atom_impl::get_property(const std::string_view name) const
// {
// for (auto &&[
tag
, ref] : mCachedRefs)
// for (auto &&[
item_name
, ref] : mCachedRefs)
// {
// if (
tag
== name)
// if (
item_name
== name)
// return ref.as<std::string>();
// }
...
...
@@ -175,9 +175,9 @@ int atom::atom_impl::get_charge() const
// void atom::atom_impl::set_property(const std::string_view name, const std::string &value)
// {
// for (auto &&[
tag
, ref] : mCachedRefs)
// for (auto &&[
item_name
, ref] : mCachedRefs)
// {
// if (
tag
!= name)
// if (
item_name
!= name)
// continue;
// ref = value;
...
...
src/parser.cpp
View file @
a5d43998
...
...
@@ -269,7 +269,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
{
const
auto
kEOF
=
std
::
char_traits
<
char
>::
eof
();
CIFToken
result
=
CIFToken
::
U
nknown
;
CIFToken
result
=
CIFToken
::
U
NKNOWN
;
int
quoteChar
=
0
;
State
state
=
State
::
Start
;
m_bol
=
false
;
...
...
@@ -279,7 +279,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
reserved_words_automaton
dag
;
while
(
result
==
CIFToken
::
U
nknown
)
while
(
result
==
CIFToken
::
U
NKNOWN
)
{
auto
ch
=
get_next_char
();
...
...
@@ -287,7 +287,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
{
case
State
:
:
Start
:
if
(
ch
==
kEOF
)
result
=
CIFToken
::
E
of
;
result
=
CIFToken
::
E
ND_OF_FILE
;
else
if
(
ch
==
'\n'
)
{
m_bol
=
true
;
...
...
@@ -298,7 +298,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
else
if
(
ch
==
'#'
)
state
=
State
::
Comment
;
else
if
(
ch
==
'_'
)
state
=
State
::
Tag
;
state
=
State
::
ItemName
;
else
if
(
ch
==
';'
and
m_bol
)
state
=
State
::
TextItem
;
else
if
(
ch
==
'?'
)
...
...
@@ -316,7 +316,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
case
State
:
:
White
:
if
(
ch
==
kEOF
)
result
=
CIFToken
::
E
of
;
result
=
CIFToken
::
E
ND_OF_FILE
;
else
if
(
not
is_space
(
ch
))
{
state
=
State
::
Start
;
...
...
@@ -335,7 +335,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
m_token_buffer
.
clear
();
}
else
if
(
ch
==
kEOF
)
result
=
CIFToken
::
E
of
;
result
=
CIFToken
::
E
ND_OF_FILE
;
else
if
(
not
is_any_print
(
ch
))
error
(
"invalid character in comment"
);
break
;
...
...
@@ -344,7 +344,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
if
(
not
is_non_blank
(
ch
))
{
retract
();
result
=
CIFToken
::
V
alue
;
result
=
CIFToken
::
V
ALUE
;
}
else
state
=
State
::
Value
;
...
...
@@ -366,7 +366,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
{
assert
(
m_token_buffer
.
size
()
>=
2
);
m_token_value
=
std
::
string_view
(
m_token_buffer
.
data
()
+
1
,
m_token_buffer
.
size
()
-
3
);
result
=
CIFToken
::
V
alue
;
result
=
CIFToken
::
V
ALUE
;
}
else
if
(
ch
==
kEOF
)
error
(
"unterminated textfield"
);
...
...
@@ -387,7 +387,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
if
(
is_white
(
ch
))
{
retract
();
result
=
CIFToken
::
V
alue
;
result
=
CIFToken
::
V
ALUE
;
if
(
m_token_buffer
.
size
()
<
2
)
error
(
"Invalid quoted string token"
);
...
...
@@ -403,11 +403,11 @@ sac_parser::CIFToken sac_parser::get_next_token()
error
(
"invalid character in quoted string"
);
break
;
case
State
:
:
Tag
:
case
State
:
:
ItemName
:
if
(
not
is_non_blank
(
ch
))
{
retract
();
result
=
CIFToken
::
Tag
;
result
=
CIFToken
::
ITEM_NAME
;
m_token_value
=
std
::
string_view
(
m_token_buffer
.
data
(),
m_token_buffer
.
size
());
}
break
;
...
...
@@ -422,7 +422,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
if
(
not
is_non_blank
(
ch
))
{
retract
();
result
=
CIFToken
::
V
alue
;
result
=
CIFToken
::
V
ALUE
;
m_token_value
=
std
::
string_view
(
m_token_buffer
.
data
(),
m_token_buffer
.
size
());
}
else
...
...
@@ -467,7 +467,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
if
(
not
is_non_blank
(
ch
))
{
retract
();
result
=
CIFToken
::
V
alue
;
result
=
CIFToken
::
V
ALUE
;
m_token_value
=
std
::
string_view
(
m_token_buffer
.
data
(),
m_token_buffer
.
size
());
break
;
}
...
...
@@ -483,7 +483,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
if
(
VERBOSE
>=
5
)
{
std
::
cerr
<<
get_token_name
(
result
);
if
(
result
!=
CIFToken
::
E
of
)
if
(
result
!=
CIFToken
::
E
ND_OF_FILE
)
std
::
cerr
<<
" "
<<
std
::
quoted
(
m_token_value
);
std
::
cerr
<<
'\n'
;
}
...
...
@@ -710,7 +710,7 @@ bool sac_parser::parse_single_datablock(const std::string &datablock, const data
void
sac_parser
::
parse_file
()
{
while
(
m_lookahead
!=
CIFToken
::
E
of
)
while
(
m_lookahead
!=
CIFToken
::
E
ND_OF_FILE
)
{
switch
(
m_lookahead
)
{
...
...
@@ -735,10 +735,10 @@ void sac_parser::parse_file()
void
sac_parser
::
parse_global
()
{
match
(
CIFToken
::
GLOBAL
);
while
(
m_lookahead
==
CIFToken
::
Tag
)
while
(
m_lookahead
==
CIFToken
::
ITEM_NAME
)
{
match
(
CIFToken
::
Tag
);
match
(
CIFToken
::
V
alue
);
match
(
CIFToken
::
ITEM_NAME
);
match
(
CIFToken
::
V
ALUE
);
}
}
...
...
@@ -747,7 +747,7 @@ void sac_parser::parse_datablock()
static
const
std
::
string
kUnitializedCategory
(
"<invalid>"
);
std
::
string
cat
=
kUnitializedCategory
;
// intial value acts as a guard for empty category names
while
(
m_lookahead
==
CIFToken
::
LOOP
or
m_lookahead
==
CIFToken
::
Tag
or
m_lookahead
==
CIFToken
::
SAVE_NAME
)
while
(
m_lookahead
==
CIFToken
::
LOOP
or
m_lookahead
==
CIFToken
::
ITEM_NAME
or
m_lookahead
==
CIFToken
::
SAVE_NAME
)
{
switch
(
m_lookahead
)
{
...
...
@@ -757,12 +757,12 @@ void sac_parser::parse_datablock()
match
(
CIFToken
::
LOOP
);
std
::
vector
<
std
::
string
>
tag
s
;
std
::
vector
<
std
::
string
>
item_name
s
;
while
(
m_lookahead
==
CIFToken
::
Tag
)
while
(
m_lookahead
==
CIFToken
::
ITEM_NAME
)
{
std
::
string
catName
,
itemName
;
std
::
tie
(
catName
,
itemName
)
=
split_
tag
_name
(
m_token_value
);
std
::
tie
(
catName
,
itemName
)
=
split_
item
_name
(
m_token_value
);
if
(
cat
==
kUnitializedCategory
)
{
...
...
@@ -772,19 +772,19 @@ void sac_parser::parse_datablock()
else
if
(
not
iequals
(
cat
,
catName
))
error
(
"inconsistent categories in loop_"
);
tag
s
.
push_back
(
itemName
);
item_name
s
.
push_back
(
itemName
);
match
(
CIFToken
::
Tag
);
match
(
CIFToken
::
ITEM_NAME
);
}
while
(
m_lookahead
==
CIFToken
::
V
alue
)
while
(
m_lookahead
==
CIFToken
::
V
ALUE
)
{
produce_row
();
for
(
auto
tag
:
tag
s
)
for
(
auto
item_name
:
item_name
s
)
{
produce_item
(
cat
,
tag
,
m_token_value
);
match
(
CIFToken
::
V
alue
);
produce_item
(
cat
,
item_name
,
m_token_value
);
match
(
CIFToken
::
V
ALUE
);
}
}
...
...
@@ -792,10 +792,10 @@ void sac_parser::parse_datablock()
break
;
}
case
CIFToken
:
:
Tag
:
case
CIFToken
:
:
ITEM_NAME
:
{
std
::
string
catName
,
itemName
;
std
::
tie
(
catName
,
itemName
)
=
split_
tag
_name
(
m_token_value
);
std
::
tie
(
catName
,
itemName
)
=
split_
item
_name
(
m_token_value
);
if
(
not
iequals
(
cat
,
catName
))
{
...
...
@@ -804,11 +804,11 @@ void sac_parser::parse_datablock()
produce_row
();
}
match
(
CIFToken
::
Tag
);
match
(
CIFToken
::
ITEM_NAME
);
produce_item
(
cat
,
itemName
,
m_token_value
);
match
(
CIFToken
::
V
alue
);
match
(
CIFToken
::
V
ALUE
);
break
;
}
...
...
src/pdb/reconstruct.cpp
View file @
a5d43998
...
...
@@ -239,18 +239,18 @@ void checkAtomRecords(datablock &db)
// Rewrite the coordinates and other items that look better in a fixed format
// Be careful not to nuke invalidly formatted data here
for
(
auto
[
tag
,
prec
]
:
std
::
vector
<
std
::
tuple
<
std
::
string_view
,
std
::
string
::
size_type
>>
{
for
(
auto
[
item_name
,
prec
]
:
std
::
vector
<
std
::
tuple
<
std
::
string_view
,
std
::
string
::
size_type
>>
{
{
"cartn_x"
,
3
},
{
"cartn_y"
,
3
},
{
"cartn_z"
,
3
},
{
"occupancy"
,
2
},
{
"b_iso_or_equiv"
,
2
}
})
{
if
(
row
[
tag
].
empty
())
if
(
row
[
item_name
].
empty
())
continue
;
float
v
;
auto
s
=
row
.
get
<
std
::
string
>
(
tag
);
auto
s
=
row
.
get
<
std
::
string
>
(
item_name
);
if
(
auto
[
ptr
,
ec
]
=
cif
::
from_chars
(
s
.
data
(),
s
.
data
()
+
s
.
length
(),
v
);
ec
!=
std
::
errc
())
continue
;
...
...
@@ -259,7 +259,7 @@ void checkAtomRecords(datablock &db)
char
b
[
12
];
if
(
auto
[
ptr
,
ec
]
=
cif
::
to_chars
(
b
,
b
+
sizeof
(
b
),
v
,
cif
::
chars_format
::
fixed
,
prec
);
ec
==
std
::
errc
())
row
.
assign
(
tag
,
{
b
,
static_cast
<
std
::
string
::
size_type
>
(
ptr
-
b
)
},
false
,
false
);
row
.
assign
(
item_name
,
{
b
,
static_cast
<
std
::
string
::
size_type
>
(
ptr
-
b
)
},
false
,
false
);
}
}
}
...
...
@@ -268,21 +268,21 @@ void checkAtomRecords(datablock &db)
if
(
cv
)
{
// See if there are items that are no longer known
for
(
auto
tag
:
atom_site
.
get_items
())
for
(
auto
item_name
:
atom_site
.
get_items
())
{
if
(
cv
->
get_validator_for_item
(
tag
)
!=
nullptr
)
if
(
cv
->
get_validator_for_item
(
item_name
)
!=
nullptr
)
continue
;
auto
r
=
atom_site
.
find_first
(
key
(
tag
)
!=
null
);
auto
r
=
atom_site
.
find_first
(
key
(
item_name
)
!=
null
);
if
(
not
r
)
{
if
(
cif
::
VERBOSE
>
0
)
std
::
clog
<<
"Dropping unknown item "
<<
tag
<<
'\n'
;
std
::
clog
<<
"Dropping unknown item "
<<
item_name
<<
'\n'
;
atom_site
.
remove_item
(
tag
);
atom_site
.
remove_item
(
item_name
);
}
else
if
(
cif
::
VERBOSE
>
0
)
std
::
clog
<<
"Keeping unknown item "
<<
std
::
quoted
(
tag
)
<<
" in atom_site since it is not empty
\n
"
;
std
::
clog
<<
"Keeping unknown item "
<<
std
::
quoted
(
item_name
)
<<
" in atom_site since it is not empty
\n
"
;
}
}
}
...
...
@@ -733,19 +733,19 @@ void reconstruct_pdbx(file &file, std::string_view dictionary)
// Start by renaming items that may have old names based on alias info
for
(
auto
tag
:
cat
.
get_items
())
for
(
auto
item_name
:
cat
.
get_items
())
{
auto
iv
=
cv
->
get_validator_for_item
(
tag
);
auto
iv
=
cv
->
get_validator_for_item
(
item_name
);
if
(
iv
)
// know, must be OK then`
continue
;
iv
=
cv
->
get_validator_for_aliased_item
(
tag
);
iv
=
cv
->
get_validator_for_aliased_item
(
item_name
);
if
(
not
iv
)
continue
;
if
(
cif
::
VERBOSE
>
0
)
std
::
clog
<<
"Renaming "
<<
tag
<<
" to "
<<
iv
->
m_tag
<<
" in category "
<<
cat
.
name
()
<<
'\n'
;
cat
.
rename_item
(
tag
,
iv
->
m_tag
);
std
::
clog
<<
"Renaming "
<<
item_name
<<
" to "
<<
iv
->
m_item_name
<<
" in category "
<<
cat
.
name
()
<<
'\n'
;
cat
.
rename_item
(
item_name
,
iv
->
m_item_name
);
}
for
(
auto
link
:
validator
.
get_links_for_child
(
cat
.
name
()))
...
...
@@ -780,13 +780,13 @@ void reconstruct_pdbx(file &file, std::string_view dictionary)
}
// validate all values, and if they do not validate replace the content with an unknown flag
for
(
auto
tag
:
cat
.
get_items
())
for
(
auto
item_name
:
cat
.
get_items
())
{
auto
iv
=
cv
->
get_validator_for_item
(
tag
);
auto
iv
=
cv
->
get_validator_for_item
(
item_name
);
if
(
not
iv
)
continue
;
auto
ix
=
cat
.
get_item_ix
(
tag
);
auto
ix
=
cat
.
get_item_ix
(
item_name
);
for
(
auto
row
:
cat
)
{
...
...
@@ -796,7 +796,7 @@ void reconstruct_pdbx(file &file, std::string_view dictionary)
if
(
not
iv
->
validate_value
(
value
,
ec
))
{
if
(
cif
::
VERBOSE
>
0
)
std
::
clog
<<
"Replacing value ("
<<
std
::
quoted
(
value
)
<<
") for item "
<<
tag
<<
" since it does not validate
\n
"
;
std
::
clog
<<
"Replacing value ("
<<
std
::
quoted
(
value
)
<<
") for item "
<<
item_name
<<
" since it does not validate
\n
"
;
row
[
ix
]
=
"?"
;
}
...
...
src/text.cpp
View file @
a5d43998
...
...
@@ -215,19 +215,19 @@ std::string trim_copy(std::string_view s)
// --------------------------------------------------------------------
std
::
tuple
<
std
::
string
,
std
::
string
>
split_
tag_name
(
std
::
string_view
tag
)
std
::
tuple
<
std
::
string
,
std
::
string
>
split_
item_name
(
std
::
string_view
item_name
)
{
if
(
tag
.
empty
())
throw
std
::
runtime_error
(
"empty
tag
"
);
if
(
tag
[
0
]
!=
'_'
)
throw
std
::
runtime_error
(
"
tag '"
+
std
::
string
{
tag
}
+
"' does not start with underscore"
);
if
(
item_name
.
empty
())
throw
std
::
runtime_error
(
"empty
item_name
"
);
if
(
item_name
[
0
]
!=
'_'
)
throw
std
::
runtime_error
(
"
item_name '"
+
std
::
string
{
item_name
}
+
"' does not start with underscore"
);
auto
s
=
tag
.
find
(
'.'
);
auto
s
=
item_name
.
find
(
'.'
);
if
(
s
==
std
::
string
::
npos
)
// throw std::runtime_error("
tag does not contain dot (" + std::string{ tag
} + ')');
return
std
::
tuple
<
std
::
string
,
std
::
string
>
{
""
,
tag
.
substr
(
1
)
};
// throw std::runtime_error("
item_name does not contain dot (" + std::string{ item_name
} + ')');
return
std
::
tuple
<
std
::
string
,
std
::
string
>
{
""
,
item_name
.
substr
(
1
)
};
else
return
std
::
tuple
<
std
::
string
,
std
::
string
>
{
tag
.
substr
(
1
,
s
-
1
),
tag
.
substr
(
s
+
1
)};
return
std
::
tuple
<
std
::
string
,
std
::
string
>
{
item_name
.
substr
(
1
,
s
-
1
),
item_name
.
substr
(
s
+
1
)};
}
// --------------------------------------------------------------------
...
...
src/validate.cpp
View file @
a5d43998
...
...
@@ -196,31 +196,11 @@ int type_validator::compare(std::string_view a, std::string_view b) const
// --------------------------------------------------------------------
// void ValidateItem::addLinked(ValidateItem* parent, const std::string& parentItem, const std::string& childItem)
//{
//// if (mParent != nullptr and VERBOSE)
//// cerr << "replacing parent in " << mCategory->m_name << " from " << mParent->mCategory->m_name << " to " << parent->mCategory->m_name << endl;
//// mParent = parent;
//
// if (m_type == nullptr and parent != nullptr)
// m_type = parent->m_type;
//
// if (parent != nullptr)
// {
// mLinked.push_back({parent, parentItem, childItem});
//
// parent->mChildren.insert(this);
////
//// if (mCategory->mKeys == std::vector<std::string>{mTag})
//// parent->mForeignKeys.insert(this);
// }
//}
void
item_validator
::
operator
()(
std
::
string_view
value
)
const
{
std
::
error_code
ec
;
if
(
not
validate_value
(
value
,
ec
))
throw
std
::
system_error
(
ec
,
std
::
string
{
value
}
+
" does not match rx for "
+
m_
tag
);
throw
std
::
system_error
(
ec
,
std
::
string
{
value
}
+
" does not match rx for "
+
m_
item_name
);
}
bool
item_validator
::
validate_value
(
std
::
string_view
value
,
std
::
error_code
&
ec
)
const
noexcept
...
...
@@ -243,27 +223,27 @@ bool item_validator::validate_value(std::string_view value, std::error_code &ec)
void
category_validator
::
add_item_validator
(
item_validator
&&
v
)
{
if
(
v
.
m_mandatory
)
m_mandatory_items
.
insert
(
v
.
m_
tag
);
m_mandatory_items
.
insert
(
v
.
m_
item_name
);
v
.
m_category
=
this
;
auto
r
=
m_item_validators
.
insert
(
std
::
move
(
v
));
if
(
not
r
.
second
and
VERBOSE
>=
4
)
std
::
cout
<<
"Could not add validator for item "
<<
v
.
m_
tag
<<
" to category "
<<
m_name
<<
'\n'
;
std
::
cout
<<
"Could not add validator for item "
<<
v
.
m_
item_name
<<
" to category "
<<
m_name
<<
'\n'
;
}
const
item_validator
*
category_validator
::
get_validator_for_item
(
std
::
string_view
tag
)
const
const
item_validator
*
category_validator
::
get_validator_for_item
(
std
::
string_view
item_name
)
const
{
const
item_validator
*
result
=
nullptr
;
auto
i
=
m_item_validators
.
find
(
item_validator
{
std
::
string
(
tag
)
});
auto
i
=
m_item_validators
.
find
(
item_validator
{
std
::
string
(
item_name
)
});
if
(
i
!=
m_item_validators
.
end
())
result
=
&*
i
;
else
if
(
VERBOSE
>
4
)
std
::
cout
<<
"No validator for
tag "
<<
tag
<<
'\n'
;
std
::
cout
<<
"No validator for
item "
<<
item_name
<<
'\n'
;
return
result
;
}
const
item_validator
*
category_validator
::
get_validator_for_aliased_item
(
std
::
string_view
tag
)
const
const
item_validator
*
category_validator
::
get_validator_for_aliased_item
(
std
::
string_view
item_name
)
const
{
const
item_validator
*
result
=
nullptr
;
...
...
@@ -271,8 +251,8 @@ const item_validator *category_validator::get_validator_for_aliased_item(std::st
{
for
(
auto
&
ai
:
iv
.
m_aliases
)
{
const
auto
&
[
cat
,
name
]
=
split_
tag
_name
(
ai
.
m_name
);
if
(
iequals
(
name
,
tag
)
and
iequals
(
cat
,
m_name
))
const
auto
&
[
cat
,
name
]
=
split_
item
_name
(
ai
.
m_name
);
if
(
iequals
(
name
,
item_name
)
and
iequals
(
cat
,
m_name
))
{
result
=
&
iv
;
break
;
...
...
@@ -324,19 +304,19 @@ const category_validator *validator::get_validator_for_category(std::string_view
return
result
;
}
item_validator
*
validator
::
get_validator_for_item
(
std
::
string_view
tag
)
const
item_validator
*
validator
::
get_validator_for_item
(
std
::
string_view
item_name
)
const
{
item_validator
*
result
=
nullptr
;
std
::
string
cat
,
item
;
std
::
tie
(
cat
,
item
)
=
split_
tag_name
(
tag
);
std
::
tie
(
cat
,
item
)
=
split_
item_name
(
item_name
);
auto
*
cv
=
get_validator_for_category
(
cat
);
if
(
cv
!=
nullptr
)
result
=
const_cast
<
item_validator
*>
(
cv
->
get_validator_for_item
(
item
));
if
(
result
==
nullptr
and
VERBOSE
>
4
)
std
::
cout
<<
"No validator for item "
<<
tag
<<
'\n'
;
std
::
cout
<<
"No validator for item "
<<
item_name
<<
'\n'
;
return
result
;
}
...
...
@@ -361,11 +341,11 @@ void validator::add_link_validator(link_validator &&v)
auto
piv
=
pcv
->
get_validator_for_item
(
v
.
m_parent_keys
[
i
]);
if
(
piv
==
nullptr
)
throw
std
::
runtime_error
(
"unknown parent
tag
_"
+
v
.
m_parent_category
+
'.'
+
v
.
m_parent_keys
[
i
]);
throw
std
::
runtime_error
(
"unknown parent
item
_"
+
v
.
m_parent_category
+
'.'
+
v
.
m_parent_keys
[
i
]);
auto
civ
=
ccv
->
get_validator_for_item
(
v
.
m_child_keys
[
i
]);
if
(
civ
==
nullptr
)
throw
std
::
runtime_error
(
"unknown child
tag
_"
+
v
.
m_child_category
+
'.'
+
v
.
m_child_keys
[
i
]);
throw
std
::
runtime_error
(
"unknown child
item
_"
+
v
.
m_child_category
+
'.'
+
v
.
m_child_keys
[
i
]);
if
(
civ
->
m_type
==
nullptr
and
piv
->
m_type
!=
nullptr
)
const_cast
<
item_validator
*>
(
civ
)
->
m_type
=
piv
->
m_type
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment