Skip to content

Commit

Permalink
make it compile in MSVC2015
Browse files Browse the repository at this point in the history
  • Loading branch information
rmsalinas committed Dec 14, 2018
1 parent 602a4d6 commit e148dbc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/fbow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ void Vocabulary::setParams(int aligment, int k, int desc_type, int desc_size, in

//give memory
_params._total_size=_params._block_size_bytes_wp*_params._nblocks;
_data = Data_ptr((char*)AlignedAlloc(_params._aligment, _params._total_size), &AlignedFree);
_data = std::unique_ptr<char[], decltype(&AlignedFree)>((char*)AlignedAlloc(_params._aligment, _params._total_size), &AlignedFree);

memset(_data.get(), 0, _params._total_size);

}
Expand Down Expand Up @@ -183,8 +184,8 @@ void Vocabulary::fromStream(std::istream &str)
if (sig!=55824124) throw std::runtime_error("Vocabulary::fromStream invalid signature");
//read string
str.read((char*)&_params,sizeof(params));
_data = Data_ptr((char*)AlignedAlloc(_params._aligment, _params._total_size), &AlignedFree);
if (_data==0) throw std::runtime_error("Vocabulary::fromStream Could not allocate data");
_data = std::unique_ptr<char[], decltype(&AlignedFree)>((char*)AlignedAlloc(_params._aligment, _params._total_size), &AlignedFree);
if (_data.get() == nullptr) throw std::runtime_error("Vocabulary::fromStream Could not allocate data");
str.read(_data.get(), _params._total_size);
}

Expand Down
12 changes: 7 additions & 5 deletions src/fbow.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,20 @@ class FBOW_API Vocabulary
}

static inline void AlignedFree(void *ptr){
if(ptr==nullptr)return;
unsigned char *uptr=(unsigned char *)ptr;
unsigned char off= *(uptr-1);
uptr-=off;
std::free(uptr);
}

using Data_ptr = std::unique_ptr<char[], decltype(&AlignedFree)>;
// using Data_ptr = std::unique_ptr<char[], decltype(&AlignedFree)>;

friend class VocabularyCreator;

public:

Vocabulary() = default;
Vocabulary(): _data((char*)nullptr,&AlignedFree){}
Vocabulary(Vocabulary&&) = default;

//transform the features stored as rows in the returned BagOfWords
Expand All @@ -107,7 +108,7 @@ class FBOW_API Vocabulary
//returns the branching factor (number of children per node)
uint32_t getK()const{return _params._m_k;}
//indicates whether this object is valid
bool isValid()const{return _data!=0;}
bool isValid()const{return _data.get()!=nullptr;}
//total number of blocks
size_t size()const{return _params._nblocks;}
//removes all data
Expand All @@ -129,7 +130,8 @@ class FBOW_API Vocabulary
uint32_t _m_k=0;//number of children per node
};
params _params;
Data_ptr _data = Data_ptr(nullptr, &AlignedFree);//pointer to data
std::unique_ptr<char[], decltype(&AlignedFree)> _data;


//structure represeting a information about node in a block
struct block_node_info{
Expand Down Expand Up @@ -194,7 +196,7 @@ class FBOW_API Vocabulary


//returns a block structure pointing at block b
inline Block getBlock(uint32_t b) { assert(_data != 0); assert(b < _params._nblocks); return Block(_data.get() + b * _params._block_size_bytes_wp, _params._desc_size, _params._desc_size_bytes_wp, _params._feature_off_start, _params._child_off_start); }
inline Block getBlock(uint32_t b) { assert(_data.get() != nullptr); assert(b < _params._nblocks); return Block(_data.get() + b * _params._block_size_bytes_wp, _params._desc_size, _params._desc_size_bytes_wp, _params._feature_off_start, _params._child_off_start); }
//given a block already create with getBlock, moves it to point to block b
inline void setBlock(uint32_t b, Block &block) { block._blockstart = _data.get() + b * _params._block_size_bytes_wp; }

Expand Down

0 comments on commit e148dbc

Please sign in to comment.