473,383 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Dynamic Namespaces

Joe
Hi folks,

I am writing a application in which different components will be added
with time. Each component in each own C++ source , header file. I want
each component to have a generic interface (functions).
Each component will have a unique namespace to encapsulate the generic
functions to the component. My question is this: Is it possible for the
main routine that processes these components to dynamically solve the
namespace before calling the appropriate function ?
Example: Every component will have a GetID() function.
Component 1 (comp1.cpp)
---------------------------------------
namespace comp_one
{
long GetID(void);
}

Component 2 (comp2.cpp)
---------------------------------------
namespace comp_two
{
long GetID(void);
}

MAIN routine (main.cpp)
------------------------------------

// scan through settings file
MaxComps = read from ini file;

for (int i=1;i<MaxComps;i++)
{
< Namespace i >::GetID();

// do something ...

}

// continue

Reagrds
joe

Dec 14 '06 #1
1 1853

Joe je napisao:
Hi folks,

I am writing a application in which different components will be added
with time. Each component in each own C++ source , header file. I want
each component to have a generic interface (functions).
Each component will have a unique namespace to encapsulate the generic
functions to the component. My question is this: Is it possible for the
main routine that processes these components to dynamically solve the
namespace before calling the appropriate function ?
Example: Every component will have a GetID() function.
Component 1 (comp1.cpp)
---------------------------------------
namespace comp_one
{
long GetID(void);
}

Component 2 (comp2.cpp)
---------------------------------------
namespace comp_two
{
long GetID(void);
}

MAIN routine (main.cpp)
------------------------------------

// scan through settings file
MaxComps = read from ini file;

for (int i=1;i<MaxComps;i++)
{
< Namespace i >::GetID();

// do something ...

}

// continue

Reagrds
joe
Namespaces are thing for diferent usage . You probably mis-interpret
meaning of namespace.

Why yuo need namespace for every component? Use class and make member
function
GetID():

class Com1
{
// . . . .
long GetID();
};

class Com2
{
// . . . .
long GetID();
};
Or better use virtual functions:

class BaseComponent
{
// ....
virtual long GetID() = 0;
};

class Com1 : public BaseComponent
{
//
long GetID() { /* ... */ }
};

So you can make container of 'BaseComponent*' and call GetIDs very
easy.
Some advice (do not use it for 100%) : use namespace to avoid name
conflicts with other libs

Dec 14 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of...
11
by: Random | last post by:
I'm confused about the proper use and usefulness of namespaces. I beleive I understand the purpose is so the developer can put classes within namespaces to essentially organize your code. And I...
0
by: Greg Taylor | last post by:
I'm using the IE webcontrols (obviously) trying to dynamically generate a tabstrip based of a DTS package. I can get the tabstrip to show if I assign the generation after the page completely loads...
3
by: JL | last post by:
I have a VB.NET desktop program that reads/writes data to a server using a Java-based Web Service. This web service, in identical formats, is located on several servers with each server being a...
5
by: Sakcee | last post by:
python provides a great way of dynamically creating fuctions calls and class names from string a function/class name can be stored as string and called/initilzed e.g def foo(a,b): return...
7
by: bambam | last post by:
import works in the main section of the module, but does not work as I hoped when run inside a function. That is, the modules import correctly, but are not visible to the enclosing (global)...
5
by: Andrus | last post by:
How to compile source code into dynamic method ? System.Reflection.Emit.DynamicMethod requires IL code for creation. How to use C# source code to create method instead of manually creating IL...
26
by: Aaron \Castironpi\ Brady | last post by:
Hello all, To me, this is a somewhat unintuitive behavior. I want to discuss the parts of it I don't understand. .... f= lambda: n .... 9 9
0
by: leon70 | last post by:
Hi Group, I built a gSoap 2.7.11 Web services client in C++ on AIX and have got it talking to the remote service. The service is sending back an array of objects to my client but the client is...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.