Open Lighting Architecture  Latest Git
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Macros
Macro.h File Reference

Detailed Description

Helper macros.

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define DISALLOW_COPY_AND_ASSIGN(TypeName)
 Creates dummy copy constructor and assignment operator declarations. More...
 
#define OLA_UNUSED
 Mark unused arguments & types. More...
 
#define OLA_FALLTHROUGH
 Mark switch cases as fallthrough when required. More...
 
#define STATIC_ASSERT(x)   extern int __dummy[static_cast<int>x]
 Compile time assert(). More...
 
#define PACK(__Declaration__)   __Declaration__ __attribute__((__packed__))
 Pack structures. More...
 

Macro Definition Documentation

#define DISALLOW_COPY_AND_ASSIGN (   TypeName)
Value:
TypeName(const TypeName&); \
void operator=(const TypeName&)

Creates dummy copy constructor and assignment operator declarations.

Use this in the private: section of a class to prevent copying / assignment.

Example
1 class Foo {
2  public:
3  Foo() { ... }
4 
5  private:
6  DISALLOW_COPY_AND_ASSIGN(Foo);
7  };
#define OLA_FALLTHROUGH

Mark switch cases as fallthrough when required.

Note
We are not currently using [[fallthrough]]; because we need C++98 compatibility
Example
1 switch (cond) {
2  case 'foo':
3  doFoo();
4  // after foo fallthrough to bar because $REASON
5  OLA_FALLTHROUGH
6  case 'bar':
#define OLA_UNUSED

Mark unused arguments & types.

Example
1 void Foo(OLA_UNUSED int bar) {}
2 
3 OLA_UNUSED typedef int Baz;
#define PACK (   __Declaration__)    __Declaration__ __attribute__((__packed__))

Pack structures.

In order to account for platform differences with regard to packing, we need to use the following macro while declaring types that need to have a specific binary layout. Taken from: http://stackoverflow.com/questions/1537964/ visual-c-equivalent-of-gccs-attribute-packed

Example
1 PACK(
2 struct foo_s {
3  uint16_t bar;
4 });
#define STATIC_ASSERT (   x)    extern int __dummy[static_cast<int>x]

Compile time assert().

Example
1 PACK(
2 struct foo_s {
3  uint16_t bar;
4 });
5 STATIC_ASSERT(sizeof(foo_s) == 2);