-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add QMetaEnum usage for autogenerated code #317
base: master
Are you sure you want to change the base?
Conversation
@@ -32,10 +32,14 @@ | |||
#include <QDebug> | |||
|
|||
namespace facelift { | |||
|
|||
namespace Enum { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In facelift, namespaces are used to group entities which belong together into a layer. A upper-level layer (such as "facelift") should not have any dependency to a lower layer (such as "facelift::ipc"). Your change is breaking that rule.
Also, if you introduce a "Enum" namespace (whose name is also not right), you should also introduce a "Struct" namespace, but I do not see any benefit in doing so anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, but coding standards/guidelines in facelift, also community page, etc. are EMPTY. This means that you cannot expect any coding standards from anyone.
Also separate namespace for utility makes sense and is a common practice in the software world, especially when you do not want to create a class/struct with all static methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In facelift, namespaces are used to group entities which belong together into a layer. A upper-level layer (such as "facelift") should not have any dependency to a lower layer (such as "facelift::ipc"). Your change is breaking that rule.
in this case namespace is used for its straight purpose - name scope.
Any other options like different name, class or structure are worst alternatives
Also, if you introduce a "Enum" namespace (whose name is also not right),
please suggest a better name
you should also introduce a "Struct" namespace, but I do not see any benefit in doing so anyway.
it's not needed at the moment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually StringConversionHandler is not needed at all
and in the future it should be replaced with toString template function
with different specifications and SFINAE principle.
Also @bitmouse suggested the idea to move the enums stuff into a separate folder.
src/model/FaceliftEnum.cpp
Outdated
|
||
void onAssignFromStringError(const QString &s) | ||
void fromStringError(const QString &string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad function name. Either the function name indicates what the function does (with a verb), or it indicates when it is called (onXXXXX).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree!
how about raiseFatalError ?
str << ", "; | ||
} | ||
str << "]"; | ||
return s; | ||
} | ||
}; | ||
|
||
template<typename ElementType> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you changing those names ??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know the reason, why changed names, but I like the new version more. It follows general practices in software, in templates, so it should be easier to read for experienced user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes it's not related to the current changes, but
typename ElementType, typename Type, typename TypeName are bad in most cases and only T is enough here and I just made this small change in current PR.
We need a separate task for replacing non common template parameters names and
hold something like ElementType only for rare cases when it's needed for better readability.
// Returns the enumaration value of the given enumeration key, or nullptr if key is not defined. | ||
// TODO change std::unique_ptr to std::optional when it will be possible | ||
template<typename T> | ||
std::unique_ptr<T> fromString(const QString &string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are causing some data to be allocated on the heap, which is definitely not needed to convert a string to an enum.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered that, only std::optional should be here.
and other options like struct, out parameter are worse and
std::unique_ptr will be replaced with std::optional in the future
No description provided.