text:
/*
 * Copyright 2010,
 *
 * Olivier Stasse,
 *
 *
 * JRL/LAAS, CNRS/AIST
 *
 * This file is part of dynamicsJRLJapan.
 * dynamicsJRLJapan is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * dynamicsJRLJapan is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * You should have received a copy of the GNU Lesser General Public License
 * along with dynamicsJRLJapan.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  Research carried out within the scope of the Associated
 *  International Laboratory: Joint Japanese-French Robotics
 *  Laboratory (JRL)
 *
 */
/* @doc Object used to parse a VRML file describing a robot. */

/*! System includes */
#include <fstream>
#include <sstream>
#include <map>
#include <string.h>

/*! Parsing related macros */
//#define BOOST_SPIRIT_DEBUG
//#define BOOST_SPIRIT_RULE_SCANNERTYPE_LIMIT 2
#define DEPTH_MAX 40

/*!  Framework includes */
//#define DEBUG_MODE
#include "Debug.h"

/*! Boost includes */
#include "boost/version.hpp"

#if BOOST_VERSION < 104000
#include <boost/spirit.hpp>
#include <boost/spirit/phoenix/binders.hpp>
#include <boost/spirit/utility/chset.hpp>
#else
#include <boost/spirit/include/classic.hpp>
#include <boost/spirit/include/phoenix1_binders.hpp>
#include <boost/spirit/include/classic_chset.hpp>
#endif

#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>

//#include "SpiritVRMLReader.t.cpp"

/*!  Framework includes */
#include "JointFreeFlyerPrivate.h"
#include "JointTranslationPrivate.h"
#include "JointAnchorPrivate.h"
#include "JointRotationPrivate.h"
#include "MultiBody.h"
#include "SpiritVRMLReader.h"

using namespace std;
using namespace boost::spirit;

#if BOOST_VERSION < 104000
using namespace boost::spirit::utility;
#else
using namespace boost::spirit::classic;
using namespace boost::spirit::classic::utility;
#endif

using namespace phoenix;

//#define SVRBIND(x) bind(&SpiritVRMLReader::x,this,_1)
#define SVRBIND(x) &x
#define SVRBIND2(x,y) bind(&SpiritOpenHRP::x)y

namespace dynamicsJRLJapan
{
  namespace VRMLReader
  {

    struct s_DataForParsing
    {

      // Variable to build the VRML tree.
      int NbOfBodies;

      // Depth
      int Depth;

      // Joint memory allocation done for new depth.
      //bool JointMemoryAllocationForNewDepth;

      // Current Link.
      internalLink CurrentLink;

      // Vector of current branch
      vector<Body *> CurrentBody;

      // Stack of Rotation Matrix for display.
      vector<matrix3d> StackOfRotationMatrixDisplay;

      // CurrentTranslation.
      MAL_S3_VECTOR_TYPE(double) JointTranslation;

      // Rotation axis and quantity.
      vector3d RotationAxis;

      // aName (for several entities)
      string aName;

      // Inertie matrix
      double mi[9];
      int index_mi;

      // Mass of the body.
      double mass;

      // Center of Mass.
      vector3d cm;

      // Constructor
      s_DataForParsing()
      {
	CurrentLink.aJoint = 0;
      }

      // String for the url.
      BodyGeometricalData m_BodyGeometry;

      // Generic vector3d.
      vector3d m_Genericvec3d;

      // vector of vector3d.
      std::vector<vector3d> m_vectorgvec3d;
    };

    struct SkipGrammar : public grammar<SkipGrammar>
    {
      template <typename ScannerT>
      struct definition
      {
	definition(SkipGrammar const &self)
	{
	  skip_r = space_p | comment_p("#",eol_p);
	};

	rule<ScannerT> skip_r;
	rule<ScannerT> const& start() const {return skip_r;}
      };
    };

    /*! \brief Object to read a VRML file in the OpenHRP format. */
    struct SpiritOpenHRP : public grammar<SpiritOpenHRP>
    {

      void fskyColor(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<< "fskyColor: "<< s<< endl;
      }

      void fViewpointPos(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<< "fViewpointPos: "<< s<< endl;
      }

      void fViewpointOri(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<< "fViewpointOri: "<< s<< endl;
      }

      void fNI_Type(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<< "fNIType: "<< s<< endl;

      }

      void fNI_Headlight(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<< "fHeadlight: "<< s<< endl;

      }

      void fNI_AvatarSize(double s) const
      {
	if (m_Verbose>1)
	  std::cout<< "fAvataSize: "<< s<< endl;
      }

      void fSFInt32(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<< "fSFInt32: " << s<< endl;
      }

      void fCylinderSensor(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout << "fCylinderSensor: "<< s << endl;
      }

      void fCSAngle(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout << "fCSAngle: "<< s << endl;
      }

      void fTCBChildren(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<< "fTCBChildren: " << s<< endl;
      }

      void fDisplay(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<< s<< endl;
      }
      void fShapeBlock(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<< "fShapeBlock: " << s<< endl;
      }

      void fRoute(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<< "fRoute: " << s<< endl;
      }

      void fTransformBlock(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<<"fTransformBlock: "<< s<< endl;
      }
      void fTransformBlockDef(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<<"fTransformBlockDef: "<< s<< endl;
      }

      void fTransformChildren(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<<"fTransformChildren: "<< s<< endl;
      }

      void fTransformToField(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<<"fTransformToField: "<< s<< endl;
      }

      void fISFromNameToField(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<<"ISFromNameToField: "<< s<< endl;
      }

      void fProtoSndBlock(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<<"ProtoSndBlock: "<< s<< endl;
      }

      void fProtoBlock(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<<"ProtoBlock: "<< s<< endl;
      }

      void fNameToField(char const* str, char const* end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<<"NameToField:" << s<< endl;
      }
      void fNameToField2(char const* str, char const* end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<<"IS NameToField:" << s<< endl;
      }

      void fIgnoreComment(char const *str, char const *end) const
      {
	string s(str,end);
	//  std::cout << "IgnoreComment :" << s << endl;
      }

      void fProtoLineName(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout << "fProtoLineName :" << s << endl;
      }

      void ProtoType(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout << "ProtoType :" << s << endl;
      }

      void GiveDataDefault(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout << "GiveDataDefault :" << s << endl;
      }

      void HumanoidBody(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout << "HumanoidBody :" << s << endl;
      }

      void fAssignHumanoidName(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout << "Humanoid Name :" << s << endl;
      }

      void fHumanoidname(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<< "Specified name of the Humanoid: |" << s<<"|" << endl;
      }

      void fHumanoidversion(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<< "Specified version of the Humanoid: |" << s<<"|" << endl;
      }

      void fHumanoidName(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<< "Reading the name of the Humanoid: |" << s<<"|" << endl;
      }
      void fHumanoidinfo(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<< "Reading the info of the Humanoid: |" << s<<"|" << endl;
      }
      void fHumanoidinfoline(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<< "Reading the infoline of the Humanoid: |" << s<<"|" << endl;
      }
      void fBodyChildren(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<< "Block of the body children: |" << s<<"|" << endl;

      }
      void fBodySubBlock(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<< "Sub Block of the body : |" << s<<"|" << endl;

      }

      void fProtoName(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<< "Reading the name of the proto: |" << s<<"|" << endl;
      }

      void fAddBody() const
      {
	if (m_Verbose>1)
	  {
	    std::cout << "Starting Body." << std::endl;
	  }
	int lDepth = m_DataForParsing->Depth;
	Body * lCurrentBody = m_DataForParsing->CurrentBody[lDepth];
	lCurrentBody->setLabel(m_DataForParsing->NbOfBodies++);
	lCurrentBody->setName((char *)(m_DataForParsing->aName).c_str());
	lCurrentBody->setInertie(m_DataForParsing->mi);
	lCurrentBody->setMass(m_DataForParsing->mass);
	lCurrentBody->localCenterOfMass(m_DataForParsing->cm);
	if (m_DataForParsing->Depth!=0)
	  {
	    lCurrentBody->setLabelMother(m_DataForParsing->CurrentBody[lDepth-1]->getLabel());

	  }
	m_MultiBody->addBody(*lCurrentBody);
	m_MultiBody->addLink(*m_DataForParsing->CurrentBody[lDepth-1],
			     *lCurrentBody,
			     m_DataForParsing->CurrentLink);
	//	m_DataForParsing->JointMemoryAllocationForNewDepth=false;
	m_ListOfURLs->push_back(m_DataForParsing->m_BodyGeometry);
	lCurrentBody->setInitialized(true);
	if (m_Verbose>1)
	  {
	    std::cout << "Adding Body." << std::endl;
	  }
      }
      void fJCDEFBlocks(char const *str, char const *end) const
      {
	string s(str,end);
	m_DataForParsing->aName=s;
	if (m_Verbose>1)
	  std::cout<< "Reading aName (part of the JointChildrenBlock): |" << s<<"|" << endl;

      }

      void fDEFName(char const *str, char const *end) const
      {
	string s(str,end);
	m_DataForParsing->aName=s;

	if (m_Verbose>1)
	  std::cout<< "Reading the name of the DEF block: |" << s<<"|" << endl;
      }

      void fJointBlockName() const
      {
	if (m_Verbose>1)
	  std::cout<< "Reading the `name of the JointPrivate BlockName: |"
		   << m_DataForParsing->aName<<"| p: " << m_DataForParsing->CurrentLink.aJoint << endl;
      }

      void fBodySubBlockName() const
      {
	/*
	  if (m_DataForParsing->CurrentBody[m_DataForParsing->Depth]!=0)
	  {
	  delete m_DataForParsing->CurrentBody[m_DataForParsing->Depth];
	  std::cout << "Current depth :" << m_DataForParsing->Depth << std::endl;
	  }*/
	m_DataForParsing->CurrentBody[m_DataForParsing->Depth]->setName((char *)m_DataForParsing->aName.c_str());
	m_DataForParsing->m_BodyGeometry.resetURL( );
	if (m_Verbose>1)
	  {
	    std::cout<< "Reading the name of the BodySubBlockName: |" << m_DataForParsing->aName<<"|" << endl;
	    std::cout<< "Depth: " << m_DataForParsing->Depth << " "
		     <<m_DataForParsing->CurrentBody[m_DataForParsing->Depth] << endl;
	  }
      }

      void fSFVec3f_0(double x) const
      {
	m_DataForParsing->m_Genericvec3d(0) = x;
	if (m_Verbose>1)
	  std::cout<< "SFVec3f_0" << x<<"|" << endl;
      }

      void fSFVec3f_1(double x) const
      {
	m_DataForParsing->m_Genericvec3d(1) = x;
	if (m_Verbose>1)
	  std::cout<< "SFVec3f_1" << x<<"|" << endl;

      }

      void fSFVec3f_2(double x) const
      {
	m_DataForParsing->m_Genericvec3d(2) = x;
	if (m_Verbose>1)
	  std::cout<< "SFVec3f_2" << x<<"|" << endl;
      }

      void fPushGenericvec3d() const
      {
	m_DataForParsing->m_vectorgvec3d.push_back(m_DataForParsing->m_Genericvec3d);
      }

      void fJointTranslationX(double x) const
      {
	m_DataForParsing->JointTranslation(0) = x;
      }

      void fJointTranslationY(double y) const
      {
	m_DataForParsing->JointTranslation(1) = y;
      }

      void fJointTranslationZ(double z) const
      {
	m_DataForParsing->JointTranslation(2) = z;

	// IMPORTANT POLICY: all the free joint have their static
	// translation set to zero.
	if (m_DataForParsing->CurrentLink.aJoint->type()!=JointPrivate::FREE_JOINT)
	  m_DataForParsing->CurrentLink.aJoint->setStaticTranslation(m_DataForParsing->JointTranslation);
	else
	  {
	    MAL_S3_VECTOR_TYPE(double) lnull;
	    lnull(0) = lnull(1) = lnull(2) = 0.0;
	    m_DataForParsing->CurrentLink.aJoint->setStaticTranslation(lnull);
	  }

	if (m_Verbose>1)
	  cout << "JointPrivate" << m_DataForParsing->CurrentLink.aJoint->getName()
	       << ":" << m_DataForParsing->JointTranslation << endl;
      }

      void fTransformInstanceRotationX(double x) const
      {
	if (m_Verbose>1)
	  cout << "Transform rotation (AxisX):" << x << endl;
      }

      void fTransformInstanceRotationY(double x) const
      {
	if (m_Verbose>1)
	  cout << "Transform rotation (AxisY):" << x << endl;
      }

      void fTransformInstanceRotationZ(double x) const
      {
	if (m_Verbose>1)
	  cout << "Transform rotation (AxisZ):" << x << endl;
      }

      void fTransformInstanceRotationAngle(double x) const
      {
	if (m_Verbose>1)
	  cout << "Transform rotation (Angle):" << x << endl;
      }

      void fJointRotationX(double x)  const
      {
	m_DataForParsing->RotationAxis(0) = x;
      }

      void fJointRotationY(double y) const
      {
	m_DataForParsing->RotationAxis(1) = y;
      }

      void fJointRotationZ(double z) const
      {
	m_DataForParsing->RotationAxis(2) = z;
      }

      void fJointRotationAngle(double lQ) const
      {
	double lQuantity = lQ;
	matrix3d R;
	matrix3d displayR;
	// Conversion from rotation axis to rotation matrix.
	AxisAngle2Matrix(m_DataForParsing->RotationAxis, lQuantity, R);

	// From the current branch of rotation computes
	// the rotation at the global level for display.
	if (m_DataForParsing->Depth!=0)
	  {
	    matrix3d pR = m_DataForParsing->StackOfRotationMatrixDisplay[m_DataForParsing->Depth-1];
	    MAL_S3x3_C_eq_A_by_B(displayR,pR,R);
	  }
	else
	  {
	    MAL_S3x3_MATRIX_SET_IDENTITY(displayR);
	  }

	m_DataForParsing->StackOfRotationMatrixDisplay[m_DataForParsing->Depth] = displayR;
        if (m_Verbose>1)
	  cout << "StackOfRotationMatrixDisplay["
	       << m_DataForParsing->Depth << " ] = "
	       << displayR  << endl;

	// Then set the static rotation at the level joint
	// and
	m_DataForParsing->CurrentLink.aJoint->setStaticRotation(R);
	m_DataForParsing->m_BodyGeometry.setRotationForDisplay(displayR);
	if (lQ!=0.0)
	  {
	    if (m_Verbose>1){
	      std::cerr << m_DataForParsing->aName
			<< " JointRotation:" << R << endl;
	      std::cerr << "Axis: "<< m_DataForParsing->RotationAxis
			<< " angle: " << lQuantity<<endl;
	      std::cerr << "displayR: " << displayR << endl;
	    }
	  }
      }

      void fBodyMass(double mass) const
      {
	m_DataForParsing->mass = mass;
      }

      void fBodyCenterOfMassX(double x) const
      {
	m_DataForParsing->cm[0] = x;
	if (m_Verbose>1)
	  std::cout << "fBodyCenterOfMassX :" << x << endl;

      }

      void fBodyCenterOfMassY(double y) const
      {
	m_DataForParsing->cm[1] = y;
	if (m_Verbose>1)
	  std::cout << "fBodyCenterOfMassY :" << y <<endl;
      }

      void fBodyCenterOfMassZ(double z)  const
      {
	m_DataForParsing->cm[2] = z;

	if (m_Verbose>1)
	  std::cout << "fBodyCenterOfMassZ :" << z <<endl;
      }

      void fBodyInlineUrl(const char *str, const char *end)  const
      {
	string s(str,end);

	m_DataForParsing->m_BodyGeometry.addURL(s);

	if (m_Verbose>1)
	  std::cout << "fBodyInlineUrl:" << s << endl;
      }

      void fJointType(char const *str, char const *end)  const
      {
	MAL_S3_VECTOR(lnull,double);
	lnull[0]=0.0;lnull[1]=0.0;lnull[2]=0.0;

	string s(str,end);
	if (m_Verbose>1)
	  cout << "jointType: " << s << endl;

	if (s=="free")
	  {

	    m_DataForParsing->CurrentLink.aJoint = new JointFreeflyerPrivate();
	    m_DataForParsing->CurrentLink.aJoint->setIDinActuated(-1);
	    m_DataForParsing->CurrentLink.aJoint->setName(m_DataForParsing->aName);

	    m_DataForParsing->CurrentLink.aJoint->type(JointPrivate::FREE_JOINT);
	  }
	else if (s=="rotate")
	  {
	    ODEBUG("Joint Rotation Private");
	    m_DataForParsing->CurrentLink.aJoint = new JointRotationPrivate();
	    m_DataForParsing->CurrentLink.aJoint->setIDinActuated(-1);
	    m_DataForParsing->CurrentLink.aJoint->setName(m_DataForParsing->aName);

	    m_DataForParsing->CurrentLink.aJoint->type(JointPrivate::REVOLUTE_JOINT);
	  }
	else if (s=="slide")
	  {
	    m_DataForParsing->CurrentLink.aJoint = new JointTranslationPrivate();
	    m_DataForParsing->CurrentLink.aJoint->setIDinActuated(-1);
	    m_DataForParsing->CurrentLink.aJoint->setName(m_DataForParsing->aName);

	    m_DataForParsing->CurrentLink.aJoint->type(JointPrivate::PRISMATIC_JOINT);

	  }

      }

      void fJointID(int aJointID)  const
      {
	m_DataForParsing->CurrentLink.aJoint->setIDinActuated(aJointID);
	if (m_Verbose>1)
	  std::cout << "JointID :" << aJointID << endl;
      }

      void fJointXAxis(char const ach)  const
      {
	MAL_S3_VECTOR(lxaxis,double);
	lxaxis[0]=1.0;lxaxis[1]=0.0;lxaxis[2]=0.0;
	m_DataForParsing->CurrentLink.aJoint->type(JointPrivate::REVOLUTE_JOINT);
	m_DataForParsing->CurrentLink.aJoint->axis(lxaxis);
      }

      void fJointYAxis(char const end)  const
      {

	MAL_S3_VECTOR(lyaxis,double);
	lyaxis[0]=0.0;lyaxis[1]=1.0;lyaxis[2]=0.0;
	m_DataForParsing->CurrentLink.aJoint->type(JointPrivate::REVOLUTE_JOINT);
	m_DataForParsing->CurrentLink.aJoint->axis(lyaxis);

      }

      void fJointZAxis(char const end) const
      {
	MAL_S3_VECTOR(lzaxis,double);
	lzaxis[0]=0.0;lzaxis[1]=0.0;lzaxis[2]=1.0;
	m_DataForParsing->CurrentLink.aJoint->type(JointPrivate::REVOLUTE_JOINT);
	m_DataForParsing->CurrentLink.aJoint->axis(lzaxis);

      }

      void fJointLLimit(double r) const
      {
	m_DataForParsing->CurrentLink.aJoint->lowerBound(0,r);
	if (m_Verbose>1)
	  std::cout << "fJointLLimit: "  << r << endl;
      }

      void fJointULimit(double r) const
      {
	m_DataForParsing->CurrentLink.aJoint->upperBound(0,r);
	if (m_Verbose>1)
	  std::cout << "fJointULimit: "  << r << endl;
      }

      void fJointLVLimit(double r) const
      {
	m_DataForParsing->CurrentLink.aJoint->lowerVelocityBound(0,r);
	if (m_Verbose>1)
	  std::cout << "fJointLVLimit: "  << r << endl;
      }

      void fJointUVLimit(double r) const
      {
	m_DataForParsing->CurrentLink.aJoint->upperVelocityBound(0,r);
	if (m_Verbose>1)
	  std::cout << "fJointUVLimit: "  << r << endl;
      }

      void fJointEquivalentInertia(double r) const
      {
	m_DataForParsing->CurrentLink.aJoint->equivalentInertia(r);
	if (m_Verbose>1)
	  std::cout << "fJointEquivalentInertia: "  << r << endl;
      }

      void fForceSensorName(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<< "fForceSensorName"<< endl;
      }

      void fFSTranslationX(double x) const
      {
	if (m_Verbose>1)
	  std::cout << "fFSTranslationX :" << x << endl;
      }

      void fFSTranslationY(double y) const
      {
	if (m_Verbose>1)
	  std::cout << "fFSTranslationY :" << y <<endl;
      }

      void fFSTranslationZ(double z) const
      {
	if (m_Verbose>1)
	  std::cout << "fFSTranslationZ :" << z <<endl;
      }

      void fFSRotationX(double x) const
      {
	if (m_Verbose>1)
	  std::cout << "fFSRotationX :" << x << endl;
      }

      void fFSRotationY(double y) const
      {
	if (m_Verbose>1)
	  std::cout << "fFSRotationY :" << y <<endl;
      }

      void fFSRotationZ(double z) const
      {
	if (m_Verbose>1)
	  std::cout << "fFSRotationZ :" << z <<endl;
      }

      void fFSAngle(double z) const
      {
	if (m_Verbose>1)
	  std::cout << "fFSAngle :" << z <<endl;
      }

      void fFSID(int aFSID) const
      {
	if (m_Verbose>1)
	  std::cout << "FSID :" << aFSID << endl;
      }

      void fAccelerationSensorName(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<< "fAccelerationSensorName"<< endl;
      }

      void fASTranslationX(double x) const
      {
	if (m_Verbose>1)
	  std::cout << "fASTranslationX :" << x << endl;
      }

      void fASTranslationY(double y) const
      {
	if (m_Verbose>1)
	  std::cout << "fASTranslationY :" << y <<endl;
      }

      void fASTranslationZ(double z) const
      {
	if (m_Verbose>1)
	  std::cout << "fASTranslationZ :" << z <<endl;
      }

      void fASRotationX(double x) const
      {
	if (m_Verbose>1)
	  std::cout << "fASRotationX :" << x << endl;
      }

      void fASRotationY(double y) const
      {
	if (m_Verbose>1)
	  std::cout << "fASRotationY :" << y <<endl;
      }

      void fASRotationZ(double z) const
      {
	if (m_Verbose>1)
	  std::cout << "fASRotationZ :" << z <<endl;
      }

      void fASAngle(double z) const
      {
	if (m_Verbose>1)
	  std::cout << "fASAngle :" << z <<endl;
      }

      void fASID(int aASID) const
      {
	if (m_Verbose>1)
	  std::cout << "ASID :" << aASID << endl;
      }

      void fGyrometerSensorName(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<< "fAccelerationSensorName"<< endl;
      }

      void fGyroTranslationX(double x) const
      {
	if (m_Verbose>1)
	  std::cout << "fGyroTranslationX :" << x << endl;
      }

      void fGyroTranslationY(double y) const
      {
	if (m_Verbose>1)
	  std::cout << "fGyroTranslationY :" << y <<endl;
      }

      void fGyroTranslationZ(double z) const
      {
	if (m_Verbose>1)
	  std::cout << "fGyroTranslationZ :" << z <<endl;
      }

      void fGyroRotationX(double x) const
      {
	if (m_Verbose>1)
	  std::cout << "fGyroRotationX :" << x << endl;
      }

      void fGyroRotationY(double y) const
      {
	if (m_Verbose>1)
	  std::cout << "fGyroRotationY :" << y <<endl;
      }

      void fGyroRotationZ(double z) const
      {
	if (m_Verbose>1)
	  std::cout << "fGyroRotationZ :" << z <<endl;
      }

      void fGyroAngle(double z) const
      {
	if (m_Verbose>1)
	  std::cout << "fGyroAngle :" << z <<endl;
      }

      void fGyroID(int aGyroID) const
      {
	if (m_Verbose>1)
	  std::cout << "GyroID :" << aGyroID << endl;
      }

      void fFillmomentsOfInertia(double z) const
      {
	m_DataForParsing->mi[m_DataForParsing->index_mi++]=z;
	if (m_DataForParsing->index_mi==9)
	  {
	    if (m_Verbose>1)
	      {
		for(int i=0;i<9;i++)
		  {
		    cout << m_DataForParsing->mi[i] << " ";
		    if (i%3==2)
		      cout<< endl;
		  }
	      }
	    m_DataForParsing->index_mi=0;
	  }
      }

      void fSensorBlockName(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<< "fSensorBlockName: "<< s << endl;
      }
      void fVisionSensorName(char const *str, char const *end) const
      {
	string s(str,end);
	if (m_Verbose>1)
	  std::cout<< "fVisionSensorName: "<< endl;
      }

      void fVSTranslationX(double x) const
      {
	if (m_Verbose>1)
	  std::cout << "fVSTranslationX :" << x << endl;
      }

      void fVSTranslationY(double y) const
      {
	if (m_Verbose>1)
	  std::cout << "fVSTranslationY :" << y <<endl;
      }

      void fVSTranslationZ(double z) const
      {
	if (m_Verbose>1)
	  std::cout << "fVSTranslationZ :" << z <<endl;
      }

      void fVSRotationX(double x) const
      {
	if (m_Verbose>1)
	  std::cout << "fVSRotationX :" << x << endl;
      }

      void fVSRotationY(double y) const
      {
	if (m_Verbose>1)
	  std::cout << "fVSRotationY :" << y <<endl;
      }

      void fVSRotationZ(double z) const
      {
	if (m_Verbose>1)
	  std::cout << "fVSRotationZ :" << z <<endl;
      }

      void fVSAngle(double z) const
      {
	if (m_Verbose>1)
	  std::cout << "fVSAngle :" << z <<endl;
      }

      void fVSID(int aVSID) const
      {
	if (m_Verbose>1)
	  std::cout << "VSID :" << aVSID << endl;
      }

      void fIncreaseDepth() const
      {
	int lDepth = m_DataForParsing->Depth;
	// After the initial body.
	if (lDepth>0)
	  {

	    // Check wether or not the current body is virtual or not.
	    if (!m_DataForParsing->CurrentBody[lDepth]->getInitialized())
	      {
		// If it is virtual then do a basic initialization.
		Body * lCurrentBody = m_DataForParsing->CurrentBody[lDepth];
		lCurrentBody->setLabelMother(m_DataForParsing->CurrentBody[lDepth-1]->getLabel());

		char Buffer[1024];
		memset(Buffer,0,1024);
		sprintf(Buffer,"VIRTUAL_%d", m_DataForParsing->NbOfBodies);
		lCurrentBody->setLabel(m_DataForParsing->NbOfBodies++);
		lCurrentBody->setName(Buffer);
		m_MultiBody->addBody(*lCurrentBody);
		m_MultiBody->addLink(*m_DataForParsing->CurrentBody[lDepth-1],
				     *lCurrentBody,
				     m_DataForParsing->CurrentLink);

		lCurrentBody->setLabelMother(m_DataForParsing->CurrentBody[lDepth-1]->getLabel());
		lCurrentBody->setInitialized(true);
	      }
	  }

	// Increase Depth.
	m_DataForParsing->Depth++;

	// Creates a default body.
	m_DataForParsing->CurrentBody[m_DataForParsing->Depth] = new Body() ;

	MAL_S3x3_MATRIX_SET_IDENTITY(m_DataForParsing->StackOfRotationMatrixDisplay[m_DataForParsing->Depth]);

	if (m_Verbose>1)
	  std::cout << "Increased depth "<< m_DataForParsing->Depth << endl;
      }

      void fDecreaseDepth() const
      {
	m_DataForParsing->Depth--;

	if (m_Verbose>1)
	  std::cout << "Decreased depth "<< m_DataForParsing->Depth << endl;
      }

      // The parser object is copied a lot, so instead of keeping its own table
      // of variables, it keeps track of a reference to a common table.
      SpiritOpenHRP()
      {
	m_Verbose = 5;
      }

      template <typename ScannerT>
      struct definition
      {

	// bool ParseVRMLFile(char const *str)

	definition(SpiritOpenHRP const &self)
	{

	  // Basic types
	  SFBool_r = str_p("TRUE") | str_p("FALSE");

	  SFVec3f_r = real_p[SVRBIND2(fSFVec3f_0,(self,arg1))] >>
	    real_p[SVRBIND2(fSFVec3f_1,(self,arg1))] >>
	    real_p[SVRBIND2(fSFVec3f_2,(self,arg1))];
	  MFVec3f_r = *((SFVec3f_r)[SVRBIND2(fPushGenericvec3d,(self))]
			| ch_p(','));
	  MFInt32_r = *(int_p | ch_p(','));

	  // Coordinate rules
	  Coordinate_r = str_p("Coordinate")
	    >> ch_p('{')
	    >> str_p("point")
	    >> str_p('[')
	    >> MFVec3f_r
	    >> str_p(']')
	    >> ch_p('}');

	  // Fields to link a name and field
	  scaleMultiple_r = str_p("scale")>> !str_p("Orientation");
	  NameToField_r = str_p("center") | str_p("children") |
	    str_p("rotation") | scaleMultiple_r |
	    str_p("translation") | str_p("bboxCenter") | str_p("bboxSize") |
	    str_p("addChildren") | str_p("removeChildren") | str_p("viewpoints") | str_p("humanoidBody") |
	    str_p("transmitter") | str_p("receiver");

	  TransformToField_r = (NameToField_r)[SVRBIND2(fNameToField,(self,arg1,arg2))]
	    >> *(blank_p)
	    >> (str_p("IS"))[SVRBIND2(fISFromNameToField,(self,arg1,arg2))]
	    >> (NameToField_r)[SVRBIND2(fNameToField2,(self,arg1,arg2))];

	  TransformInstanceRotation_r = str_p("rotation") >>
	    (real_p)[SVRBIND2(fTransformInstanceRotationX,(self,arg1))] >>
	    (real_p)[SVRBIND2(fTransformInstanceRotationY,(self,arg1))] >>
	    (real_p)[SVRBIND2(fTransformInstanceRotationZ,(self,arg1))] >>
	    (real_p)[SVRBIND2(fTransformInstanceRotationAngle,(self,arg1))];

	  TransformInstanceTranslation_r = (str_p("translation"))[SVRBIND2(fDisplay,(self,arg1,arg2))] >>
	    real_p>> real_p>> real_p;

	  // Fields for group
	  GroupBlock_r = str_p("Group")
	    >> ch_p('{')
	    >> *(TransformToField_r)
	    >> ch_p('}');

	  Route_r = str_p("ROUTE")[SVRBIND2(fRoute,(self,arg1,arg2))]
	    >> lexeme_d[+(alnum_p|'.'|'_')][SVRBIND2(fRoute,(self,arg1,arg2))]
	    >> str_p("TO")[SVRBIND2(fRoute,(self,arg1,arg2))]
	    >> lexeme_d[+(alnum_p|'.'|'_')][SVRBIND2(fRoute,(self,arg1,arg2))];

	  // Fields of Transform block.
	  TCBChildrenBlock_r = ch_p('[')
	    >> *(GroupBlock_r|TransformBlock_r | ShapeInline_r | Sensors_r | Shape_r )
	    >> ch_p(']');
	  TCBChildren_r = (str_p("children"))
	    [SVRBIND2(fTCBChildren,(self,arg1,arg2))]
	    >> Shape_r | GroupBlock_r| ShapeInline_r | TransformBlock_r |Sensors_r | TCBChildrenBlock_r ;

	  TransformChildrenBlock_r = ch_p('[')
	    >> *(GroupBlock_r | TCBChildren_r)
	    >> ch_p(']');

	  TransformChildren_r= str_p("children")[SVRBIND2(fTransformChildren,(self,arg1,arg2))]
	    >> ((str_p("IS")  >> str_p("children")) |
		TransformChildrenBlock_r);

	  TransformLine_r = (TransformToField_r)[SVRBIND2(fTransformToField,(self,arg1,arg2))]|
	    TransformChildren_r | TCBChildren_r  ;

	  TransformBlock_r = ((str_p("DEF")>> lexeme_d[+alnum_p] >>
			       (str_p("Transform"))[SVRBIND2(fTransformBlockDef,(self,arg1,arg2))] )
			      |(str_p("Transform"))[SVRBIND2(fTransformBlock,(self,arg1,arg2))])
	    >> ch_p('{')
	    >> *(TransformLine_r | TransformInstanceRotation_r | TransformInstanceTranslation_r)
	    >> ch_p('}');

	  // Fields of Proto []block.

	  SFVec3f_r= str_p("SFVec3f")
	    >> (+alpha_p)[SVRBIND2(fProtoLineName,(self,arg1,arg2))]
	    >> real_p >> real_p >> real_p;

	  MF_brackets_r= ch_p('[') >> ch_p(']');
	  MFNode_r= str_p("MFNode")
	    >> (+alpha_p)[SVRBIND2(fProtoLineName,(self,arg1,arg2))]
	    >> !MF_brackets_r;

	  SFNode_r= str_p("SFNode")
	    >> (+alpha_p)[SVRBIND2(fProtoLineName,(self,arg1,arg2))]
	    >> !((ch_p('[') >> ch_p(']')) | str_p("NULL"));

	  MFFloat_r= str_p("MFFloat") >> (+alpha_p)[SVRBIND2(fProtoLineName,(self,arg1,arg2))]
				      >>  ch_p('[') >> *(real_p) >> ch_p(']');

	  SFRotation_r= str_p("SFRotation")
	    >> (+alpha_p)[SVRBIND2(fProtoLineName,(self,arg1,arg2))]
	    >> real_p >> real_p >> real_p >> real_p;

	  SFString_r = str_p("SFString") >> (+alpha_p)[SVRBIND2(fProtoLineName,(self,arg1,arg2))] >> ch_p('"') >>
	    *(alnum_p|ch_p('.')) >> ch_p('"');

	  MFString_r= str_p("MFString") >> (+alpha_p)[SVRBIND2(fProtoLineName,(self,arg1,arg2))] >> !MF_brackets_r;

	  SFFloat_r = str_p("SFFloat") >> (+alpha_p)[SVRBIND2(fProtoLineName,(self,arg1,arg2))] >> *(real_p);

	  SFInt32_r = str_p("SFInt32") >> (+alpha_p)[SVRBIND2(fSFInt32,(self,arg1,arg2))] >> *(int_p);;
	  ProtoLineTitle_r = str_p("exposedField") | str_p("field") | str_p("eventIn") ;

	  ProtoLine_r=  ProtoLineTitle_r >> (SFVec3f_r | SFInt32_r |
					     SFNode_r | MFNode_r | MFFloat_r |
					     SFRotation_r | SFString_r | MFString_r | SFFloat_r);

	  ProtoBlock_r = ch_p('[') >> *(ProtoLine_r) >> ch_p(']');

	  ProtoSndBlock_r = ch_p('{') >> *(TransformBlock_r| GroupBlock_r|Route_r )>> ch_p('}');

	  Proto_r= str_p("PROTO") >> (+alpha_p)[SVRBIND2(fProtoName,(self,arg1,arg2))]
				  >> (ProtoBlock_r)[SVRBIND2(fProtoBlock,(self,arg1, arg2))]
				  >> (ProtoSndBlock_r)[SVRBIND2(fProtoSndBlock,(self,arg1,arg2))];

	  // Part of the joints.

	  // Read the translation of the joint.
	  JointTranslation_r = str_p("translation") >>
	    (real_p)[SVRBIND2(fJointTranslationX,(self,arg1))] >>
	    (real_p)[SVRBIND2(fJointTranslationY,(self,arg1))] >>
	    (real_p)[SVRBIND2(fJointTranslationZ,(self,arg1))];

	  // Read the rotation of the joint.
	  JointRotation_r = str_p("rotation") >>
	    (real_p)[SVRBIND2(fJointRotationX,(self,arg1))] >>
	    (real_p)[SVRBIND2(fJointRotationY,(self,arg1))] >>
	    (real_p)[SVRBIND2(fJointRotationZ,(self,arg1))] >>
	    (real_p)[SVRBIND2(fJointRotationAngle,(self,arg1))];

	  // Type of the joint.
	  JointType_r = str_p("jointType") >> ch_p('"')
					   >> (+alpha_p)[SVRBIND2(fJointType,(self,arg1,arg2))]
					   >> ch_p('"');

	  // Identifient of the joint.
	  JointID_r = str_p("jointId") >> (int_p)[SVRBIND2(fJointID,(self,arg1))];

	  // Specify the axis along which the rotation take place for this joint.
	  JointAxis_r = str_p("jointAxis") >> ch_p('"')
					   >> ( (ch_p('X'))[SVRBIND2(fJointXAxis,(self,arg1))] |
						(ch_p('Y'))[SVRBIND2(fJointYAxis,(self,arg1))] |
						(ch_p('Z'))[SVRBIND2(fJointZAxis,(self,arg1))] )
					   >> ch_p('"');
	  // Not used
	  Jointdh_r = str_p("dh") >> ch_p('[') >> *(real_p)
				  >> ch_p(']'); // not used.

	  // Lower Position Limit for the joint.
	  Jointllimit_r = str_p("llimit") >> ch_p('[') >> (real_p)[SVRBIND2(fJointLLimit,(self,arg1))]
					  >> ch_p(']');

	  // Upper Position Limit for the joint.
	  Jointulimit_r = str_p("ulimit") >> ch_p('[') >> (real_p)[SVRBIND2(fJointULimit,(self,arg1))]
					  >> ch_p(']');

	  // Lower Speed Limit for the joint
	  Jointlvlimit_r = str_p("lvlimit") >> ch_p('[') >> (real_p)[SVRBIND2(fJointLVLimit,(self,arg1))]
					    >> ch_p(']');

	  // Upper Speed Limit for the joint.
	  Jointuvlimit_r = str_p("uvlimit") >> ch_p('[') >> (real_p)[SVRBIND2(fJointUVLimit,(self,arg1))]
					    >> ch_p(']');

	  // Upper Speed Limit for the joint.
	  Jointequivalentinertia_r = str_p("equivalentInertia") >> (real_p)[SVRBIND2(fJointEquivalentInertia,(self,arg1))] ;

	  JointField_r = JointType_r |
	    JointTranslation_r |
	    JointAxis_r |
	    JointRotation_r |
	    JointID_r |
	    Jointdh_r |
	    Jointllimit_r |
	    Jointulimit_r |
	    Jointlvlimit_r |
	    Jointuvlimit_r |
            Jointequivalentinertia_r ;

	  // Parts of the force sensor
	  FSTranslation_r = str_p("translation") >>
	    (real_p)[SVRBIND2(fFSTranslationX,(self,arg1))] >>
	    (real_p)[SVRBIND2(fFSTranslationY,(self,arg1))] >>
	    (real_p)[SVRBIND2(fFSTranslationZ,(self,arg1))];

	  // Read the rotation of the force sensor.
	  FSRotation_r = str_p("rotation") >>
	    (real_p)[SVRBIND2(fFSRotationX,(self,arg1))] >>
	    (real_p)[SVRBIND2(fFSRotationY,(self,arg1))] >>
	    (real_p)[SVRBIND2(fFSRotationZ,(self,arg1))] >>
	    (real_p)[SVRBIND2(fFSAngle,(self,arg1))];
	  FSID_r = str_p("sensorId") >> (int_p)[SVRBIND2(fFSID,(self,arg1))];
	  ForceSensorBlock_r = *(FSTranslation_r | FSRotation_r | FSID_r );
	  ForceSensor_r = str_p("ForceSensor") >> ch_p('{') >> ForceSensorBlock_r >> ch_p('}');

	  // Parts of the Gyroscope sensor
	  GyroTranslation_r = str_p("translation") >>
	    (real_p)[SVRBIND2(fGyroTranslationX,(self,arg1))] >>
	    (real_p)[SVRBIND2(fGyroTranslationY,(self,arg1))] >>
	    (real_p)[SVRBIND2(fGyroTranslationZ,(self,arg1))];

	  // Read the rotation of the Gyroscope sensor.
	  GyroRotation_r = str_p("rotation") >>
	    (real_p)[SVRBIND2(fGyroRotationX,(self,arg1))] >>
	    (real_p)[SVRBIND2(fGyroRotationY,(self,arg1))] >>
	    (real_p)[SVRBIND2(fGyroRotationZ,(self,arg1))] >>
	    (real_p)[SVRBIND2(fGyroAngle,(self,arg1))];
	  GyroID_r = str_p("sensorId") >> (int_p)[SVRBIND2(fGyroID,(self,arg1))];
	  GyrometerSensorBlock_r = *(GyroTranslation_r | GyroRotation_r | GyroID_r);
	  GyrometerSensor_r =  str_p("Gyro") >> ch_p('{') >> GyrometerSensorBlock_r >> ch_p('}');

	  // Parts of the Acceleration sensor
	  ASTranslation_r = str_p("translation") >>
	    (real_p)[SVRBIND2(fASTranslationX,(self,arg1))] >>
	    (real_p)[SVRBIND2(fASTranslationY,(self,arg1))] >>
	    (real_p)[SVRBIND2(fASTranslationZ,(self,arg1))];

	  // Read the rotation of the Acceleration sensor.
	  ASRotation_r = str_p("rotation") >>
	    (real_p)[SVRBIND2(fASRotationX,(self,arg1))] >>
	    (real_p)[SVRBIND2(fASRotationY,(self,arg1))] >>
	    (real_p)[SVRBIND2(fASRotationZ,(self,arg1))] >>
	    (real_p)[SVRBIND2(fASAngle,(self,arg1))];
	  ASID_r = str_p("sensorId") >> (int_p)[SVRBIND2(fASID,(self,arg1))];
	  AccelerationSensorBlock_r = *(ASTranslation_r | ASRotation_r | ASID_r);
	  AccelerationSensor_r =  str_p("AccelerationSensor") >> ch_p('{')
							      >> AccelerationSensorBlock_r >> ch_p('}');

	  // Read the vision sensor.

	  // Translation
	  VSTranslation_r = str_p("translation") >>
	    (real_p)[SVRBIND2(fVSTranslationX,(self,arg1))] >>
	    (real_p)[SVRBIND2(fVSTranslationY,(self,arg1))] >>
	    (real_p)[SVRBIND2(fVSTranslationZ,(self,arg1))];

	  // Read the rotation of the Acceleration sensor.
	  VSRotation_r = str_p("rotation") >>
	    (real_p)[SVRBIND2(fVSRotationX,(self,arg1))] >>
	    (real_p)[SVRBIND2(fVSRotationY,(self,arg1))] >>
	    (real_p)[SVRBIND2(fVSRotationZ,(self,arg1))] >>
	    (real_p)[SVRBIND2(fVSAngle,(self,arg1))];

	  VSID_r = str_p("sensorId") >> (int_p)[SVRBIND2(fVSID,(self,arg1))];

	  VSFrontClipDistance_r = str_p("frontClipDistance") >> real_p;
	  VSBackClipDistance_r = str_p("backClipDistance") >> real_p;
	  VSwidth_r = str_p("width") >> int_p;
	  VSheight_r = str_p("height") >> int_p;
	  VStype_r = str_p("type") >> ch_p('"') >> lexeme_d[+alnum_p] >> ch_p('"');
	  VSFieldOfView_r = str_p("fieldOfView") >> real_p;
	  VSName_r = str_p("name") >> ch_p('"') >> lexeme_d[+alnum_p] >> ch_p('"');

	  VisionSensorBlock_r = *(VSTranslation_r | VSRotation_r | VSID_r |
				  VSFrontClipDistance_r | VSBackClipDistance_r  |
				  VSwidth_r | VSheight_r | VStype_r | VSName_r |
				  VSFieldOfView_r  );
	  VisionSensor_r = str_p("VisionSensor") >> ch_p('{') >> VisionSensorBlock_r >> ch_p('}');

	  CSAngle_r = (lexeme_d[+alnum_p])[SVRBIND2(fCSAngle,(self,arg1,arg2))]
	    >> str_p("IS") >> (lexeme_d[+alnum_p])[SVRBIND2(fCSAngle,(self,arg1,arg2))];
	  CylinderSensorBlock_r = *(CSAngle_r);

	  CylinderSensor_r = (str_p("CylinderSensor"))
	    [SVRBIND2(fCylinderSensor,(self,arg1,arg2))]
	    >> ch_p('{') >> CylinderSensorBlock_r >> ch_p('}');

	  ListSensors_r =  VisionSensor_r |
	    AccelerationSensor_r |
	    ForceSensor_r |
	    GyrometerSensor_r |
	    CylinderSensor_r;

	  Sensors_r =  str_p("DEF") >> (lexeme_d[+(alpha_p|ch_p('_'))] )
	    [SVRBIND2(fSensorBlockName,(self,arg1,arg2))]
				    >> ListSensors_r ;

	  // Parts of the body
	  CenterOfMass_r = str_p("centerOfMass") >>
	    (real_p)[SVRBIND2(fBodyCenterOfMassX,(self,arg1))] >>
	    (real_p)[SVRBIND2(fBodyCenterOfMassY,(self,arg1))] >>
	    (real_p)[SVRBIND2(fBodyCenterOfMassZ,(self,arg1))];

	  Mass_r = str_p("mass") >> (real_p)[SVRBIND2(fBodyMass,(self,arg1))];
	  MomentsOfInertia_r = str_p("momentsOfInertia") >> ch_p('[')
							 >> *((real_p)[SVRBIND2(fFillmomentsOfInertia,(self,arg1))])
							 >> ch_p(']') ;

	  // Material block
	  DiffuseColor_r = str_p("diffuseColor") >>
	    real_p >> real_p >> real_p ;
	  SpecularColor_r = str_p("specularColor") >>
	    real_p >> real_p >> real_p;
	  EmissiveColor_r = str_p("emissiveColor") >>
	    real_p >> real_p >> real_p;
	  Shininess_r = str_p("shininess") >> real_p;
	  Transparency_r = str_p("transparency") >> real_p;
	  AmbientIntensity_r = str_p("ambientIntensity") >> real_p;

	  MaterialBlock_r = *( DiffuseColor_r  |
			       SpecularColor_r |
			       EmissiveColor_r |
			       Shininess_r     |
			       Transparency_r  |
			       AmbientIntensity_r );

	  // Appearance block
	  AppearanceBlock_r = (str_p("material"))[SVRBIND2(fDisplay,(self,arg1,arg2))]
	    >> str_p("Material")
	    >> ch_p('{') >> *(MaterialBlock_r[SVRBIND2(fDisplay,(self,arg1,arg2))]) >> ch_p('}');

	  AppearanceUse_r = str_p("USE")  >>  lexeme_d[+(alnum_p|'_')][SVRBIND2(fShapeBlock,(self,arg1,arg2))];
	  AppearanceDef_r = str_p("DEF")
	    >> ( (lexeme_d[+(alnum_p|'_')][SVRBIND2(fDisplay,(self,arg1,arg2))]
		  >> str_p("Appearance")) | str_p("Appearance") )
	    >>  ch_p('{')
	    >> AppearanceBlock_r[SVRBIND2(fDisplay,(self,arg1,arg2))]
	    >> ch_p('}') ;

	  AppearanceHeader_r = str_p("appearance")[SVRBIND2(fDisplay,(self,arg1,arg2))] >>
	    (AppearanceDef_r[SVRBIND2(fDisplay,(self,arg1,arg2))] | AppearanceUse_r[SVRBIND2(fDisplay,(self,arg1,arg2))]);

	  // Geometry block

	  //
	  // Box
	  GeometryBox_r = str_p("Box")[SVRBIND2(fDisplay,(self,arg1,arg2))]
	    >>  ch_p('{')
	    >>  str_p("size") >> real_p >> real_p >>real_p
	    >> ch_p('}');

	  // Cylinder
	  GeometryCylinder_r = str_p("Cylinder")[SVRBIND2(fDisplay,(self,arg1,arg2))]
	    >> ch_p('{')
	    >> str_p("radius") >> real_p
	    >> str_p("height") >> real_p
	    >> ch_p('}');

	  // IndexedFaceSet

	  IFSccwfield_r = str_p("ccw") >> SFBool_r;
	  IFSconvexfield_r = str_p("convex") >> SFBool_r;
	  IFSsolidfield_r = str_p("solid") >> SFBool_r;
	  IFScreaseAngle_r = str_p("creaseAngle") >> real_p;
	  IFScoord_r = str_p("coord") >> Coordinate_r;

	  IFScoordIndex_r = str_p("coordIndex")
	    >> ch_p('[')
	    >> *( MFInt32_r
		  >> ((str_p("-1") >> ch_p(','))
		      | str_p("-1")
		      )
		  )
	    >> ch_p(']');

	  IndexedFaceSet_r = str_p("IndexedFaceSet")
	    >> ch_p ('{')
	    >> IFSccwfield_r |
	    IFSconvexfield_r |
	    IFSsolidfield_r  |
	    IFScreaseAngle_r |
	    IFScoord_r
	    >> ch_p ('{');
	  // Header
	  GeometryHeader_r = str_p("geometry")[SVRBIND2(fDisplay,(self,arg1,arg2))]
	    >>  GeometryBox_r |
	    GeometryCylinder_r;

	  // Shape block
	  ShapeBlock_r = AppearanceHeader_r |
	    GeometryHeader_r[SVRBIND2(fDisplay,(self,arg1,arg2))];

	  Shape_r = (str_p("Shape"))[SVRBIND2(fDisplay,(self,arg1,arg2))]
	    >> ch_p('{')
	    >> *ShapeBlock_r
	    >> ch_p('}');

	  BodySubBlock_r =CenterOfMass_r | Mass_r | MomentsOfInertia_r ;
	  ShapeInlineUrl_r = str_p("url")
	    >> ch_p('"')
	    >> (lexeme_d[+(alnum_p|ch_p('_')|ch_p('.')|ch_p('/'))])[SVRBIND2(fBodyInlineUrl,(self,arg1,arg2))]
	    >> ch_p('"');

	  ShapeBlockInline_r = ch_p('{') >>
	    *(ShapeInlineUrl_r)>> ch_p('}');

	  ShapeInline_r = (str_p("Inline") >> ShapeBlockInline_r );

	  BodyChildrenField_r=  ShapeInline_r | Sensors_r | Shape_r | TransformBlock_r;

	  BodyChildren_r = str_p("children") >> (ch_p('[')
						 >> *BodyChildrenField_r
						 >> ch_p(']')) |
	        Shape_r;

	  // Define the entry rules for body and hint
	  BodyBlock_r =  (str_p("Segment"))[SVRBIND2(fBodySubBlockName,(self))]
	    >> ch_p('{')
	    >> *((BodySubBlock_r)[SVRBIND2(fBodySubBlock,(self,arg1,arg2))] |
		 (BodyChildren_r)[SVRBIND2(fBodyChildren,(self,arg1,arg2))] )
	    >> ch_p('}');

	  JointChildrenDEFBlocks_r = str_p("DEF") >> (lexeme_d[+(alnum_p|ch_p('_'))])
	    [SVRBIND2(fJCDEFBlocks,(self,arg1,arg2))] |
	    ( (BodyBlock_r)[SVRBIND2(fAddBody,(self))]|
	      JointBlock_r |
	      ListSensors_r);

	  JointChildren_r = str_p("children") >> (ch_p('['))
					      >> *( JointChildrenDEFBlocks_r )
					      >> ch_p(']');

	  JointBlock_r = (str_p("Joint"))[SVRBIND2(fJointBlockName,(self))]
	    >> ch_p('{')[SVRBIND2(fIncreaseDepth,(self))]
	    >> *(JointField_r | JointChildren_r )
	    >> ch_p('}')[SVRBIND2(fDecreaseDepth,(self))];

	  DEFBlock_r = str_p("DEF")
	    >> (lexeme_d[+(alnum_p|ch_p('_'))])[SVRBIND2(fDEFName,(self,arg1,arg2))]
	    >> JointBlock_r;

	  HumanoidVersion_r = str_p("version") >> ch_p('"')
					       >> (lexeme_d[+(alnum_p|'.')])
	    [SVRBIND2(fHumanoidversion,(self,arg1,arg2))]
					       >> ch_p('"');
          HumanoidName_r = str_p("name") >> ch_p('"') >> (lexeme_d[+(alnum_p)])
	    [SVRBIND2(fHumanoidname,(self,arg1,arg2))]
					 >> ch_p('"');
	  HumanoidInfoLine_r = ch_p('"')
	    >> *((lexeme_d[+(alnum_p|':'|'.'|',')])[SVRBIND2(fHumanoidinfoline,(self,arg1,arg2))])
	    >> ch_p('"');

	  HumanoidInfo_r = (str_p("info"))[SVRBIND2(fHumanoidinfo,(self,arg1,arg2))]
	    >> ch_p('[') >> *(HumanoidInfoLine_r) >> ch_p(']');

	  // Define the entry rules for huanoid.
	  HumanoidBlock_r =  *(str_p("humanoidBody")
			       >> ch_p('[') >> *DEFBlock_r >> ch_p(']') |
			       HumanoidName_r | HumanoidVersion_r |
			       HumanoidInfo_r );

	  HumanoidTrail_r = str_p("Humanoid")
	    >> ch_p('{') >> HumanoidBlock_r >> ch_p('}');

	  Humanoid_r = (str_p("DEF"))[SVRBIND2(fProtoName,(self,arg1,arg2))]
	    >> (lexeme_d[+alnum_p])[SVRBIND2(fAssignHumanoidName,(self,arg1,arg2))]
	    >> HumanoidTrail_r;

	  // Navigation Info
	  NIavatarSize_r = str_p("avatarSize") >> (real_p)[SVRBIND2(fNI_AvatarSize,(self,arg1))];
	  NIHeadlight_r = str_p("headlight") >> SFBool_r;
	  NIType_r = str_p("type") >> ch_p('[')
				   >> ch_p('"') >> str_p("EXAMINE") >> ch_p('"')
				   >> ch_p(',')
				   >> ch_p('"') >> str_p("ANY")  >> ch_p('"')
				   >> ch_p(']');
	  NavigationInfo_r = str_p("NavigationInfo") >> ch_p('{') >>
	    *((NIType_r)[SVRBIND2(fNI_Type,(self,arg1,arg2))] |
	      (NIHeadlight_r)[SVRBIND2(fNI_Headlight,(self,arg1,arg2))] |
	      (NIavatarSize_r))>> ch_p('}');

	  // Background
	  skyColor_r = str_p("skyColor") >> real_p >> real_p >> real_p;
	  Background_r = str_p("Background")
	    >> ch_p('{') >> *( (skyColor_r)[SVRBIND2(fskyColor,(self,arg1,arg2))] )
	    >> ch_p('}');

	  // Viewpoint
	  ViewpointOri_r = str_p("orientation")>> real_p >> real_p >> real_p >> real_p;
	  ViewpointPos_r = str_p("position") >> real_p >> real_p >> real_p;
	  Viewpoint_r = str_p("Viewpoint") >> ch_p('{') >> *(
							     (ViewpointPos_r)[SVRBIND2(fViewpointPos,(self,arg1,arg2))]|
							     (ViewpointOri_r)[SVRBIND2(fViewpointOri,(self,arg1,arg2))]
							     ) >> ch_p('}');

	  EntryPoint = *(Proto_r|
			 Humanoid_r|
			 Background_r |
			 NavigationInfo_r |
			 Viewpoint_r );

	  BOOST_SPIRIT_DEBUG_RULE(scaleMultiple_r);
	  BOOST_SPIRIT_DEBUG_RULE(NameToField_r);
	  BOOST_SPIRIT_DEBUG_RULE(TransformToField_r);
	  BOOST_SPIRIT_DEBUG_RULE(TransformInstanceRotation_r);
	  BOOST_SPIRIT_DEBUG_RULE(TransformInstanceTranslation_r);
	  BOOST_SPIRIT_DEBUG_RULE(GroupBlock_r);
	  BOOST_SPIRIT_DEBUG_RULE(Route_r);
	  BOOST_SPIRIT_DEBUG_RULE(TransformBlock_r);
	  BOOST_SPIRIT_DEBUG_RULE(TCBChildren_r);
	  BOOST_SPIRIT_DEBUG_RULE(TCBChildrenBlock_r);
	  BOOST_SPIRIT_DEBUG_RULE(TransformChildrenBlock_r);
	  BOOST_SPIRIT_DEBUG_RULE(TransformChildren_r);
	  BOOST_SPIRIT_DEBUG_RULE(TransformLine_r);
	  BOOST_SPIRIT_DEBUG_RULE(SFVec3f_r);
	  BOOST_SPIRIT_DEBUG_RULE(MF_brackets_r);
	  BOOST_SPIRIT_DEBUG_RULE(MFNode_r);
	  BOOST_SPIRIT_DEBUG_RULE(SFNode_r);
	  BOOST_SPIRIT_DEBUG_RULE(MFFloat_r);
	  BOOST_SPIRIT_DEBUG_RULE(SFRotation_r);
	  BOOST_SPIRIT_DEBUG_RULE(SFString_r);
	  BOOST_SPIRIT_DEBUG_RULE(MFString_r);
	  BOOST_SPIRIT_DEBUG_RULE(SFFloat_r);
	  BOOST_SPIRIT_DEBUG_RULE(SFInt32_r);

	  BOOST_SPIRIT_DEBUG_RULE(ProtoLineTitle_r);
	  BOOST_SPIRIT_DEBUG_RULE(ProtoLine_r);
	  BOOST_SPIRIT_DEBUG_RULE(ProtoBlock_r);
	  BOOST_SPIRIT_DEBUG_RULE(ProtoSndBlock_r);
	  BOOST_SPIRIT_DEBUG_RULE(Proto_r);

	  BOOST_SPIRIT_DEBUG_RULE(JointTranslation_r);
	  BOOST_SPIRIT_DEBUG_RULE(JointRotation_r);
	  BOOST_SPIRIT_DEBUG_RULE(JointType_r);
	  BOOST_SPIRIT_DEBUG_RULE(JointID_r);
	  BOOST_SPIRIT_DEBUG_RULE(JointAxis_r);
	  BOOST_SPIRIT_DEBUG_RULE(Jointdh_r);
	  BOOST_SPIRIT_DEBUG_RULE(Jointllimit_r);
	  BOOST_SPIRIT_DEBUG_RULE(Jointulimit_r);
	  BOOST_SPIRIT_DEBUG_RULE(Jointlvlimit_r);
	  BOOST_SPIRIT_DEBUG_RULE(Jointuvlimit_r);
          BOOST_SPIRIT_DEBUG_RULE(Jointequivalentinertia_r);
          BOOST_SPIRIT_DEBUG_RULE(JointField_r);
	  BOOST_SPIRIT_DEBUG_RULE(DEFBlock_r);
	  BOOST_SPIRIT_DEBUG_RULE(JointBlock_r);

	  BOOST_SPIRIT_DEBUG_RULE(FSTranslation_r);
	  BOOST_SPIRIT_DEBUG_RULE(FSRotation_r);
	  BOOST_SPIRIT_DEBUG_RULE(FSID_r);
	  BOOST_SPIRIT_DEBUG_RULE(ForceSensorBlock_r);
	  BOOST_SPIRIT_DEBUG_RULE(ForceSensor_r);

	  BOOST_SPIRIT_DEBUG_RULE(BodyChildren_r);
	  BOOST_SPIRIT_DEBUG_RULE(BodyBlock_r);

	  BOOST_SPIRIT_DEBUG_RULE(GyroRotation_r);
	  BOOST_SPIRIT_DEBUG_RULE(GyroTranslation_r);
	  BOOST_SPIRIT_DEBUG_RULE(GyroID_r);
	  BOOST_SPIRIT_DEBUG_RULE(GyrometerSensorBlock_r);
	  BOOST_SPIRIT_DEBUG_RULE(GyrometerSensor_r);

	  BOOST_SPIRIT_DEBUG_RULE(ASTranslation_r);
	  BOOST_SPIRIT_DEBUG_RULE(ASRotation_r);
	  BOOST_SPIRIT_DEBUG_RULE(ASID_r);
	  BOOST_SPIRIT_DEBUG_RULE(AccelerationSensorBlock_r);
	  BOOST_SPIRIT_DEBUG_RULE(AccelerationSensor_r);

	  BOOST_SPIRIT_DEBUG_RULE(VSTranslation_r);
	  BOOST_SPIRIT_DEBUG_RULE(VSRotation_r);
	  BOOST_SPIRIT_DEBUG_RULE(VSID_r);
	  BOOST_SPIRIT_DEBUG_RULE(VSFrontClipDistance_r);
	  BOOST_SPIRIT_DEBUG_RULE(VSBackClipDistance_r);
	  BOOST_SPIRIT_DEBUG_RULE(VSwidth_r);
	  BOOST_SPIRIT_DEBUG_RULE(VSheight_r);
	  BOOST_SPIRIT_DEBUG_RULE(VStype_r);
	  BOOST_SPIRIT_DEBUG_RULE(VSFieldOfView_r);
	  BOOST_SPIRIT_DEBUG_RULE(VSName_r);
	  BOOST_SPIRIT_DEBUG_RULE(VisionSensorBlock_r);
	  BOOST_SPIRIT_DEBUG_RULE(VisionSensor_r);
	  BOOST_SPIRIT_DEBUG_RULE(CylinderSensorBlock_r);
	  BOOST_SPIRIT_DEBUG_RULE(CylinderSensor_r);
	  BOOST_SPIRIT_DEBUG_RULE(CSAngle_r);

	  BOOST_SPIRIT_DEBUG_RULE(ListSensors_r);
	  BOOST_SPIRIT_DEBUG_RULE( Sensors_r);
	  BOOST_SPIRIT_DEBUG_RULE( CenterOfMass_r);
	  BOOST_SPIRIT_DEBUG_RULE(Mass_r);
	  BOOST_SPIRIT_DEBUG_RULE( MomentsOfInertia_r);

	  BOOST_SPIRIT_DEBUG_RULE(BodySubBlock_r);
	  BOOST_SPIRIT_DEBUG_RULE( ShapeInlineUrl_r);
	  BOOST_SPIRIT_DEBUG_RULE( ShapeBlockInline_r);
	  BOOST_SPIRIT_DEBUG_RULE( ShapeInline_r);
	  BOOST_SPIRIT_DEBUG_RULE( BodyChildrenField_r);
	  BOOST_SPIRIT_DEBUG_RULE( BodyChildren_r);
	  BOOST_SPIRIT_DEBUG_RULE( BodyBlock_r);
	  BOOST_SPIRIT_DEBUG_RULE( GeometryHeader_r);
	  BOOST_SPIRIT_DEBUG_RULE( GeometryBox_r);
	  BOOST_SPIRIT_DEBUG_RULE( GeometryCylinder_r);
	  BOOST_SPIRIT_DEBUG_RULE( Shape_r);
	  BOOST_SPIRIT_DEBUG_RULE( ShapeBlock_r);
	  BOOST_SPIRIT_DEBUG_RULE(AppearanceBlock_r);
	  BOOST_SPIRIT_DEBUG_RULE( AppearanceHeader_r);
	  BOOST_SPIRIT_DEBUG_RULE(  AppearanceUse_r);
	  BOOST_SPIRIT_DEBUG_RULE( AppearanceDef_r);
	  BOOST_SPIRIT_DEBUG_RULE( MaterialBlock_r);
	  BOOST_SPIRIT_DEBUG_RULE( JointChildrenDEFBlocks_r);
	  BOOST_SPIRIT_DEBUG_RULE( JointChildren_r);
	  BOOST_SPIRIT_DEBUG_RULE(  HumanoidBlock_r);
	  BOOST_SPIRIT_DEBUG_RULE( HumanoidTrail_r);
	  BOOST_SPIRIT_DEBUG_RULE( Humanoid_r);
	  BOOST_SPIRIT_DEBUG_RULE(HumanoidVersion_r);
	  BOOST_SPIRIT_DEBUG_RULE( HumanoidName_r);
	  BOOST_SPIRIT_DEBUG_RULE( HumanoidInfo_r);
	  BOOST_SPIRIT_DEBUG_RULE(HumanoidInfoLine_r);
	  BOOST_SPIRIT_DEBUG_RULE( NIavatarSize_r);
	  BOOST_SPIRIT_DEBUG_RULE( NIHeadlight_r);
	  BOOST_SPIRIT_DEBUG_RULE( NIType_r);
	  BOOST_SPIRIT_DEBUG_RULE( NavigationInfo_r);
	  BOOST_SPIRIT_DEBUG_RULE(skyColor_r);
	  BOOST_SPIRIT_DEBUG_RULE( Background_r);
	  BOOST_SPIRIT_DEBUG_RULE( ViewpointOri_r);
	  BOOST_SPIRIT_DEBUG_RULE( ViewpointPos_r);
	  BOOST_SPIRIT_DEBUG_RULE( Viewpoint_r);
	  BOOST_SPIRIT_DEBUG_RULE( EntryPoint);

	}

	// Tree of the robot.
	rule<ScannerT> scaleMultiple_r, NameToField_r, TransformToField_r,
	  TransformInstanceRotation_r, TransformInstanceTranslation_r,
	  GroupBlock_r, Route_r,
	  TransformBlock_r, TCBChildren_r, TCBChildrenBlock_r, TransformChildrenBlock_r,
	  TransformChildren_r,
	  TransformLine_r, SFVec3f_r, MF_brackets_r, MFNode_r, SFNode_r, MFFloat_r,
	  SFRotation_r, SFString_r, MFString_r, SFFloat_r, SFInt32_r,
	  ProtoLineTitle_r, ProtoLine_r, ProtoBlock_r, ProtoSndBlock_r, Proto_r;

	rule<ScannerT> JointTranslation_r, JointRotation_r, JointType_r,
	  JointID_r, JointAxis_r, Jointdh_r,
	  Jointllimit_r, Jointulimit_r,
	  Jointlvlimit_r, Jointuvlimit_r,
          Jointequivalentinertia_r,
          JointField_r, DEFBlock_r, JointBlock_r;

	rule<ScannerT> SFBool_r,MFVec3f_r,MFInt32_r;

	rule<ScannerT> Coordinate_r;

	rule<ScannerT> FSTranslation_r, FSRotation_r, FSID_r,
	  ForceSensorBlock_r, ForceSensor_r;

	rule<ScannerT> GyroRotation_r,  GyroTranslation_r, GyroID_r,
	  GyrometerSensorBlock_r, GyrometerSensor_r;

	rule<ScannerT> ASTranslation_r, ASRotation_r, ASID_r,
	  AccelerationSensorBlock_r, AccelerationSensor_r;

	rule<ScannerT> VSTranslation_r, VSRotation_r, VSID_r,
	  VSFrontClipDistance_r, VSBackClipDistance_r,
	  VSwidth_r,  VSheight_r, VStype_r, VSFieldOfView_r, VSName_r,
	  VisionSensorBlock_r, VisionSensor_r,
	  CylinderSensorBlock_r, CylinderSensor_r, CSAngle_r;

	rule<ScannerT> ListSensors_r, Sensors_r, CenterOfMass_r,Mass_r, MomentsOfInertia_r;

	rule<ScannerT> BodySubBlock_r, ShapeInlineUrl_r, ShapeBlockInline_r, ShapeInline_r,
	  BodyChildrenField_r, BodyChildren_r, BodyBlock_r;

	// IndexedFaceSet
	rule<ScannerT> IndexedFaceSet_r, IFSccwfield_r,
	  IFSconvexfield_r, IFSsolidfield_r, IFScreaseAngle_r,
	  IFScoord_r, IFScoordIndex_r;

	rule<ScannerT> GeometryHeader_r, GeometryBox_r, GeometryCylinder_r;

	rule<ScannerT> Transparency_r,AmbientIntensity_r;

	rule<ScannerT> Shape_r, ShapeBlock_r,AppearanceBlock_r, AppearanceHeader_r,
	  AppearanceUse_r, AppearanceDef_r, MaterialBlock_r,
	  DiffuseColor_r, SpecularColor_r, EmissiveColor_r, Shininess_r;

	rule<ScannerT> JointChildrenDEFBlocks_r, JointChildren_r,
	  HumanoidBlock_r, HumanoidTrail_r, Humanoid_r,
	  HumanoidVersion_r, HumanoidName_r, HumanoidInfo_r,HumanoidInfoLine_r;

	rule<ScannerT> NIavatarSize_r, NIHeadlight_r, NIType_r, NavigationInfo_r;

	rule<ScannerT> skyColor_r, Background_r, ViewpointOri_r,
	  ViewpointPos_r, Viewpoint_r, EntryPoint;

	rule<ScannerT> const& start() const {return EntryPoint;}

      };

      void Init(MultiBody *aMB,
		struct s_DataForParsing *aDFP,
		vector<BodyGeometricalData> *aListOfURLs)
      {
	m_MultiBody=aMB;
	m_DataForParsing=aDFP;
	m_ListOfURLs=aListOfURLs;

	m_DataForParsing->NbOfBodies = 0;

	// Resize stacks
	m_DataForParsing->CurrentBody.resize(DEPTH_MAX);
	m_DataForParsing->StackOfRotationMatrixDisplay.resize(DEPTH_MAX);

	// Creation du corps de reference
	m_DataForParsing->CurrentBody[0] = new Body();
	m_DataForParsing->CurrentBody[0]->setLabel(m_DataForParsing->NbOfBodies++);
	m_MultiBody->addBody(*m_DataForParsing->CurrentBody[0]);
	m_DataForParsing->Depth = 0;

	// Initialization of the initial matrix.
	MAL_S3x3_MATRIX_SET_IDENTITY(m_DataForParsing->StackOfRotationMatrixDisplay[0]);

	matrix4d eye;
	MAL_S4x4_MATRIX_SET_IDENTITY(eye);
	m_DataForParsing->CurrentLink.label= 0;
	m_DataForParsing->CurrentLink.aJoint = new JointFreeflyerPrivate(eye);
	ODEBUG(" m_DataForParsing->CurrentLink.aJoint->m_globalConfiguration"<<
	       m_DataForParsing->CurrentLink.aJoint->initialPosition());

	//	m_DataForParsing->JointMemoryAllocationForNewDepth = true;
	m_DataForParsing->CurrentLink.indexCorps1 = 0;
	m_DataForParsing->CurrentLink.indexCorps2 = 0;
	m_DataForParsing->index_mi = 0;
      }

      int getVerbose()
      {return m_Verbose;}

      void setVerbose(int lVerbose)
      {m_Verbose = lVerbose;}

    private:

      MultiBody * m_MultiBody;
      struct s_DataForParsing *m_DataForParsing;
      vector<BodyGeometricalData> *m_ListOfURLs;
      int m_Verbose;
    };

  };
};

license: ISC

extension: hpp


text:
package env

import "reflect"

func handleString(value reflect.Value, rawVal string) error {
	value.SetString(rawVal)
	return nil
}

func handleStringSlice(value reflect.Value, rawArr []string) error {
	if len(rawArr) == 0 {
		return nil
	}
	value.Set(reflect.ValueOf(rawArr))
	return nil
}

license: MIT

license_type: permissive

branch_name: refs/heads/master

gha_language: Go

extension: go


text:
package uid_test

import (
	"testing"

	"github.com/billglover/uid"
)

func TestUID(t *testing.T) {
	g := uid.NewGenerator()
	id, err := g.NextID()

	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}

	if len(id) != 12 {
		t.Fatalf("uid should be 12 bytes, got %d", len(id))
	}
}

func TestUIDString(t *testing.T) {
	g := uid.NewGenerator()
	id, err := g.NextStringID()

	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}

	if id == "" {
		t.Fatalf("uid should not be empty")
	}
}

func TestUnique(t *testing.T) {
	g := uid.NewGenerator()

	m := make(map[string]bool, 100000)

	for i := 0; i < 100000; i++ {
		id, err := g.NextStringID()
		if err != nil {
			t.Fatalf("unexpected error: %v", err)
		}

		if m[id] {
			t.Fatalf("uid %s reissued after %d robots.", id, i)
		}
		m[id] = true
	}
}

func BenchmarkUID(b *testing.B) {
	g := uid.NewGenerator()
	b.ResetTimer()

	b.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			_, _ = g.NextID()
		}
	})
}

func BenchmarkUIDString(b *testing.B) {
	g := uid.NewGenerator()
	b.ResetTimer()

	b.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			_, _ = g.NextID()
		}
	})
}

repository: billglover/uid

repo_name: billglover/uid


text:
package csv_test

import (
	"testing"
	"time"

	"github.com/influxdata/flux"
	_ "github.com/influxdata/flux/builtin" // We need to import the builtins for the tests to work.
	"github.com/influxdata/flux/execute"
	"github.com/influxdata/flux/querytest"
	"github.com/influxdata/flux/stdlib/csv"
	"github.com/influxdata/flux/stdlib/universe"
)

func TestFromCSV_NewQuery(t *testing.T) {
	tests := []querytest.NewQueryTestCase{
		{
			Name:    "from no args",
			Raw:     `import "csv" csv.from()`,
			WantErr: true,
		},
		{
			Name:    "from conflicting args",
			Raw:     `import "csv" csv.from(csv:"d", file:"b")`,
			WantErr: true,
		},
		{
			Name:    "from repeat arg",
			Raw:     `import "csv" csv.from(csv:"telegraf", csv:"oops")`,
			WantErr: true,
		},
		{
			Name:    "from",
			Raw:     `import "csv" csv.from(csv:"telegraf", chicken:"what is this?")`,
			WantErr: true,
		},
		{
			Name: "fromCSV text",
			Raw:  `import "csv" csv.from(csv: "1,2") |> range(start:-4h, stop:-2h) |> sum()`,
			Want: &flux.Spec{
				Operations: []*flux.Operation{
					{
						ID: "fromCSV0",
						Spec: &csv.FromCSVOpSpec{
							CSV: "1,2",
						},
					},
					{
						ID: "range1",
						Spec: &universe.RangeOpSpec{
							Start: flux.Time{
								Relative:   -4 * time.Hour,
								IsRelative: true,
							},
							Stop: flux.Time{
								Relative:   -2 * time.Hour,
								IsRelative: true,
							},
							TimeColumn:  "_time",
							StartColumn: "_start",
							StopColumn:  "_stop",
						},
					},
					{
						ID: "sum2",
						Spec: &universe.SumOpSpec{
							AggregateConfig: execute.DefaultAggregateConfig,
						},
					},
				},
				Edges: []flux.Edge{
					{Parent: "fromCSV0", Child: "range1"},
					{Parent: "range1", Child: "sum2"},
				},
			},
		},
		{
			Name:    "fromCSV File",
			Raw:     `import "csv" csv.from(file: "f.txt") |> range(start:-4h, stop:-2h) |> sum()`,
			WantErr: true,
		},
	}
	for _, tc := range tests {
		tc := tc
		t.Run(tc.Name, func(t *testing.T) {
			t.Parallel()
			querytest.NewQueryTestHelper(t, tc)
		})
	}
}

func TestFromCSVOperation_Marshaling(t *testing.T) {
	data := []byte(`{"id":"fromCSV","kind":"fromCSV","spec":{"csv":"1,2"}}`)
	op := &flux.Operation{
		ID: "fromCSV",
		Spec: &csv.FromCSVOpSpec{
			CSV: "1,2",
		},
	}
	querytest.OperationMarshalingTestHelper(t, data, op)
}

repository: davidgs/flux

repo_name: davidgs/flux

gha_license_id: MIT


text:
SUMMARY = "Add support for global workspace shortcuts"
LICENSE = "LGPLv2.1"
LIC_FILES_CHKSUM = " \
	file://COPYING.LIB;md5=2d5025d4aa3495befef8f17206a5b0a1 \
"

inherit kde-kf5 cmake-lib

DEPENDS += " \
    kconfig \
    kcoreaddons \
    kcrash \
    kdbusaddons \
    kservice \
    ${@bb.utils.contains("DISTRO_FEATURES", "x11", "virtual/xserver qtx11extras", "", d)} \
"

PV = "${KF5_VERSION}"
SRC_URI[md5sum] = "8b2a252d99308aece33663cf9522c43a"
SRC_URI[sha256sum] = "687a063cd8c390c0d0a99bacb1ef9c589a0720fbfb499668a3845026ab0f9c70"

# cross libs / headers
CMAKE_ALIGN_SYSROOT[1] = "KF5GlobalAccel, -S${libdir}/lib, -S${STAGING_LIBDIR}/lib"
CMAKE_ALIGN_SYSROOT[2] = "KF5GlobalAccel, -S${includedir}, -S${STAGING_INCDIR}"

FILES_${PN} += " \
    ${datadir}/dbus-1 \
    ${datadir}/kservices5 \
    ${OE_QMAKE_PATH_PLUGINS} \
"

FILES_${PN}-dbg += " \
    ${OE_QMAKE_PATH_PLUGINS}/*/.debug \
"

extension: bb


text:
include ${BPN}.inc

SRC_URI = "https://github.com/tpm2-software/${BPN}/releases/download/${PV}/${BPN}-${PV}.tar.gz \
           file://0001-Makefile.am-Update-CODE_COVERAGE_RULES-for-new-autoc.patch \
"
SRC_URI[md5sum] = "048ea77be36f881b7b6ecefbc1cf7dbd"
SRC_URI[sha256sum] = "7dfd05f7d2c4d5339d1c9ecbdba25f4ea6df70e96b09928e15e0560cce02d525"

S = "${WORKDIR}/${BPN}-${PV}"

repository: robertlinux/meta-secure-core

repo_name: robertlinux/meta-secure-core


text:
package main

import (
	"context"
	"encoding/json"
	"github.com/Chathuru/kubernetes-cluster-autoscaler/pkg/cloud/openstack"
	"github.com/Chathuru/kubernetes-cluster-autoscaler/pkg/cloud/openstack/handel-node-delete"
	"github.com/Chathuru/kubernetes-cluster-autoscaler/pkg/cloud/openstack/handle-node-add"
	"github.com/Chathuru/kubernetes-cluster-autoscaler/pkg/common/datastructures"
	"github.com/Chathuru/kubernetes-cluster-autoscaler/pkg/common/functions"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/runtime/schema"
	"k8s.io/apimachinery/pkg/watch"
	"k8s.io/client-go/dynamic"
	"k8s.io/client-go/rest"
	"log"
	"plugin"
	"sync"
)

var (
	wg                  sync.WaitGroup
	cloudType           string
	modifyEventAnalyzer func(datastructures.Event, string, string, string, string, string)
	deleteEventAnalyzer func(datastructures.Event, string, string, string, string, string)
)

func checkErr(err error) {
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	cloudType = openstackinit.ReadConfig()

	if cloudType != "OpenStack" {
		pluginName := cloudType + ".so"
		plugIn, err := plugin.Open("plugin/" + pluginName)
		if err != nil {
			log.Fatalf("[ERROR] Cloud not load the plugin %s in plugin directory %v", pluginName, err)
		}

		var ok bool
		modifyEventAnalyzerSymbol, err := plugIn.Lookup("ModifyEventAnalyzer")
		modifyEventAnalyzer, ok = modifyEventAnalyzerSymbol.(func(datastructures.Event, string, string, string, string, string))
		if err != nil || !ok {
			log.Fatalf("[ERROR] Something went wrong while loading plugin %v", err)
		}

		deleteEventAnalyzerSymbol, err := plugIn.Lookup("DeleteEventAnalyzer")
		deleteEventAnalyzer, ok = deleteEventAnalyzerSymbol.(func(datastructures.Event, string, string, string, string, string))
		if err != nil || !ok {
			log.Fatalf("[ERROR] Something went wrong while loading plugin %v", err)
		}
		log.Printf("[INFO] %s plugin loaded succesfully", cloudType)
	}

	config := functions.LoadKubeConfig()
	dynamicClient, err := dynamic.NewForConfig(config)
	checkErr(err)

	resource := schema.GroupVersionResource{Version: "v1", Resource: "pods"}
	w, err := dynamicClient.Resource(resource).Namespace("").Watch(context.TODO(), metav1.ListOptions{})
	checkErr(err)

	defer w.Stop()
	wg.Add(1)

	log.Println("[INFO] K8s cluster auto scalar started")
	for {
		wCh := w.ResultChan()

		for event := range wCh {
			eventFilter(event, config)
		}
	}
}

func eventFilter(event watch.Event, config *rest.Config) {
	defer handlenodeadd.PanicRecovery()

	b, _ := json.Marshal(event)
	var EventList datastructures.Event
	err := json.Unmarshal(b, &EventList)
	if err != nil {
		panic("Need to write the code. Stop containing")
	}

	switch EventList.Type {
	case "MODIFIED":
		if cloudType == "OpenStack" {
			handlenodeadd.ModifyEventAnalyzer(EventList, config)
		} else {
			modifyEventAnalyzer(EventList, openstackinit.ProjectName, openstackinit.ClientSecret, openstackinit.ClientID, openstackinit.AWSRegion, openstackinit.AuthFile)
		}
	case "DELETED":
		if cloudType == "OpenStack" {
			handelnodedelete.DeleteEventAnalyzer(EventList, config)
		} else {
			deleteEventAnalyzer(EventList, openstackinit.ProjectName, openstackinit.ClientSecret, openstackinit.ClientID, openstackinit.AWSRegion, openstackinit.AuthFile)
		}
	}
}

repository: Chathuru/kubernetes-cluster-autoscaler

repo_name: Chathuru/kubernetes-cluster-autoscaler


text:
// Fill out your copyright notice in the Description page of Project Settings.

#include "AzureKinectDeviceActions.h"
#include "AzureKinectDevice.h"

FText FAzureKinectDeviceActions::GetName() const
{
	return NSLOCTEXT("AzureKinectDeviceActions", "AssetTypeActions_AzureKinectDevice", "Azure Kinect Device");
}

FColor FAzureKinectDeviceActions::GetTypeColor() const
{
	return FColor::White;
}

UClass* FAzureKinectDeviceActions::GetSupportedClass() const
{
	return UAzureKinectDevice::StaticClass();
}

uint32 FAzureKinectDeviceActions::GetCategories()
{
	return EAssetTypeCategories::Media;
}

repository: nama-gatsuo/AzureKinectForUE

repo_name: nama-gatsuo/AzureKinectForUE

extension: cpp


text:
require ${PN}.inc

PV = "${OPIE_GIT_PV}"
PR = "r2"

SRC_URI = "${OPIE_GIT};protocol=git;subpath=inputmethods/handwriting \
	${OPIE_GIT};protocol=git;subpath=etc/qimpen"

repository: overo/overo-oe-natty

repo_name: overo/overo-oe-natty

branch_name: HEAD


text:
package digitalocean

type Domains struct {
	Domains []Domain     `json:"domains"`
	Meta    DropletsMeta `json:"meta"`
}

type Domain struct {
	Name     string `json:"name"`
	Ttl      int    `json:"ttl"`
	ZoneFile string `json:"zone_file"`
}

type NewDomain struct {
	Name      string `json:"name"`
	IpAddress string `json:"ip_address"`
}


text:
/**
 * Copyright 2016 IBM Corp.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package main

import (
	"bytes"
	"encoding/json"
	"flag"
	"fmt"
	"go/format"
	"io/ioutil"
	"net/http"
	"os"
	"sort"
	"strings"
	"text/template"

	"golang.org/x/tools/imports"
)

const SoftLayerMetadataAPIURL = "https://api.softlayer.com/metadata/v3.1"

type Type struct {
	Name       string              `json:"name"`
	Base       string              `json:"base"`
	TypeDoc    string              `json:"typeDoc"`
	Properties map[string]Property `json:"properties"`
	ServiceDoc string              `json:"serviceDoc"`
	Methods    map[string]Method   `json:"methods"`
	NoService  bool                `json:"noservice"`
	Overview   string              `json:"docOverview"`
	Deprecated bool                `json:"deprecated"`
}

type Property struct {
	Name       string `json:"name"`
	Type       string `json:"type"`
	TypeArray  bool   `json:"typeArray"`
	Form       string `json:"form"`
	Doc        string `json:"doc"`
	Overview   string `json:"docOverview"`
	Deprecated bool   `json:"deprecated"`
}

type Method struct {
	Name       string      `json:"name"`
	Type       string      `json:"type"`
	TypeArray  bool        `json:"typeArray"`
	Doc        string      `json:"doc"`
	Static     bool        `json:"static"`
	NoAuth     bool        `json:"noauth"`
	Limitable  bool        `json:"limitable"`
	Filterable bool        `json:"filterable"`
	Maskable   bool        `json:"maskable"`
	Parameters []Parameter `json:"parameters"`
	Overview   string      `json:"docOverview"`
	Deprecated bool        `json:"deprecated"`
}

type Parameter struct {
	Name         string      `json:"name"`
	Type         string      `json:"type"`
	TypeArray    bool        `json:"typeArray"`
	Doc          string      `json:"doc"`
	DefaultValue interface{} `json:"defaultValue"`
}

// Define custom template functions
var fMap = template.FuncMap{
	"convertType":     ConvertType,         // Converts SoftLayer types to Go types
	"removePrefix":    RemovePrefix,        // Remove 'SoftLayer_' prefix. if it exists
	"removeReserved":  RemoveReservedWords, // Substitute language-reserved identifiers
	"titleCase":       strings.Title,       // TitleCase the argument
	"desnake":         Desnake,             // Remove '_' from Snake_Case
	"goDoc":           GoDoc,               // Format a go doc string
	"tags":            Tags,                // Remove omitempty tags if required
	"phraseMethodArg": phraseMethodArg,     // Get proper phrase for method argument
	"getTypePrefix":   getTypePrefix,       // resturns [], * or nothing.
	"deprecatedDoc":   deprecatedDoc,       // Marks things as deprecated if needed.
}

var datatype = fmt.Sprintf(`%s

%s

package datatypes

{{range .}}{{.TypeDoc|goDoc}}
type {{.Name|removePrefix}} struct {
	{{.Base|removePrefix}}

{{$base := .Name}}{{range .Properties}}{{.Doc|goDoc}}{{deprecatedDoc .Deprecated}}`+
	`{{$thisType := convertType .Type "datatypes" $base .Name}}
	{{.Name|titleCase}} {{getTypePrefix .TypeArray $thisType}}{{$thisType}}`+
	"`json:\"{{.Name|tags}}\" xmlrpc:\"{{.Name|tags}}\"`"+`

{{end}}
}

{{end}}
`, license, codegenWarning)

var services = fmt.Sprintf(`%s

%s

package services

import (
	"fmt"
	"strings"
)

{{range .}}{{$base := .Name|removePrefix}}{{.TypeDoc|goDoc}}{{deprecatedDoc .Deprecated}}
	type {{$base}} struct {
		Session *session.Session
		Options sl.Options
	}

	// Get{{$base | desnake}}Service returns an instance of the {{$base}} SoftLayer service
	func Get{{$base | desnake}}Service(sess *session.Session) {{$base}} {
		return {{$base}}{Session: sess}
	}

	func (r {{$base}}) Id(id int) {{$base}} {
		r.Options.Id = &id
		return r
	}

	func (r {{$base}}) Mask(mask string) {{$base}} {
		if !strings.HasPrefix(mask, "mask[") && (strings.Contains(mask, "[") || strings.Contains(mask, ",")) {
			mask = fmt.Sprintf("mask[%%s]", mask)
		}

		r.Options.Mask = mask
		return r
	}

	func (r {{$base}}) Filter(filter string) {{$base}} {
		r.Options.Filter = filter
		return r
	}

	func (r {{$base}}) Limit(limit int) {{$base}} {
		r.Options.Limit = &limit
		return r
	}

	func (r {{$base}}) Offset(offset int) {{$base}} {
		r.Options.Offset = &offset
		return r
	}

	{{$rawBase := .Name}}{{range .Methods}}{{$methodName := .Name}}{{.Doc|goDoc}}{{deprecatedDoc .Deprecated}}
	func (r {{$base}}) {{.Name|titleCase}}({{range .Parameters}}{{phraseMethodArg $methodName .Name .TypeArray .Type}}{{end}}) ({{if .Type|ne "void"}}resp {{if .TypeArray}}[]{{end}}{{convertType .Type "services"}}, {{end}}err error) {
		{{if .Type|eq "void"}}var resp datatypes.Void
		{{end}}{{if or (eq .Name "placeOrder") (eq .Name "verifyOrder")}}err = datatypes.SetComplexType(orderData)
		if err != nil {
			return
		}
		{{end}}{{if len .Parameters | lt 0}}params := []interface{}{
			{{range .Parameters}}{{.Name|removeReserved}},
			{{end}}
		}
		{{end}}err = r.Session.DoRequest("{{$rawBase}}", "{{.Name}}", {{if len .Parameters | lt 0}}params{{else}}nil{{end}}, &r.Options, &resp)
	return
	}
	{{end}}

{{end}}
`, license, codegenWarning)

func generateAPI() {
	var meta map[string]Type

	flagset := flag.NewFlagSet(os.Args[1], flag.ExitOnError)
	outputPath := flag.String("o", ".", "the root of the go project to be refreshed")
	flagset.Parse(os.Args[2:])

	jsonResp, code, err := makeHttpRequest(SoftLayerMetadataAPIURL, "GET", new(bytes.Buffer))

	if err != nil {
		fmt.Printf("Error retrieving metadata API: %s", err)
		os.Exit(1)
	}

	if code != 200 {
		fmt.Printf("Unexpected HTTP status code received while retrieving metadata API: %d", code)
		os.Exit(1)
	}

	err = json.Unmarshal(jsonResp, &meta)
	if err != nil {
		fmt.Printf("Error unmarshaling json response: %s", err)
		os.Exit(1)
	}

	// Build an array of Types, sorted by name
	// This will ensure consistency in the order that code is later emitted
	keys := getSortedKeys(meta)

	sortedTypes := make([]Type, 0, len(keys))
	sortedServices := make([]Type, 0, len(keys))

	for _, name := range keys {
		t := meta[name]
		sortedTypes = append(sortedTypes, t)
		addComplexType(&t)
		fixDatatype(&t, meta)

		// Not every datatype is also a service
		if !t.NoService {
			createGetters(&t)
			sortedServices = append(sortedServices, t)
		}
	}

	// Services can be subclasses of other services. Copy methods from each service's 'Base' entity to
	// the child service, only if a same-named method does not already exist (i.e., overridden by the
	// child service)
	for i, service := range sortedServices {
		sortedServices[i].Methods = getBaseMethods(service, meta)
		fixReturnType(&sortedServices[i])
	}

	err = writePackage(*outputPath, "datatypes", sortedTypes, datatype)
	if err != nil {
		fmt.Printf("Error writing to file: %s", err)
	}

	err = writePackage(*outputPath, "services", sortedServices, services)
	if err != nil {
		fmt.Printf("Error writing to file: %s", err)
	}
}

// Exported template functions

func RemovePrefix(args ...interface{}) string {
	s := args[0].(string)

	if strings.HasPrefix(s, "SoftLayer_") {
		return s[10:]
	}

	return s
}

// ConvertType takes the name of the type to convert, and the package context.
func ConvertType(args ...interface{}) string {
	t := args[0].(string)
	p := args[1].(string)

	// Convert softlayer types to golang types
	switch t {
	case "unsignedLong", "unsignedInt":
		return "uint"
	case "boolean":
		return "bool"
	case "dateTime":
		if p != "datatypes" {
			return "datatypes.Time"
		} else {
			return "Time"
		}
	case "decimal", "float":
		if p != "datatypes" {
			return "datatypes.Float64"
		} else {
			return "Float64"
		}
	case "base64Binary":
		return "[]byte"
	case "json", "enum":
		return "string"
	}

	if strings.HasPrefix(t, "SoftLayer_") {
		t = RemovePrefix(t)
		if p != "datatypes" {
			return "datatypes." + t
		}
		// A Property called Resource that is an 'Entity' can be multiple types in reality
		// Specifically this is for Container_Search_Result
		if len(args) >= 4 && args[3] == "resource" && t == "Entity" {
			return "interface{}"
		}
		return t
	}

	if strings.HasPrefix(t, "McAfee_") {
		if p != "datatypes" {
			return "datatypes." + t
		}
		return t
	}

	return t
}

func RemoveReservedWords(args ...interface{}) string {
	n := args[0].(string)

	// Replace language reserved identifiers with alternatives
	switch n {
	case "type":
		return "typ"
	}

	return n
}

// Remove '_' from Snake_Case values
func Desnake(args ...interface{}) string {
	s := args[0].(string)
	return strings.Replace(s, "_", "", -1)
}

// Formats a string into a comment.  For now, just each comment line with "//"
func GoDoc(args ...interface{}) string {
	s := args[0].(string)
	if s == "" {
		s = "no documentation yet"
	}

	return "// " + strings.Replace(s, "\n", "\n// ", -1)
}

// Remove omitempty tags if required
func Tags(args ...interface{}) string {
	n := args[0].(string)

	switch n {
	case "resourceRecords":
		return n
	default:
		return n + ",omitempty"
	}
}

// private

func createGetters(service *Type) {
	for _, p := range service.Properties {
		if p.Form == "relational" {
			m := Method{
				Name:       "get" + strings.Title(p.Name),
				Type:       p.Type,
				TypeArray:  p.TypeArray,
				Doc:        "Retrieve " + p.Doc, // TODO lowercase the first letter
				Parameters: []Parameter{},
			}

			service.Methods[m.Name] = m
		}
	}
}

// Special case for ensuring we can set a complexType on product orders.
func addComplexType(dataType *Type) {
	// Only adding this to the base product order type. All others embed this one.
	if dataType.Name == "SoftLayer_Container_Product_Order" {
		dataType.Properties["complexType"] = Property{
			Name: "complexType",
			Type: "string",
			Form: "local",
			Doc:  "Added by softlayer-go. This hints to the API what kind of product order this is.",
		}
	} else if dataType.Name == "SoftLayer_Container_User_Customer_External_Binding" {
		dataType.Properties["complexType"] = Property{
			Name: "complexType",
			Type: "string",
			Form: "local",
			Doc:  "Added by softlayer-go. This hints to the API what kind of binding this is.",
		}
	}
}

// Special case for fixing some datatype properties in the metadata
func fixDatatype(t *Type, meta map[string]Type) {
	if strings.HasPrefix(t.Name, "SoftLayer_Dns_Domain_ResourceRecord_") {
		baseRecordType, _ := meta["SoftLayer_Dns_Domain_ResourceRecord"]
		for propName, prop := range t.Properties {
			baseRecordType.Properties[propName] = prop
		}
		meta["SoftLayer_Dns_Domain_ResourceRecord"] = baseRecordType
	} else if t.Name == "SoftLayer_Container_User_Customer_External_Binding_Verisign" || t.Name == "SoftLayer_Container_User_Customer_External_Binding_Verisign_Totp" {
		baseType, _ := meta["SoftLayer_Container_User_Customer_External_Binding"]
		for propName, prop := range t.Properties {
			baseType.Properties[propName] = prop
		}
		meta["SoftLayer_Container_User_Customer_External_Binding"] = baseType
	}
}

// Special case for fixing some broken return types in the metadata
func fixReturnType(service *Type) {
	brokenServices := map[string]string{
		"SoftLayer_Network_Application_Delivery_Controller_LoadBalancer_Service":       "deleteObject",
		"SoftLayer_Network_Application_Delivery_Controller_LoadBalancer_VirtualServer": "deleteObject",
		"SoftLayer_Network_Application_Delivery_Controller":                            "deleteLiveLoadBalancerService",
	}

	if methodName, ok := brokenServices[service.Name]; ok {
		method := service.Methods[methodName]
		method.Type = "void"
		service.Methods[methodName] = method
	}
}

// Return formatted method argument phrase used by the method generation.
func phraseMethodArg(methodName string, argName string, isArray bool, argType string) string {
	argName = RemoveReservedWords(argName)

	// Handle special case - placeOrder/verifyOrder should take any kind of order type.
	if (methodName == "placeOrder" || methodName == "verifyOrder" || methodName == "placeQuote") &&
		strings.HasPrefix(argType, "SoftLayer_Container_Product_Order") {
		return fmt.Sprintf("%s interface{}, ", argName)
	}

	refPrefix := "*"
	if isArray {
		refPrefix = "[]"
	}

	argType = ConvertType(argType, "services")

	return fmt.Sprintf("%s %s%s, ", argName, refPrefix, argType)
}

func combineMethods(baseMethods map[string]Method, subclassMethods map[string]Method) map[string]Method {
	r := map[string]Method{}

	// Copy all subclass methods into the result set
	for k, v := range subclassMethods {
		r[k] = v
	}

	// Copy each method from the base class into the result set, but only if a like-named method
	// does not already exist (a method in the child should override a same-named method in the parent)
	for k, v := range baseMethods {
		if _, ok := r[k]; !ok {
			r[k] = v
		}
	}

	return r
}

func getBaseMethods(s Type, typeMap map[string]Type) map[string]Method {
	var methods, baseMethods map[string]Method

	methods = s.Methods

	if s.Base != "SoftLayer_Entity" {
		baseMethods = getBaseMethods(typeMap[s.Base], typeMap)

		// Add base methods to current service methods
		methods = combineMethods(baseMethods, methods)
	}

	// return my methods
	return methods
}

func getSortedKeys(m map[string]Type) []string {
	keys := make([]string, 0, len(m))
	for key := range m {
		if validCheck(key) {
			keys = append(keys, key)
		}
	}
	sort.Strings(keys)

	return keys
}

func validCheck(name string) bool {

	if strings.HasPrefix(name, "BluePages_") {
		return false
	}
	if strings.HasPrefix(name, "IntegratedOfferingTeam_") {
		return false
	}
	return true
}
func writePackage(base string, pkg string, meta []Type, ts string) error {
	var currPrefix string
	var start int

	for i, t := range meta {
		components := strings.Split(RemovePrefix(t.Name), "_")

		if i == 0 {
			currPrefix = components[0]
			continue
		}

		if components[0] != currPrefix {
			err := writeGoFile(base, pkg, currPrefix, meta[start:i], ts)
			if err != nil {
				return err
			}

			currPrefix = components[0]
			start = i
		}
	}

	writeGoFile(base, pkg, currPrefix, meta[start:], ts)

	return nil
}

// Executes a template against the metadata structure, and generates a go source file with the result
func writeGoFile(base string, pkg string, name string, meta []Type, ts string) error {
	filename := base + "/" + pkg + "/" + strings.ToLower(name) + ".go"

	// Generate the source
	var buf bytes.Buffer
	t := template.New(pkg).Funcs(fMap)
	template.Must(t.Parse(ts)).Execute(&buf, meta)

	/*if pkg == "services" && name == "Account"{
		fmt.Println(string(buf.String()))
		os.Exit(0)
	}*/
	// Add the imports
	src, err := imports.Process(filename, buf.Bytes(), &imports.Options{Comments: true})
	if err != nil {
		fmt.Printf("Error processing imports: %s", err)
	}

	// Format
	pretty, err := format.Source(src)
	if err != nil {
		return fmt.Errorf("Error while formatting source: %s", err)
	}

	f, err := os.Create(filename)
	if err != nil {
		return fmt.Errorf("Error creating file: %s", err)
	}
	defer f.Close()
	fmt.Fprintf(f, "%s", pretty)

	return nil
}

func makeHttpRequest(url string, requestType string, requestBody *bytes.Buffer) ([]byte, int, error) {
	client := http.DefaultClient

	req, err := http.NewRequest(requestType, url, requestBody)
	if err != nil {
		return nil, 0, err
	}

	resp, err := client.Do(req)
	if err != nil {
		return nil, 520, err
	}

	defer resp.Body.Close()

	responseBody, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, resp.StatusCode, err
	}

	return responseBody, resp.StatusCode, nil
}

func getTypePrefix(isArray bool, theType string) string {
	if isArray {
		return "[]"
	}
	if theType != "interface{}" {
		return "*"
	}
	return ""
}

func deprecatedDoc(isDeprecated bool) string {
	if isDeprecated {
		return "\n// Deprecated: This function has been marked as deprecated."
	}
	return ""
}

repository: softlayer/softlayer-go

repo_name: softlayer/softlayer-go


text:
//go:build !js
// +build !js

package lib

import (
	"io"
	"os"
)

func mkdirAll(path string, perm os.FileMode) error {
	return os.MkdirAll(path, perm)
}

func stat(path string) (bool, bool, error) {
	pathStat, err := os.Stat(path)
	if err != nil {
		if os.IsNotExist(err) {
			return false, false, nil
		}
		return false, false, err
	}
	return true, pathStat.IsDir(), nil
}

func openFile(path string) (io.ReadCloser, error) {
	return os.Open(path)
}

func writeFile(filename string, bytes []byte) error {
	return os.WriteFile(filename, bytes, 0644)
}

repository: protoconf/protoconf

repo_name: protoconf/protoconf

branch_name: refs/heads/main


text:
require linux-ti-staging_4.1.bb

BRANCH = "ti-rt-linux-4.1.y"

SRCREV = "c6d2ee60de8003e5491ab131307570581529029f"

repository: joelagnel/meta-ti

repo_name: joelagnel/meta-ti