TheSwamp

Code Red => .NET => Topic started by: It's Alive! on April 19, 2007, 07:33:53 AM

Title: A New ResultBuffer Class
Post by: It's Alive! on April 19, 2007, 07:33:53 AM
Opinion needed
I want to write a resbuf wrapper class for my little Intellicad project.
If you were writing one using  .Net 2.0 generics would you use a similar TypedValue structure
or use one of the built-in generic dictionaries I.e

Code: [Select]
static Dictionary<int, Object^> ^ToDictionary(resbuf * inl_List)
{
    Dictionary<int, Object^> ^mDict = gcnew Dictionary<int, Object^>();
    //
    for (resbuf * lList=inl_List; lList; lList=lList->rbnext)
    {
        switch ( lList->restype )
        {
        case RTSTR:
            mDict->Add(lList->restype , safe_cast<Object^>(gcnew String(lList->resval.rstring)));
            break;

        case RTSHORT :
            mDict->Add(lList->restype , safe_cast<Object^>(lList->resval.rint));
            break;

        case RTLONG :
            mDict->Add(lList->restype , safe_cast<Object^>(lList->resval.rlong));
            break;

        case RTREAL :
            mDict->Add(lList->restype , safe_cast<Object^>(lList->resval.rreal));
            break;
            //todo add the rest of the types
        }
    }
    return mDict;
}
//
static List<KeyValuePair<int, Object^>> ^ToList(resbuf * inl_List)
{
    List<KeyValuePair<int, Object^>> ^mList = //
        gcnew List<KeyValuePair<int, Object^>>(ToDictionary(inl_List));
    return mList;
}

Thanks
Title: Re: A New ResultBuffer Class
Post by: TonyT on April 19, 2007, 08:37:45 AM
A dictionary stores a list of key/value pairs with the
constraint that there can be no duplicate keys, which
I think rules it out for the intended purpose.

I would just yank the source for TypedValue from the
Autodesk libraries with reflector and use it with a List<>


     
Opinion needed
I want to write a resbuf wrapper class for my little Intellicad project.
If you were writing one using  .Net 2.0 generics would you use a similar TypedValue structure
or use one of the built-in generic dictionaries I.e

Code: [Select]
static Dictionary<int, Object^> ^ToDictionary(resbuf * inl_List)
{
    Dictionary<int, Object^> ^mDict = gcnew Dictionary<int, Object^>();
    //
    for (resbuf * lList=inl_List; lList; lList=lList->rbnext)
    {
        switch ( lList->restype )
        {
        case RTSTR:
            mDict->Add(lList->restype , safe_cast<Object^>(gcnew String(lList->resval.rstring)));
            break;

        case RTSHORT :
            mDict->Add(lList->restype , safe_cast<Object^>(lList->resval.rint));
            break;

        case RTLONG :
            mDict->Add(lList->restype , safe_cast<Object^>(lList->resval.rlong));
            break;

        case RTREAL :
            mDict->Add(lList->restype , safe_cast<Object^>(lList->resval.rreal));
            break;
            //todo add the rest of the types
        }
    }
    return mDict;
}
//
static List<KeyValuePair<int, Object^>> ^ToList(resbuf * inl_List)
{
    List<KeyValuePair<int, Object^>> ^mList = //
        gcnew List<KeyValuePair<int, Object^>>(ToDictionary(inl_List));
    return mList;
}

Thanks

Title: Re: A New ResultBuffer Class
Post by: It's Alive! on April 19, 2007, 02:59:43 PM
A dictionary stores a list of key/value pairs with the
constraint that there can be no duplicate keys, which
I think rules it out for the intended purpose.

I would just yank the source for TypedValue from the
Autodesk libraries with reflector and use it with a List<>

Thanks Tony,
I was headed down the wrong path using the Dictionary<>.  :oops:
I was considering using the built-n KeyValuePair<> but opted to make a TypedValue class as you suggested.
Well now the easy part works getting an unmanaged resbuf in a list now I just have to figure out how to do the reverse. 8-)
Dan
Title: Re: A New ResultBuffer Class
Post by: TonyT on April 19, 2007, 10:20:14 PM
Marshalling beween resbuf and TypedValue is not exactly
trivial, because some unmanged types have very different
managed representations (namely, unmanaged selection sets
and the managed counterpart are vastly different).

To see how involved it is, have a look at these
methods of the ResultBuffer in reflector:

TypedValueToResbuf()
ResbufToTypedValue()


A dictionary stores a list of key/value pairs with the
constraint that there can be no duplicate keys, which
I think rules it out for the intended purpose.

I would just yank the source for TypedValue from the
Autodesk libraries with reflector and use it with a List<>

Thanks Tony,
I was headed down the wrong path using the Dictionary<>.  :oops:
I was considering using the built-n KeyValuePair<> but opted to make a TypedValue class as you suggested.
Well now the easy part works getting an unmanaged resbuf in a list now I just have to figure out how to do the reverse. 8-)
Dan

Title: Re: A New ResultBuffer Class
Post by: It's Alive! on April 20, 2007, 12:00:46 AM
Not only that, but I will also have to build each of the Types as well, Point2d, Point3d …
Might be biting off more than I can chew. But I am learning tons
Title: Re: A New ResultBuffer Class
Post by: TonyT on April 20, 2007, 10:12:29 AM
IOW, you're writing your own .NET API for IntelliCAD ? :o

Not only that, but I will also have to build each of the Types as well, Point2d, Point3d …
Might be biting off more than I can chew. But I am learning tons

Title: Re: A New ResultBuffer Class
Post by: It's Alive! on April 24, 2007, 05:43:49 AM
Marshalling beween resbuf and TypedValue is not exactly
trivial, because some unmanged types have very different
managed representations (namely, unmanaged selection sets
and the managed counterpart are vastly different).

To see how involved it is, have a look at these
methods of the ResultBuffer in reflector:

TypedValueToResbuf()
ResbufToTypedValue()

Well it does not increment the selection set like AutoCad does

http://www.theswamp.org/index.php?topic=12218.msg151554#msg151554

Title: Re: A New ResultBuffer Class
Post by: TonyT on April 25, 2007, 06:04:57 AM
Sorry, I don't follow.

What doesn't increment the selection set like AutoCAD does?

Marshalling beween resbuf and TypedValue is not exactly
trivial, because some unmanged types have very different
managed representations (namely, unmanaged selection sets
and the managed counterpart are vastly different).

To see how involved it is, have a look at these
methods of the ResultBuffer in reflector:

TypedValueToResbuf()
ResbufToTypedValue()

Well it does not increment the selection set like AutoCad does

http://www.theswamp.org/index.php?topic=12218.msg151554#msg151554


Title: Re: A New ResultBuffer Class
Post by: It's Alive! on April 25, 2007, 06:25:13 AM
Did you click the link?

Edit Sorry,

Intellicad ,when I pass a selection set through the Resultbuffer.
Autocad would not return the same selection set name. It looks like it’s handled differently internally though.
Acad <Selection set: 2>    ,  Icad  <Selection set: 115643127>
Title: Re: A New ResultBuffer Class
Post by: It's Alive! on April 25, 2007, 06:29:55 AM
Anyway , here is what I have so far if anyone is interested
Title: Re: A New ResultBuffer Class
Post by: TonyT on April 26, 2007, 07:33:08 PM
Hi Dan.

When using a generic list type, rather than having separate
overloaded constructors for arrays and List<T>, you can
write just one:

Code: [Select]

    public class MyList<T> : List<T>
    {
          // accept any object that can enumerate T, such as
          // T[]; List<T>; ICollection<T>; IEnumerable<T>, etc.

          public MyList(IEnumerable<T> items)
          {
               AddRange(items);
          }

          //.......
    }


Anyway , here is what I have so far if anyone is interested
Title: Re: A New ResultBuffer Class
Post by: It's Alive! on April 27, 2007, 01:59:44 PM
Way cool. Thanks Tony!
I sure am glad you hang out here at TheSwamp.
It’s so great to be able to learn from someone with your talents.
Thanks