Idlcpp Tutorials for C + + Hybrid Programming Python chapter (9)

Source: Internet
Author: User

Previous Idlcpp Tutorial in this C + + mixed programming Python chapter (8)

The first one in this C + + mixed programming Idlcpp tutorial (i)

Compared with the previous project, the engineering PYTHONTUTORIAL7 in addition to four documents PYTHONTUTORIAL7.CPP, Tutorial7.cpp, tutorial7.i, tutorial7.py outside, Tutorial6.cpp was also added to the project. The content of PythonTutorial7.cpp basically and PythonTutorial6.cpp identical, no longer repeat. First look at the contents of tutorial7.i:

#import"tutorial6.i"namespacetutorial{structRay3<t>{Ray3 (); Ray3 (Constvector3<t>& origin,Constvector3<t>&direction); voidGetPoint (vector3<t>& point, T T)Const; Vector3<T> GetPoint (T t)Const; Vector3<T>M_origin; Vector3<T>m_direction;    }; Export Ray3<float>; Export Ray3<Double>; typedef RAY3<float>ray3f; typedef RAY3<Double>Ray3d; #{Template<typename t>inline Ray3<T>:: Ray3 () {} template<typename t>inline Ray3<t>::ray3 (Constvector3<t>& origin,Constvector3<t>&direction): M_origin (Origin), m_direction (direction) {} template<typename t>inlinevoidRay3<t>::getpoint (vector3<t>& point, T T)Const{point.x= m_origin.x + m_direction.x *T; Point.y= M_ORIGIN.Y + M_DIRECTION.Y *T; Point.z= M_origin.z + m_direction.z *T; } template<typename t>inline Vector3<T> Ray3<t>::getpoint (T t)Const    {        returnVector3<t> (m_origin.x + m_direction.x *T, M_ORIGIN.Y+ M_DIRECTION.Y *T, M_origin.z+ m_direction.z *t); }    #}}

First line

#import "TUTORIAL6.I"

The template class Vector3 is used in the definition of the later Ray3, so this file is introduced here first.

struct ray3<t>

The template class Ray3 is defined here. There are two member variables, M_origin and m_direction, of type vector3<t>. A ray is represented in this class in the form of a M_origin + m_direction * t (T >= 0) parametric equation. There are two overloaded functions named GetPoint that are used to obtain a point coordinate on the ray.

Export ray3<float>;

Export ray3<double>;

Template instantiation, which indicates that idlcpp generates the appropriate type of metadata information.

typedef ray3<float> RAY3F;

typedef ray3<double> RAY3D;

Defines the type alias for ease of use.

The contents of the Tutorial7.h generated after compilation are as follows:

//Do not EDIT the This FILE, it's generated by Idlcpp//http://www.idlcpp.org#pragmaOnce#include"./tutorial6.h"namespacetutorial{Template<typename t>structRay3 { Public: Ray3 (); Ray3 (Constvector3<t>& origin,Constvector3<t>&direction); voidGetPoint (vector3<t>& point,t T)Const ; Vector3<T> GetPoint (T t)Const ; Vector3<T>M_origin; Vector3<T>m_direction;    }; typedef RAY3<float>ray3f; typedef RAY3<Double>Ray3d; Template<typename t>inline Ray3<T>:: Ray3 () {} template<typename t>inline Ray3<t>::ray3 (Constvector3<t>& origin,Constvector3<t>&direction): M_origin (Origin), m_direction (direction) {} template<typename t>inlinevoidRay3<t>::getpoint (vector3<t>& point, T T)Const{point.x= m_origin.x + m_direction.x *T; Point.y= M_ORIGIN.Y + M_DIRECTION.Y *T; Point.z= M_origin.z + m_direction.z *T; } template<typename t>inline Vector3<T> Ray3<t>::getpoint (T t)Const    {        returnVector3<t> (m_origin.x + m_direction.x *T, M_ORIGIN.Y+ M_DIRECTION.Y *T, M_origin.z+ m_direction.z *t); }    }

And then the Tutorial7.cpp.

" Tutorial7.h "  "tutorial7.mh " "Tutorial7.ic"   "tutorial7.mc"

Because the template class code is written in the header file, so Tutorial7.cpp only need to include the corresponding four files.

In addition the template class Ray3 used the template class Vector3, so its instantiation type ray3<float> and ray3<double> are also used to Vector3 instantiation type vector3<float> And VECTOR3<DOUBLE>, the metadata information for vector3<float> is also used in the corresponding ray3<float> meta-data. So in this project, we need to add Tutorial6.cpp.

Finally, take a look at the contents of tutorial7.py

p = Paf.float.NewArray (3);p [0]= 1;p [1] = 2;p [2] = 3; Ray=paf.tutorial.Ray3f (Paf.tutorial.Vector3f.s_zero, paf.tutorial.Vector3f (p));p T=paf.tutorial.Vector3f (0,0,0); Ray.getpoint (PT,2);Print(pt.x._);Print(pt.y._);Print(pt.z._);p T= Ray.getpoint (3);Print(pt.x._);Print(pt.y._);Print(pt.z._);

First line:

p = Paf.float.NewArray (3);

Creates an array of type float, with a total of three elements, where float is the built-in type. The native types of C + + are supported in Idlcpp, as follows:

BOOLCharsignedCharunsignedCharwchar_t Shortunsigned ShortLongunsignedLongLong LongunsignedLong Longintunsignedint    floatDoubleLong Double

Consider that there are spaces in the middle of some types, which are useful for scripting, as well as aliases for these types, see typedef.i in Pafcore

Compile execution with results such as:

Idlcpp Tutorials for C + + Hybrid Programming Python chapter (9)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.