CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Pseudo Classes - Include two more copies of the same code.

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
mbradley



Joined: 11 Jul 2009
Posts: 118
Location: California, USA

View user's profile Send private message Visit poster's website

Pseudo Classes - Include two more copies of the same code.
PostPosted: Mon Nov 14, 2011 10:47 pm     Reply with quote

I have rewritten my Class code to allow a type of code reuse in the CCS compiler.

Please let me know if you find this usefull or have any comments.

I maintain the source here:
http://www.mculabs.com/snippets/pclass.html

Imagine you have a nice piece of code, and you need more than one instance of it in your source, what do you do? In CCS you would (unless I hear another way) copy the file over, give it a new name, and rename all the functions and variables.

I had a new circular buffer piece of code that I wrote, and I needed two instances of it. So I just use this:
Code:

#include "pclass.h"

         ClassDef gpsBuffer
            ClassInclude "cls_circbuffer.c"
            ClassEnd

         ClassDef compassBuffer
            ClassInclude "cls_circbuffer.c"
            ClassEnd


And to use the two instances, I can do this:
Code:

         g = gpsBuffer_getChr();
         c = compassBuffer_getChr();

_________________
Michael Bradley
www.mculabs.com
Open Drivers and Projects
MikeW



Joined: 15 Sep 2003
Posts: 184
Location: Warrington UK

View user's profile Send private message

thank you
PostPosted: Tue Nov 15, 2011 5:32 am     Reply with quote

Michael,

thank you, keep em coming !!!
n-squared



Joined: 03 Oct 2006
Posts: 99

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Sun Nov 20, 2011 4:06 pm     Reply with quote

Hi
Great stuff!
Looks like I am going to use this method in many of my projects.

Thanks.

BR
Noam
_________________
Every solution has a problem.
mbradley



Joined: 11 Jul 2009
Posts: 118
Location: California, USA

View user's profile Send private message Visit poster's website

PostPosted: Sun Nov 20, 2011 4:15 pm     Reply with quote

Thank you,

Although it makes for a bit of funky looking source, if you got a solid routine or set of functions, this works great for creating two copies of it.

I use it most for circular buffers, and for FIFO buffers. I have also used my old one for serial routines that I can use with chips with more than one uart.
_________________
Michael Bradley
www.mculabs.com
Open Drivers and Projects
Eduardo__



Joined: 23 Nov 2011
Posts: 197
Location: Brazil

View user's profile Send private message

Cool
PostPosted: Thu Nov 24, 2011 6:54 am     Reply with quote

Cool!

I´m going to try it later.
I´ve not found information in CCS Help about these preprocessors. I mean ## preprocessors use in:

#define __mDEFCLASS(cls,def) ##cls##_##def

Another question, CCS compiler isolates the variable names inside the class?
Is it possible to create workspaces inside programs, like C++?
It would be good for creating universal drivers and another resources.

Thanks for information. Very Happy
_________________
Eduardo Guilherme Brandt
mbradley



Joined: 11 Jul 2009
Posts: 118
Location: California, USA

View user's profile Send private message Visit poster's website

PostPosted: Thu Nov 24, 2011 12:30 pm     Reply with quote

CCS is not isolating variable names with my macros....

In summarize what's going on, if you use my macros, it will prepend all functions and variables names, in essence creating unique names for these.

Any var inside a function is like any other var inside a function, unique to that function.

However, if you have any global vars needed for the class, preface them with clsVar() to make them unique to the class.

The ## is for concatenation,

So , if we say:
clsFn(myClass,myFunc(aVar))
{
}

Turns into:
__mDEFCLASS(myClass,myFunc(aVar))
{
}

And this turns expands to:

myClass_myFunc(aVar)
{
}
_________________
Michael Bradley
www.mculabs.com
Open Drivers and Projects
Eduardo__



Joined: 23 Nov 2011
Posts: 197
Location: Brazil

View user's profile Send private message

Classes
PostPosted: Fri Nov 25, 2011 5:55 am     Reply with quote

Anyway, that´s a good code.
Thank you a lot!
_________________
Eduardo Guilherme Brandt
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group