-unsigned Batch::get_index_size() const
-{
- if(data_type==UNSIGNED_SHORT)
- return sizeof(unsigned short);
- else if(data_type==UNSIGNED_INT)
- return sizeof(unsigned);
- return sizeof(unsigned char);
-}
-
-template<typename T>
-void Batch::append_index(T i)
-{
- data.insert(data.end(), sizeof(T), 0);
- *(T *)(&data[data.size()-sizeof(T)]) = i;
-}
-
-unsigned Batch::get_index(unsigned i) const
-{
- if(data_type==UNSIGNED_SHORT)
- return *(unsigned short *)&data[i*sizeof(unsigned short)];
- else if(data_type==UNSIGNED_INT)
- return *(unsigned *)&data[i*sizeof(unsigned )];
- else
- return data[i];
-}
-
-template<typename T, typename U>
-void Batch::expand_data()
-{
- unsigned count = data.size()/sizeof(T);
- data.resize(count*sizeof(U));
- for(unsigned i=count; i--;)
- *(U *)(&data[i*sizeof(U)]) = convert<T, U>(*(T *)(&data[i*sizeof(T)]));
-}
-
-template<typename T, typename U>
-void Batch::shrink_data()
-{
- unsigned count = data.size()/sizeof(T);
- for(unsigned i=0; i<count; ++i)
- *(U *)(&data[i*sizeof(U)]) = convert<T, U>(*(T *)(&data[i*sizeof(T)]));
- data.resize(count*sizeof(U));
-}
-
-template<typename T, typename U>
-U Batch::convert(T i) const
-{
- if(!static_cast<T>(~i))
- return ~0;
- else
- return i;
-}
-
-void Batch::unlink_from_ibuf()
-{
- if(next_in_ibuf)
- next_in_ibuf->prev_in_ibuf = prev_in_ibuf;
- if(prev_in_ibuf)
- {
- prev_in_ibuf->next_in_ibuf = next_in_ibuf;
- prev_in_ibuf->update_ibuf_offsets();
- }
- else if(next_in_ibuf)
- {
- next_in_ibuf->ibuf_offset = 0;
- next_in_ibuf->update_ibuf_offsets();
- }
-}
-
-void Batch::update_ibuf_offsets()
-{
- for(Batch *b=this; b->next_in_ibuf; b=b->next_in_ibuf)
- b->next_in_ibuf->ibuf_offset = b->ibuf_offset+b->data.size();
-}
-