diff options
author | Noel Grandin <noel@peralex.com> | 2014-08-21 14:41:58 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2014-08-26 04:30:03 -0500 |
commit | 37b9ea92ba81d74764a2345a9c75c65bfd272d2b (patch) | |
tree | 114a35309769e5bf7097737a9e8a5ff6e723e856 /include/basic | |
parent | 34827767b1551f7a61bcd53947255ad2d2a9e5da (diff) |
convert SBX flag bits to type-safe enum
Change-Id: I18d5d6a27f06ee60a5cb3dc393bf05b51bba4817
Reviewed-on: https://gerrit.libreoffice.org/11070
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Tested-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'include/basic')
-rw-r--r-- | include/basic/sbx.hxx | 6 | ||||
-rw-r--r-- | include/basic/sbxcore.hxx | 30 | ||||
-rw-r--r-- | include/basic/sbxdef.hxx | 68 |
3 files changed, 65 insertions, 39 deletions
diff --git a/include/basic/sbx.hxx b/include/basic/sbx.hxx index 76e1bcc17a29..c7532a147fbd 100644 --- a/include/basic/sbx.hxx +++ b/include/basic/sbx.hxx @@ -52,9 +52,9 @@ struct SbxParamInfo const OUString aName; // Name of the parameter SbxBaseRef aTypeRef; // Object, if object type SbxDataType eType; // Data type - sal_uInt16 nFlags; // Flag-Bits + SbxFlagBits nFlags; // Flag-Bits sal_uInt32 nUserData; // IDs etc. - SbxParamInfo( const OUString& s, SbxDataType t, sal_uInt16 n, SbxBase* b = NULL ) + SbxParamInfo( const OUString& s, SbxDataType t, SbxFlagBits n, SbxBase* b = NULL ) : aName( s ), aTypeRef( b ), eType( t ), nFlags( n ), nUserData( 0 ) {} ~SbxParamInfo() {} }; @@ -79,7 +79,7 @@ public: SbxInfo(); SbxInfo( const OUString&, sal_uInt32 ); - void AddParam( const OUString&, SbxDataType, sal_uInt16=SBX_READ ); + void AddParam( const OUString&, SbxDataType, SbxFlagBits=SBX_READ ); const SbxParamInfo* GetParam( sal_uInt16 n ) const; // index starts with 1! const OUString& GetComment() const { return aComment; } const OUString& GetHelpFile() const { return aHelpFile; } diff --git a/include/basic/sbxcore.hxx b/include/basic/sbxcore.hxx index 4745fe3ef85b..c755a6f5714b 100644 --- a/include/basic/sbxcore.hxx +++ b/include/basic/sbxcore.hxx @@ -56,7 +56,7 @@ class BASIC_DLLPUBLIC SbxBase : virtual public SvRefBase virtual bool LoadData( SvStream&, sal_uInt16 ); virtual bool StoreData( SvStream& ) const; protected: - sal_uInt16 nFlags; // Flag-Bits + SbxFlagBits nFlags; // Flag-Bits SbxBase(); SbxBase( const SbxBase& ); @@ -65,12 +65,12 @@ protected: SBX_DECL_PERSIST(0,0,0); public: TYPEINFO(); - inline void SetFlags( sal_uInt16 n ); - inline sal_uInt16 GetFlags() const; - inline void SetFlag( sal_uInt16 n ); - inline void ResetFlag( sal_uInt16 n ); - inline bool IsSet( sal_uInt16 n ) const; - inline bool IsReset( sal_uInt16 n ) const; + inline void SetFlags( SbxFlagBits n ); + inline SbxFlagBits GetFlags() const; + inline void SetFlag( SbxFlagBits n ); + inline void ResetFlag( SbxFlagBits n ); + inline bool IsSet( SbxFlagBits n ) const; + inline bool IsReset( SbxFlagBits n ) const; inline bool CanRead() const; inline bool CanWrite() const; inline bool IsModified() const; @@ -107,23 +107,23 @@ public: typedef tools::SvRef<SbxBase> SbxBaseRef; -inline void SbxBase::SetFlags( sal_uInt16 n ) +inline void SbxBase::SetFlags( SbxFlagBits n ) { nFlags = n; } -inline sal_uInt16 SbxBase::GetFlags() const +inline SbxFlagBits SbxBase::GetFlags() const { return nFlags; } -inline void SbxBase::SetFlag( sal_uInt16 n ) +inline void SbxBase::SetFlag( SbxFlagBits n ) { nFlags |= n; } -inline void SbxBase::ResetFlag( sal_uInt16 n ) +inline void SbxBase::ResetFlag( SbxFlagBits n ) { nFlags &= ~n; } -inline bool SbxBase::IsSet( sal_uInt16 n ) const -{ return ( nFlags & n ) != 0; } +inline bool SbxBase::IsSet( SbxFlagBits n ) const +{ return ( nFlags & n ) != SBX_NONE; } -inline bool SbxBase::IsReset( sal_uInt16 n ) const -{ return ( nFlags & n ) == 0; } +inline bool SbxBase::IsReset( SbxFlagBits n ) const +{ return ( nFlags & n ) == SBX_NONE; } inline bool SbxBase::CanRead() const { return IsSet( SBX_READ ); } diff --git a/include/basic/sbxdef.hxx b/include/basic/sbxdef.hxx index 35ea07f71dc5..d9f3b97e49ea 100644 --- a/include/basic/sbxdef.hxx +++ b/include/basic/sbxdef.hxx @@ -212,29 +212,55 @@ typedef sal_uIntPtr SbxError; // Preserve old type // Flag-Bits: -#define SBX_READ 0x0001 // Read permission -#define SBX_WRITE 0x0002 // Write permission -#define SBX_READWRITE 0x0003 // Read/Write permission -#define SBX_DONTSTORE 0x0004 // Don't store object -#define SBX_MODIFIED 0x0008 // Object was changed -#define SBX_FIXED 0x0010 // Fixed data type (SbxVariable) -#define SBX_CONST 0x0020 // Definition of const value -#define SBX_OPTIONAL 0x0040 // Parameter is optional -#define SBX_HIDDEN 0x0080 // Element is invisible -#define SBX_INVISIBLE 0x0100 // Element is not found by Find() -#define SBX_EXTSEARCH 0x0200 // Object is searched completely -#define SBX_EXTFOUND 0x0400 // Variable was found through extended search -#define SBX_GBLSEARCH 0x0800 // Global search via Parents -#define SBX_RESERVED 0x1000 // reserved -#define SBX_PRIVATE 0x1000 // #110004, #112015, cannot conflict with SBX_RESERVED -#define SBX_NO_BROADCAST 0x2000 // No broadcast on Get/Put -#define SBX_REFERENCE 0x4000 // Parameter is Reference (DLL-call) -#define SBX_NO_MODIFY 0x8000 // SetModified is suppressed -#define SBX_WITH_EVENTS 0x0080 // Same value as unused SBX_HIDDEN -#define SBX_DIM_AS_NEW 0x0800 // Same value as SBX_GBLSEARCH, cannot conflict as one +enum SbxFlagBits { + SBX_NONE = 0x0000, + SBX_READ = 0x0001, // Read permission + SBX_WRITE = 0x0002, // Write permission + SBX_READWRITE = 0x0003, // Read/Write permission + SBX_DONTSTORE = 0x0004, // Don't store object + SBX_MODIFIED = 0x0008, // Object was changed + SBX_FIXED = 0x0010, // Fixed data type (SbxVariable) + SBX_CONST = 0x0020, // Definition of const value + SBX_OPTIONAL = 0x0040, // Parameter is optional + SBX_HIDDEN = 0x0080, // Element is invisible + SBX_INVISIBLE = 0x0100, // Element is not found by Find() + SBX_EXTSEARCH = 0x0200, // Object is searched completely + SBX_EXTFOUND = 0x0400, // Variable was found through extended search + SBX_GBLSEARCH = 0x0800, // Global search via Parents + SBX_RESERVED = 0x1000, // reserved + SBX_PRIVATE = 0x1000, // #110004, #112015, cannot conflict with SBX_RESERVED + SBX_NO_BROADCAST = 0x2000, // No broadcast on Get/Put + SBX_REFERENCE = 0x4000, // Parameter is Reference (DLL-call) + SBX_NO_MODIFY = 0x8000, // SetModified is suppressed + SBX_WITH_EVENTS = 0x0080, // Same value as unused SBX_HIDDEN + SBX_DIM_AS_NEW = 0x0800, // Same value as SBX_GBLSEARCH, cannot conflict as one // is used for objects, the other for variables only -#define SBX_VAR_TO_DIM 0x2000 // Same value as SBX_NO_BROADCAST, cannot conflict as + SBX_VAR_TO_DIM = 0x2000, // Same value as SBX_NO_BROADCAST, cannot conflict as // used for variables without broadcaster only +}; +// make combining these type-safe +inline SbxFlagBits operator| (SbxFlagBits lhs, SbxFlagBits rhs) +{ + return static_cast<SbxFlagBits>(static_cast<sal_uInt16>(lhs) | static_cast<sal_uInt16>(rhs)); +} +inline SbxFlagBits operator& (SbxFlagBits lhs, SbxFlagBits rhs) +{ + return static_cast<SbxFlagBits>(static_cast<sal_uInt16>(lhs) & static_cast<sal_uInt16>(rhs)); +} +inline SbxFlagBits& operator|= (SbxFlagBits& lhs, SbxFlagBits rhs) +{ + lhs = static_cast<SbxFlagBits>(static_cast<sal_uInt16>(lhs) | static_cast<sal_uInt16>(rhs)); + return lhs; +} +inline SbxFlagBits operator~ (SbxFlagBits rhs) +{ + return static_cast<SbxFlagBits>(0xffff & ~(static_cast<sal_uInt16>(rhs))); +} +inline SbxFlagBits& operator&= (SbxFlagBits& lhs, SbxFlagBits rhs) +{ + lhs = static_cast<SbxFlagBits>(static_cast<sal_uInt16>(lhs) & static_cast<sal_uInt16>(rhs)); + return lhs; +} // Broadcaster-IDs: #define SBX_HINT_DYING SFX_HINT_DYING |