00001 #include "xi-Value.h" 00002 00003 namespace xi { 00004 00005 Value::Value(const char* s) { 00006 factor = 1; 00007 val = s; 00008 if (val == 0 || strlen(val) == 0) return; 00009 char* v = new char[strlen(val) + 5]; 00010 strcpy(v, val); 00011 int pos = strlen(v) - 1; 00012 if (v[pos] == 'K' || v[pos] == 'k') { 00013 v[pos] = '\0'; 00014 factor = 1024; 00015 } 00016 if (v[pos] == 'M' || v[pos] == 'm') { 00017 v[pos] = '\0'; 00018 factor = 1024 * 1024; 00019 } 00020 val = v; 00021 } 00022 00023 int Value::getIntVal(void) { 00024 if (val == 0 || strlen(val) == 0) return 0; 00025 return (atoi((const char*)val) * factor); 00026 } 00027 00028 void Value::print(XStr& str) { str << val; } 00029 00030 ValueList::ValueList(Value* v, ValueList* n) : val(v), next(n) {} 00031 00032 void ValueList::print(XStr& str) { 00033 if (val) { 00034 str << "["; 00035 val->print(str); 00036 str << "]"; 00037 } 00038 if (next) next->print(str); 00039 } 00040 00041 void ValueList::printValue(XStr& str) { 00042 if (val) { 00043 val->print(str); 00044 } 00045 if (next) { 00046 die("Unsupported type"); 00047 } 00048 } 00049 00050 void ValueList::printValueProduct(XStr& str) { 00051 if (!val) die("Must have a value for an array dimension"); 00052 00053 str << "("; 00054 val->print(str); 00055 str << ")"; 00056 if (next) { 00057 str << " * "; 00058 next->printValueProduct(str); 00059 } 00060 } 00061 00062 void ValueList::printZeros(XStr& str) { 00063 str << "[0]"; 00064 if (next) next->printZeros(str); 00065 } 00066 00067 } // namespace xi