LCOV - code coverage report
Current view: top level - lunchbox - persistentMap.cpp (source / functions) Hit Total Coverage
Test: Lunchbox Lines: 6 35 17.1 %
Date: 2015-07-07 14:54:45 Functions: 4 15 26.7 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2014-2015, 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 <servus/uri.h>
      20             : 
      21             : namespace lunchbox
      22             : {
      23             : namespace detail
      24             : {
      25             : class PersistentMap
      26             : {
      27             : public:
      28             :     PersistentMap() : swap( false ) {}
      29             :     virtual ~PersistentMap() {}
      30             :     virtual size_t setQueueDepth( const size_t ) { return 0; }
      31             :     virtual bool insert( const std::string& key, const void* data,
      32             :                          const size_t size ) = 0;
      33             :     virtual std::string operator [] ( const std::string& key ) const = 0;
      34             :     virtual bool fetch( const std::string&, const size_t ) const
      35             :         { return true; }
      36             :     virtual bool contains( const std::string& key ) const = 0;
      37             :     virtual bool flush() = 0;
      38             : 
      39             :     bool swap;
      40             : };
      41             : }
      42             : }
      43             : 
      44             : // Impls - need detail::PersistentMap interface above
      45             : #include "leveldb/persistentMap.h"
      46             : #include "skv/persistentMap.h"
      47             : 
      48             : namespace
      49             : {
      50           2 : lunchbox::detail::PersistentMap* _newImpl( const servus::URI& uri )
      51             : {
      52             :     // Update handles() below on any change here!
      53             : #ifdef LUNCHBOX_USE_LEVELDB
      54             :     if( lunchbox::leveldb::PersistentMap::handles( uri ))
      55             :         return new lunchbox::leveldb::PersistentMap( uri );
      56             : #endif
      57             : #ifdef LUNCHBOX_USE_SKV
      58             :     if( lunchbox::skv::PersistentMap::handles( uri ))
      59             :         return new lunchbox::skv::PersistentMap( uri );
      60             : #endif
      61             : 
      62           2 :     if( !uri.getScheme().empty( ))
      63           2 :         LBTHROW( std::runtime_error(
      64             :                      std::string( "No suitable implementation found for: " ) +
      65             :                          boost::lexical_cast< std::string >( uri )));
      66             : 
      67             : #ifdef LUNCHBOX_USE_LEVELDB
      68             :     return new lunchbox::leveldb::PersistentMap( uri );
      69             : #endif
      70           0 :     LBTHROW( std::runtime_error(
      71             :                  std::string( "No suitable implementation found for: " ) +
      72             :                      boost::lexical_cast< std::string >( uri )));
      73             : }
      74             : }
      75             : 
      76             : namespace lunchbox
      77             : {
      78           2 : PersistentMap::PersistentMap( const std::string& uri )
      79           4 :     : _impl( _newImpl( servus::URI( uri )))
      80           0 : {}
      81             : 
      82           0 : PersistentMap::PersistentMap( const servus::URI& uri )
      83           0 :     : _impl( _newImpl( uri ))
      84           0 : {}
      85             : 
      86           0 : PersistentMap::~PersistentMap()
      87             : {
      88           0 :     delete _impl;
      89           0 : }
      90             : 
      91           0 : bool PersistentMap::handles( const servus::URI& uri )
      92             : {
      93             : #ifdef LUNCHBOX_USE_LEVELDB
      94             :     if( lunchbox::leveldb::PersistentMap::handles( uri ))
      95             :         return true;
      96             : #endif
      97             : #ifdef LUNCHBOX_USE_SKV
      98             :     if( lunchbox::skv::PersistentMap::handles( uri ))
      99             :         return true;
     100             : #endif
     101             : 
     102           0 :     if( !uri.getScheme().empty( ))
     103           0 :         return false;
     104             : 
     105             : #ifdef LUNCHBOX_USE_LEVELDB
     106             :     return true;
     107             : #endif
     108           0 :     return false;
     109             : }
     110             : 
     111           0 : size_t PersistentMap::setQueueDepth( const size_t depth )
     112             : {
     113           0 :     return _impl->setQueueDepth( depth );
     114             : }
     115             : 
     116           0 : bool PersistentMap::_insert( const std::string& key, const void* data,
     117             :                              const size_t size )
     118             : {
     119           0 :     return _impl->insert( key, data, size );
     120             : }
     121             : 
     122           0 : std::string PersistentMap::operator [] ( const std::string& key ) const
     123             : {
     124           0 :     return (*_impl)[ key ];
     125             : }
     126             : 
     127           0 : bool PersistentMap::fetch( const std::string& key, const size_t sizeHint ) const
     128             : {
     129           0 :     return _impl->fetch( key, sizeHint );
     130             : }
     131             : 
     132           0 : bool PersistentMap::contains( const std::string& key ) const
     133             : {
     134           0 :     return _impl->contains( key );
     135             : }
     136             : 
     137           0 : bool PersistentMap::flush()
     138             : {
     139           0 :     return _impl->flush();
     140             : }
     141             : 
     142           0 : void PersistentMap::setByteswap( const bool swap )
     143             : {
     144           0 :     _impl->swap = swap;
     145           0 : }
     146             : 
     147           0 : bool PersistentMap::_swap() const
     148             : {
     149           0 :     return _impl->swap;
     150             : }
     151             : 
     152          81 : }

Generated by: LCOV version 1.11