Search code examples
c++ocamlswigoracle-coherence

How to use SWIG with "using"


I am attempting to use SWIG 2.0.4 on a C++ library, I have the following in my .i file:

%module coh
%{
#include "coherence/lang.ns"
#include "coherence/net/CacheFactory.hpp"
#include "coherence/net/NamedCache.hpp"
%}

%include "coherence/lang.ns"
%include "coherence/net/CacheFactory.hpp"
%include "coherence/net/NamedCache.hpp"

I swig it with:

$ swig -c++ -ocaml -I/opt/coherence-cpp/include coh.i

But get the error message:

/opt/coherence-cpp/include/coherence/net/CacheFactory.hpp:31: Error: Syntax error in input(1)

Line 31 of that file is:

using coherence::run::xml::XmlElement;

Is the using keyword not supported? Is there a workaround for this, or should I just write a C++ wrapper of my own, and SWIG that instead? Thanks!

UPDATE: I decided to write my own wrapper (and in future, to take a different approach from the start).


Solution

  • MSDN has this to say:

    Note the difference between the using directive and the using declaration : the using declaration allows an individual name to be used without qualification, the using directive allows all the names in a namespace to be used without qualification.

    (I'm guessing that) SWIG supports the "using directive" but not the "using declaration".

    That is to say, you can use:

    using namespace somenamespace::mynamespace;
    

    But you can't use:

    using somenamespace::mynamespace::MySymbol;