Sign in to follow this  

converting an xml c++ parser to be c

This topic is 3838 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Help Wanted forum or rentacoder.com or some similar site would be where to look for help.

People here will only help you if you do it yourself, but run into problems.

But posting several kLOC of code and asking for someone to convert it is somewhat unrealistic.

Especially since fully standard-compliant validating XML parsers written in C are abundant on google.

The code is pretty well written, it doesn't contain too many high-level concepts, so as soon as you remove classes, you should have a pretty decent solution.

General advice:

// C++
class X {
void foo( int x, int y );
int m_local;
}

// in C
typedef struct XClass {
int m_local;
} X;

int X_foo( X *x, int x, int y);




This should take care of classes.

Share this post


Link to post
Share on other sites
yeah i mean the only real class it has is


class DLLENTRY ToXMLStringTool
{
public:
ToXMLStringTool(): buf(NULL),buflen(0){}
~ToXMLStringTool();
void freeBuffer();

XMLSTR toXML(XMLCSTR source);

private:
XMLSTR buf;
int buflen;
};




so how would you convert that with the constructor/destuctor

Share this post


Link to post
Share on other sites
Quote:
Original post by Prog101
yeah i mean the onnly real class it has is

*** Source Snippet Removed ***

so how would you convert that with the constructor/destuctor


In what way are constructor and destructor different from regular methods?

Don't mind the syntax, look at the function they perform.

Constructor:
- Allocates the structure that holds class data
- Initializes some of the local variables
- Optionally performs some other, user define processing in body, same as any other method

Share this post


Link to post
Share on other sites
i have looked all over for a good c xml parser to use with a license that does not resrict me using it for a published game, if you know of any c xml parser would you post the .h and .c files on here?

Share this post


Link to post
Share on other sites
Quote:
Original post by Prog101
i have looked all over for a good c xml parser to use with a license that does not resrict me using it for a published game, if you know of any c xml parser would you post the .h and .c files on here?


http://www.saunalahti.fi/~samiuus/toni/xmlproc/

Just the first suitable link from google. Should be more.

Share this post


Link to post
Share on other sites
Quote:
Original post by Prog101
yeah i mean the only real class it has is


so how would you convert that with the constructor/destuctor


Simply move the functions to their own file for simplicity reasons, and have


struct myStruct
{
XMLSTR buf;
int buflen;
}MYSTRUCT;





The first parameter of the class should be of void foo(struct myStruct *bar,...

The constructor and destructor act just like normal functions, but you'll have to remember to call them appropriately. There are ways around this of course, and it is possible to make C more object oriented, but that's a little more complicated.

Share this post


Link to post
Share on other sites

This topic is 3838 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this