Replace RefCounter with a smart pointer

Replaced ```RefCounter``` class with a smart pointer like ```std::shared_ptr``` to get rid of ugly preprocessor conditionals and complicated ref/deref operations.
This feature is enabled when ```ENABLE_CXX11``` option is not set, otherwise ```std::shared_ptr``` is used.