Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
- /*
- The following code is still beta, use it at your own risk.
- This file contains a series of defines and functions that will
- allow you to use linkSetData memory for lists. These lists will
- not have all the versatility of normal LSL lists.
- The format in LinksetData memory are as follows.
- The first entry in a list is the master header file. It is
- defined as the following.
- linkset listName is the list listName and the data is the number of
- entries the list.
- <listName> -> <list entries number>
- the format of each list entry is as follows
- <listName>|<entrynumber>:<data>
- */
- // next version will use the firestorm preprocessor
- //#define GetlinkListLength getlinkListLength
- // The first step is the define the linkSetList entry
- integer linkSetDefine(string listName)
- {
- // test to see if entry already exists, if so return error
- // of -1
- if(llLinksetDataRead(listName) != "")
- return -1;
- else
- llLinksetDataWrite(listName, "0");
- return 1; // linkSetList Created.
- }
- // add a entry to the linkset entry and increment the
- // the count by one when adding. create the linkSet
- // if it does not exist. any data other than a string
- // must be typecast to a string.
- integer addLinkData(string listName, string data)
- {
- integer tcList;
- // if listName exists, add link
- // and increment count.
- if(linkSetDefine(listName) == 1)
- tcList = incrmLinkCount(listName, 0);
- else
- tcList = incrmLinkCount(listName, 1);
- llLinksetDataWrite(listName +"|"+ (string) tcList +":"+data, "0");
- return tcList;
- }
- // get count total from base and increase it by 'count'
- integer incrmLinkCount(string listName, integer count)
- {
- integer currentNum = (integer) llLinksetDataRead(listName);
- currentNum += count;
- llLinksetDataWrite(listName, (string) currentNum);
- return currentNum;
- }
- // Return the number of entries in a linkSetList
- integer getlinkListLength(string listName)
- {
- // return error if linkSetList does not exits of -1
- integer listLength = (integer) llLinksetDataRead(listName);
- if(listLength == 0)
- return -1;
- else
- return (listLength + 1);
- }
- /*
- The following fuctions return entries in a linkList.
- None of them currently support negative indexes.
- */
- // returns a string that is at index in src
- string linkList2String(string src, integer index)
- {
- string found;
- string searchFor = src+"\\|"+(string) index +":";
- found = (string) llLinksetDataFindKeys("^" + searchFor, 0, 1);
- return llGetSubString(found, (llSubStringIndex(found, ":") + 1), -1);
- }
- // returns a integer that is at index in src
- integer linkList2Integer(string src, integer index)
- {
- string found;
- string searchFor = src+"\\|"+(string) index +":";
- found = (string) llLinksetDataFindKeys("^" + searchFor, 0, 1);
- return (integer) llGetSubString(found, (llSubStringIndex(found, ":") + 1), -1);
- }
- // returns a float that is at index in src
- float linkList2Float(string src, integer index)
- {
- string found;
- string searchFor = src+"\\|"+(string) index +":";
- found = (string) llLinksetDataFindKeys("^" + searchFor, 0, 1);
- return (float) llGetSubString(found, (llSubStringIndex(found, ":") + 1), -1);
- }
- // returns a key that is at index in src
- key linkList2Key(string src, integer index)
- {
- string found;
- string searchFor = src+"\\|"+(string) index +":";
- found = (string) llLinksetDataFindKeys("^" + searchFor, 0, 1);
- return (key) llGetSubString(found, (llSubStringIndex(found, ":") + 1), -1);
- }
- // returns a rotation that is at index in src
- rotation linkList2Rot(string src, integer index)
- {
- string found;
- string searchFor = src+"\\|"+(string) index +":";
- found = (string) llLinksetDataFindKeys("^" + searchFor, 0, 1);
- return (rotation) llGetSubString(found, (llSubStringIndex(found, ":") + 1), -1);
- }
- // returns a vector that is at index in src
- vector linkList2Vector(string src, integer index)
- {
- string found;
- string searchFor = src+"\\|"+(string) index +":";
- found = (string) llLinksetDataFindKeys("^" + searchFor, 0, 1);
- return (vector) llGetSubString(found, (llSubStringIndex(found, ":") + 1), -1);
- }
- // Returns a list that is a subset of a linkList.
- // be aware of memory limtations since linkLists can
- // be significnally larger than script memory.
- //
- // if the end parameter is a -1 the function will return
- // everything from start to the end of the linkList.
- // linkList2List(listName, 0, -1) will return the entire linkList
- // as a list.
- list linkList2List(string listName, integer start, integer end)
- {
- // check see if linkList exists, return emply list if does not.
- if(llLinksetDataRead(listName) == "")
- return [""];
- // linkList exist, but start is out of bounds,
- // return a empty list.
- integer listLength = getlinkListLength(listName);
- if(start > listLength)
- return [""];
- // if end of linkList is longer than linkList, set end to
- // listLength
- if(end > listLength || end == -1)
- end = listLength;
- integer i;
- list tl;
- for(i = start; i < (end + 1); i++)
- {
- // DS("i : " + (string)i);
- tl += linkList2String(listName, i);
- }
- return tl;
- }
- // Returns a string with the linklist converted to string
- // with seperator between entries.
- string linkListDump2String(string listName, string seperator)
- {
- integer i;
- integer endofList = getlinkListLength(listName);
- string rc;
- for (i = 0; i < endofList; i++)
- rc += linkList2String(listName, i) + seperator;
- return rc;
- }
- // returns a string with the linkList converted to string
- // with commas(,) between entries
- string linkList2CSV(string linkName)
- {
- return linkListDump2String(linkName, ",");
- }
- // removes entries from start to end of linkName. returning the new size of
- // linkName;
- // if a -1 is used for the end parameter then the linkList will be deleted
- // from start to end of the linkLIst
- integer linkListDeleteSubList(string linkName, integer start, integer end)
- {
- integer i;
- list tl;
- integer tmpEnd = (integer) llLinksetDataRead(linkName);
- string tmpData;
- if(end == -1)
- end = tmpEnd;
- // remove entries from linkName, start to end
- for(i = start; i < (end + 1); ++i)
- tl = llLinksetDataDeleteFound("^" + linkName+"\\|"+(string) i +":", "");
- llLinksetDataWrite(linkName, (string) (start-1));
- for(i = (end+1); i < (tmpEnd+1); i++)
- {
- tmpData = linkList2String(linkName, i);
- addLinkData(linkName, tmpData);
- tl = llLinksetDataDeleteFound("^" + linkName+"\\|"+(string) i +":", "");
- }
- return (integer) llLinksetDataRead(linkName);
- }
- // The following takes list (src) and puts it in linkList (dest) starting at
- // position start. If start is a -1, then the list is appended to the end
- // of the linkLinks. The function returns the new length of the linkList.
- integer listInsertLinkList (string linkName, list src, integer start)
- {
- integer i;
- string tmplink = (string) llGenerateKey();
- // if start is longer than linkName, then just append
- // the output to linkName.
- if(start == -1 || start > getlinkListLength(linkName))
- {
- for(i = 0; i < llGetListLength(src); i++)
- addLinkData(linkName, llList2String(src, i));
- }
- else // insert src into linkList at position indicated by start
- {
- // move linkName from 0 to start to tmplink
- for(i = 0; i < start; ++i)
- addLinkData(tmplink, linkList2String(linkName, i));
- // add list src to the end of tmplink
- for(i = 0; i < llGetListLength(src); i++)
- addLinkData(tmplink, llList2String(src, i));
- for(i = start; i < getlinkListLength(linkName); i++)
- addLinkData(tmplink, linkList2String(linkName, i));
- // delete old linkList, then move data from tmplink to
- // listLink.
- linkListRemove(linkName);
- for (i = 0; i< getlinkListLength(tmplink); i++)
- addLinkData(linkName, linkList2String(tmplink, i));
- linkListRemove(tmplink);
- }
- return getlinkListLength(linkName);
- }
- // function to remove a linkList
- // returns -1 if not successful
- // returns 1 if successful
- integer linkListRemove(string linkName)
- {
- llLinksetDataDeleteFound("^" + linkName+"\\|", "");
- llLinksetDataDeleteFound("^" + linkName, "");
- return 1;
- }
- // returns the index of the first instance of needle
- // in linkList of linkName
- integer linkListFind(string linkName, string needle)
- {
- string findTmp = (string) llLinksetDataFindKeys("^" + linkName + "\\|" + ".*:.*" + needle +".*", 0, 1);
- list tmpList = llParseString2List(findTmp, [":", "|"], []);
- if(llGetListLength(tmpList) < 1)
- return -1;
- else
- return llList2Integer(tmpList, 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement