Skip to content

Commit e148dbc

Browse files
committed
make it compile in MSVC2015
1 parent 602a4d6 commit e148dbc

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/fbow.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ void Vocabulary::setParams(int aligment, int k, int desc_type, int desc_size, in
4242

4343
//give memory
4444
_params._total_size=_params._block_size_bytes_wp*_params._nblocks;
45-
_data = Data_ptr((char*)AlignedAlloc(_params._aligment, _params._total_size), &AlignedFree);
45+
_data = std::unique_ptr<char[], decltype(&AlignedFree)>((char*)AlignedAlloc(_params._aligment, _params._total_size), &AlignedFree);
46+
4647
memset(_data.get(), 0, _params._total_size);
4748

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

src/fbow.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,20 @@ class FBOW_API Vocabulary
7272
}
7373

7474
static inline void AlignedFree(void *ptr){
75+
if(ptr==nullptr)return;
7576
unsigned char *uptr=(unsigned char *)ptr;
7677
unsigned char off= *(uptr-1);
7778
uptr-=off;
7879
std::free(uptr);
7980
}
8081

81-
using Data_ptr = std::unique_ptr<char[], decltype(&AlignedFree)>;
82+
// using Data_ptr = std::unique_ptr<char[], decltype(&AlignedFree)>;
8283

8384
friend class VocabularyCreator;
8485

8586
public:
8687

87-
Vocabulary() = default;
88+
Vocabulary(): _data((char*)nullptr,&AlignedFree){}
8889
Vocabulary(Vocabulary&&) = default;
8990

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

134136
//structure represeting a information about node in a block
135137
struct block_node_info{
@@ -194,7 +196,7 @@ class FBOW_API Vocabulary
194196

195197

196198
//returns a block structure pointing at block b
197-
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); }
199+
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); }
198200
//given a block already create with getBlock, moves it to point to block b
199201
inline void setBlock(uint32_t b, Block &block) { block._blockstart = _data.get() + b * _params._block_size_bytes_wp; }
200202

0 commit comments

Comments
 (0)