Message ID | 20210725171827.23643-5-laurent.pinchart@ideasonboard.com |
---|---|
State | Accepted |
Headers | show |
Series |
|
Related | show |
On Sun, Jul 25, 2021 at 08:18:26PM +0300, Laurent Pinchart wrote: > Use the newly introduced Flags<> class to store a bitfield of > File::OpenMode in a type-safe way. The existing File::OpenMode enum is > renamed to File::OpenModeFlag to free the File::OpenMode for the Flags<> > type alias. > After reading 5/5 please add Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> To this and 3/5 Thanks j > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > --- > Changes since v1: > > - Don't enable bitwise operators on File::OpenMode > --- > include/libcamera/base/file.h | 4 +++- > src/libcamera/base/file.cpp | 9 +++++++-- > 2 files changed, 10 insertions(+), 3 deletions(-) > > diff --git a/include/libcamera/base/file.h b/include/libcamera/base/file.h > index 452a658b409f..eebb24024025 100644 > --- a/include/libcamera/base/file.h > +++ b/include/libcamera/base/file.h > @@ -30,13 +30,15 @@ public: > > using MapFlags = Flags<MapFlag>; > > - enum OpenMode { > + enum OpenModeFlag { > NotOpen = 0, > ReadOnly = (1 << 0), > WriteOnly = (1 << 1), > ReadWrite = ReadOnly | WriteOnly, > }; > > + using OpenMode = Flags<OpenModeFlag>; > + > File(const std::string &name); > File(); > ~File(); > diff --git a/src/libcamera/base/file.cpp b/src/libcamera/base/file.cpp > index e180c5479098..0860457421a1 100644 > --- a/src/libcamera/base/file.cpp > +++ b/src/libcamera/base/file.cpp > @@ -58,7 +58,7 @@ LOG_DEFINE_CATEGORY(File) > */ > > /** > - * \enum File::OpenMode > + * \enum File::OpenModeFlag > * \brief Mode in which a file is opened > * \var File::NotOpen > * \brief The file is not open > @@ -70,6 +70,11 @@ LOG_DEFINE_CATEGORY(File) > * \brief The file is open for reading and writing > */ > > +/** > + * \typedef File::OpenMode > + * \brief An OR combination of File::OpenModeFlag values > + */ > + > /** > * \brief Construct a File to represent the file \a name > * \param[in] name The file name > @@ -168,7 +173,7 @@ bool File::open(File::OpenMode mode) > return false; > } > > - int flags = (mode & ReadWrite) - 1; > + int flags = static_cast<OpenMode::Type>(mode & ReadWrite) - 1; > if (mode & WriteOnly) > flags |= O_CREAT; > > -- > Regards, > > Laurent Pinchart >
diff --git a/include/libcamera/base/file.h b/include/libcamera/base/file.h index 452a658b409f..eebb24024025 100644 --- a/include/libcamera/base/file.h +++ b/include/libcamera/base/file.h @@ -30,13 +30,15 @@ public: using MapFlags = Flags<MapFlag>; - enum OpenMode { + enum OpenModeFlag { NotOpen = 0, ReadOnly = (1 << 0), WriteOnly = (1 << 1), ReadWrite = ReadOnly | WriteOnly, }; + using OpenMode = Flags<OpenModeFlag>; + File(const std::string &name); File(); ~File(); diff --git a/src/libcamera/base/file.cpp b/src/libcamera/base/file.cpp index e180c5479098..0860457421a1 100644 --- a/src/libcamera/base/file.cpp +++ b/src/libcamera/base/file.cpp @@ -58,7 +58,7 @@ LOG_DEFINE_CATEGORY(File) */ /** - * \enum File::OpenMode + * \enum File::OpenModeFlag * \brief Mode in which a file is opened * \var File::NotOpen * \brief The file is not open @@ -70,6 +70,11 @@ LOG_DEFINE_CATEGORY(File) * \brief The file is open for reading and writing */ +/** + * \typedef File::OpenMode + * \brief An OR combination of File::OpenModeFlag values + */ + /** * \brief Construct a File to represent the file \a name * \param[in] name The file name @@ -168,7 +173,7 @@ bool File::open(File::OpenMode mode) return false; } - int flags = (mode & ReadWrite) - 1; + int flags = static_cast<OpenMode::Type>(mode & ReadWrite) - 1; if (mode & WriteOnly) flags |= O_CREAT;
Use the newly introduced Flags<> class to store a bitfield of File::OpenMode in a type-safe way. The existing File::OpenMode enum is renamed to File::OpenModeFlag to free the File::OpenMode for the Flags<> type alias. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- Changes since v1: - Don't enable bitwise operators on File::OpenMode --- include/libcamera/base/file.h | 4 +++- src/libcamera/base/file.cpp | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-)