Skip to content

Commit

Permalink
Changed to track latest changes to cppcomponent
Browse files Browse the repository at this point in the history
  • Loading branch information
jbandela committed Jul 22, 2013
1 parent 97e20fd commit af626e1
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 66 deletions.
1 change: 1 addition & 0 deletions example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ int main(){
#endif
// Open a scope so db goes out of scope so we can delete the database
{
leveldb_cc::ReadOptions op1;
int major, minor;
std::tie(major, minor) = leveldb_cc::DB::GetVersion();
std::cout << "Trying leveldb version " << major << "." << minor << "\n";
Expand Down
103 changes: 51 additions & 52 deletions leveldb_cc_dll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@
#include "leveldb/cache.h"

#include "leveldb_interfaces.h"

#include<memory>

struct IGetNative
struct IGetNative:public cppcomponents::define_interface<cppcomponents::uuid<
0xAAF3BE95,0xA1A8,0x4DCE,0x8672,0xCEF27CD7EEC9
>>
{
typedef
cppcomponents::uuid<
0xAAF3BE95,0xA1A8,0x4DCE,0x86,0x72,0xCE,0xF2,0x7C,0xD7,0xEE,0xC9
>
uuid;


void* get_native();

Expand All @@ -32,16 +29,17 @@ using namespace cppcomponents;

inline std::string NotCreatable(){ return ""; }

typedef runtime_class<NotCreatable, ISnapshot, NoConstructorFactoryInterface, DefaultStaticInterface, IGetNative> SnapShot_t;
typedef runtime_class<NotCreatable, object_interfaces<ISnapshot, IGetNative>, factory_interface<NoConstructorFactoryInterface>> SnapShot_t;

struct SnapShotImplementation:public implement_runtime_class<SnapShotImplementation, SnapShot_t>
{
const leveldb::Snapshot* snapshot_;

void* IGetNative_get_native(){
return const_cast<leveldb::Snapshot*>(snapshot_);
}

SnapShotImplementation(const leveldb::Snapshot* s):snapshot_(s){
get_implementation<IGetNative>()->get_native = [this]()->void*{
return const_cast<leveldb::Snapshot*>(snapshot_);
};
}


Expand Down Expand Up @@ -89,38 +87,36 @@ struct ComparatorFromIComparator:public leveldb::Comparator{


};
typedef cppcomponents::runtime_class<LRUCacheComponentName, ICache, LRUCacheFactoryInterface, LRUCacheStaticInterface,IGetNative>
typedef cppcomponents::runtime_class < LRUCacheComponentName, cppcomponents::object_interfaces<ICache,IGetNative>,
cppcomponents::factory_interface < LRUCacheFactoryInterface >>
LRUCachePrivate_t;

struct LRUCacheImplementation
:public implement_runtime_class<LRUCacheImplementation,LRUCachePrivate_t>
{
std::unique_ptr<leveldb::Cache> cache_;

auto IGetNative_get_native()->void*{ return cache_.get(); };
LRUCacheImplementation(std::uint64_t capacity) : cache_(leveldb::NewLRUCache(static_cast<std::size_t>(capacity))){
get_implementation<IGetNative>()->get_native =
[this]()->void*{return cache_.get();};

}


};
typedef cppcomponents::runtime_class<BloomFilterComponentName, IFilterPolicy, BloomFilterFactoryInterface, BloomFilterStaticInterface,IGetNative>
typedef cppcomponents::runtime_class < BloomFilterComponentName, cppcomponents::object_interfaces<IFilterPolicy,IGetNative>,
cppcomponents::factory_interface < BloomFilterFactoryInterface >>
BloomFilterPrivate_t;

struct BloomFilterPolicyImplementation
:public implement_runtime_class<BloomFilterPolicyImplementation,BloomFilterPrivate_t>
{
std::unique_ptr<const leveldb::FilterPolicy> filter_;

auto IGetNative_get_native()->void*{ return const_cast<leveldb::FilterPolicy*>(filter_.get()); };
BloomFilterPolicyImplementation(std::int32_t bits) : filter_(leveldb::NewBloomFilterPolicy(bits)){
get_implementation<IGetNative>()->get_native =
[this]()->void*{return const_cast<leveldb::FilterPolicy*>(filter_.get());};

}

};
typedef cppcomponents::runtime_class<OptionsComponentName, IOptions, cppcomponents::DefaultFactoryInterface, cppcomponents::DefaultStaticInterface, IGetNative> OptionsPrivate_t;
typedef runtime_class<OptionsComponentName, cppcomponents::object_interfaces<IOptions,IGetNative>> OptionsPrivate_t;

struct OptionsImplementation
: public implement_runtime_class<OptionsImplementation, OptionsPrivate_t>
Expand Down Expand Up @@ -204,6 +200,7 @@ struct OptionsImplementation
};

void set_block_cache(use<ICache> ic){
cache_ = ic;
if(!ic){
options_.block_cache = nullptr;
}else{
Expand All @@ -212,6 +209,7 @@ struct OptionsImplementation
}
};
void set_filter_policy(use<IFilterPolicy> ic){
fp_ = ic;
if(!ic){
options_.filter_policy = nullptr;
}else{
Expand All @@ -221,26 +219,19 @@ struct OptionsImplementation
};



OptionsImplementation(){

get_implementation<IGetNative>()->get_native = [this]()->void*{
void* IGetNative_get_native(){
return &options_;
};
OptionsImplementation(){}




}


use<IFilterPolicy> fp_;
use<ICache> cache_;


};


typedef cppcomponents::runtime_class<ReadOptionsComponentName, IReadOptions, cppcomponents::DefaultFactoryInterface,
cppcomponents::DefaultStaticInterface,IGetNative> ReadOptionsPrivate_t;
typedef cppcomponents::runtime_class<ReadOptionsComponentName, object_interfaces<IReadOptions,IGetNative>> ReadOptionsPrivate_t;

struct ReadOptionsImplementation
: public implement_runtime_class<ReadOptionsImplementation, ReadOptionsPrivate_t>
Expand All @@ -267,17 +258,14 @@ struct ReadOptionsImplementation

};

ReadOptionsImplementation(){

get_implementation<IGetNative>()->get_native =
[this](){return &options_;};

};
auto IGetNative_get_native()->void*{
return &options_;
};
ReadOptionsImplementation(){}


};
typedef cppcomponents::runtime_class<WriteOptionsComponentName, IWriteOptions, cppcomponents::DefaultFactoryInterface,
cppcomponents::DefaultStaticInterface, IGetNative> WriteOptionsPrivate_t;
typedef cppcomponents::runtime_class<WriteOptionsComponentName,object_interfaces<IWriteOptions,IGetNative>> WriteOptionsPrivate_t;

struct WriteOptionsImplementation
: public implement_runtime_class<WriteOptionsImplementation,
Expand All @@ -293,11 +281,15 @@ struct WriteOptionsImplementation
options_.sync = b;
};

auto IGetNative_get_native()->void*{
return &options_;
};
WriteOptionsImplementation(){
get_implementation<IGetNative>()->get_native = [this]()->void*{
return &options_;

};




}


Expand Down Expand Up @@ -332,8 +324,7 @@ Status StatusFromLevelDBStatus(leveldb::Status& s){

}

typedef cppcomponents::runtime_class<WriteBatchComponentName, IWriteBatch, cppcomponents::DefaultFactoryInterface,
cppcomponents::DefaultStaticInterface, IGetNative> WriteBatchPrivate_t;
typedef cppcomponents::runtime_class<WriteBatchComponentName, object_interfaces<IWriteBatch,IGetNative> > WriteBatchPrivate_t;

struct WriteBatchImplementation
:public implement_runtime_class<WriteBatchImplementation,
Expand Down Expand Up @@ -362,18 +353,22 @@ struct WriteBatchImplementation

};

auto IGetNative_get_native()->void*{
return &wb_;
};
WriteBatchImplementation(){


get_implementation<IGetNative>()->get_native =
[this]()->void*{ return &wb_;};



}



};

typedef runtime_class<NotCreatable, IIterator, NoConstructorFactoryInterface, DefaultStaticInterface> IteratorPrivate_t;
typedef runtime_class<NotCreatable,object_interfaces<IIterator>,factory_interface<NoConstructorFactoryInterface>> IteratorPrivate_t;

struct IteratorImplementation
:public implement_runtime_class<IteratorImplementation,IteratorPrivate_t>{
Expand Down Expand Up @@ -441,10 +436,14 @@ struct DBImplementation:public implement_runtime_class<DBImplementation,
auto Write(use<IWriteOptions> wo,
use<IWriteBatch> wb)
->Status{
auto s = db_->Write(*static_cast<leveldb::WriteOptions*>(wo
.QueryInterface<IGetNative>().get_native()),
static_cast<leveldb::WriteBatch*>(wb
.QueryInterface<IGetNative>().get_native()));
auto wop = *static_cast<leveldb::WriteOptions*>(wo
.QueryInterface<IGetNative>().get_native());

auto wbat = static_cast<leveldb::WriteBatch*>(wb
.QueryInterface<IGetNative>().get_native());
auto s = db_->Write(wop,wbat);


return StatusFromLevelDBStatus(s);

};
Expand Down
3 changes: 2 additions & 1 deletion leveldb_interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ namespace leveldb_cc{

struct IHandler:cppcomponents::define_interface<
cppcomponents::uuid<0x549DA77F, 0x2FC1, 0x449F, 0x9749, 0x2E8F83F94BD1>>{
void Delete(Slice);
void Put(Slice, Slice);
void Delete(Slice);



Expand Down
4 changes: 2 additions & 2 deletions msvc_project/leveldb_cc_dll/leveldb_cc_dll.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120_CTP_Nov2012</PlatformToolset>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
Expand All @@ -42,7 +42,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<ReferencePath>C:\Users\jrb\Source\Repos\leveldb_cross_compiler\leveldbwin\leveldb_src\include;C:\Users\jrb\Source\Repos\leveldb_cross_compiler\leveldbwin\win32_impl_src;$(ReferencePath)</ReferencePath>
<IncludePath>C:\Users\jrb\Source\Repos\leveldb_cross_compiler\leveldbwin\leveldb_src\include;C:\Users\jrb\Source\Repos\leveldb_cross_compiler\leveldbwin\win32_impl_src;c:\Users\jrb\Source\Repos\cppcomponents;$(IncludePath)</IncludePath>
<IncludePath>C:\Users\jrb\Source\Repos\leveldb_cross_compiler\leveldbwin\leveldb_src\include;C:\Users\jrb\Source\Repos\leveldb_cross_compiler\leveldbwin\win32_impl_src;c:\Users\jrb\Source\Repos\cppcomponents;C:\Users\jrb\Source\Repos\leveldb\include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
Expand Down
2 changes: 1 addition & 1 deletion slice.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ namespace cross_compiler_interface{
ret.end = ret.begin + s.size();
return ret;
}
static leveldb_cc::Slice to_original_type(converted_type& c){
static leveldb_cc::Slice to_original_type(const converted_type& c){
leveldb_cc::Slice ret(c.begin,c.end - c.begin);
return ret;
}
Expand Down
12 changes: 2 additions & 10 deletions status.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ inline std::string Status::ToString() const {
#pragma pack(push,1)
struct status_cross_type{
const char* state;
void (CROSS_CALL_CALLING_CONVENTION *deleter)(const char*);

};
#pragma pack(pop)
Expand All @@ -188,12 +187,9 @@ inline std::string Status::ToString() const {
}

}
inline void CROSS_CALL_CALLING_CONVENTION delete_state(const char* s){
delete [] s;
}

inline void status_to_cross(const Status& s, status_cross_type& sc){
sc.state = nullptr;
sc.deleter = &delete_state;
if(s.state_){
sc.state = Status::CopyState(s.state_);
}
Expand All @@ -218,13 +214,9 @@ namespace cross_compiler_interface{
leveldb_cc::status_to_cross(s,ret);
return ret;
}
static original_type to_original_type(leveldb_cc::status_cross_type& sc){
static original_type to_original_type(const leveldb_cc::status_cross_type& sc){
leveldb_cc::Status ret;
leveldb_cc::modify_status(ret,sc);
if(sc.state){
sc.deleter(sc.state);
}

return ret;
}
};
Expand Down

0 comments on commit af626e1

Please sign in to comment.