C++ Interface

Posts   
 
    
tmatelich
User
Posts: 95
Joined: 14-Oct-2009
# Posted on: 05-Nov-2009 21:15:28   

95% of my interaction with my database is in C# or C++/cli, but there are a few cases where having a native class to manipulate would be really nice. Of course, I could make it by hand, but that doesn't necessarily keep it up to date. What I'm envisioning is something like


//classname.h
namespace Foo
{
 class ClassNameNative
 {
    int id;
    std::string textfield;
    double value;
 }
}

//classname_marshall.cpp
namespace Foo
{
 //insert various marshalling functions here

 void Marshal(ClassNameNative const& native, ClassNameEntity^ cli)
 {
    Marshall(cli->id, native.id);
    Marshall(cli->textfield, native.textfield);
    Marshall(cli->value, native.value);
 }
}

I've only looked briefly, but I think the main thing I'd be missing here is typenames to use for native. I couldn't connect to the svn repository for some reason, has anyone done any work on this area?

Thanks, Tom

Walaa avatar
Walaa
Support Team
Posts: 14987
Joined: 21-Aug-2005
# Posted on: 06-Nov-2009 09:20:03   

Would you please elaborate in more details, why you want these classes?

And do you want them to map the generated entityClasses? (only to hold data I suppose)

tmatelich
User
Posts: 95
Joined: 14-Oct-2009
# Posted on: 06-Nov-2009 19:11:05   

I generate database entries from native code, then I have one spot where I marshal them field by field in C++/cli and add them to the database. I strongly dislike maintaining duplicate versions of my classes.

My predecessor actually used map<string,string> which he converted to xml and then deserialized. This is slow and error prone.

Since LLBLGen already knows about the entity structure I want, I was hoping I could get it to do even more work for me.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 09-Nov-2009 06:06:35   

If you can write the class by yourself and all the dynamic stuff could be provided by LLBLGen metadata, it's likely you can write a template for it. You should start with an example of the final code you would like and from there start your template. For more information see the SDK documentation.

David Elizondo | LLBLGen Support Team
tmatelich
User
Posts: 95
Joined: 14-Oct-2009
# Posted on: 09-Nov-2009 19:34:03   

Thanks for the feedback. I ended up just making some convenience functions for the native/managed transition. A 1-1 mapping would be nice, but there's too many gotchas to bother with at this point.