Author: sapient
Date: Thu Aug 23 06:34:59 2007
New Revision: 19738
URL: http://svn.gna.org/viewcvs/wesnoth?rev=19738&view=rev
Log:
added some comments to variable_info constructor, and re-arranged one clause
slightly
Modified:
trunk/src/variable.cpp
Modified: trunk/src/variable.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/variable.cpp?rev=19738&r1=19737&r2=19738&view=diff
==============================================================================
--- trunk/src/variable.cpp (original)
+++ trunk/src/variable.cpp Thu Aug 23 06:34:59 2007
@@ -219,7 +219,7 @@
key = varname;
std::string::const_iterator itor = std::find(key.begin(),key.end(),'.');
int dot_index = key.find('.');
- // "mover.modifications.trait[0]"
+ // example varname = "unit_store.modifications.trait[0]"
while(itor != key.end()) { // subvar access
std::string element=key.substr(0,dot_index);
key = key.substr(dot_index+1);
@@ -232,7 +232,7 @@
const std::string index_str(index_start+1,index_end);
inner_index =
static_cast<size_t>(lexical_cast_default<int>(index_str));
if(inner_index > MaxLoop) {
- LOG_NG << "variable_info: index greater than "
<< MaxLoop
+ ERR_NG << "variable_info: index greater than "
<< MaxLoop
<< ", truncated\n";
inner_index = MaxLoop;
}
@@ -241,23 +241,20 @@
size_t size = vars->get_children(element).size();
if(size <= inner_index) {
- if(!force_valid) {
- if(inner_explicit_index) {
- WRN_NG << "variable_info: invalid WML
array index, "
- << varname << std::endl;
- return;
- }
- if(key != "length") {
- WRN_NG << "variable_info: retrieving
member of non-existant WML container, "
- << varname << std::endl;
- return;
- }
- } else {
+ if(force_valid) {
// Add elements to the array until the
requested size is attained
for(; size <= inner_index; ++size) {
vars->add_child(element);
}
- }
+ } else if(inner_explicit_index) {
+ WRN_NG << "variable_info: invalid WML array
index, "
+ << varname << std::endl;
+ return;
+ } else if(key != "length") {
+ WRN_NG << "variable_info: retrieving member of
non-existant WML container, "
+ << varname << std::endl;
+ return;
+ } //else return length 0 for non-existant WML array
(handled below)
}
if(!inner_explicit_index && key == "length") {
switch(vartype) {
@@ -267,6 +264,7 @@
<< varname << std::endl;
is_valid = force_valid ||
repos->temporaries.child(varname) != NULL;
break;
+ case variable_info::TYPE_SCALAR:
default:
// Store the length of the array as a temporary
variable
repos->temporaries[varname] =
lexical_cast<std::string>(size);
@@ -282,7 +280,8 @@
vars = vars->get_children(element)[inner_index];
itor = std::find(key.begin(),key.end(),'.');
dot_index = key.find('.');
- }
+ } // end subvar access
+
const std::string::iterator index_start =
std::find(key.begin(),key.end(),'[');
explicit_index = index_start != key.end();
if(explicit_index) {
@@ -290,7 +289,7 @@
const std::string index_str(index_start+1,index_end);
index =
static_cast<size_t>(lexical_cast_default<int>(index_str));
if(index > MaxLoop) {
- LOG_NG << "variable_info: index greater than " <<
MaxLoop
+ ERR_NG << "variable_info: index greater than " <<
MaxLoop
<< ", truncated\n";
index = MaxLoop;
}
@@ -327,6 +326,7 @@
explicit_index = false;
index = 0;
} else {
+ // Final variable is not an explicit index [...]
switch(vartype) {
case variable_info::TYPE_ARRAY:
case variable_info::TYPE_CONTAINER:
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits