📄 params.cpp
字号:
e << "Attempting to set a code-stream attribute " "field using an integer value which is incompatible " "with the flags defined for the field!\n"; e << "The attribute name is \"" << name << "\"."; } } else assert(*cp == 'I'); if (record_idx >= ap->num_records) ap->augment_records(record_idx+1); assert((record_idx >= 0) && (record_idx < ap->num_records)); ap->values[field_idx+ap->num_fields*record_idx].is_set = true; ap->values[field_idx+ap->num_fields*record_idx].ival = value; this->empty = false;}/*****************************************************************************//* kdu_params::set (bool) *//*****************************************************************************/void kdu_params::set(const char *name, int record_idx, int field_idx, bool value){ kd_attribute *ap; char const *cp; assert((record_idx >= 0) && (field_idx >= 0)); for (ap=attributes; ap != NULL; ap=ap->next) if (strcmp(name,ap->name) == 0) break; if (ap == NULL) { kdu_error e; e << "Attempt to set a code-stream attribute using " "the invalid name, \"" << name << "\"!"; } if ((ap->flags & ALL_COMPONENTS) && (comp_idx != -1)) { kdu_error e; e << "Attempt to set a non-tile-specific code-stream attribute " "in a specific component!\n"; e << "The attribute name is \"" << name << "\"."; } if (field_idx >= ap->num_fields) { kdu_error e; e << "Attempt to set a code-stream attribute, with an " "invalid field index!\n"; e << "The attribute name is \"" << name << "\".\n"; e << "The field index is " << field_idx << "."; } cp = ap->values[field_idx].pattern; if (*cp != 'B') { kdu_error e; e << "Attempting to set a non-boolean code-stream parameter " "attribute field with the boolean access method!\n"; e << "The attribute name is \"" << name << "\"."; } if (record_idx >= ap->num_records) ap->augment_records(record_idx+1); assert((record_idx >= 0) && (record_idx < ap->num_records)); ap->values[field_idx+ap->num_fields*record_idx].is_set = true; ap->values[field_idx+ap->num_fields*record_idx].ival = (value)?1:0; this->empty = false;}/*****************************************************************************//* kdu_params::set (float) *//*****************************************************************************/void kdu_params::set(const char *name, int record_idx, int field_idx, double value){ kd_attribute *ap; char const *cp; assert((record_idx >= 0) && (field_idx >= 0)); for (ap=attributes; ap != NULL; ap=ap->next) if (strcmp(name,ap->name) == 0) break; if (ap == NULL) { kdu_error e; e << "Attempt to set a code-stream attribute using " "the invalid name, \"" << name << "\"!"; } if ((ap->flags & ALL_COMPONENTS) && (comp_idx != -1)) { kdu_error e; e << "Attempt to set a non-tile-specific code-stream attribute " "in a specific component!\n"; e << "The attribute name is \"" << name << "\"."; } if (field_idx >= ap->num_fields) { kdu_error e; e << "Attempt to set a code-stream attribute, with an " "invalid field index!\n"; e << "The attribute name is \"" << name << "\".\n"; e << "The field index is " << field_idx << "."; } cp = ap->values[field_idx].pattern; if (*cp != 'F') { kdu_error e; e << "Attempting to set an integer code-stream parameter " "attribute field with the floating point access method!\n"; e << "The attribute name is \"" << name << "\"."; } if (record_idx >= ap->num_records) ap->augment_records(record_idx+1); assert((record_idx >= 0) && (record_idx < ap->num_records)); ap->values[field_idx+ap->num_fields*record_idx].is_set = true; ap->values[field_idx+ap->num_fields*record_idx].fval = (float) value; this->empty = false;}/*****************************************************************************//* kdu_params::set_derived *//*****************************************************************************/void kdu_params::set_derived(const char *name){ kd_attribute *ap; for (ap=attributes; ap != NULL; ap=ap->next) if (strcmp(name,ap->name) == 0) break; if (ap == NULL) { kdu_error e; e << "Invalid attribute name, \"" << name << "\", supplied to the " "`kdu_params::set_derived' function."; } ap->derived = true;}/*****************************************************************************//* kdu_params::parse_string *//*****************************************************************************/bool kdu_params::parse_string(char *string){ kd_attribute *ap; char *delim; size_t name_len; for (delim=string; *delim != '\0'; delim++) if ((*delim == ' ') || (*delim == '\t') || (*delim == '\n')) { kdu_error e; e << "Malformed attribute string, \"" << string << "\"!\n"; e << "White space characters are illegal!"; } else if ((*delim == ':') || (*delim == '=')) break; name_len = (size_t)(delim - string); for (ap=attributes; ap != NULL; ap=ap->next) if ((strncmp(ap->name,string,name_len)==0) && (strlen(ap->name)==name_len)) break; if (ap == NULL) { if (this == first_cluster) { kdu_params *scan; for (scan=this->next_cluster; scan != NULL; scan=scan->next_cluster) if (scan->parse_string(string)) return(true); } return false; } assert(ap != NULL); if (*delim == '\0') { kdu_error e; e << "Attribute \"" << ap->name << "\" is missing parameters:\n\n\t"; ap->describe(e,allow_tiles,allow_comps,true); e << "\nParameter values must be separated from the attribute name " "and optional location specifiers by an '=' sign!\n"; } int target_tile = -2; int target_comp = -2; if (*delim == ':') { delim++; while (*delim != '=') if (*delim == '\0') break; else if ((*delim == 'T') && (target_tile < 0)) target_tile = (int) strtol(delim+1,&delim,10); else if ((*delim == 'C') && (target_comp < 0)) target_comp = (int) strtol(delim+1,&delim,10); else { kdu_error e; e << "Malformed location specifier encountered in attribute " "string, \"" << string << "\"!\n"; e << "Tile specifiers following the the colon must have the " "form \"T<num>\", while component specifiers must have the " "form \"C<num>\". There may be at most one of each!"; } } if (target_tile < -1) target_tile = this->tile_idx; if (target_comp < -1) target_comp = this->comp_idx; // Locate the object to which the attribute belongs. if ((this->tile_idx != target_tile) || (this->comp_idx != target_comp)) { kdu_params *target; target = access_relation(target_tile,target_comp); if (target == NULL) { kdu_error e; e << "Attribute string, \"" << string << "\", refers to a non-" "existent tile-component!"; } return target->parse_string(string); } // Perform accessibility checks if (marked) { kdu_error e; e << "Illegal attempt to modify a `kdu_params' object " "which has already been marked!"; } if ((ap->flags & ALL_COMPONENTS) && (comp_idx != -1)) { kdu_error e; e << "Attempt to set a non-tile-specific code-stream attribute " "in a specific component!\n"; e << "Problem occurred while parsing the attribute string, \"" << string << "\"."; } if (*delim != '=') { kdu_error e; e << "Malformed attribute string, \"" << string << "\"!\n"; e << "Parameter values must be separated from the attribute name " "and optional location specifiers by an '=' sign!"; } if ((ap->num_records > 0) && ap->parsed) { // Attribute already set by parsing. if ((!allow_insts) || ((next_inst == NULL) && (new_instance() == NULL))) { kdu_error e; e << "The supplied attribute string, \"" << string << "\", refers " "to code-stream parameters which have already been parsed out " "of some string. Moreover, multiple instances of this attribute " "are not permitted here!"; } assert(next_inst != NULL); return next_inst->parse_string(string); } delete_unparsed_attribute(ap->name); ap->parsed = true; // Finally, we get around to parsing the parameter values. bool open_record; int fld, rec = 0; char *cp = delim + 1; while (*cp != '\0') { // Process a record. if (rec > 0) { if (*cp != ',') { kdu_error e; e << "Malformed attribute string, \"" << string << "\"!\n"; e << "Problem encountered at \"" << cp << "\".\n"; e << "Records must be separated by commas."; } cp++; // Skip over the inter-record comma. } if ((rec > 0) && !(ap->flags & MULTI_RECORD)) { kdu_error e; e << "Malformed attribute string, \"" << string << "\"!\n"; e << "Attribute does not support multiple parameter records!"; } open_record = false; if (*cp == '{') { cp++; open_record = true; } else if (ap->num_fields > 1) { kdu_error e; e << "Malformed attribute string, \"" << string << "\"!\n"; e << "Problem encountered at \"" << cp << "\".\n"; e << "Records must be enclosed by curly braces, i.e., '{' and '}'."; } ap->augment_records(rec+1); for (fld=0; fld < ap->num_fields; fld++) { if (fld > 0) { if (*cp != ',') { kdu_error e; e << "Malformed attribute string, \"" << string << "\"!\n"; e << "Problem encountered at \"" << cp << "\".\n"; e << "Fields must be separated by commas."; } cp++; // Skip over the inter-field comma. } att_val *att = ap->values + rec*ap->num_fields + fld; assert(!att->is_set); char const *pp = att->pattern; if (*pp == 'F') { att->fval = (float) strtod(cp,&delim); if (delim == cp) { kdu_error e; e << "Malformed attribute string, \"" << string << "\"!\n"; e << "Problem encountered at \"" << cp << "\".\n"; e << "Expected a floating point field."; } cp = delim; } else if (*pp == 'I') { att->ival = (int) strtol(cp,&delim,10); if (delim == cp) { kdu_error e; e << "Malformed attribute string, \"" << string << "\"!\n"; e << "Problem encountered at \"" << cp << "\".\n"; e << "Expected an integer field."; } cp = delim; } else if (*pp == 'B') { if (strncmp(cp,"yes",3) == 0) { att->ival = 1; cp += 3; } else if (strncmp(cp,"no",2) == 0) { att->ival = 0; cp += 2; } else { kdu_error e; e << "Malformed attribute string, \"" << string << "\"!\n"; e << "Problem encountered at \"" << cp << "\".\n"; e << "Expected a boolean field identifier, i.e., one of " "\"yes\" or \"no\"."; } } else if (*pp == '(') { char buf[80], *bp, *dp; int val; bool success = false; do { pp = parse_translator_entry(pp+1,',',buf,80,val); for (bp=buf, dp=cp; *bp != '\0'; bp++, dp++) if (*bp != *dp) break; success = (*bp == '\0') && ((*dp==',') || (*dp=='}') || (*dp=='\0')); } while ((*pp == ',') && !success); if (!success) { kdu_error e; e << "Malformed attribute string, \"" << string << "\"!\n"; e << "Problem encountered at \"" << cp << "\".\n"; display_options(att->pattern,e); } att->ival = val; cp = dp; } else if (*pp == '[') { att->ival = 0; do { char buf[80], *bp, *dp; int val; bool success = false; pp = att->pattern; if (*cp == '|') cp++; do { pp = parse_translator_entry(pp+1,'|',buf,80,val); for (bp=buf, dp=cp; *bp != '\0'; bp++, dp++) if (*bp != *dp)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -