General question about includes

Hi everyone!

I've been searching for the solution to the following question for a while with no success. Hopefully you will be able to help or clear me out.

So the situation is this:

There is this library RapidXML for XML processing, which is basically (for what i need) just one .hpp file. It has some standart includes and all the code that is needed for XML processing.
Now I am writing sort of xml reader library (which uses RapidXML) for specific xml files. This library reads xml file and creates array of stuctures which would be much more convienient to use later than RapidXML library directly.

And there's of course the main program which uses the actual array of structures.

This project has 4 files:

rapidxml.hpp
1
2
3
4
5

#define something
#include <some_basic_includes_for_rapidxml>

//actual classes and code 


MyLibrary.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

#include "rapidxml.hpp"

struct MyStructure {
    int a, b, c;
};

class MyClass {
    private:
        rapidxml::xml_document<> *doc;
        //other private rapidxml namespace variables
    public:
        MyClass();
        ~MyClass();
        int getNodeAmmount();
        int getNodes(MyStructure *nodes, int length);
 
}


MyLibrary.cpp
 
//just the actual code for MyClass functions 


Main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
#include "MyLibrary.h"

int main() {
    //some irrelevant code...

    MyClass *myclass = new MyClass();
    int num = myclass->getNodeAmmount();
    MyStructure *nodes = new MyStructure[num];
    myclass->getNodes(nodes, num);

   //further proccessing
}



At the moment I could add something like using namespace rapidxml to the main file and that would compile. The problem is that I dont want that main program (or any other that includes MyLibrary.h) could see rapidxml and especially includes from rapidxml.hpp (altough those are more or less standard includes). Is there a way to do this. I've tried placing #include "rapidxml.hpp" inside MyClass definition, but that doesnt really compile. What I want to do is make MyLibrary like an interface or wrapper and programs which use MyLibrary shouldn't and (for what I want) musn't see "inside parts" of MyLibrary.

I hope it is possible to understand what am I explaining. If not, please ask. Thank you for you patience.
closed account (DSLq5Di1)
I dont fully understand what your question is..

Assuming your library fully encapsulates rapidxml and you are not referencing anything from rapidxml in main.. your code should perform as desired, without the need to introduce rapidxml's namespace in main.
My question is how do I make that main program wouldn't "see" includes from MyLibrary (in this case rapidxml). Say I include MyLibrary in main I could do some xml parsing via MyLibrary interface (MyClass) but if I wanted to use rapidxml directly from main, I would have to include rapidxml.hpp
The only way to accomplish this would be if mylibrary.h does not include rapidxml.hpp.

In that event, you wouldn't be able to use any RapidXML classes in mylibrary.h.

There's a workaround that involves void pointers and typecasting, but it generally isn't worth it. If I were you I just wouldn't worry about it and just accept that rapidxml will be included.
Topic archived. No new replies allowed.