App: Apply clang format (part 1)
This commit is contained in:
@@ -31,162 +31,166 @@
|
||||
|
||||
namespace App
|
||||
{
|
||||
/// A bidirectional string-integer mapping
|
||||
/*!
|
||||
* This is mainly intended for two purposes: working around the difficulty
|
||||
* in C++ of sharing enumerations between different source files,
|
||||
* namespaces, etc. and as the data type stored by App::PropertyEnumeration
|
||||
*
|
||||
* Internally, Enumeration maintains
|
||||
* -# Either a const pointer to an array of C-style strings, or a vector
|
||||
* of C++ std::strings
|
||||
* -# An integer index into that array/vector representing the string
|
||||
* representing the instance's value.
|
||||
*
|
||||
* If built with FC_DEBUG defined, some boundaries of passed in pointers
|
||||
* will be checked. Otherwise, the caller has the responsibility of
|
||||
* checking the limits of given indices.
|
||||
*
|
||||
* \todo Implement lazy copy
|
||||
*/
|
||||
class AppExport Enumeration
|
||||
/// A bidirectional string-integer mapping
|
||||
/*!
|
||||
* This is mainly intended for two purposes: working around the difficulty
|
||||
* in C++ of sharing enumerations between different source files,
|
||||
* namespaces, etc. and as the data type stored by App::PropertyEnumeration
|
||||
*
|
||||
* Internally, Enumeration maintains
|
||||
* -# Either a const pointer to an array of C-style strings, or a vector
|
||||
* of C++ std::strings
|
||||
* -# An integer index into that array/vector representing the string
|
||||
* representing the instance's value.
|
||||
*
|
||||
* If built with FC_DEBUG defined, some boundaries of passed in pointers
|
||||
* will be checked. Otherwise, the caller has the responsibility of
|
||||
* checking the limits of given indices.
|
||||
*
|
||||
* \todo Implement lazy copy
|
||||
*/
|
||||
class AppExport Enumeration
|
||||
{
|
||||
public:
|
||||
class Object
|
||||
{
|
||||
public:
|
||||
class Object {
|
||||
public:
|
||||
virtual ~Object() = default;
|
||||
virtual const char* data() const = 0;
|
||||
virtual bool isEqual(const char*) const = 0;
|
||||
virtual bool isCustom() const = 0;
|
||||
};
|
||||
virtual ~Object() = default;
|
||||
virtual const char* data() const = 0;
|
||||
virtual bool isEqual(const char*) const = 0;
|
||||
virtual bool isCustom() const = 0;
|
||||
};
|
||||
|
||||
public:
|
||||
/// Constructs an empty Enumeration object
|
||||
Enumeration();
|
||||
public:
|
||||
/// Constructs an empty Enumeration object
|
||||
Enumeration();
|
||||
|
||||
/// Standard copy constructor
|
||||
Enumeration(const Enumeration& other);
|
||||
/// Standard copy constructor
|
||||
Enumeration(const Enumeration& other);
|
||||
|
||||
/// Constructs an Enumeration with a single element
|
||||
explicit Enumeration(const char *valStr);
|
||||
/// Constructs an Enumeration with a single element
|
||||
explicit Enumeration(const char* valStr);
|
||||
|
||||
/// Constructs an Enumeration using val within list
|
||||
Enumeration(const char **list, const char *valStr);
|
||||
/// Constructs an Enumeration using val within list
|
||||
Enumeration(const char** list, const char* valStr);
|
||||
|
||||
/// Standard destructor
|
||||
~Enumeration();
|
||||
/// Standard destructor
|
||||
~Enumeration();
|
||||
|
||||
/** Sets the enumeration string list
|
||||
* The list is a NULL terminated array of pointers to const
|
||||
* char* strings.
|
||||
* \code
|
||||
* const char enums[] = {"Black","White","Other",NULL}
|
||||
* \endcode
|
||||
*
|
||||
* If Enumeration was already valid, will attempt to preserve
|
||||
* the string-representation value of the Enumeration
|
||||
*
|
||||
* Enumeration does not take ownership of the passed object
|
||||
*/
|
||||
void setEnums(const char **plEnums);
|
||||
/** Sets the enumeration string list
|
||||
* The list is a NULL terminated array of pointers to const
|
||||
* char* strings.
|
||||
* \code
|
||||
* const char enums[] = {"Black","White","Other",NULL}
|
||||
* \endcode
|
||||
*
|
||||
* If Enumeration was already valid, will attempt to preserve
|
||||
* the string-representation value of the Enumeration
|
||||
*
|
||||
* Enumeration does not take ownership of the passed object
|
||||
*/
|
||||
void setEnums(const char** plEnums);
|
||||
|
||||
/// Set all enum values as vector of strings
|
||||
/*!
|
||||
* This method causes the Enumeration to dynamically allocate
|
||||
* it's own array of C Strings, which will be deleted by the
|
||||
* destructor or subsequent calls to setEnums(). So, it is
|
||||
* important to make sure the Enumeration stays in scope as
|
||||
* long as values returned by getCStr are in use.
|
||||
*
|
||||
* If Enumeration was already valid, will attempt to preserve
|
||||
* the string-representation value of the Enumeration
|
||||
*/
|
||||
void setEnums(const std::vector<std::string> &values);
|
||||
/// Set all enum values as vector of strings
|
||||
/*!
|
||||
* This method causes the Enumeration to dynamically allocate
|
||||
* it's own array of C Strings, which will be deleted by the
|
||||
* destructor or subsequent calls to setEnums(). So, it is
|
||||
* important to make sure the Enumeration stays in scope as
|
||||
* long as values returned by getCStr are in use.
|
||||
*
|
||||
* If Enumeration was already valid, will attempt to preserve
|
||||
* the string-representation value of the Enumeration
|
||||
*/
|
||||
void setEnums(const std::vector<std::string>& values);
|
||||
|
||||
/// Set the enum using a C string
|
||||
void setValue(const char *value);
|
||||
/// Set the enum using a C string
|
||||
void setValue(const char* value);
|
||||
|
||||
/// Overload of setValue(const char *value)
|
||||
void setValue(const std::string &value) {setValue(value.c_str());}
|
||||
/// Overload of setValue(const char *value)
|
||||
void setValue(const std::string& value)
|
||||
{
|
||||
setValue(value.c_str());
|
||||
}
|
||||
|
||||
/// Set the enum using a long
|
||||
/*!
|
||||
* if checkRange is set to true, throws Base::ValueError when
|
||||
* values are set out of range
|
||||
*
|
||||
* Checks for boundaries via assert()
|
||||
*/
|
||||
void setValue(long value, bool checkRange = false);
|
||||
/// Set the enum using a long
|
||||
/*!
|
||||
* if checkRange is set to true, throws Base::ValueError when
|
||||
* values are set out of range
|
||||
*
|
||||
* Checks for boundaries via assert()
|
||||
*/
|
||||
void setValue(long value, bool checkRange = false);
|
||||
|
||||
/// Checks if the property is set to a certain string value
|
||||
bool isValue(const char *value) const;
|
||||
/// Checks if the property is set to a certain string value
|
||||
bool isValue(const char* value) const;
|
||||
|
||||
/// Checks if a string is included in the enumeration
|
||||
bool contains(const char *value) const;
|
||||
/// Checks if a string is included in the enumeration
|
||||
bool contains(const char* value) const;
|
||||
|
||||
/// Return the value as C string
|
||||
/*!
|
||||
* Returns NULL if the enumeration is invalid.
|
||||
*/
|
||||
const char * getCStr() const;
|
||||
/// Return the value as C string
|
||||
/*!
|
||||
* Returns NULL if the enumeration is invalid.
|
||||
*/
|
||||
const char* getCStr() const;
|
||||
|
||||
/// Return value as integer
|
||||
/*!
|
||||
* Returns -1 if the Enumeration isn't valid
|
||||
*/
|
||||
int getInt() const;
|
||||
/// Return value as integer
|
||||
/*!
|
||||
* Returns -1 if the Enumeration isn't valid
|
||||
*/
|
||||
int getInt() const;
|
||||
|
||||
/// get all possible enum values as vector of strings
|
||||
std::vector<std::string> getEnumVector() const;
|
||||
/// get all possible enum values as vector of strings
|
||||
std::vector<std::string> getEnumVector() const;
|
||||
|
||||
/// returns true if the enum list is non-empty, false otherwise
|
||||
bool hasEnums() const;
|
||||
/// returns true if the enum list is non-empty, false otherwise
|
||||
bool hasEnums() const;
|
||||
|
||||
/// Returns true if the instance is in a usable state
|
||||
bool isValid() const;
|
||||
/// Returns true if the instance is in a usable state
|
||||
bool isValid() const;
|
||||
|
||||
/// Returns the highest usable integer value for this enum
|
||||
/*!
|
||||
* Returns -1 if the enumeration is not valid according to isValid()
|
||||
*/
|
||||
int maxValue() const;
|
||||
/// Returns the highest usable integer value for this enum
|
||||
/*!
|
||||
* Returns -1 if the enumeration is not valid according to isValid()
|
||||
*/
|
||||
int maxValue() const;
|
||||
|
||||
/// Returns true if any of the items is a user-defined string
|
||||
bool isCustom() const;
|
||||
/// Returns true if any of the items is a user-defined string
|
||||
bool isCustom() const;
|
||||
|
||||
/// Assignment operator
|
||||
Enumeration & operator=(const Enumeration &other);
|
||||
/// Assignment operator
|
||||
Enumeration& operator=(const Enumeration& other);
|
||||
|
||||
/// true iff our string representation matches other's
|
||||
/*!
|
||||
* Returns false if either Enumeration is not valid.
|
||||
*/
|
||||
bool operator==(const Enumeration &other) const;
|
||||
/// true iff our string representation matches other's
|
||||
/*!
|
||||
* Returns false if either Enumeration is not valid.
|
||||
*/
|
||||
bool operator==(const Enumeration& other) const;
|
||||
|
||||
/// true iff our string representation matches other
|
||||
/*!
|
||||
* Returns false if Enumeration is not valid.
|
||||
*/
|
||||
bool operator==(const char *other) const;
|
||||
protected:
|
||||
/// true iff our string representation matches other
|
||||
/*!
|
||||
* Returns false if Enumeration is not valid.
|
||||
*/
|
||||
bool operator==(const char* other) const;
|
||||
|
||||
/// Number of items
|
||||
int countItems() const;
|
||||
protected:
|
||||
/// Number of items
|
||||
int countItems() const;
|
||||
|
||||
private:
|
||||
/// Handle to C Strings of possible enumeration values
|
||||
using ObjectPtr = std::shared_ptr<Object>;
|
||||
std::vector<ObjectPtr> enumArray;
|
||||
private:
|
||||
/// Handle to C Strings of possible enumeration values
|
||||
using ObjectPtr = std::shared_ptr<Object>;
|
||||
std::vector<ObjectPtr> enumArray;
|
||||
|
||||
/// Integer value of the enumeration
|
||||
/*!
|
||||
* This serves as an index into enumArray to get the string
|
||||
* representation.
|
||||
*/
|
||||
int _index;
|
||||
/// Integer value of the enumeration
|
||||
/*!
|
||||
* This serves as an index into enumArray to get the string
|
||||
* representation.
|
||||
*/
|
||||
int _index;
|
||||
|
||||
friend class PropertyEnumeration;
|
||||
}; // class Enumeration
|
||||
} // namespace App
|
||||
friend class PropertyEnumeration;
|
||||
}; // class Enumeration
|
||||
} // namespace App
|
||||
|
||||
#endif // #ifndef BASE_ENUMERATION_H
|
||||
#endif // #ifndef BASE_ENUMERATION_H
|
||||
|
||||
Reference in New Issue
Block a user