00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 #include "w_defines.h"
00031 
00032 
00033 
00034 
00035 #ifdef __GNUC__
00036      #pragma implementation
00037 #endif
00038 
00039 #define VEC_T_C
00040 #include <cstdlib>
00041 #include <w_stream.h>
00042 #include <w_base.h>
00043 #include <w_minmax.h>
00044 #include "basics.h"
00045 #include "vec_t.h"
00046 #include "umemcmp.h"
00047 #include "w_debug.h"
00048 
00049 
00050 
00051 
00052 
00053 
00054 
00055 
00056 
00057 
00058 
00059 
00060 
00061 
00062 
00063 
00064 void
00065 vec_t::mkchunk(
00066     int                maxsize,
00067     int                offset, 
00068     vec_t            &result 
00069 ) const
00070 {
00071     int i;
00072 
00073     w_assert1( _base[0].ptr != zero_location );
00074 
00075     DBG(<<"offset " << offset << " in vector :");
00076     result.reset();
00077 
00078     
00079     
00080     
00081     int        first_chunk=0, first_chunk_offset=0, first_chunk_len=0;
00082     {
00083         
00084         int skipped=0, skipping;
00085 
00086         for(i=0; i<this->count(); i++) {
00087             skipping = this->len(i);
00088             if(skipped + skipping > offset) {
00089                 
00090                 first_chunk = i;
00091                 first_chunk_offset = offset - skipped;
00092                 first_chunk_len = skipping - first_chunk_offset;
00093                 if(first_chunk_len > maxsize) {
00094                     first_chunk_len = maxsize;
00095                 }
00096 
00097         DBG(<<"put " << W_ADDR(this->ptr(i)) << 
00098             "+" << first_chunk_offset << ", " << first_chunk_len);
00099 
00100                 result.put((char*)this->ptr(i)+first_chunk_offset,first_chunk_len);
00101                 break;
00102             }
00103             skipped += skipping;
00104         }
00105         if(first_chunk_len == 0) return;
00106     }
00107 
00108     if(first_chunk_len < maxsize) {
00109         
00110         int used, is_using ;
00111 
00112         used = first_chunk_len;
00113         for(i=first_chunk+1; i<this->count(); i++) {
00114             is_using = this->len(i);
00115             if(used + is_using <= maxsize) {
00116                 
00117                 used += is_using;
00118 
00119                 DBG(<<"put " << W_ADDR(this->ptr(i)) << ", " << is_using);
00120                 result.put(this->ptr(i),is_using);
00121             } else {
00122                 
00123                 result.put(this->ptr(i),maxsize-used);
00124                 used = maxsize;
00125                 break;
00126             }
00127         }
00128     }
00129 }
00130 
00131