📄 params.cpp
字号:
max_records = 1; this->values = new att_val[max_records*num_fields]; for (ch=pattern, num_fields=0; *ch != '\0'; ch++, num_fields++) { values[num_fields].pattern = ch; if ((*ch == 'F') || (*ch == 'B') || (*ch == 'I')) continue; char term = '\0'; if (*ch == '(') term = ')'; else if (*ch == '[') term = ']'; for (ch++; (*ch != term) && (*ch != '\0'); ch++); } derived = false; parsed = false; next = NULL;}/*****************************************************************************//* kd_attribute::augment_records *//*****************************************************************************/void kd_attribute::augment_records(int new_records){ if (new_records <= num_records) return; if (max_records < new_records) { // Need to allocate more storage. if (!(flags & kdu_params::MULTI_RECORD)) { kdu_error e; e << "Attempting to write multiple records to a code-stream " "attribute, \"" << name << "\", which can " "accept only single attributes!"; } int alloc_records = max_records + new_records; att_val *alloc_vals = new att_val[alloc_records*num_fields]; int rec, fld; att_val *new_p, *old_p; for (new_p=alloc_vals, old_p=values, rec=0; rec < max_records; rec++) for (fld=0; fld < num_fields; fld++) *(new_p++) = *(old_p++); for (; rec < alloc_records; rec++) for (old_p -= num_fields, fld=0; fld < num_fields; fld++) { *new_p = *(old_p++); new_p->is_set = false; new_p++; } delete[] values; values = alloc_vals; max_records = alloc_records; } num_records = new_records;}/*****************************************************************************//* kd_attribute::describe *//*****************************************************************************/void kd_attribute::describe(ostream &stream, bool allow_tiles, bool allow_comps, bool include_comments){ char locators[3]; int loc_pos = 0; if (allow_tiles) locators[loc_pos++] = 'T'; if (allow_comps && !(flags & kdu_params::ALL_COMPONENTS)) locators[loc_pos++] = 'C'; locators[loc_pos++] = '\0'; if (loc_pos < 2) stream << name << "={"; else stream << name << "[:<" << locators << ">]={"; for (int fnum=0; fnum < num_fields; fnum++) { if (fnum != 0) stream << ","; char const *cp = values[fnum].pattern; assert(cp != NULL); if (*cp == 'I') stream << "<int>"; else if (*cp == 'B') stream << "<yes/no>"; else if (*cp == 'F') stream << "<float>"; else if (*cp == '(') { char buf[80]; int val; stream << "ENUM<"; do { cp = parse_translator_entry(cp+1,',',buf,80,val); stream << buf; if (*cp == ',') stream << *cp; } while (*cp == ','); stream << ">"; } else if (*cp == '[') { char buf[80]; int val; stream << "FLAGS<"; do { cp = parse_translator_entry(cp+1,'|',buf,80,val); stream << buf; if (*cp == '|') stream << *cp; } while (*cp == '|'); stream << ">"; } } stream << "}"; if (flags & kdu_params::MULTI_RECORD) stream << ",...\n"; else stream << "\n"; if (include_comments) stream << "\t" << comment << "\n";}/* ========================================================================= *//* kdu_params *//* ========================================================================= *//*****************************************************************************//* kdu_params::kdu_params *//*****************************************************************************/kdu_params::kdu_params(const char *cluster_name, bool allow_tiles, bool allow_comps, bool allow_insts){ this->cluster_name = cluster_name; this->tile_idx = -1; this->comp_idx = -1; this->inst_idx = 0; this->num_comps = 0; this->allow_tiles = allow_tiles; this->allow_comps = allow_comps; this->allow_insts = allow_insts; this->attributes = NULL; this->empty = true; this->marked = false; first_cluster = this; next_cluster = NULL; first_tile = this; next_tile = NULL; first_comp = this; next_comp = NULL; first_inst = this; next_inst = NULL;}/*****************************************************************************//* kdu_params::~kdu_params *//*****************************************************************************/kdu_params::~kdu_params(){ kd_attribute *att; kdu_params *csp; while ((att=attributes) != NULL) { attributes = att->next; delete(att); } // Process instance list if (first_inst == NULL) return; // Function being used to delete all elements of instance list. if (this != first_inst) { // Relink instance list. for (csp=first_inst; this != csp->next_inst; csp=csp->next_inst); csp->next_inst = this->next_inst; return; } while ((csp=next_inst) != NULL) { // Delete rest of instance list. next_inst = csp->next_inst; csp->first_inst = NULL; // Prevent further instance list processing. delete csp; } // Process component list assert(this == first_inst); if (first_comp == NULL) return; // Function being used to delete all elements of a component list. if (this != first_comp) { // Relink component list. for (csp=first_comp; this != csp->next_comp; csp=csp->next_comp); csp->next_comp = this->next_comp; return; } while ((csp=next_comp) != NULL) { // Delete rest of component list. next_comp = csp->next_comp; csp->first_comp = NULL; // Prevent further component list processing. delete csp; } // Process tile list assert(this == first_comp); if (first_tile == NULL) return; // Function being used to delete all elements of a tile list. if (this != first_tile) { // Relink tile list. for (csp=first_tile; this != csp->next_tile; csp=csp->next_tile); csp->next_tile = this->next_tile; return; } while ((csp=next_tile) != NULL) { // Delete rest of tile list. next_tile = csp->next_tile; csp->first_tile = NULL; // Prevent further tile list processing. delete csp; } // Process cluster list assert(this == first_tile); if (first_cluster == NULL) return; // Function being used to delete all elements of the cluster list. if (this != first_cluster) { // Relink cluster list. for (csp=first_cluster; this != csp->next_cluster; csp=csp->next_cluster); csp->next_cluster = this->next_cluster; return; } while ((csp=next_cluster) != NULL) { // Delete entire cluster list. next_cluster = csp->next_cluster; csp->first_cluster = NULL; // Prevent further cluster list processing. delete csp; }}/*****************************************************************************//* kdu_params::link *//*****************************************************************************/kdu_params * kdu_params::link(kdu_params *existing, int tile_idx, int comp_idx){ kdu_params *cluster, *prev_cluster; assert((this->tile_idx == -1) && (this->comp_idx == -1) && (this->inst_idx == 0)); this->tile_idx = tile_idx; this->comp_idx = comp_idx; assert((tile_idx >= -1) && (comp_idx >= -1)); if (!allow_tiles) assert(tile_idx < 0); if (!allow_comps) assert(comp_idx < 0); cluster=existing->first_inst->first_comp->first_tile->first_cluster; for (prev_cluster=NULL; cluster != NULL; prev_cluster=cluster, cluster=cluster->next_cluster) if (strcmp(cluster->cluster_name,this->cluster_name) == 0) break; if (cluster == NULL) { /* Link as head of new cluster. */ assert((tile_idx == -1) && (comp_idx == -1)); /* Cluster head must have component and tile indices of -1. */ if (prev_cluster != NULL) { this->first_cluster = prev_cluster->first_cluster; this->next_cluster = prev_cluster->next_cluster; prev_cluster->next_cluster = this; } else { this->first_cluster = this; this->next_cluster = NULL; } return this; } kdu_params *tile, *prev_tile; this->first_cluster = this->next_cluster = NULL; for (tile=cluster, prev_tile=NULL; (tile != NULL) && (tile->tile_idx < this->tile_idx); prev_tile=tile, tile=tile->next_tile); if ((tile==NULL) || (tile->tile_idx > tile_idx)) { // Link as new tile in existing cluster. assert(prev_tile != NULL); /* Illegal to have a new cluster head here. See comments with constructor definition. */ assert((tile_idx >= 0) && (comp_idx == -1)); /* Tile head must have component index of -1. */ assert(allow_tiles); this->first_tile = prev_tile->first_tile; this->next_tile = prev_tile->next_tile; prev_tile->next_tile = this; return this; } kdu_params *comp, *prev_comp; this->first_tile = this->next_tile = NULL; for (comp=tile, prev_comp=NULL; (comp != NULL) && (comp->comp_idx < this->comp_idx); prev_comp=comp, comp=comp->next_comp); if ((comp == NULL) || (comp->comp_idx > comp_idx)) { // Link as new component in existing tile. assert(prev_comp != NULL); /* Illegal to have a new tile head here. See comments with constructor definition. */ assert(comp_idx >= 0); assert(allow_comps); this->first_comp = prev_comp->first_comp; this->next_comp = prev_comp->next_comp; this->num_comps = prev_comp->num_comps; prev_comp->next_comp = this; for (kdu_params *scan=first_comp; scan != NULL; scan=scan->next_comp) scan->num_comps++; return this; } // Must be new instance of current tile-component. this->first_comp = this->next_comp = NULL; assert(allow_insts); assert((comp->tile_idx == tile_idx) && (comp->comp_idx == comp_idx)); while (comp->next_inst != NULL) comp = comp->next_inst; this->first_inst = comp->first_inst; comp->next_inst = this; this->inst_idx = comp->inst_idx + 1; return this;}/*****************************************************************************//* kdu_params::copy_from *//*****************************************************************************/void kdu_params::copy_from(kdu_params *source_ref, int source_tile, int target_tile, int instance, int skip_components, int discard_levels, bool transpose, bool vflip, bool hflip){ if (source_ref->cluster_name != this->cluster_name) { kdu_error e; e << "Illegal attempt to copy a `kdu_params' object to " "one which has been derived differently."; } kdu_params *source = source_ref; // Keep `source_ref' for cluster navigation bool skip_this_cluster = false; if (source == source->first_tile) while ((source->tile_idx != source_tile) && (source->next_tile != NULL)) source = source->next_tile; if (source->tile_idx != source_tile) skip_this_cluster = true; kdu_params *target = this; if (target == target->first_tile) while ((target->tile_idx != target_tile) && (target->next_tile != NULL)) target = target->next_tile; if (target->tile_idx != target_tile) skip_this_cluster = true; if (source->comp_idx != target->comp_idx) skip_this_cluster = true; bool all_comps = (source == source->first_comp) && (target == target->first_comp); while ((source != NULL) && (target != NULL) && !skip_this_cluster)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -