Hide internal functions or modules

Posted By: nekokuruma

Hide internal functions or modules - 06/03/15 14:52

A Question for you as a user of a Lite-C library or framework.

Suppose the used library has got the modules Engine, Car and Helicopter in normal Header and Source file implementation.
Now Car and Helicopter uses Engine and calls Engine functions which should be defined in the header file because they are used by Car, Helicopter and maybe other vehicles (provided by the library) in future.
But the client which will use the Car module and Helicopter module should NOT use the Engine module.

Code:
Engine.h

struct {
    int rpm;
} Engine;

Engine_setRpm (Engine* this, int rpm);


--------------
Car.h

struct {
   . . .
   Engine* engine;
   int tireTemp;
} Car;

Car_accelerate(Car* this, int value);


--------------
Helicopter.h

struct {
   . . .
   Engine* engine;
   int altitude;
} Helicopter;

Helicopter_gotoAltitude(Helicopter* this, int value);




Now my question is what would you like to see in a library:

A) Function name which indicates that this function should never be used outside the library itself

Library_Engine_LibInternal_setRpm (Engine* this, int rpm);


B) leave the function name unchanged and add a comment

/*
Private
Do not use this function if you are a client of the framework and if you do not implement new features for the framework.
*/
Library_Engine_setRpm (Engine* this, int rpm);


C) Separate free to use by client modules and internal modules

vehicles/internal/engine.h
vehicles/helicopter.h
vehicles/car.h

Which maybe get a little messy over time when the library grows I suppose?



What are your methods to write/structure your code so that it is best protected by accidently using internal implementations which are not intended to use by client.
I am looking forward to hear how you implement your Lite-C Work or what you’d like to see in a Lite-C library considering the mentioned problem.
Posted By: Wjbender

Re: Hide internal functions or modules - 06/03/15 16:27

if you need to code something ,and , you want to prevent your code from being visible and prevent needless cluttering , I suggest that you write a dll (plugin) , if you have a pro licence or a plugin licence ,in such cases you may redistribute the build dll and simply keep your source code private ,if you don't have any of these licences you may redistribute your dll but you must provide the source code along with it.

hence the only part of viewable code wil be function declarations and definitions in a .c/.h file to be included in a user's project ,along with the dll wich the engine will automatically load up .

Posted By: nekokuruma

Re: Hide internal functions or modules - 06/03/15 17:08

Hey thanks for the reply. I never programmed a dll before and just skimmed the wiki article.
Now I must decide which way I go the plain Lite-C way or the dll way.

As I read you have to do a little rewriting like (_VAR(_FLOAT(a)+_FLOAT(b)));
I do believe I will stay plain Lite-C wink (At least for the moment).
Posted By: Wjbender

Re: Hide internal functions or modules - 06/03/15 17:30

yes , like imperial and metric conversion ,you have to convert (type cast) from engine types to c++ types and vice versa to successfully use values and types in c++ .

stick it out a little longer with lite-c if your new to c++ , once you have enough knowledge you could always try out doing a dll later .

good luck and welcome
© 2024 lite-C Forums