Jump to content


Photo

Dynamic Structured List 1.2


  • Please log in to reply
3 replies to this topic

#1 famous

famous

    GMC Member

  • GMC Member
  • 169 posts
  • Version:Unknown

Posted 11 July 2012 - 04:06 PM

Download: www.mevedia.de/DSL
(includes a GM8 Example, or Code below)
After some requests for more than 1 Value for every Entry of a ds_list i wrote this solution. It's like ds_list, but with arbitary Fields and faster sort.

1.2
dl_copy_structure(list, destlist);
Copy Structure of list to destlist.
  • New Structure-Fieldīs will be added to all Entrys if List is already filled. (for dl_field_add.. Functions)
1.1
dl_insert(list, index);
Insert Entry after given index.
dl_swap(list, first, second);
Swap 2 Entrys by his Index.
dl_find_string_read_string(list, field, findstr);
Search in any Field of all Entrys findstr and read a String from given Field.
dl_find_string_read_real(list, field, findstr);
Search in any Field of all Entrys findstr and read a Real from given Field.
dl_find_real_read_string(list, field, findstr);
Search in any Field of all Entrys findreal and read a String from given Field.
dl_find_real_read_real(list, field, findstr);
Search in any Field of all Entrys findreal and read a Real from given Field.

Functions

dl_create_list();
Create a new List and returns the ID.
dl_free_list(list);
Delete the given List.


dl_field_add_string(list, name, str);
Add a Structure-Field to list with a default Value.
dl_field_add_real(list, name, real);
Add a Structure-Field to list with a default Value.
dl_field_delete(list, name);
Remove the given Structure-Field from list.

dl_add(list);
Add new Entry with pre-constructed Structure.
dl_insert(list, index);
Insert Entry after given index.
dl_swap(list, first, second);
Swap 2 Entrys by his Index.
dl_delete_byindex(list, index);
Delete Entry by his Index.
dl_clear(list);
Clear all Entrys from list.
dl_size(list);
Returns the number of Entrys in list.
dl_sort_bystring(list, field, sort);
Sort a List by given Structure-Field. (use dl_sort_asc or dl_sort_desc for sort)
dl_sort_byreal(list, field, sort);
Sort a List by given Structure-Field. (use dl_sort_asc or dl_sort_desc for sort)

dl_read_string(list, index, fieldname);
Read the Value from given Structure Field from given Entry.
dl_read_real(list, index, fieldname);
Read the Value from given Structure Field from given Entry.
dl_write_string(list, index, fieldname, str);
Write a Value in given Structure Field in given Entry.
dl_write_real(list, index, fieldname, real);
Write a Value in given Structure Field in given Entry.
dl_find_string_read_string(list, field, findstr);
Search in any Field of all Entrys findstr and read a String from given Field.
dl_find_string_read_real(list, field, findstr);
Search in any Field of all Entrys findstr and read a Real from given Field.
dl_find_real_read_string(list, field, findstr);
Search in any Field of all Entrys findreal and read a String from given Field.
dl_find_real_read_real(list, field, findstr);
Search in any Field of all Entrys findreal and read a Real from given Field.

Example
// DynamicStructuredList 1.0 by Alex W.
// www.mevedia.de

list = dl_create_list();

// Build Structure
// We can define a default Value.
dl_field_add_string(list, "Name", "");
dl_field_add_real(list, "Age", 0);

// Use List / add Entrys
// Structure will be now used for every List-Entry.
index = dl_add(list); // Returns Index 0
      dl_write_string(list, index, "Name", "Xa");
      dl_write_real(list, index, "Age", 16);
index = dl_add(list); // Returns Index 1
      dl_write_string(list, index, "Name", "Aim");
      dl_write_real(list, index, "Age", 16);
index = dl_add(list); // Returns Index 2
      dl_write_string(list, index, "Name", "Tim");
      dl_write_real(list, index, "Age", 16);

index = dl_add(list); // Returns Index 3
      dl_write_string(list, index, "Name", "Sven");
      dl_write_real(list, index, "Age", 28);
      
index = dl_add(list); // Returns Index 4
      dl_write_string(list, index, "Name", "Lisa");
      dl_write_real(list, index, "Age", 23);
      dl_delete_byindex(list, 3);
// Sort List
// Use dl_sort_asc or dl_sort_desc.
dl_sort_bystring(list, "Name", dl_sort_asc);


// Read List
// dl_size() returns all Entrys, but Index starts from zero.
c=0;
repeat(dl_size(list))
{
show_message(dl_read_string(list, c, "Name")+" is "+string(dl_read_real(list, c, "Age"))+" years old!");
c+=1;
}

Edited by famous, 12 July 2012 - 12:47 PM.

  • 0

#2 famous

famous

    GMC Member

  • GMC Member
  • 169 posts
  • Version:Unknown

Posted 11 July 2012 - 05:37 PM

Some new Functions in 1.1. Please test and tell me bugs (if).
  • 0

#3 famous

famous

    GMC Member

  • GMC Member
  • 169 posts
  • Version:Unknown

Posted 11 July 2012 - 07:36 PM

And again a small Update.
  • Small fix
  • dl_copy_structure()
  • dl_field_add.. Functions will be added now to already existing Entrys

  • 0

#4 famous

famous

    GMC Member

  • GMC Member
  • 169 posts
  • Version:Unknown

Posted 11 July 2012 - 09:31 PM

Sub-level List in a Structure-Field

A Structure-Field can hold another DSL, so you can use many Sub-Level DSL as you need.

list = dl_create_list();
dl_field_add_real(list, "Inventar", 0);

Here is our Field to handle a sub-level DSL. Best way to add Entrys is to put the creation Code of a Entry into a extra Script.

index = dl_add(argument0);
 dl_write_real(argument0, index, "Inventar", dl_create_list());

So every Entry will have a Field with a linked sub-level DSL.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users