00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __loaded__array_creator_cpp__
00021 #define __loaded__array_creator_cpp__
00022 using namespace std;
00023 #line 1 "array-creator.c++"
00024 #include "array-creator.h"
00025 #include "array-iterator.h"
00026 #include "symbol.h"
00027 #include "numbers.h"
00028 #include "data-io.h"
00029
00030
00031
00032
00033
00034
00035
00036
00037 void Creator::ensure_size(int S)
00038 {
00039 if (S >= content.size(0))
00040 {
00041 Unsigned4 next_index = content[0];
00042 int prev_allocation = content.size(0);
00043 int new_allocation = prev_allocation*2;
00044 while(S<new_allocation) S*=2;
00045 assert(new_allocation);
00046 Array<1,Data> before = content;
00047 content = Array<1,Data>(new_allocation);
00048 for(unsigned int i = 0 ; i < next_index ; i ++)
00049 content[i]=before[i];
00050 }
00051 };
00052
00053 void Creator::append(Data& val)
00054 {
00055 Unsigned4 next_index=(Unsigned4)content[0];
00056 ensure_size(next_index+1);
00057 content[(int)next_index]=val;
00058 next_index = next_index+1;
00059 content[0]=next_index;
00060 }
00061
00062 template<int D, class T>
00063 Data Creator::createAndFillTarget(Size<8> s)
00064 {
00065
00066 Size<D> correct_size;
00067 correct_size.takeFrom(s);
00068 typedef Array<D,T> Result;
00069 Result result(correct_size);
00070
00071 typename Result::positions position(result);
00072 for(;position.more(); ++position)
00073 {
00074 Content cur = getContentData();
00081 int idx;
00082 for(int d = 0 ; d < D-1 ; d++)
00083 {
00084 idx=position[d];
00085 cur=(Content)cur[idx];
00086 }
00087 Data data = cur[position[D-1]];
00088 ::convertTo(data,*position.current());
00089 }
00090 return result;
00091 }
00092
00093 Array<1,Data> Creator::getContentData()
00094 {
00095 Unsigned4 next_index=(Unsigned4)content[0];
00096 return content(From<1>(1),Size<1>(next_index-1));
00097 }
00098
00099 void updateSize(Array<1,Data> content, Size<8>& size, int last_depth, int depth)
00100 {
00101
00102 int s = content.size()[0];
00103 if (s > size[depth])
00104 size[depth]=s;
00105 if (depth!=last_depth)
00106 {
00107 Array<1,Data>::values element(content);
00108 int i = 0;
00109 for ( ; element.more(); ++element)
00110 {
00111 ++i;
00112 Array<1,Data> e=*element;
00113 updateSize(e,size,last_depth,1+depth);
00114 }
00115 }
00116 }
00117
00118 void Creator::updateSize(Size<8>& size, int last_depth, int depth)
00119 {
00120 ::updateSize(getContentData(),size,last_depth,depth);
00121 }
00122
00123 Data Creator::convertTo(Unsigned4 dimension, Symbol type)
00124 {
00125
00126 assert(dimension);
00127 Size<8> size;
00128 updateSize(size,dimension-1);
00129
00130 #define ARRAY_TYPE(D,T) \
00131 if (D==dimension && QString(type) == QString(#T)) \
00132 return createAndFillTarget<D,T>(size);
00133 ARRAY_TYPES
00134 #undef ARRAY_TYPE
00135 assert(0);
00136 }
00137 #endif // __loaded__array_creator_cpp__