Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
MoReFEM
CoreLibrary
MoReFEM
Commits
c611c885
Commit
c611c885
authored
Mar 17, 2016
by
GILLES Sebastien
Browse files
#820
Script create accessors: add splittng of comment line should the comment be too lengthy.
parent
c9d57c0d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Scripts/create_accessors.py
View file @
c611c885
...
...
@@ -33,7 +33,7 @@ def IsTemplate(template):
class
CreateAccessors
:
def
__init__
(
self
,
template_args
,
class_name
,
typename
,
attribute_name
,
dox_comment
,
is_constant
):
def
__init__
(
self
,
template_args
,
class_name
,
typename
,
attribute_name
,
dox_comment
,
is_constant
,
Nchar_max
=
110
):
self
.
_typename
=
typename
...
...
@@ -42,6 +42,7 @@ class CreateAccessors:
attribute_name
+=
"_"
self
.
_attribute_name
=
attribute_name
self
.
_Nchar_max
=
Nchar_max
self
.
_is_constant
=
is_constant
self
.
_dox_comment
=
dox_comment
self
.
_method_name
=
FromDataAttrToMethodName
(
attribute_name
)
...
...
@@ -94,6 +95,8 @@ class CreateAccessors:
self
.
_template_args
=
False
if
template_args
:
template_args
=
template_args
.
strip
()
assert
(
template_args
[
0
]
is
'<'
),
"Template args argument should be a string delimited by <>."
assert
(
template_args
[
-
1
]
is
'>'
),
"Template args argument should be a string delimited by <>."
...
...
@@ -114,6 +117,53 @@ class CreateAccessors:
return
True
def
_PrintComment
(
self
,
dox_comment
,
shift_first_line
=
7
,
with_delimiters
=
True
):
"""Prepare Doxygen comment, which might be splitted on several lines if it is too long.
\param[in] with_delimiters Whether C/C++ comment delimiters should be added or not.
\param[in] shift_first_line To make relatively even lines, this shift might be applied
to firect line, to take into accoutn for instance the width of
\\
brief or \param[in].
"""
size_max
=
self
.
_Nchar_max
if
len
(
dox_comment
)
<
size_max
:
if
with_delimiters
:
return
"//! {0}"
.
format
(
dox_comment
)
else
:
return
dox_comment
lines
=
[]
current_size_max
=
size_max
-
shift_first_line
while
len
(
dox_comment
)
>=
current_size_max
:
pos_eol
=
current_size_max
current_size_max
=
size_max
while
dox_comment
[
pos_eol
]
!=
' '
:
assert
pos_eol
>
0
pos_eol
-=
1
lines
.
append
(
dox_comment
[:
pos_eol
])
dox_comment
=
dox_comment
[
pos_eol
+
1
:]
if
dox_comment
:
lines
.
append
(
dox_comment
)
if
with_delimiters
:
ret
=
"
\n
/*!
\n
*
\\
brief "
+
"
\n
* "
.
join
(
lines
)
+
"
\n
*/"
else
:
ret
=
"
\n
* "
.
join
(
lines
)
+
"
\n
"
return
ret
def
_TemplateHeader
(
self
):
"""Generates the template header in definition of the accessor."""
assert
(
self
.
_IsTemplateClass
()),
"Should not be called for non template classes."
...
...
@@ -130,7 +180,7 @@ class CreateAccessors:
def
_ConstantAccessorDeclaration
(
self
):
"""Write the constant accessor declaration."""
print
(
"//!
Constant accessor to the {dox}"
.
format
(
dox
=
self
.
_accessor_dox
))
print
(
self
.
_PrintComment
(
"
Constant accessor to the {dox}"
.
format
(
dox
=
self
.
_accessor_dox
))
)
print
(
"const {type}& Get{method}() const noexcept;
\n
"
.
format
(
type
=
self
.
_typename
,
method
=
self
.
_method_name
))
...
...
@@ -150,7 +200,7 @@ class CreateAccessors:
def
_NonConstantAccessorDeclaration
(
self
):
"""Write the non constant accessor declaration."""
print
(
"//!
Non constant accessor to the {dox}"
.
format
(
dox
=
self
.
_accessor_dox
))
print
(
self
.
_PrintComment
(
"
Non constant accessor to the {dox}"
.
format
(
dox
=
self
.
_accessor_dox
))
)
print
(
"{type}& GetNonCst{method}() noexcept;
\n
"
.
format
(
type
=
self
.
_typename
,
method
=
self
.
_method_name
))
def
_NonConstantAccessorDefinition
(
self
):
...
...
@@ -171,7 +221,7 @@ class CreateAccessors:
IMPORTANT: It is assumed that derived class correctly define _DataAttributeStorage().
"""
print
(
"//! {dox}"
.
format
(
dox
=
self
.
_dox_comment
))
print
(
self
.
_PrintComment
(
self
.
_dox_comment
))
self
.
_DataAttributeStorage
()
...
...
@@ -182,17 +232,17 @@ class SmartPtr(CreateAccessors):
"""
def
__init__
(
self
,
template_args
,
class_name
,
typename
,
smartptr
,
attribute_name
,
dox_comment
):
def
__init__
(
self
,
template_args
,
class_name
,
typename
,
smartptr
,
attribute_name
,
dox_comment
,
Nchar_max
=
110
):
self
.
_smartptr
=
smartptr
CreateAccessors
.
__init__
(
self
,
template_args
,
class_name
,
typename
,
attribute_name
,
dox_comment
,
is_constant
=
False
)
CreateAccessors
.
__init__
(
self
,
template_args
,
class_name
,
typename
,
attribute_name
,
dox_comment
,
Nchar_max
=
Nchar_max
,
is_constant
=
False
)
local
=
attribute_name
[:
-
1
]
print
(
"* \param[in] {local} {dox}
\n
"
.
format
(
local
=
local
,
dox
=
dox_comment
))
print
(
"
* \param[in] {local} {dox}
\n
"
.
format
(
local
=
local
,
dox
=
self
.
_PrintComment
(
dox_comment
,
with_delimiters
=
False
,
shift_first_line
=
len
(
local
)
+
7
)
))
print
(
"{attr} = std::make_unique<{type}>();"
.
format
(
attr
=
attribute_name
,
\
type
=
typename
))
...
...
@@ -214,14 +264,14 @@ class Reference(CreateAccessors):
"""
def
__init__
(
self
,
template_args
,
class_name
,
typename
,
attribute_name
,
dox_comment
,
is_const
):
def
__init__
(
self
,
template_args
,
class_name
,
typename
,
attribute_name
,
dox_comment
,
is_const
,
Nchar_max
=
110
):
self
.
_is_constant
=
is_const
self
.
_const_preffix
=
self
.
_is_constant
and
"const "
or
''
CreateAccessors
.
__init__
(
self
,
template_args
,
class_name
,
typename
,
attribute_name
,
dox_comment
,
is_const
)
CreateAccessors
.
__init__
(
self
,
template_args
,
class_name
,
typename
,
attribute_name
,
dox_comment
,
is_const
,
Nchar_max
)
local
=
attribute_name
[:
-
1
]
print
(
"* \param[in] {local} {dox}
\n
"
.
format
(
local
=
local
,
dox
=
dox_comment
))
print
(
"* \param[in] {local} {dox}
\n
"
.
format
(
local
=
local
,
dox
=
self
.
_PrintComment
(
dox_comment
,
with_delimiters
=
False
,
shift_first_line
=
len
(
local
))
))
print
(
"{const}{type}& {local},
\n
"
.
format
(
const
=
self
.
_const_preffix
,
type
=
typename
,
local
=
local
))
print
(
"{attr}({local}),"
.
format
(
local
=
local
,
attr
=
attribute_name
))
...
...
Write
Preview
Supports
Markdown
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