Language Bindings

From Libvisual wiki

Contents

libvisual-cpp

Release Status

libvisual-cpp is still in development. A stable release is expected to be available by the end of this year.

In the meantime, you may download libvisual-cpp from CVS.


Developers

  • Chong Kai Xiong 'descender' (descender AT phreaker DOT net)


Goals

In no particular order:

  • Greater ease-of-use
  1. OOP with C++ class constructs
  2. Compile-time type safety
  3. Work well with the standard library and Boost
  • Low overhead
  1. Little additional memory requirement
  2. Little additional function call overhead.


Design and Implementation

Guiding Principles:

  • no naked pointers
  • references instead of pointers where possible
  • const-correctness


Naming

  • All identifiers are placed under the Lv namespace.
  • Overloading and templates are used to exclude type names from the C original function identifiers and facilitate generic programming.


Enums

  • All enums will have their own types
  • All 6 bitwise operators (^, &, |, ^=, &=, |=) are overloaded for enum types that represent flags.


Strings

  • All C null-terminated string arguments will be wrapped using std::string.


Functions

  • Function call overhead of trivial function wrappers is avoided by inlining.


Callbacks

  • Callback function parameters are wrapped with functors so that any of the 2 types of functions may be passed:
  1. non-static member functions
  2. static member functions, free functions
  • For convenience, arguments and return values may be bound to functors.
  • Functor adaptors for accepting extra arguments that underlying function do not use or know.


Error Handling

  • Wrap all(?) errors in C++ exception classes.
  • Exception classes derived from appropriate standard exceptions i.e. std::runtime_error for run-time errors, std::invalid_argument for invalid arguments and so on.
  • Macro to switch between error handling options based on a #define. Options include:
  1. Throwing exceptions
  2. Returning error values
  3. Terminate


Reference Counting

  • Reference counting is automatically performed using copy constructors, assignment operators and destructors.


OOP

  • Mirror VisObject object hierarchy with equivalent C++ class hierarchy.


Collections

  • VisCollection-based types will be created with:
  1. Template specialization: typedef Lv::Collection<MyObject> MyObjectCollection;
  2. Subclassing i.e. deriving from Lv::AbstractCollection.
  • Ditto for VisList or VisHashMap based types.
  • std::list<>-style interface for VisList
  • std::tr1::unordered_map<>-style interface for VisHashMap.
  • std::list<>, std::tr1::unordered_map<> combined style interface for VisHashlist.


Multithreading

  • Helper objects to acquire and release lock when scope is exited.
  • Helper object to log lock acquisition and release.