Benryves' Chagrin

Published May 18, 2008
Advertisement
Much to benryves' chagrin, I've yet to give up on attempting to make Text my own little collection instead of using LinkedList<> or StringCollection. This iteration of 'design' is somewhat better than the last IMHO.

public class Text:System.Collections.IList where T:Text.TextNode{  public class TextNode:ICloneable  {    public string text;    internal TextNode prev;    internal TextNode next;    public void PushPrevious(TextNode insertee){...}    public void PushNext(TextNode insertee){...}    public TextNode PopPrevious(){...}    public TextNode PopNext(){...}    public TextNode Pop(){...}  }  private T rootTextNode;  private T currentTextNode;  // Rest of Text code}


For review of what my previous one looked like:
public class TextLine{  public String data;  public T extradata;  public TextLine nextNode;  public TextLine prevNode;  public TextLine(){...}  public TextLine(String text){...}  public TextLine(T data){...}  public TextLine(String text,T data){...}  public TextLine(TextLine previous,TextLine next){...}  public TextLine(String text,TextLine previous,TextLine next){...}  public TextLine(T data,TextLine previous,TextLine next){...}  public TextLine(String text,T data,TextLine previous,TextLine next){...}  protected void QuickSetup(String text,T data,TextLine previous,TextLine next){...}}


No freakin' idea what I was thinking. Apparently to insert or remove a node, you had to make a new one at the specified spot. Like singletonesque nodes or something... [headshake] Washu is going to kill me.

Anyway, now I should just have to implement System.Collections.IList in it and it *should* be good to go. The only problem I've met so far is the some of the methods receive arguements of the type object. I scanned through the available exceptions for something akin to TypeNotSupportedException, but didn't find any. I went ahead and made up my own, but if there is a standard procedure for handling something like this, I'd be grateful if someone could leave it in a comment or message me. Thanks.

Edit: Or, in freaking retrospect, I could just implement IList and IList instead. :/
Previous Entry Introductions
Next Entry WOW! AN UPDATE!
0 likes 1 comments

Comments

benryves
My suggestion was not so much to replace your custom collection with one of the ones from Systems.Collections.Generic, but that it might be easier if you hid one of these existing collections inside your own and used it to store the data for you, as it would already implement numerous useful interfaces for you. Something like this:

public class MyCustomCollection<T> : ICollection<T> {

    private LinkedList<T> Storage;

    public void Add(T item) {
        this.Storage.Add(item);
        // ... custom linking magic ...
    }

    public bool Remove(T item) {
        bool Removed = this.Storage.Remove(item);
        if (Removed) {
            // ... custom unlinking magic ...
        }
        return Removed;
    }

    public IEnumerator<T> GetEnumerator() { return this.Storage.GetEnumerator(); }

    // ... and so on and so forth ...

}

Hm, on second thoughts, I've been writing software in C# to work against PHP software, so reimplemented PHP's arrays in C# using the above method. PHP's arrays work as associative (ordered) arrays, dictionaries, stacks and who knows what else, resulting in some rather creative (ie, ugly) code to hack it on top of .NET's existing collections. [grin]
May 18, 2008 07:41 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement