jeudi 2 mars 2017

how to create interface file in swig for the following header files?

How to create a interface for following 3 header files using SWIG shall i create 3 different .i files and include all the three .i files in a special .i file please help me CNode.h

#ifndef __MW__CNODE__H__
#define __MW__CNODE__H__

namespace MW
{
    class CNode{
    public:
        CNode() :m_id(0){}
        CNode(double x, double y, double z){
            m_xyz[0] = x;
            m_xyz[1] = y;
            m_xyz[2] = z;
        }
        long    GetID(){ return m_id;  }
        void    SetID(long id){ m_id = id; }

        double *GetXYZ(){ return m_xyz;  }
        void    SetXYZ(double *xyz){ 
            m_xyz[0] = xyz[0];
            m_xyz[1] = xyz[1];
            m_xyz[2] = xyz[2];
        }

        void SetXYZ(double x , double y , double z){
            m_xyz[0] = x;
            m_xyz[1] = y;

            m_xyz[2] = z;
        }

        double GetX(){ return m_xyz[0]; }
        double GetY(){ return m_xyz[1]; }
        double GetZ(){ return m_xyz[2]; }

    private:
        long m_id;
        double m_xyz[3];
    };
}

#endif


**Node.h**


#ifndef __MW__NODE__H__
#define __MW__NODE__H__

#include "CNode.h"

namespace MW
{
    class Node{
    public:
        Node(){}
        int create(){ m_node = new CNode; return 0; }
        int create(long id, double x, double y, double z){
            create();
            m_node->SetID(id);
            m_node->SetXYZ(x, y, z);
            return 0;
        }
        long    GetID(){ return m_node->GetID(); }
        void    SetID(long id){ m_node->SetID(id); }

        double *GetXYZ(){ return m_node->GetXYZ(); }
        void    SetXYZ(double *xyz){ m_node->SetXYZ(xyz); }

        void    SetNode(CNode *node){ m_node = node;  }
        CNode   *GetNode(){ return m_node; }

        void SetXYZ(double x, double y, double z){
            m_node->SetXYZ(x, y, z);
        }

        double GetX(){ return m_node->GetX(); }
        double GetY(){ return m_node->GetY(); }
        double GetZ(){ return m_node->GetZ(); }
    private:
        CNode *m_node;
    };
}

#endif


**NodeList.h**


#ifndef __MW__NODELIST__H__
#define __MW__NODELIST__H__

#include <iostream>
#include <vector>

#include "Node.h"
#include "CNode.h"

namespace MW
{
    class NodeList
    {
    public:
        NodeList(){ m_node = new Node; }

        void add(Node *node){
            m_nodeList.push_back(node->GetNode());
        }

        static Node *CreateNode(long id, double x, double y, double z){
            MW::Node *node = new MW::Node;
            node->create(id, x, y, z);
            return node;
        }

        //std::vector<CNode *>::iterator iterator(){ m_nodeItr = m_nodeList.begin(); return m_nodeItr; }
        void begin(){ m_nodeItr = m_nodeList.begin(); }
        void end(){ m_nodeItr = m_nodeList.end(); }
        Node *next(){ 
            std::vector<CNode *>::iterator cur = m_nodeItr;
            m_nodeItr++;
            m_node->SetNode((CNode *)(*cur));
            return m_node;
        }

        bool hasNext(){ return (m_nodeItr != m_nodeList.end() ? true : false); }
        int clear(){
            begin();
            for (CNode *node : m_nodeList){
                delete node; node = 0;
            }
            return 0;
        }

        void print(){
            begin();
            while (hasNext()){
                Node *node = next();
                std::cout << node->GetID() << "," << node->GetX() << "," << node->GetY() << "," << node->GetZ() << std::endl;
            }

        }
    private:
        std::vector<CNode *> m_nodeList;
        std::vector<CNode *>::iterator m_nodeItr;
        Node *m_node;
    };
};

#endif

this is my mw_wrapper.cpp file

// mw_wrapper.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include "Node.h"
#include "Element.h"`enter code here`

#include "NodeList.h"
#include "ElementList.h"

MW::Node *CreateNode(long id, double x, double y, double z){
    return MW::NodeList::CreateNode(id, x, y, z);
}


int _tmain(int argc, _TCHAR* argv[])
{

    Node section :
        1, 150.0, 140.0, 30.0
        2, 150.0, 120.0, 30.0
        3, 137.5, 120.0, 30.0
        4, 137.5, 140.0, 30.0
        5, 150.0, 100.0, 30.0
        6, 137.5, 100.0, 30.0
        7, 175.0, 140.0, 30.0
        8, 175.0, 120.0, 30.0,
        9, 162.5, 120.0, 30.0
        10, 162.5, 140.0, 30.0


    MW::NodeList nodeList;
    nodeList.add(CreateNode(1, 150.0, 140.0, 30.0));
    nodeList.add(CreateNode(2, 150.0, 120.0, 30.0));
    nodeList.add(CreateNode(3, 137.5, 120.0, 30.0));
    nodeList.add(CreateNode(4, 137.5, 140.0, 30.0));
    nodeList.add(CreateNode(5, 150.0, 100.0, 30.0));
    nodeList.add(CreateNode(6, 137.0, 100.0, 30.0));
    nodeList.add(CreateNode(7, 175.0, 140.0, 30.0));
    nodeList.add(CreateNode(8, 175.0, 120.0, 30.0));
    nodeList.add(CreateNode(9, 162.5, 120.0, 30.0));
    nodeList.add(CreateNode(10, 162.5, 140.0, 30.0));



    // data access for node list
    nodeList.begin();
    while (nodeList.hasNext()){
        MW::Node *node = nodeList.next();
        std::cout << node->GetID() << "," << node->GetX() << "," << node->GetY() << "," << node->GetZ() << std::endl;
    }



    // clear the node list for memory
    nodeList.clear();



    return 0;
}

Aucun commentaire:

Enregistrer un commentaire