Home | History | Annotate | Download | only in brillo
      1 // Copyright 2014 The Chromium OS Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef LIBBRILLO_BRILLO_BRILLO_EXPORT_H_
      6 #define LIBBRILLO_BRILLO_BRILLO_EXPORT_H_
      7 
      8 // Use BRILLO_EXPORT attribute to decorate your classes, methods and variables
      9 // that need to be exported out of libbrillo. By default, any symbol not
     10 // explicitly marked with BRILLO_EXPORT attribute is not exported.
     11 
     12 // Put BRILLO_EXPORT in front of methods or variables and in between the
     13 // class and the tag name:
     14 /*
     15 
     16 BRILLO_EXPORT void foo();
     17 
     18 class BRILLO_EXPORT Bar {
     19  public:
     20   void baz();  // Exported since it is a member of an exported class.
     21 };
     22 
     23 */
     24 
     25 // Exporting a class automatically exports all of its members. However there are
     26 // no export entries for non-static member variables since they are not accessed
     27 // directly, but rather through "this" pointer. Class methods, type information,
     28 // virtual table (if any), and static member variables are exported.
     29 
     30 // Finally, template functions and template members of a class may not be
     31 // inlined by the compiler automatically and the out-of-line version will not
     32 // be exported and fail to link. Marking those inline explicitly might help.
     33 // Alternatively, exporting specific instantiation of the template could be
     34 // used with "extern template" and combining this with BRILLO_EXPORT.
     35 #define BRILLO_EXPORT __attribute__((__visibility__("default")))
     36 
     37 // On occasion you might need to disable exporting a particular symbol if
     38 // you don't want the clients to see it. For example, you can explicitly
     39 // hide a member of an exported class:
     40 /*
     41 
     42 class BRILLO_EXPORT Foo {
     43  public:
     44   void bar();  // Exported since it is a member of an exported class.
     45 
     46  private:
     47   BRILLO_PRIVATE void baz();  // Explicitly removed from export table.
     48 };
     49 
     50 */
     51 
     52 // Note that even though a class may have a private member it doesn't mean
     53 // that it must not be exported, since the compiler might still need it.
     54 // For example, an inline public method calling a private method will not link
     55 // if that private method is not exported.
     56 // So be careful with hiding members if you don't want to deal with obscure
     57 // linker errors.
     58 #define BRILLO_PRIVATE __attribute__((__visibility__("hidden")))
     59 
     60 #endif  // LIBBRILLO_BRILLO_BRILLO_EXPORT_H_
     61