///////////////////////////////////// // Functions ///////////////////////////////////// int array_create(object store, string name); int array_delete(object store, string name); int array_set_string(object store, string name, int i, string entry); int array_set_int(object store, string name, int i, int entry); int array_set_float(object store, string name, int i, float entry); int array_set_object(object store, string name, int i, object entry); // returns "" or 0 on error string array_get_string(object store, string name, int i); int array_get_int(object store, string name, int i); float array_get_float(object store, string name, int i); object array_get_object(object store, string name, int i); // changes memory usage of array (deletes x[ > size_new]) int array_shrink(object store, string name, int size_new); // gets current maximum size of array int array_get_size(object store, string name); int array_exists(object store, string name); ///////////////////////////////////// // Notes: // // * Arrays are dynamic and may be increased in size by just _set_'ing a new // element // * There are no restrictions on what is in the array (can have multiple // types in the same array // * Arrays start at index 0 ///////////////////////////////////// ///////////////////////////////////// // Error Returns ///////////////////////////////////// int SDL_SUCCESS = 1; int SDL_ERROR_ALREADY_EXISTS = 1001; int SDL_ERROR_DOES_NOT_EXIST = 1002; int SDL_ERROR_OUT_OF_BOUNDS = 1003; int SDL_ERROR_NO_ZERO_SIZE = 1004; int SDL_ERROR_NOT_VALID_OBJECT = 1005; ///////////////////////////////////// // Implementation ///////////////////////////////////// int array_create(object store, string name) { // error checking if (GetLocalInt(store,name)) return SDL_ERROR_ALREADY_EXISTS; else { // Initialize the size (always one greater than the actual size) SetLocalInt(store,name,1); return SDL_SUCCESS; } } int array_delete(object store, string name) { // error checking int size=GetLocalInt(store,name); if (size==0) return SDL_ERROR_DOES_NOT_EXIST; int i; for (i=0; isize) SetLocalInt(store,name,i+2); return SDL_SUCCESS; } int array_set_int(object store, string name, int i, int entry) { return array_set_string(store,name,i,IntToString(entry)); } int array_set_float(object store, string name, int i, float entry) { return array_set_string(store,name,i,FloatToString(entry)); } int array_set_object(object store, string name, int i, object entry) { // object is a little more complicated. // we want to create an object as a local variable too if (!GetIsObjectValid(entry)) return SDL_ERROR_NOT_VALID_OBJECT; int results=array_set_string(store,name,i,"OBJECT"); if (results==SDL_SUCCESS) SetLocalObject(store,name+"_"+IntToString(i)+"_OBJECT",entry); return results; } string array_get_string(object store, string name, int i) { // error checking int size=GetLocalInt(store,name); if (size==0 || i>size) return ""; return GetLocalString(store,name+"_"+IntToString(i)); } int array_get_int(object store, string name, int i) { return StringToInt(array_get_string(store,name,i)); } float array_get_float(object store, string name, int i) { return StringToFloat(array_get_string(store,name,i)); } object array_get_object(object store, string name, int i) { return GetLocalObject(store,name+"_"+IntToString(i)+"_OBJECT"); } int array_shrink(object store, string name, int size_new) { // error checking int size=GetLocalInt(store,name); if (size==0) return SDL_ERROR_DOES_NOT_EXIST; if (size==size_new || size