SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
CircularBuffer.h
Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 2013 Engeniy Andreev (gsomix)
00008  */
00009 
00010 #ifndef __CIRCULARBUFFER_H_
00011 #define __CIRCULARBUFFER_H_
00012 
00013 #include <shogun/base/SGObject.h>
00014 #include <shogun/lib/SGVector.h>
00015 #include <shogun/lib/Tokenizer.h>
00016 
00017 namespace shogun
00018 {
00019 
00029 class CCircularBuffer : public CSGObject
00030 {
00031 public:
00033     CCircularBuffer();
00034 
00039     CCircularBuffer(int32_t buffer_size);
00040 
00042     ~CCircularBuffer();
00043 
00048     void set_tokenizer(CTokenizer* tokenizer);
00049 
00055     int32_t push(SGVector<char> source);
00056 
00062     int32_t push(FILE* source, int32_t source_size);
00063 
00069     SGVector<char> pop(int32_t num_chars);
00070 
00076     bool has_next();
00077 
00084     index_t next_token_idx(index_t &start);
00085 
00091     void skip_characters(int32_t num_chars);
00092 
00094     int32_t available() const
00095     {
00096         return m_bytes_available;
00097     }
00098 
00100     int32_t num_bytes_contained() const
00101     {
00102         return m_bytes_count;
00103     }
00104 
00106     void clear();
00107 
00109     virtual const char* get_name() const { return "CircularBuffer"; }
00110 
00111 private:
00113     void init();
00114 
00116     int32_t append_chunk(const char* source, int32_t source_size,
00117                     bool from_buffer_begin);
00118 
00120     int32_t append_chunk(FILE* source, int32_t source_size,
00121                     bool from_buffer_begin);
00122 
00124     void detach_chunk(char** dest, int32_t* dest_size, int32_t dest_offset, int32_t num_bytes,
00125                     bool from_buffer_begin);
00126 
00130     bool has_next_locally(char* begin, char* end);
00131 
00135     index_t next_token_idx_locally(index_t &start, char* begin, char* end);
00136 
00138     void move_pointer(char** pointer, char* new_position);
00139 
00140 private:
00142     SGVector<char> m_buffer;
00143 
00145     char* m_buffer_end;
00146 
00148     char* m_begin_pos;
00149 
00151     char* m_end_pos;
00152 
00154     CTokenizer* m_tokenizer;
00155 
00157     index_t m_last_idx;
00158 
00160     int32_t m_bytes_available;
00161 
00163     int32_t m_bytes_count;
00164 };
00165 
00166 }
00167 
00168 #endif /* _CIRCULARBUFFER_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation