LCOV - code coverage report
Current view: top level - lunchbox - persistentMap.cpp (source / functions) Hit Total Coverage
Test: lcov2.info Lines: 19 30 63.3 %
Date: 2014-10-01 Functions: 9 13 69.2 %

          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             : #include "uri.h"
      20             : 
      21             : namespace lunchbox
      22             : {
      23             : namespace detail
      24             : {
      25           7 : class PersistentMap
      26             : {
      27             : public:
      28           7 :     virtual ~PersistentMap() {}
      29             :     virtual bool insert( const std::string& key, const void* data,
      30             :                          const size_t size ) = 0;
      31             :     virtual std::string operator [] ( const std::string& key ) const = 0;
      32             :     virtual bool contains( const std::string& key ) const = 0;
      33             : };
      34             : }
      35             : }
      36             : 
      37             : // Impls - need detail::PersistentMap interface
      38             : #include "leveldb/persistentMap.h"
      39             : #include "skv/persistentMap.h"
      40             : 
      41             : namespace
      42             : {
      43           8 : lunchbox::detail::PersistentMap* _newImpl( const lunchbox::URI& uri )
      44             : {
      45             :     // Update handles() below on any change here!
      46             : #ifdef LUNCHBOX_USE_LEVELDB
      47           8 :     if( lunchbox::leveldb::PersistentMap::handles( uri ))
      48           6 :         return new lunchbox::leveldb::PersistentMap( uri );
      49             : #endif
      50             : #ifdef LUNCHBOX_USE_SKV
      51             :     if( lunchbox::skv::PersistentMap::handles( uri ))
      52             :         return new lunchbox::skv::PersistentMap( uri );
      53             : #endif
      54             : 
      55           3 :     if( !uri.getScheme().empty( ))
      56           1 :         LBTHROW( std::runtime_error(
      57             :                      std::string( "No suitable implementation found for: " ) +
      58             :                          boost::lexical_cast< std::string >( uri )));
      59             : 
      60             : #ifdef LUNCHBOX_USE_LEVELDB
      61           2 :     return new lunchbox::leveldb::PersistentMap( uri );
      62             : #endif
      63             :     LBTHROW( std::runtime_error(
      64             :                  std::string( "No suitable implementation found for: " ) +
      65             :                      boost::lexical_cast< std::string >( uri )));
      66             : }
      67             : }
      68             : 
      69             : namespace lunchbox
      70             : {
      71           8 : PersistentMap::PersistentMap( const std::string& uri )
      72          10 :     : _impl( _newImpl( URI( uri )))
      73           6 : {}
      74             : 
      75           0 : PersistentMap::PersistentMap( const URI& uri )
      76           0 :     : _impl( _newImpl( uri ))
      77           0 : {}
      78             : 
      79           6 : PersistentMap::~PersistentMap()
      80             : {
      81           6 :     delete _impl;
      82           6 : }
      83             : 
      84           0 : bool PersistentMap::handles( const URI& uri )
      85             : {
      86             : #ifdef LUNCHBOX_USE_LEVELDB
      87           0 :     if( lunchbox::leveldb::PersistentMap::handles( uri ))
      88           0 :         return true;
      89             : #endif
      90             : #ifdef LUNCHBOX_USE_SKV
      91             :     if( lunchbox::skv::PersistentMap::handles( uri ))
      92             :         return true;
      93             : #endif
      94             : 
      95           0 :     if( !uri.getScheme().empty( ))
      96           0 :         return false;
      97             : 
      98             : #ifdef LUNCHBOX_USE_LEVELDB
      99           0 :     return true;
     100             : #endif
     101             :     return false;
     102             : }
     103             : 
     104          18 : bool PersistentMap::_insert( const std::string& key, const void* data,
     105             :                              const size_t size )
     106             : {
     107          18 :     return _impl->insert( key, data, size );
     108             : }
     109             : 
     110          33 : std::string PersistentMap::operator [] ( const std::string& key ) const
     111             : {
     112          33 :     return (*_impl)[ key ];
     113             : }
     114             : 
     115           0 : bool PersistentMap::contains( const std::string& key ) const
     116             : {
     117           0 :     return _impl->contains( key );
     118             : }
     119             : 
     120          90 : }

Generated by: LCOV version 1.10