LCOV - code coverage report
Current view: top level - lunchbox - persistentMap.cpp (source / functions) Hit Total Coverage
Test: lcov2.info Lines: 21 21 100.0 %
Date: 2014-08-05 Functions: 9 10 90.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2014, Stefan.Eilemann@epfl.ch
       3             :  *
       4             :  * This library is free software; you can redistribute it and/or modify it under
       5             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       6             :  * by the Free Software Foundation.
       7             :  *
       8             :  * This library is distributed in the hope that it will be useful, but WITHOUT
       9             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      10             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      11             :  * details.
      12             :  *
      13             :  * You should have received a copy of the GNU Lesser General Public License
      14             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      15             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      16             :  */
      17             : 
      18             : #include "persistentMap.h"
      19             : 
      20             : #include "uri.h"
      21             : 
      22             : namespace lunchbox
      23             : {
      24             : namespace detail
      25             : {
      26           7 : class PersistentMap
      27             : {
      28             : public:
      29           7 :     virtual ~PersistentMap() {}
      30             :     virtual bool insert( const std::string& key, const std::string& value ) = 0;
      31             :     virtual std::string operator [] ( const std::string& key ) const = 0;
      32             : };
      33             : }
      34             : }
      35             : 
      36             : // Impls - need detail::PersistentMap interface
      37             : #include "leveldb/persistentMap.h"
      38             : 
      39             : namespace
      40             : {
      41           8 : lunchbox::detail::PersistentMap* _newImpl( const std::string& uristr )
      42             : {
      43           8 :     const lunchbox::URI& uri( uristr );
      44             : 
      45             : #ifdef LUNCHBOX_USE_LEVELDB
      46           8 :     if( lunchbox::leveldb::PersistentMap::handles( uri ))
      47           6 :         return new lunchbox::leveldb::PersistentMap( uri );
      48             : #endif
      49             : 
      50           3 :     if( !uri.getScheme().empty( ))
      51             :         throw std::runtime_error(
      52           1 :             std::string( "No suitable implementation found for: " ) + uristr );
      53             : 
      54             : #ifdef LUNCHBOX_USE_LEVELDB
      55           2 :     return new lunchbox::leveldb::PersistentMap( uri );
      56             : #endif
      57             :     throw std::runtime_error(
      58           8 :         std::string( "No suitable implementation found for: " ) + uristr );
      59             : }
      60             : }
      61             : 
      62             : namespace lunchbox
      63             : {
      64           8 : PersistentMap::PersistentMap( const std::string& uri )
      65           8 :     : _impl( _newImpl( uri ))
      66             : {
      67           6 : }
      68             : 
      69           6 : PersistentMap::~PersistentMap()
      70             : {
      71           6 :     delete _impl;
      72           6 : }
      73             : 
      74           3 : bool PersistentMap::insert( const std::string& key, const std::string& value)
      75             : {
      76           3 :     return _impl->insert( key, value );
      77             : }
      78             : 
      79          12 : std::string PersistentMap::operator [] ( const std::string& key ) const
      80             : {
      81          12 :     return (*_impl)[ key ];
      82             : }
      83             : 
      84          87 : }

Generated by: LCOV version 1.10