<commit_before>/*
 * gVirtuS -- A GPGPU transparent virtualization component.
 *
 * Copyright (C) 2009-2010  The University of Napoli Parthenope at Naples.
 *
 * This file is part of gVirtuS.
 *
 * gVirtuS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * gVirtuS 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with gVirtuS; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Written by: Flora Giannone <flora.giannone@studenti.uniparthenope.it>,
 *             Department of Applied Science
 */

#include <cstring>
#include "CudaDrFrontend.h"
#include "CudaUtil.h"
#include "CudaDr.h"
#include <cuda.h>
#include <stdio.h>
#include <unistd.h>
#include <dirent.h>
#include <errno.h>

using namespace std;

void listFiles( const char* path )
{
   DIR* dirFile = opendir( path );
   if ( dirFile )
   {
      struct dirent* hFile;
      errno = 0;
      while (( hFile = readdir( dirFile )) != NULL )
      {
         if ( !strcmp( hFile->d_name, "."  )) continue;
         if ( !strcmp( hFile->d_name, ".." )) continue;
         if ( strstr( hFile->d_name, ".ptx" ))
            printf( "found an .ptx file: %s", hFile->d_name );
      }
      closedir( dirFile );
   }
}
/*Sets the parameter size for the function.*/
extern CUresult cuParamSetSize(CUfunction hfunc, unsigned int numbytes) {
    CudaDrFrontend::Prepare();
    CudaDrFrontend::AddVariableForArguments(numbytes);
    CudaDrFrontend::AddDevicePointerForArguments((void*) hfunc);
    CudaDrFrontend::Execute("cuParamSetSize");
    return (CUresult) CudaDrFrontend::GetExitCode();
}

/*Sets the block-dimensions for the function.*/
extern CUresult cuFuncSetBlockShape(CUfunction hfunc, int x, int y, int z) {
    CudaDrFrontend::Prepare();
    CudaDrFrontend::AddVariableForArguments(x);
    CudaDrFrontend::AddVariableForArguments(y);
    CudaDrFrontend::AddVariableForArguments(z);
    CudaDrFrontend::AddDevicePointerForArguments((void*) hfunc);
    CudaDrFrontend::Execute("cuFuncSetBlockShape");
    return (CUresult) CudaDrFrontend::GetExitCode();
}

/*Launches a CUDA function.*/
extern CUresult cuLaunchGrid(CUfunction f, int grid_width, int grid_height) {
    CudaDrFrontend::Prepare();
    CudaDrFrontend::AddVariableForArguments(grid_width);
    CudaDrFrontend::AddVariableForArguments(grid_height);
    CudaDrFrontend::AddDevicePointerForArguments((void*) f);
    CudaDrFrontend::Execute("cuLaunchGrid");
    return (CUresult) CudaDrFrontend::GetExitCode();
}

/*Returns information about a function.*/
extern CUresult cuFuncGetAttribute(int *pi, CUfunction_attribute attrib, CUfunction hfunc) {
    CudaDrFrontend::Prepare();
    CudaDrFrontend::AddHostPointerForArguments(pi);
    CudaDrFrontend::AddVariableForArguments(attrib);
    CudaDrFrontend::AddDevicePointerForArguments((void*) hfunc);
    CudaDrFrontend::Execute("cuFuncGetAttribute");
    if (CudaDrFrontend::Success())
        *pi = *(CudaDrFrontend::GetOutputHostPointer<int>());
    return (CUresult) (CudaDrFrontend::GetExitCode());
}

/*Sets the dynamic shared-memory size for the function.*/
extern CUresult cuFuncSetSharedSize(CUfunction hfunc, unsigned int bytes) {
    CudaDrFrontend::Prepare();
    CudaDrFrontend::AddVariableForArguments(bytes);
    CudaDrFrontend::AddDevicePointerForArguments((void*) hfunc);
    CudaDrFrontend::Execute("cuFuncSetSharedSize");
    return (CUresult) (CudaDrFrontend::GetExitCode());
}

/*Launches a CUDA function.*/
extern CUresult cuLaunch(CUfunction f) {
    CudaDrFrontend::Prepare();
    CudaDrFrontend::AddDevicePointerForArguments((void*) f);
    CudaDrFrontend::Execute("cuLaunch");
    return (CUresult) CudaDrFrontend::GetExitCode();
}

/*Launches a CUDA function.*/
extern CUresult cuLaunchGridAsync(CUfunction f, int grid_width, int grid_height, CUstream hStream) {
    CudaDrFrontend::Prepare();
    CudaDrFrontend::AddVariableForArguments(grid_width);
    CudaDrFrontend::AddVariableForArguments(grid_height);
    CudaDrFrontend::AddDevicePointerForArguments((void*) f);
    CudaDrFrontend::AddDevicePointerForArguments((void*) hStream);
    CudaDrFrontend::Execute("cuLaunchGridAsync");
    return (CUresult) CudaDrFrontend::GetExitCode();
}

/*Adds a floating-point parameter to the function's argument list.*/
extern CUresult cuParamSetf(CUfunction hfunc, int offset, float value) {
    CudaDrFrontend::Prepare();
    CudaDrFrontend::AddVariableForArguments(offset);
    CudaDrFrontend::AddVariableForArguments(value);
    CudaDrFrontend::AddDevicePointerForArguments((void*) hfunc);
    CudaDrFrontend::Execute("cuParamSetf");
    return (CUresult) CudaDrFrontend::GetExitCode();
}

/*Adds an integer parameter to the function's argument list.*/
extern CUresult cuParamSeti(CUfunction hfunc, int offset, unsigned int value) {
    CudaDrFrontend::Prepare();
    CudaDrFrontend::AddVariableForArguments(offset);
    CudaDrFrontend::AddVariableForArguments(value);
    CudaDrFrontend::AddDevicePointerForArguments((void*) hfunc);
    CudaDrFrontend::Execute("cuParamSeti");
    return (CUresult) CudaDrFrontend::GetExitCode();
}

/*Adds a texture-reference to the function's argument list.*/
extern CUresult cuParamSetTexRef(CUfunction hfunc, int texunit, CUtexref hTexRef) {
    CudaDrFrontend::Prepare();
    CudaDrFrontend::AddDevicePointerForArguments((void*) hfunc);
    CudaDrFrontend::AddVariableForArguments(texunit);
    CudaDrFrontend::AddDevicePointerForArguments((void*) hTexRef);
    CudaDrFrontend::Execute("cuParamSetTexRef");
    return (CUresult) CudaDrFrontend::GetExitCode();
}

/*Adds arbitrary data to the function's argument list.*/
extern CUresult cuParamSetv(CUfunction hfunc, int offset, void *ptr, unsigned int numbytes) {
    CudaDrFrontend::Prepare();
    CudaDrFrontend::AddVariableForArguments(offset);
    CudaDrFrontend::AddVariableForArguments(numbytes);
    CudaDrFrontend::AddHostPointerForArguments((char *) ptr, numbytes);
    CudaDrFrontend::AddDevicePointerForArguments((void*) hfunc);
    CudaDrFrontend::Execute("cuParamSetv");
    return (CUresult) CudaDrFrontend::GetExitCode();
}

/*Sets the preferred cache configuration for a device function. */
extern CUresult cuFuncSetCacheConfig(CUfunction hfunc, CUfunc_cache config) {
    CudaDrFrontend::Prepare();
    CudaDrFrontend::AddVariableForArguments(config);
    CudaDrFrontend::AddDevicePointerForArguments((void*) hfunc);
    CudaDrFrontend::Execute("cuFuncSetCacheConfig");
    return (CUresult) CudaDrFrontend::GetExitCode();
}

// new Cuda 4.0 functions
extern CUresult cuLaunchKernel(CUfunction f, unsigned int gridDimX, unsigned int gridDimY, unsigned int gridDimZ, unsigned int blockDimX, unsigned int blockDimY, unsigned int blockDimZ, unsigned int sharedMemBytes, CUstream hstream , void** kernelParams, void** extra){
    cout << "cuLaunchKernel\n";

    CudaDrFrontend::Prepare();
    CudaDrFrontend::AddDevicePointerForArguments((void*) f);
    CudaDrFrontend::AddVariableForArguments(gridDimX);
    CudaDrFrontend::AddVariableForArguments(gridDimY);
    CudaDrFrontend::AddVariableForArguments(gridDimZ);
    CudaDrFrontend::AddVariableForArguments(blockDimX);
    CudaDrFrontend::AddVariableForArguments(blockDimY);
    CudaDrFrontend::AddVariableForArguments(blockDimZ);
    CudaDrFrontend::AddVariableForArguments(sharedMemBytes);
    CudaDrFrontend::AddDevicePointerForArguments((void*) hstream);
    CudaDrFrontend::AddDevicePointerForArguments(kernelParams);
    CudaDrFrontend::AddHostPointerForArguments(&extra);
    CudaDrFrontend::Execute("cuLaunchKernel");
    return (CUresult) CudaDrFrontend::GetExitCode();
}

<commit_msg>Changed Permissions<commit_after>/*
 * gVirtuS -- A GPGPU transparent virtualization component.
 *
 * Copyright (C) 2009-2010  The University of Napoli Parthenope at Naples.
 *
 * This file is part of gVirtuS.
 *
 * gVirtuS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * gVirtuS 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with gVirtuS; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Written by: Flora Giannone <flora.giannone@studenti.uniparthenope.it>,
 *             Department of Applied Science
 */

#include <cstring>
#include "CudaDrFrontend.h"
#include "CudaUtil.h"
#include "CudaDr.h"
#include <cuda.h>
#include <stdio.h>
#include <unistd.h>
#include <dirent.h>
#include <errno.h>

using namespace std;

void listFiles( const char* path )
{
   DIR* dirFile = opendir( path );
   if ( dirFile )
   {
      struct dirent* hFile;
      errno = 0;
      while (( hFile = readdir( dirFile )) != NULL )
      {
         if ( !strcmp( hFile->d_name, "."  )) continue;
         if ( !strcmp( hFile->d_name, ".." )) continue;
         if ( strstr( hFile->d_name, ".ptx" ))
            printf( "found an .ptx file: %s", hFile->d_name );
      }
      closedir( dirFile );
   }
}
/*Sets the parameter size for the function.*/
extern CUresult cuParamSetSize(CUfunction hfunc, unsigned int numbytes) {
    CudaDrFrontend::Prepare();
    CudaDrFrontend::AddVariableForArguments(numbytes);
    CudaDrFrontend::AddDevicePointerForArguments((void*) hfunc);
    CudaDrFrontend::Execute("cuParamSetSize");
    return (CUresult) CudaDrFrontend::GetExitCode();
}

/*Sets the block-dimensions for the function.*/
extern CUresult cuFuncSetBlockShape(CUfunction hfunc, int x, int y, int z) {
    CudaDrFrontend::Prepare();
    CudaDrFrontend::AddVariableForArguments(x);
    CudaDrFrontend::AddVariableForArguments(y);
    CudaDrFrontend::AddVariableForArguments(z);
    CudaDrFrontend::AddDevicePointerForArguments((void*) hfunc);
    CudaDrFrontend::Execute("cuFuncSetBlockShape");
    return (CUresult) CudaDrFrontend::GetExitCode();
}

/*Launches a CUDA function.*/
extern CUresult cuLaunchGrid(CUfunction f, int grid_width, int grid_height) {
    CudaDrFrontend::Prepare();
    CudaDrFrontend::AddVariableForArguments(grid_width);
    CudaDrFrontend::AddVariableForArguments(grid_height);
    CudaDrFrontend::AddDevicePointerForArguments((void*) f);
    CudaDrFrontend::Execute("cuLaunchGrid");
    return (CUresult) CudaDrFrontend::GetExitCode();
}

/*Returns information about a function.*/
extern CUresult cuFuncGetAttribute(int *pi, CUfunction_attribute attrib, CUfunction hfunc) {
    CudaDrFrontend::Prepare();
    CudaDrFrontend::AddHostPointerForArguments(pi);
    CudaDrFrontend::AddVariableForArguments(attrib);
    CudaDrFrontend::AddDevicePointerForArguments((void*) hfunc);
    CudaDrFrontend::Execute("cuFuncGetAttribute");
    if (CudaDrFrontend::Success())
        *pi = *(CudaDrFrontend::GetOutputHostPointer<int>());
    return (CUresult) (CudaDrFrontend::GetExitCode());
}

/*Sets the dynamic shared-memory size for the function.*/
extern CUresult cuFuncSetSharedSize(CUfunction hfunc, unsigned int bytes) {
    CudaDrFrontend::Prepare();
    CudaDrFrontend::AddVariableForArguments(bytes);
    CudaDrFrontend::AddDevicePointerForArguments((void*) hfunc);
    CudaDrFrontend::Execute("cuFuncSetSharedSize");
    return (CUresult) (CudaDrFrontend::GetExitCode());
}

/*Launches a CUDA function.*/
extern CUresult cuLaunch(CUfunction f) {
    CudaDrFrontend::Prepare();
    CudaDrFrontend::AddDevicePointerForArguments((void*) f);
    CudaDrFrontend::Execute("cuLaunch");
    return (CUresult) CudaDrFrontend::GetExitCode();
}

/*Launches a CUDA function.*/
extern CUresult cuLaunchGridAsync(CUfunction f, int grid_width, int grid_height, CUstream hStream) {
    CudaDrFrontend::Prepare();
    CudaDrFrontend::AddVariableForArguments(grid_width);
    CudaDrFrontend::AddVariableForArguments(grid_height);
    CudaDrFrontend::AddDevicePointerForArguments((void*) f);
    CudaDrFrontend::AddDevicePointerForArguments((void*) hStream);
    CudaDrFrontend::Execute("cuLaunchGridAsync");
    return (CUresult) CudaDrFrontend::GetExitCode();
}

/*Adds a floating-point parameter to the function's argument list.*/
extern CUresult cuParamSetf(CUfunction hfunc, int offset, float value) {
    CudaDrFrontend::Prepare();
    CudaDrFrontend::AddVariableForArguments(offset);
    CudaDrFrontend::AddVariableForArguments(value);
    CudaDrFrontend::AddDevicePointerForArguments((void*) hfunc);
    CudaDrFrontend::Execute("cuParamSetf");
    return (CUresult) CudaDrFrontend::GetExitCode();
}

/*Adds an integer parameter to the function's argument list.*/
extern CUresult cuParamSeti(CUfunction hfunc, int offset, unsigned int value) {
    CudaDrFrontend::Prepare();
    CudaDrFrontend::AddVariableForArguments(offset);
    CudaDrFrontend::AddVariableForArguments(value);
    CudaDrFrontend::AddDevicePointerForArguments((void*) hfunc);
    CudaDrFrontend::Execute("cuParamSeti");
    return (CUresult) CudaDrFrontend::GetExitCode();
}

/*Adds a texture-reference to the function's argument list.*/
extern CUresult cuParamSetTexRef(CUfunction hfunc, int texunit, CUtexref hTexRef) {
    CudaDrFrontend::Prepare();
    CudaDrFrontend::AddDevicePointerForArguments((void*) hfunc);
    CudaDrFrontend::AddVariableForArguments(texunit);
    CudaDrFrontend::AddDevicePointerForArguments((void*) hTexRef);
    CudaDrFrontend::Execute("cuParamSetTexRef");
    return (CUresult) CudaDrFrontend::GetExitCode();
}

/*Adds arbitrary data to the function's argument list.*/
extern CUresult cuParamSetv(CUfunction hfunc, int offset, void *ptr, unsigned int numbytes) {
    CudaDrFrontend::Prepare();
    CudaDrFrontend::AddVariableForArguments(offset);
    CudaDrFrontend::AddVariableForArguments(numbytes);
    CudaDrFrontend::AddHostPointerForArguments((char *) ptr, numbytes);
    CudaDrFrontend::AddDevicePointerForArguments((void*) hfunc);
    CudaDrFrontend::Execute("cuParamSetv");
    return (CUresult) CudaDrFrontend::GetExitCode();
}

/*Sets the preferred cache configuration for a device function. */
extern CUresult cuFuncSetCacheConfig(CUfunction hfunc, CUfunc_cache config) {
    CudaDrFrontend::Prepare();
    CudaDrFrontend::AddVariableForArguments(config);
    CudaDrFrontend::AddDevicePointerForArguments((void*) hfunc);
    CudaDrFrontend::Execute("cuFuncSetCacheConfig");
    return (CUresult) CudaDrFrontend::GetExitCode();
}

// new Cuda 4.0 functions
extern CUresult cuLaunchKernel(CUfunction f, unsigned int gridDimX, unsigned int gridDimY, unsigned int gridDimZ, unsigned int blockDimX, unsigned int blockDimY, unsigned int blockDimZ, unsigned int sharedMemBytes, CUstream hstream , void** kernelParams, void** extra){
    cout << "cuLaunchKernel\n";

    CudaDrFrontend::Prepare();
    CudaDrFrontend::AddDevicePointerForArguments((void*) f);
    CudaDrFrontend::AddVariableForArguments(gridDimX);
    CudaDrFrontend::AddVariableForArguments(gridDimY);
    CudaDrFrontend::AddVariableForArguments(gridDimZ);
    CudaDrFrontend::AddVariableForArguments(blockDimX);
    CudaDrFrontend::AddVariableForArguments(blockDimY);
    CudaDrFrontend::AddVariableForArguments(blockDimZ);
    CudaDrFrontend::AddVariableForArguments(sharedMemBytes);
    CudaDrFrontend::AddDevicePointerForArguments((void*) hstream);
    CudaDrFrontend::AddDevicePointerForArguments(kernelParams);
    CudaDrFrontend::AddHostPointerForArguments(&extra);
    CudaDrFrontend::Execute("cuLaunchKernel");
    return (CUresult) CudaDrFrontend::GetExitCode();
}

<|endoftext|>


<commit_before>#pragma once
#include "mtao/types.hpp"
#include <Eigen/Sparse>

namespace mtao::geometry {
    template <typename SimplexType, typename BType, typename SIType>
        Eigen::SparseMatrix<typename BType::Scalar>
        barycentric_matrix(int num_vertices, const Eigen::MatrixBase<SimplexType>& S, const Eigen::MatrixBase<SIType>& SI, const Eigen::MatrixBase<BType>& B) {

            using Scalar = typename BType::Scalar;
            Eigen::SparseMatrix<Scalar> A(B.cols(), num_vertices);

            std::vector<Eigen::Triplet<Scalar>> trips;
            trips.reserve(S.rows()*SI.size());

            for(int i = 0; i < B.cols(); ++i)
            {
                auto s = S.col(SI(i));
                auto b = B.col(i);
                for(int j = 0; j < b.rows(); ++j)
                {
                    trips.emplace_back(i,s(j),b(j));
                }
            }
            A.setFromTriplets(trips.begin(),trips.end());
            return A;
        }
}
<commit_msg>adding PC constant `barycentric` interpolation<commit_after>#pragma once
#include "mtao/types.hpp"
#include <Eigen/Sparse>

namespace mtao::geometry {
    //A collection of simplicies, indices into simplices, and related barycentric coordinates
    template <typename SimplexType, typename BType, typename SIType>
        Eigen::SparseMatrix<typename BType::Scalar>
        barycentric_matrix(int num_vertices, const Eigen::MatrixBase<SimplexType>& S, const Eigen::MatrixBase<SIType>& SI, const Eigen::MatrixBase<BType>& B) {
            assert(SI.size() == B.cols());

            using Scalar = typename BType::Scalar;
            Eigen::SparseMatrix<Scalar> A(B.cols(), num_vertices);

            std::vector<Eigen::Triplet<Scalar>> trips;
            trips.reserve(S.rows()*SI.size());

            for(int i = 0; i < B.cols(); ++i)
            {
                auto s = S.col(SI(i));
                auto b = B.col(i);
                for(int j = 0; j < b.rows(); ++j)
                {
                    trips.emplace_back(i,s(j),b(j));
                }
            }
            A.setFromTriplets(trips.begin(),trips.end());
            return A;
        }
    //A collection of simplicies, indices into simplices, and related barycentric coordinates
    template <typename Scalar, typename SIType>
        Eigen::SparseMatrix<Scalar>
        barycentric_matrix_face(int num_faces, const Eigen::MatrixBase<SIType>& SI) {

            Eigen::SparseMatrix<Scalar> A(SI.rows(), num_faces);

            std::vector<Eigen::Triplet<Scalar>> trips;
            trips.reserve(SI.size());

            for(int i = 0; i < SI.cols(); ++i)
            {
                trips.emplace_back(i,SI(i),1);
            }
            A.setFromTriplets(trips.begin(),trips.end());
            return A;
        }
}
<|endoftext|>


<commit_before>/*
 * Spatial Computation - Manifestation of Spatial computing.
 * Copyright © 2014 Pranav Kant
 *
 * This code is available to you under Apache License Version 2.0, January
 * 2014. You can grab a copy of license from the same repository from where you
 * fetched this code.
 */

#include "llvm/ADT/DenseMap.h"
#include "llvm/Analysis/CFGPrinter.h"
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/SCCIterator.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/CFG.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IRReader/IRReader.h"
#include "llvm/Pass.h"
#include "llvm/PassManager.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/SourceMgr.h"

#include <string>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <iostream>
#include <map>
#include <deque>

using namespace llvm;

class WaveScalar{
public:
  void runDFS(const Function &F){
    outs() << "Running DFS on function : " << F.getName() << "\n";

    //Intialize the color map.
    unsigned K = 0;
    for (Function::const_iterator I = F.begin(), IE = F.end(); I != IE; I++, K++){
      ColorMap[I] = WaveScalar::WHITE;
      IDMap[I] = K;
      const BasicBlock *pbb = &*I;
      BasicBlock *pp = const_cast<BasicBlock*>(pbb);
      setLabel(&pp, K);
      BEMap[I] = 1;
    }

    recursiveDFS (&F.getEntryBlock());
  }

  void runBFS(){
    while(!Q.empty()){
      BasicBlock *bb = const_cast<BasicBlock*>(Q.front());
      Q.pop_front();

      outs() << "Block " << IDMap[bb] << " is in Wave " << waveNo << "\n";
      const TerminatorInst *TInst = bb->getTerminator();
      for (unsigned i = 0, nsucc = TInst->getNumSuccessors(); i < nsucc; i++){
        BasicBlock *succ = TInst->getSuccessor(i);
        Color succColor = ColorMap[succ];
        if (succColor == WaveScalar::WHITE){
          ColorMap[succ] = WaveScalar::GREY;
          Q.push_back(succ);
        }
      }
      if (BEMap[bb] == 0){
        outs() << "Wave advanced at " << IDMap[bb] << "\n";
        waveNo++;
      }
      ColorMap[bb] = WaveScalar::BLACK;
    }
  }

  void annotateWaves(const Function &F, SmallVectorImpl<std::pair<const BasicBlock*, const BasicBlock*> > *res){
    waveNo = 0;
    init(F);
    setBackEdges(F, res);
    for (Function::const_iterator I = F.begin(), IE = F.end(); I != IE; I++){
      ColorMap[I] = WaveScalar::WHITE;
    }

    Q.push_back(&F.getEntryBlock());
    runBFS();
  }
private:
  enum Color {WHITE, GREY, BLACK};
  typedef DenseMap<const BasicBlock *, Color> BBColorMap;
  typedef SmallVector<const BasicBlock *, 32> BBVector;
  typedef DenseMap<const BasicBlock *, unsigned> BBIDMap;
  BBColorMap ColorMap;
  BBIDMap IDMap, BEMap;
  std::deque<const BasicBlock*> Q;
  unsigned waveNo;

  void init (const Function &F){
    //Intialize the color map.
    unsigned K = 0;
    for (Function::const_iterator I = F.begin(), IE = F.end(); I != IE; I++, K++){
      ColorMap[I] = WaveScalar::WHITE;
      IDMap[I] = K;
      const BasicBlock *pbb = &*I;
      BasicBlock *pp = const_cast<BasicBlock*>(pbb);
      setLabel(&pp, K);
      BEMap[I] = 1;
    }
  }

  void setBackEdges (const Function &F, SmallVectorImpl<std::pair<const BasicBlock*, const BasicBlock*> > *res){
    FindFunctionBackedges(F, *res);
    while (!res->empty()){
      std::pair<const BasicBlock*, const BasicBlock*> tempPair = res->pop_back_val();
      BEMap[tempPair.first] = 0;
      BEMap[tempPair.second] = 0;
    }
  }

  void setLabel(BasicBlock **succ, unsigned k){
    std::stringstream ss;
    ss << k;
    std::string str = ss.str();
    (*succ)->setName(str);
  }

  /*
   This function is used to detect backedges in CFG.
   */
  bool recursiveDFS(const BasicBlock *BB){
    ColorMap[BB] = WaveScalar::GREY;
    const TerminatorInst *TInst = BB->getTerminator();

    for (unsigned i = 0, nsucc = TInst->getNumSuccessors(); i < nsucc; i++){
      BasicBlock *succ = TInst->getSuccessor(i);
      Color succColor = ColorMap[succ];
      if (succColor == WaveScalar::WHITE){
        if (!recursiveDFS(succ))
          return false;
      }else if (succColor == WaveScalar::GREY) {
        outs() << "Detected cycle: from vertex ";
        outs() << IDMap[BB];
        outs() << " to " << IDMap[succ] << "\n";
        /*
          BEMap is initially set to 1 and it changes to 0 for all those nodes
          where backedge is detected.
        */
        BEMap[succ] = 0;
        BEMap[BB] = 0;
        return false;
      }
    }
    ColorMap[BB] = WaveScalar::BLACK;
    return true;
  } // start function

};

/*
  Wave class for waves pass. The main task of this pass is to annotate waves in
  a control flow graph.
*/
struct Waves : public FunctionPass, public SmallVectorImpl <std::pair<const BasicBlock*, const BasicBlock*> > {
  static char ID;
  Waves() : FunctionPass(ID), SmallVectorImpl(10){}

  bool runOnFunction(Function &F) {
    if (F.getName() == "main")
      return false;
    outs() << "Basic blocks of function " << F.getName() << "\n";

    SmallVectorImpl<std::pair<const BasicBlock*, const BasicBlock*> > *res = this;
    WaveScalar obj;
    obj.annotateWaves(F, res);
    F.viewCFGOnly();

    return false;
  }
};

char Waves::ID = 0;
static RegisterPass<Waves> X("annotate", "Annotate Waves", false, false);
<commit_msg>Remove DFS code<commit_after>/*
 * Spatial Computation - Manifestation of Spatial computing.
 * Copyright © 2014 Pranav Kant
 *
 * This code is available to you under Apache License Version 2.0, January
 * 2014. You can grab a copy of license from the same repository from where you
 * fetched this code.
 */

#include "llvm/ADT/DenseMap.h"
#include "llvm/Analysis/CFGPrinter.h"
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/SCCIterator.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/CFG.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IRReader/IRReader.h"
#include "llvm/Pass.h"
#include "llvm/PassManager.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/SourceMgr.h"

#include <string>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <iostream>
#include <map>
#include <deque>

using namespace llvm;

class WaveScalar{
public:
  void runBFS(){
    while(!Q.empty()){
      BasicBlock *bb = const_cast<BasicBlock*>(Q.front());
      Q.pop_front();

      outs() << "Block " << IDMap[bb] << " is in Wave " << waveNo << "\n";
      const TerminatorInst *TInst = bb->getTerminator();
      for (unsigned i = 0, nsucc = TInst->getNumSuccessors(); i < nsucc; i++){
        BasicBlock *succ = TInst->getSuccessor(i);
        Color succColor = ColorMap[succ];
        if (succColor == WaveScalar::WHITE){
          ColorMap[succ] = WaveScalar::GREY;
          Q.push_back(succ);
        }
      }
      if (BEMap[bb] == 0){
        outs() << "Wave advanced at " << IDMap[bb] << "\n";
        waveNo++;
      }
      ColorMap[bb] = WaveScalar::BLACK;
    }
  }

  void annotateWaves(const Function &F, SmallVectorImpl<std::pair<const BasicBlock*, const BasicBlock*> > *res){
    waveNo = 0;
    init(F);
    setBackEdges(F, res);
    for (Function::const_iterator I = F.begin(), IE = F.end(); I != IE; I++){
      ColorMap[I] = WaveScalar::WHITE;
    }

    Q.push_back(&F.getEntryBlock());
    runBFS();
  }
private:
  enum Color {WHITE, GREY, BLACK};
  typedef DenseMap<const BasicBlock *, Color> BBColorMap;
  typedef SmallVector<const BasicBlock *, 32> BBVector;
  typedef DenseMap<const BasicBlock *, unsigned> BBIDMap;
  BBColorMap ColorMap;
  BBIDMap IDMap, BEMap;
  std::deque<const BasicBlock*> Q;
  unsigned waveNo;

  void init (const Function &F){
    //Intialize the color map.
    unsigned K = 0;
    for (Function::const_iterator I = F.begin(), IE = F.end(); I != IE; I++, K++){
      ColorMap[I] = WaveScalar::WHITE;
      IDMap[I] = K;
      const BasicBlock *pbb = &*I;
      BasicBlock *pp = const_cast<BasicBlock*>(pbb);
      setLabel(&pp, K);
      BEMap[I] = 1;
    }
  }

  void setBackEdges (const Function &F, SmallVectorImpl<std::pair<const BasicBlock*, const BasicBlock*> > *res){
    FindFunctionBackedges(F, *res);
    while (!res->empty()){
      std::pair<const BasicBlock*, const BasicBlock*> tempPair = res->pop_back_val();
      BEMap[tempPair.first] = 0;
      BEMap[tempPair.second] = 0;
    }
  }

  void setLabel(BasicBlock **succ, unsigned k){
    std::stringstream ss;
    ss << k;
    std::string str = ss.str();
    (*succ)->setName(str);
  }
};

/*
  Wave class for waves pass. The main task of this pass is to annotate waves in
  a control flow graph.
*/
struct Waves : public FunctionPass, public SmallVectorImpl <std::pair<const BasicBlock*, const BasicBlock*> > {
  static char ID;
  Waves() : FunctionPass(ID), SmallVectorImpl(10){}

  bool runOnFunction(Function &F) {
    if (F.getName() == "main")
      return false;
    outs() << "Basic blocks of function " << F.getName() << "\n";

    SmallVectorImpl<std::pair<const BasicBlock*, const BasicBlock*> > *res = this;
    WaveScalar obj;
    obj.annotateWaves(F, res);
    F.viewCFGOnly();

    return false;
  }
};

char Waves::ID = 0;
static RegisterPass<Waves> X("annotate", "Annotate Waves", false, false);
<|endoftext|>


<commit_before>// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/display/cursor_window_controller.h"

#include "ash/display/display_controller.h"
#include "ash/display/mirror_window_controller.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ui/aura/env.h"
#include "ui/aura/window_delegate.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/base/cursor/cursors_aura.h"
#include "ui/base/hit_test.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/compositor/dip_util.h"
#include "ui/compositor/paint_context.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/display.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_operations.h"

namespace ash {

class CursorWindowDelegate : public aura::WindowDelegate {
 public:
  CursorWindowDelegate() : is_cursor_compositing_enabled_(false) {}
  ~CursorWindowDelegate() override {}

  // aura::WindowDelegate overrides:
  gfx::Size GetMinimumSize() const override { return size_; }
  gfx::Size GetMaximumSize() const override { return size_; }
  void OnBoundsChanged(const gfx::Rect& old_bounds,
                       const gfx::Rect& new_bounds) override {}
  ui::TextInputClient* GetFocusedTextInputClient() override { return nullptr; }
  gfx::NativeCursor GetCursor(const gfx::Point& point) override {
    return gfx::kNullCursor;
  }
  int GetNonClientComponent(const gfx::Point& point) const override {
    return HTNOWHERE;
  }
  bool ShouldDescendIntoChildForEventHandling(
      aura::Window* child,
      const gfx::Point& location) override {
    return false;
  }
  bool CanFocus() override { return false; }
  void OnCaptureLost() override {}
  void OnPaint(const ui::PaintContext& context) override {
    context.canvas()->DrawImageInt(cursor_image_, 0, 0);
  }
  void OnDeviceScaleFactorChanged(float device_scale_factor) override {}
  void OnWindowDestroying(aura::Window* window) override {}
  void OnWindowDestroyed(aura::Window* window) override {}
  void OnWindowTargetVisibilityChanged(bool visible) override {}
  bool HasHitTestMask() const override { return false; }
  void GetHitTestMask(gfx::Path* mask) const override {}

  // Sets cursor compositing mode on/off.
  void SetCursorCompositingEnabled(bool enabled) {
    is_cursor_compositing_enabled_ = enabled;
  }

  // Sets the cursor image for the |display|'s scale factor.
  void SetCursorImage(const gfx::ImageSkia& image,
                      const gfx::Display& display) {
    float scale_factor = display.device_scale_factor();
    const gfx::ImageSkiaRep& image_rep = image.GetRepresentation(scale_factor);
    if (!is_cursor_compositing_enabled_) {
      // Note that mirror window's scale factor is always 1.0f, therefore we
      // need to take 2x's image and paint as if it's 1x image.
      size_ = image_rep.pixel_size();
      cursor_image_ = gfx::ImageSkia::CreateFrom1xBitmap(image_rep.sk_bitmap());
    } else {
      size_ = image.size();
      cursor_image_ = gfx::ImageSkia(
          gfx::ImageSkiaRep(image_rep.sk_bitmap(), scale_factor));
    }
  }

  const gfx::Size size() const { return size_; }

 private:
  bool is_cursor_compositing_enabled_;
  gfx::ImageSkia cursor_image_;
  gfx::Size size_;

  DISALLOW_COPY_AND_ASSIGN(CursorWindowDelegate);
};

CursorWindowController::CursorWindowController()
    : is_cursor_compositing_enabled_(false),
      container_(NULL),
      cursor_type_(ui::kCursorNone),
      visible_(true),
      cursor_set_(ui::CURSOR_SET_NORMAL),
      delegate_(new CursorWindowDelegate()) {
}

CursorWindowController::~CursorWindowController() {
  SetContainer(NULL);
}

void CursorWindowController::SetCursorCompositingEnabled(bool enabled) {
  if (is_cursor_compositing_enabled_ != enabled) {
    is_cursor_compositing_enabled_ = enabled;
    delegate_->SetCursorCompositingEnabled(enabled);
    UpdateCursorImage();
    UpdateContainer();
  }
}

void CursorWindowController::UpdateContainer() {
  if (is_cursor_compositing_enabled_) {
    gfx::Screen* screen = Shell::GetScreen();
    gfx::Display display = screen->GetDisplayNearestPoint(
        screen->GetCursorScreenPoint());
    DCHECK(display.is_valid());
    if (display.is_valid())
      SetDisplay(display);
  } else {
    aura::Window* mirror_window = Shell::GetInstance()->
        display_controller()->
        mirror_window_controller()->
        GetWindow();
    if (mirror_window)
      display_ = Shell::GetScreen()->GetPrimaryDisplay();
    SetContainer(mirror_window);
  }
  // Updates the hot point based on the current display.
  UpdateCursorImage();
}

void CursorWindowController::SetDisplay(const gfx::Display& display) {
  if (!is_cursor_compositing_enabled_)
    return;

  display_ = display;
  aura::Window* root_window = Shell::GetInstance()->display_controller()->
      GetRootWindowForDisplayId(display.id());
  if (!root_window)
    return;

  SetContainer(GetRootWindowController(root_window)->GetContainer(
      kShellWindowId_MouseCursorContainer));
  SetBoundsInScreen(display.bounds());
  // Updates the hot point based on the current display.
  UpdateCursorImage();
}

void CursorWindowController::UpdateLocation() {
  if (!cursor_window_)
    return;
  gfx::Point point = aura::Env::GetInstance()->last_mouse_location();
  if (!is_cursor_compositing_enabled_) {
    Shell::GetPrimaryRootWindow()->GetHost()->ConvertPointToHost(&point);
  } else {
    point.Offset(-bounds_in_screen_.x(), -bounds_in_screen_.y());
  }
  point.Offset(-hot_point_.x(), -hot_point_.y());
  gfx::Rect bounds = cursor_window_->bounds();
  bounds.set_origin(point);
  cursor_window_->SetBounds(bounds);
}

void CursorWindowController::SetCursor(gfx::NativeCursor cursor) {
  if (cursor_type_ == cursor.native_type())
    return;
  cursor_type_ = cursor.native_type();
  UpdateCursorImage();
  UpdateCursorVisibility();
}

void CursorWindowController::SetCursorSet(ui::CursorSetType cursor_set) {
  cursor_set_ = cursor_set;
  UpdateCursorImage();
}

void CursorWindowController::SetVisibility(bool visible) {
  if (!cursor_window_)
    return;
  visible_ = visible;
  UpdateCursorVisibility();
}

void CursorWindowController::SetContainer(aura::Window* container) {
  if (container_ == container)
    return;
  container_ = container;
  if (!container) {
    cursor_window_.reset();
    return;
  }

  // Reusing the window does not work when the display is disconnected.
  // Just creates a new one instead. crbug.com/384218.
  cursor_window_.reset(new aura::Window(delegate_.get()));
  cursor_window_->SetTransparent(true);
  cursor_window_->Init(ui::LAYER_TEXTURED);
  cursor_window_->set_ignore_events(true);
  cursor_window_->set_owned_by_parent(false);
  // Call UpdateCursorImage() to figure out |cursor_window_|'s desired size.
  UpdateCursorImage();

  container->AddChild(cursor_window_.get());
  UpdateCursorVisibility();
  SetBoundsInScreen(container->bounds());
}

void CursorWindowController::SetBoundsInScreen(const gfx::Rect& bounds) {
  bounds_in_screen_ = bounds;
  UpdateLocation();
}

void CursorWindowController::UpdateCursorImage() {
  int resource_id;
  // TODO(hshi): support custom cursor set.
  if (!ui::GetCursorDataFor(cursor_set_,
                            cursor_type_,
                            display_.device_scale_factor(),
                            &resource_id,
                            &hot_point_)) {
    return;
  }
  const gfx::ImageSkia* image =
      ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id);
  gfx::ImageSkia rotated = *image;
  if (!is_cursor_compositing_enabled_) {
    switch (display_.rotation()) {
      case gfx::Display::ROTATE_0:
        break;
      case gfx::Display::ROTATE_90:
        rotated = gfx::ImageSkiaOperations::CreateRotatedImage(
            *image, SkBitmapOperations::ROTATION_90_CW);
        hot_point_.SetPoint(
            rotated.width() - hot_point_.y(),
            hot_point_.x());
        break;
      case gfx::Display::ROTATE_180:
        rotated = gfx::ImageSkiaOperations::CreateRotatedImage(
            *image, SkBitmapOperations::ROTATION_180_CW);
        hot_point_.SetPoint(
            rotated.height() - hot_point_.x(),
            rotated.width() - hot_point_.y());
        break;
      case gfx::Display::ROTATE_270:
        rotated = gfx::ImageSkiaOperations::CreateRotatedImage(
            *image, SkBitmapOperations::ROTATION_270_CW);
        hot_point_.SetPoint(
            hot_point_.y(),
            rotated.height() - hot_point_.x());
        break;
    }
  } else {
    hot_point_ = ui::ConvertPointToDIP(Shell::GetPrimaryRootWindow()->layer(),
                                       hot_point_);
  }
  delegate_->SetCursorImage(rotated, display_);
  if (cursor_window_) {
    cursor_window_->SetBounds(gfx::Rect(delegate_->size()));
    cursor_window_->SchedulePaintInRect(
        gfx::Rect(cursor_window_->bounds().size()));
    UpdateLocation();
  }
}

void CursorWindowController::UpdateCursorVisibility() {
  if (!cursor_window_)
    return;
  bool visible = (visible_ && cursor_type_ != ui::kCursorNone);
  if (visible)
    cursor_window_->Show();
  else
    cursor_window_->Hide();
}

}  // namespace ash
<commit_msg>ash: Use PaintRecorder in CursorWindowDelegate<commit_after>// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/display/cursor_window_controller.h"

#include "ash/display/display_controller.h"
#include "ash/display/mirror_window_controller.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ui/aura/env.h"
#include "ui/aura/window_delegate.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/base/cursor/cursors_aura.h"
#include "ui/base/hit_test.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/compositor/dip_util.h"
#include "ui/compositor/paint_context.h"
#include "ui/compositor/paint_recorder.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/display.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_operations.h"

namespace ash {

class CursorWindowDelegate : public aura::WindowDelegate {
 public:
  CursorWindowDelegate() : is_cursor_compositing_enabled_(false) {}
  ~CursorWindowDelegate() override {}

  // aura::WindowDelegate overrides:
  gfx::Size GetMinimumSize() const override { return size_; }
  gfx::Size GetMaximumSize() const override { return size_; }
  void OnBoundsChanged(const gfx::Rect& old_bounds,
                       const gfx::Rect& new_bounds) override {}
  ui::TextInputClient* GetFocusedTextInputClient() override { return nullptr; }
  gfx::NativeCursor GetCursor(const gfx::Point& point) override {
    return gfx::kNullCursor;
  }
  int GetNonClientComponent(const gfx::Point& point) const override {
    return HTNOWHERE;
  }
  bool ShouldDescendIntoChildForEventHandling(
      aura::Window* child,
      const gfx::Point& location) override {
    return false;
  }
  bool CanFocus() override { return false; }
  void OnCaptureLost() override {}
  void OnPaint(const ui::PaintContext& context) override {
    // No need to cache the output here, the CursorWindow is not invalidated.
    ui::PaintRecorder recorder(context);
    recorder.canvas()->DrawImageInt(cursor_image_, 0, 0);
  }
  void OnDeviceScaleFactorChanged(float device_scale_factor) override {}
  void OnWindowDestroying(aura::Window* window) override {}
  void OnWindowDestroyed(aura::Window* window) override {}
  void OnWindowTargetVisibilityChanged(bool visible) override {}
  bool HasHitTestMask() const override { return false; }
  void GetHitTestMask(gfx::Path* mask) const override {}

  // Sets cursor compositing mode on/off.
  void SetCursorCompositingEnabled(bool enabled) {
    is_cursor_compositing_enabled_ = enabled;
  }

  // Sets the cursor image for the |display|'s scale factor.
  void SetCursorImage(const gfx::ImageSkia& image,
                      const gfx::Display& display) {
    float scale_factor = display.device_scale_factor();
    const gfx::ImageSkiaRep& image_rep = image.GetRepresentation(scale_factor);
    if (!is_cursor_compositing_enabled_) {
      // Note that mirror window's scale factor is always 1.0f, therefore we
      // need to take 2x's image and paint as if it's 1x image.
      size_ = image_rep.pixel_size();
      cursor_image_ = gfx::ImageSkia::CreateFrom1xBitmap(image_rep.sk_bitmap());
    } else {
      size_ = image.size();
      cursor_image_ = gfx::ImageSkia(
          gfx::ImageSkiaRep(image_rep.sk_bitmap(), scale_factor));
    }
  }

  const gfx::Size size() const { return size_; }

 private:
  bool is_cursor_compositing_enabled_;
  gfx::ImageSkia cursor_image_;
  gfx::Size size_;

  DISALLOW_COPY_AND_ASSIGN(CursorWindowDelegate);
};

CursorWindowController::CursorWindowController()
    : is_cursor_compositing_enabled_(false),
      container_(NULL),
      cursor_type_(ui::kCursorNone),
      visible_(true),
      cursor_set_(ui::CURSOR_SET_NORMAL),
      delegate_(new CursorWindowDelegate()) {
}

CursorWindowController::~CursorWindowController() {
  SetContainer(NULL);
}

void CursorWindowController::SetCursorCompositingEnabled(bool enabled) {
  if (is_cursor_compositing_enabled_ != enabled) {
    is_cursor_compositing_enabled_ = enabled;
    delegate_->SetCursorCompositingEnabled(enabled);
    UpdateCursorImage();
    UpdateContainer();
  }
}

void CursorWindowController::UpdateContainer() {
  if (is_cursor_compositing_enabled_) {
    gfx::Screen* screen = Shell::GetScreen();
    gfx::Display display = screen->GetDisplayNearestPoint(
        screen->GetCursorScreenPoint());
    DCHECK(display.is_valid());
    if (display.is_valid())
      SetDisplay(display);
  } else {
    aura::Window* mirror_window = Shell::GetInstance()->
        display_controller()->
        mirror_window_controller()->
        GetWindow();
    if (mirror_window)
      display_ = Shell::GetScreen()->GetPrimaryDisplay();
    SetContainer(mirror_window);
  }
  // Updates the hot point based on the current display.
  UpdateCursorImage();
}

void CursorWindowController::SetDisplay(const gfx::Display& display) {
  if (!is_cursor_compositing_enabled_)
    return;

  display_ = display;
  aura::Window* root_window = Shell::GetInstance()->display_controller()->
      GetRootWindowForDisplayId(display.id());
  if (!root_window)
    return;

  SetContainer(GetRootWindowController(root_window)->GetContainer(
      kShellWindowId_MouseCursorContainer));
  SetBoundsInScreen(display.bounds());
  // Updates the hot point based on the current display.
  UpdateCursorImage();
}

void CursorWindowController::UpdateLocation() {
  if (!cursor_window_)
    return;
  gfx::Point point = aura::Env::GetInstance()->last_mouse_location();
  if (!is_cursor_compositing_enabled_) {
    Shell::GetPrimaryRootWindow()->GetHost()->ConvertPointToHost(&point);
  } else {
    point.Offset(-bounds_in_screen_.x(), -bounds_in_screen_.y());
  }
  point.Offset(-hot_point_.x(), -hot_point_.y());
  gfx::Rect bounds = cursor_window_->bounds();
  bounds.set_origin(point);
  cursor_window_->SetBounds(bounds);
}

void CursorWindowController::SetCursor(gfx::NativeCursor cursor) {
  if (cursor_type_ == cursor.native_type())
    return;
  cursor_type_ = cursor.native_type();
  UpdateCursorImage();
  UpdateCursorVisibility();
}

void CursorWindowController::SetCursorSet(ui::CursorSetType cursor_set) {
  cursor_set_ = cursor_set;
  UpdateCursorImage();
}

void CursorWindowController::SetVisibility(bool visible) {
  if (!cursor_window_)
    return;
  visible_ = visible;
  UpdateCursorVisibility();
}

void CursorWindowController::SetContainer(aura::Window* container) {
  if (container_ == container)
    return;
  container_ = container;
  if (!container) {
    cursor_window_.reset();
    return;
  }

  // Reusing the window does not work when the display is disconnected.
  // Just creates a new one instead. crbug.com/384218.
  cursor_window_.reset(new aura::Window(delegate_.get()));
  cursor_window_->SetTransparent(true);
  cursor_window_->Init(ui::LAYER_TEXTURED);
  cursor_window_->set_ignore_events(true);
  cursor_window_->set_owned_by_parent(false);
  // Call UpdateCursorImage() to figure out |cursor_window_|'s desired size.
  UpdateCursorImage();

  container->AddChild(cursor_window_.get());
  UpdateCursorVisibility();
  SetBoundsInScreen(container->bounds());
}

void CursorWindowController::SetBoundsInScreen(const gfx::Rect& bounds) {
  bounds_in_screen_ = bounds;
  UpdateLocation();
}

void CursorWindowController::UpdateCursorImage() {
  int resource_id;
  // TODO(hshi): support custom cursor set.
  if (!ui::GetCursorDataFor(cursor_set_,
                            cursor_type_,
                            display_.device_scale_factor(),
                            &resource_id,
                            &hot_point_)) {
    return;
  }
  const gfx::ImageSkia* image =
      ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id);
  gfx::ImageSkia rotated = *image;
  if (!is_cursor_compositing_enabled_) {
    switch (display_.rotation()) {
      case gfx::Display::ROTATE_0:
        break;
      case gfx::Display::ROTATE_90:
        rotated = gfx::ImageSkiaOperations::CreateRotatedImage(
            *image, SkBitmapOperations::ROTATION_90_CW);
        hot_point_.SetPoint(
            rotated.width() - hot_point_.y(),
            hot_point_.x());
        break;
      case gfx::Display::ROTATE_180:
        rotated = gfx::ImageSkiaOperations::CreateRotatedImage(
            *image, SkBitmapOperations::ROTATION_180_CW);
        hot_point_.SetPoint(
            rotated.height() - hot_point_.x(),
            rotated.width() - hot_point_.y());
        break;
      case gfx::Display::ROTATE_270:
        rotated = gfx::ImageSkiaOperations::CreateRotatedImage(
            *image, SkBitmapOperations::ROTATION_270_CW);
        hot_point_.SetPoint(
            hot_point_.y(),
            rotated.height() - hot_point_.x());
        break;
    }
  } else {
    hot_point_ = ui::ConvertPointToDIP(Shell::GetPrimaryRootWindow()->layer(),
                                       hot_point_);
  }
  delegate_->SetCursorImage(rotated, display_);
  if (cursor_window_) {
    cursor_window_->SetBounds(gfx::Rect(delegate_->size()));
    cursor_window_->SchedulePaintInRect(
        gfx::Rect(cursor_window_->bounds().size()));
    UpdateLocation();
  }
}

void CursorWindowController::UpdateCursorVisibility() {
  if (!cursor_window_)
    return;
  bool visible = (visible_ && cursor_type_ != ui::kCursorNone);
  if (visible)
    cursor_window_->Show();
  else
    cursor_window_->Hide();
}

}  // namespace ash
<|endoftext|>


<commit_before><commit_msg>#i119884# Fixed export of fontwork alignment.<commit_after><|endoftext|>


<commit_before>/***********************************************************************
filename:   CEGuiGLFWSharedBase.cpp
created:    12/2/2012
author:     Paul D Turner
*************************************************************************/
/***************************************************************************
*   Copyright (C) 2004 - 2012 Paul D Turner & The CEGUI Development Team
*
*   Permission is hereby granted, free of charge, to any person obtaining
*   a copy of this software and associated documentation files (the
*   "Software"), to deal in the Software without restriction, including
*   without limitation the rights to use, copy, modify, merge, publish,
*   distribute, sublicense, and/or sell copies of the Software, and to
*   permit persons to whom the Software is furnished to do so, subject to
*   the following conditions:
*
*   The above copyright notice and this permission notice shall be
*   included in all copies or substantial portions of the Software.
*
*   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
*   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
*   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
*   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
*   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
*   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
*   OTHER DEALINGS IN THE SOFTWARE.
***************************************************************************/
#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__HAIKU__)
# include <unistd.h>
#endif

#include "CEGUISamplesConfig.h"
#include "CEGuiGLFWSharedBase.h"
#include "SamplesFrameworkBase.h"
#include "CEGUI/CEGUI.h"

#include <stdexcept>
#include <sstream>

//----------------------------------------------------------------------------//
CEGuiGLFWSharedBase* CEGuiGLFWSharedBase::d_appInstance = 0;
double  CEGuiGLFWSharedBase::d_frameTime = 0;
int CEGuiGLFWSharedBase::d_modifiers = 0;
bool CEGuiGLFWSharedBase::d_windowSized = false;
int CEGuiGLFWSharedBase::d_newWindowWidth;
int CEGuiGLFWSharedBase::d_newWindowHeight;

//----------------------------------------------------------------------------//
CEGuiGLFWSharedBase::CEGuiGLFWSharedBase()
{
    if (d_appInstance)
        throw CEGUI::InvalidRequestException(
        "CEGuiGLFWSharedBase instance already exists!");

    d_appInstance = this;
}

//----------------------------------------------------------------------------//
CEGuiGLFWSharedBase::~CEGuiGLFWSharedBase()
{
}

//----------------------------------------------------------------------------//
void CEGuiGLFWSharedBase::run()
{
    d_sampleApp->initialise();

    // Input callbacks of glfw for CEGUI
    glfwSetKeyCallback(glfwKeyCallback);
    glfwSetCharCallback(glfwCharCallback);
    glfwSetMouseButtonCallback(glfwMouseButtonCallback);
    glfwSetMouseWheelCallback(glfwMouseWheelCallback);
    glfwSetMousePosCallback(glfwMousePosCallback);

    //Window callbacks
    glfwSetWindowSizeCallback(glfwWindowResizeCallback);
    d_windowSized = false; //The resize callback is being called immediately after setting it in this version of glfw
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    // set starting time
    d_frameTime = glfwGetTime();

    while (!d_sampleApp->isQuitting() &&
        glfwGetWindowParam(GLFW_OPENED))
    {
        if (d_windowSized)
        {
            d_windowSized = false;
            CEGUI::System::getSingleton().
                notifyDisplaySizeChanged(
                CEGUI::Sizef(static_cast<float>(d_newWindowWidth),
                static_cast<float>(d_newWindowHeight)));
        }

        drawFrame();
    }

    d_sampleApp->deinitialise();
}
//----------------------------------------------------------------------------//
void CEGuiGLFWSharedBase::destroyWindow()
{
    glfwTerminate();
}

//----------------------------------------------------------------------------//
void CEGuiGLFWSharedBase::beginRendering(const float /*elapsed*/)
{
    glClear(GL_COLOR_BUFFER_BIT);
}

//----------------------------------------------------------------------------//
void CEGuiGLFWSharedBase::endRendering()
{
    glfwSwapBuffers();
}

//----------------------------------------------------------------------------//
void CEGuiGLFWSharedBase::drawFrame()
{
    // calculate time elapsed since last frame
    double time_now = glfwGetTime();
    const double elapsed = time_now - d_frameTime;
    d_frameTime = time_now;

    d_appInstance->renderSingleFrame(static_cast<float>(elapsed));
}

//----------------------------------------------------------------------------//
void CEGuiGLFWSharedBase::glfwWindowResizeCallback(int w, int h)
{
    // We cache this in order to minimise calls to notifyDisplaySizeChanged,
    // which happens in the main loop whenever d_windowSized is set to true.
    d_windowSized = true;
    d_newWindowWidth = w;
    d_newWindowHeight = h;
}

//----------------------------------------------------------------------------//
CEGUI::Key::Scan CEGuiGLFWSharedBase::GlfwToCeguiKey(int glfwKey)
{
    switch(glfwKey)
    {
    case GLFW_KEY_ESC       : return CEGUI::Key::Escape;
    case GLFW_KEY_F1        : return CEGUI::Key::F1;
    case GLFW_KEY_F2        : return CEGUI::Key::F2;
    case GLFW_KEY_F3        : return CEGUI::Key::F3;
    case GLFW_KEY_F4        : return CEGUI::Key::F4;
    case GLFW_KEY_F5        : return CEGUI::Key::F5;
    case GLFW_KEY_F6        : return CEGUI::Key::F6;
    case GLFW_KEY_F7        : return CEGUI::Key::F7;
    case GLFW_KEY_F8        : return CEGUI::Key::F8;
    case GLFW_KEY_F9        : return CEGUI::Key::F9;
    case GLFW_KEY_F10       : return CEGUI::Key::F10;
    case GLFW_KEY_F11       : return CEGUI::Key::F11;
    case GLFW_KEY_F12       : return CEGUI::Key::F12;
    case GLFW_KEY_F13       : return CEGUI::Key::F13;
    case GLFW_KEY_F14       : return CEGUI::Key::F14;
    case GLFW_KEY_F15       : return CEGUI::Key::F15;
    case GLFW_KEY_UP        : return CEGUI::Key::ArrowUp;
    case GLFW_KEY_DOWN      : return CEGUI::Key::ArrowDown;
    case GLFW_KEY_LEFT      : return CEGUI::Key::ArrowLeft;
    case GLFW_KEY_RIGHT     : return CEGUI::Key::ArrowRight;
    case GLFW_KEY_LSHIFT    : return CEGUI::Key::LeftShift;
    case GLFW_KEY_RSHIFT    : return CEGUI::Key::RightShift;
    case GLFW_KEY_LCTRL     : return CEGUI::Key::LeftControl;
    case GLFW_KEY_RCTRL     : return CEGUI::Key::RightControl;
    case GLFW_KEY_LALT      : return CEGUI::Key::LeftAlt;
    case GLFW_KEY_RALT      : return CEGUI::Key::RightAlt;
    case GLFW_KEY_TAB       : return CEGUI::Key::Tab;
    case GLFW_KEY_ENTER     : return CEGUI::Key::Return;
    case GLFW_KEY_BACKSPACE : return CEGUI::Key::Backspace;
    case GLFW_KEY_INSERT    : return CEGUI::Key::Insert;
    case GLFW_KEY_DEL       : return CEGUI::Key::Delete;
    case GLFW_KEY_PAGEUP    : return CEGUI::Key::PageUp;
    case GLFW_KEY_PAGEDOWN  : return CEGUI::Key::PageDown;
    case GLFW_KEY_HOME      : return CEGUI::Key::Home;
    case GLFW_KEY_END       : return CEGUI::Key::End;
    case GLFW_KEY_KP_ENTER  : return CEGUI::Key::NumpadEnter;
    default                 : return CEGUI::Key::Unknown;
    }
}

//----------------------------------------------------------------------------//
CEGUI::MouseButton CEGuiGLFWSharedBase::GlfwToCeguiMouseButton(int glfwButton)
{
    switch(glfwButton)
    {
    case GLFW_MOUSE_BUTTON_LEFT     : return CEGUI::LeftButton;
    case GLFW_MOUSE_BUTTON_RIGHT    : return CEGUI::RightButton;
    case GLFW_MOUSE_BUTTON_MIDDLE   : return CEGUI::MiddleButton;
    default                         : return CEGUI::NoButton;
    }
}

//----------------------------------------------------------------------------//
void GLFWCALL CEGuiGLFWSharedBase::glfwKeyCallback(int key, int action)
{
    CEGUI::Key::Scan ceguiKey = GlfwToCeguiKey(key);

    if(action == GLFW_PRESS)
        d_sampleApp->injectKeyDown(ceguiKey);
    else if (action == GLFW_RELEASE)
        d_sampleApp->injectKeyUp(ceguiKey);
}

//----------------------------------------------------------------------------//
void GLFWCALL CEGuiGLFWSharedBase::glfwCharCallback(int character, int action)
{
    if(action == GLFW_PRESS)
        d_sampleApp->injectChar(character);
}

//----------------------------------------------------------------------------//
void GLFWCALL CEGuiGLFWSharedBase::glfwMouseButtonCallback(int key, int action)
{
    CEGUI::MouseButton ceguiMouseButton = GlfwToCeguiMouseButton(key);

    if(action == GLFW_PRESS)
        d_sampleApp->injectMouseButtonDown(ceguiMouseButton);
    else if (action == GLFW_RELEASE)
        d_sampleApp->injectMouseButtonUp(ceguiMouseButton);
}

//----------------------------------------------------------------------------//
void GLFWCALL CEGuiGLFWSharedBase::glfwMouseWheelCallback(int position)
{
    static int lastPosition = 0;
    d_sampleApp->injectMouseWheelChange(static_cast<float>(position - lastPosition));
    lastPosition = position;
}

//----------------------------------------------------------------------------//
void GLFWCALL CEGuiGLFWSharedBase::glfwMousePosCallback(int x, int y)
{
    d_sampleApp->injectMousePosition(static_cast<float>(x), static_cast<float>(y));
}

//----------------------------------------------------------------------------//
void CEGuiGLFWSharedBase::initGLFW()
{
    if(!glfwInit())
        CEGUI_THROW(CEGUI::RendererException("Failed to initialise GLFW."));
}

//----------------------------------------------------------------------------//
void CEGuiGLFWSharedBase::createGLFWWindow()
{
    if (glfwOpenWindow(s_defaultWindowWidth, s_defaultWindowHeight, 0, 0, 0, 0, 24, 8, GLFW_WINDOW) != GL_TRUE)
    {
        CEGUI_THROW(CEGUI::RendererException("Failed to open GLFW window."));
        glfwTerminate();
    }
}

//----------------------------------------------------------------------------//
void CEGuiGLFWSharedBase::setGLFWAppConfiguration()
{
    glfwSetWindowTitle("Crazy Eddie's GUI Mk-2 - Sample Application");

    //Deactivate VSYNC
    glfwSwapInterval(0);

    // Disable the mouse position in Non_Debug mode
#ifndef DEBUG
    glfwDisable(GLFW_MOUSE_CURSOR);
#endif
    // Clear Errors by GLFW, even if Setup is correct.
    glGetError();
}

//----------------------------------------------------------------------------//

<commit_msg>Properly convert from 'GLFW_KEY_SPACE' to 'CEGUI::Key::Space' in the samples.<commit_after>/***********************************************************************
filename:   CEGuiGLFWSharedBase.cpp
created:    12/2/2012
author:     Paul D Turner
*************************************************************************/
/***************************************************************************
*   Copyright (C) 2004 - 2012 Paul D Turner & The CEGUI Development Team
*
*   Permission is hereby granted, free of charge, to any person obtaining
*   a copy of this software and associated documentation files (the
*   "Software"), to deal in the Software without restriction, including
*   without limitation the rights to use, copy, modify, merge, publish,
*   distribute, sublicense, and/or sell copies of the Software, and to
*   permit persons to whom the Software is furnished to do so, subject to
*   the following conditions:
*
*   The above copyright notice and this permission notice shall be
*   included in all copies or substantial portions of the Software.
*
*   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
*   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
*   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
*   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
*   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
*   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
*   OTHER DEALINGS IN THE SOFTWARE.
***************************************************************************/
#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__HAIKU__)
# include <unistd.h>
#endif

#include "CEGUISamplesConfig.h"
#include "CEGuiGLFWSharedBase.h"
#include "SamplesFrameworkBase.h"
#include "CEGUI/CEGUI.h"

#include <stdexcept>
#include <sstream>

//----------------------------------------------------------------------------//
CEGuiGLFWSharedBase* CEGuiGLFWSharedBase::d_appInstance = 0;
double  CEGuiGLFWSharedBase::d_frameTime = 0;
int CEGuiGLFWSharedBase::d_modifiers = 0;
bool CEGuiGLFWSharedBase::d_windowSized = false;
int CEGuiGLFWSharedBase::d_newWindowWidth;
int CEGuiGLFWSharedBase::d_newWindowHeight;

//----------------------------------------------------------------------------//
CEGuiGLFWSharedBase::CEGuiGLFWSharedBase()
{
    if (d_appInstance)
        throw CEGUI::InvalidRequestException(
        "CEGuiGLFWSharedBase instance already exists!");

    d_appInstance = this;
}

//----------------------------------------------------------------------------//
CEGuiGLFWSharedBase::~CEGuiGLFWSharedBase()
{
}

//----------------------------------------------------------------------------//
void CEGuiGLFWSharedBase::run()
{
    d_sampleApp->initialise();

    // Input callbacks of glfw for CEGUI
    glfwSetKeyCallback(glfwKeyCallback);
    glfwSetCharCallback(glfwCharCallback);
    glfwSetMouseButtonCallback(glfwMouseButtonCallback);
    glfwSetMouseWheelCallback(glfwMouseWheelCallback);
    glfwSetMousePosCallback(glfwMousePosCallback);

    //Window callbacks
    glfwSetWindowSizeCallback(glfwWindowResizeCallback);
    d_windowSized = false; //The resize callback is being called immediately after setting it in this version of glfw
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    // set starting time
    d_frameTime = glfwGetTime();

    while (!d_sampleApp->isQuitting() &&
        glfwGetWindowParam(GLFW_OPENED))
    {
        if (d_windowSized)
        {
            d_windowSized = false;
            CEGUI::System::getSingleton().
                notifyDisplaySizeChanged(
                CEGUI::Sizef(static_cast<float>(d_newWindowWidth),
                static_cast<float>(d_newWindowHeight)));
        }

        drawFrame();
    }

    d_sampleApp->deinitialise();
}
//----------------------------------------------------------------------------//
void CEGuiGLFWSharedBase::destroyWindow()
{
    glfwTerminate();
}

//----------------------------------------------------------------------------//
void CEGuiGLFWSharedBase::beginRendering(const float /*elapsed*/)
{
    glClear(GL_COLOR_BUFFER_BIT);
}

//----------------------------------------------------------------------------//
void CEGuiGLFWSharedBase::endRendering()
{
    glfwSwapBuffers();
}

//----------------------------------------------------------------------------//
void CEGuiGLFWSharedBase::drawFrame()
{
    // calculate time elapsed since last frame
    double time_now = glfwGetTime();
    const double elapsed = time_now - d_frameTime;
    d_frameTime = time_now;

    d_appInstance->renderSingleFrame(static_cast<float>(elapsed));
}

//----------------------------------------------------------------------------//
void CEGuiGLFWSharedBase::glfwWindowResizeCallback(int w, int h)
{
    // We cache this in order to minimise calls to notifyDisplaySizeChanged,
    // which happens in the main loop whenever d_windowSized is set to true.
    d_windowSized = true;
    d_newWindowWidth = w;
    d_newWindowHeight = h;
}

//----------------------------------------------------------------------------//
CEGUI::Key::Scan CEGuiGLFWSharedBase::GlfwToCeguiKey(int glfwKey)
{
    switch(glfwKey)
    {
    case GLFW_KEY_ESC       : return CEGUI::Key::Escape;
    case GLFW_KEY_F1        : return CEGUI::Key::F1;
    case GLFW_KEY_F2        : return CEGUI::Key::F2;
    case GLFW_KEY_F3        : return CEGUI::Key::F3;
    case GLFW_KEY_F4        : return CEGUI::Key::F4;
    case GLFW_KEY_F5        : return CEGUI::Key::F5;
    case GLFW_KEY_F6        : return CEGUI::Key::F6;
    case GLFW_KEY_F7        : return CEGUI::Key::F7;
    case GLFW_KEY_F8        : return CEGUI::Key::F8;
    case GLFW_KEY_F9        : return CEGUI::Key::F9;
    case GLFW_KEY_F10       : return CEGUI::Key::F10;
    case GLFW_KEY_F11       : return CEGUI::Key::F11;
    case GLFW_KEY_F12       : return CEGUI::Key::F12;
    case GLFW_KEY_F13       : return CEGUI::Key::F13;
    case GLFW_KEY_F14       : return CEGUI::Key::F14;
    case GLFW_KEY_F15       : return CEGUI::Key::F15;
    case GLFW_KEY_UP        : return CEGUI::Key::ArrowUp;
    case GLFW_KEY_DOWN      : return CEGUI::Key::ArrowDown;
    case GLFW_KEY_LEFT      : return CEGUI::Key::ArrowLeft;
    case GLFW_KEY_RIGHT     : return CEGUI::Key::ArrowRight;
    case GLFW_KEY_LSHIFT    : return CEGUI::Key::LeftShift;
    case GLFW_KEY_RSHIFT    : return CEGUI::Key::RightShift;
    case GLFW_KEY_LCTRL     : return CEGUI::Key::LeftControl;
    case GLFW_KEY_RCTRL     : return CEGUI::Key::RightControl;
    case GLFW_KEY_LALT      : return CEGUI::Key::LeftAlt;
    case GLFW_KEY_RALT      : return CEGUI::Key::RightAlt;
    case GLFW_KEY_TAB       : return CEGUI::Key::Tab;
    case GLFW_KEY_ENTER     : return CEGUI::Key::Return;
    case GLFW_KEY_BACKSPACE : return CEGUI::Key::Backspace;
    case GLFW_KEY_INSERT    : return CEGUI::Key::Insert;
    case GLFW_KEY_DEL       : return CEGUI::Key::Delete;
    case GLFW_KEY_PAGEUP    : return CEGUI::Key::PageUp;
    case GLFW_KEY_PAGEDOWN  : return CEGUI::Key::PageDown;
    case GLFW_KEY_HOME      : return CEGUI::Key::Home;
    case GLFW_KEY_END       : return CEGUI::Key::End;
    case GLFW_KEY_KP_ENTER  : return CEGUI::Key::NumpadEnter;
    case GLFW_KEY_SPACE     : return CEGUI::Key::Space;
    default                 : return CEGUI::Key::Unknown;
    }
}

//----------------------------------------------------------------------------//
CEGUI::MouseButton CEGuiGLFWSharedBase::GlfwToCeguiMouseButton(int glfwButton)
{
    switch(glfwButton)
    {
    case GLFW_MOUSE_BUTTON_LEFT     : return CEGUI::LeftButton;
    case GLFW_MOUSE_BUTTON_RIGHT    : return CEGUI::RightButton;
    case GLFW_MOUSE_BUTTON_MIDDLE   : return CEGUI::MiddleButton;
    default                         : return CEGUI::NoButton;
    }
}

//----------------------------------------------------------------------------//
void GLFWCALL CEGuiGLFWSharedBase::glfwKeyCallback(int key, int action)
{
    CEGUI::Key::Scan ceguiKey = GlfwToCeguiKey(key);

    if(action == GLFW_PRESS)
        d_sampleApp->injectKeyDown(ceguiKey);
    else if (action == GLFW_RELEASE)
        d_sampleApp->injectKeyUp(ceguiKey);
}

//----------------------------------------------------------------------------//
void GLFWCALL CEGuiGLFWSharedBase::glfwCharCallback(int character, int action)
{
    if(action == GLFW_PRESS)
        d_sampleApp->injectChar(character);
}

//----------------------------------------------------------------------------//
void GLFWCALL CEGuiGLFWSharedBase::glfwMouseButtonCallback(int key, int action)
{
    CEGUI::MouseButton ceguiMouseButton = GlfwToCeguiMouseButton(key);

    if(action == GLFW_PRESS)
        d_sampleApp->injectMouseButtonDown(ceguiMouseButton);
    else if (action == GLFW_RELEASE)
        d_sampleApp->injectMouseButtonUp(ceguiMouseButton);
}

//----------------------------------------------------------------------------//
void GLFWCALL CEGuiGLFWSharedBase::glfwMouseWheelCallback(int position)
{
    static int lastPosition = 0;
    d_sampleApp->injectMouseWheelChange(static_cast<float>(position - lastPosition));
    lastPosition = position;
}

//----------------------------------------------------------------------------//
void GLFWCALL CEGuiGLFWSharedBase::glfwMousePosCallback(int x, int y)
{
    d_sampleApp->injectMousePosition(static_cast<float>(x), static_cast<float>(y));
}

//----------------------------------------------------------------------------//
void CEGuiGLFWSharedBase::initGLFW()
{
    if(!glfwInit())
        CEGUI_THROW(CEGUI::RendererException("Failed to initialise GLFW."));
}

//----------------------------------------------------------------------------//
void CEGuiGLFWSharedBase::createGLFWWindow()
{
    if (glfwOpenWindow(s_defaultWindowWidth, s_defaultWindowHeight, 0, 0, 0, 0, 24, 8, GLFW_WINDOW) != GL_TRUE)
    {
        CEGUI_THROW(CEGUI::RendererException("Failed to open GLFW window."));
        glfwTerminate();
    }
}

//----------------------------------------------------------------------------//
void CEGuiGLFWSharedBase::setGLFWAppConfiguration()
{
    glfwSetWindowTitle("Crazy Eddie's GUI Mk-2 - Sample Application");

    //Deactivate VSYNC
    glfwSwapInterval(0);

    // Disable the mouse position in Non_Debug mode
#ifndef DEBUG
    glfwDisable(GLFW_MOUSE_CURSOR);
#endif
    // Clear Errors by GLFW, even if Setup is correct.
    glGetError();
}

//----------------------------------------------------------------------------//

<|endoftext|>


<commit_before>/*******************************************************************************
 *
 * Filename: ps5000aBlockMSOCon.c
 *
 * Description:
 *   This is a console mode program that demonstrates how to use some of
 *	 the PicoScope 5000 Series (ps5000a) driver API functions to perform Block Mode
 *   on any PS5xxx scope
 *
 *	Supported PicoScope models:
 *
 *		PicoScope 5242D MSO & 5442D MSO
 *		PicoScope 5243D MSO & 5443D MSO
 *		PicoScope 5244D MSO & 5444D MSO
 *
 * Examples:
 *   Collect a block of samples when a trigger event occurs
 *	 Handle power source changes
 *
 *	To build this application:-
 *
 *		If Microsoft Visual Studio (including Express/Community Edition) is being used:
 *
 *			Select the solution configuration (Debug/Release) and platform (x86/x64)
 *			Ensure that the 32-/64-bit ps5000a.lib can be located
 *			Ensure that the ps5000aApi.h and PicoStatus.h files can be located
 *
 *		Otherwise:
 *
 *			 Set up a project for a 32-/64-bit console mode application
 *			 Add this file to the project
 *			 Add ps5000a.lib to the project (Microsoft C only)
 *			 Add ps5000aApi.h and PicoStatus.h to the project
 *			 Build the project
 *
 *  Linux platforms:
 *
 *		Ensure that the libps5000a driver package has been installed using the
 *		instructions from https://www.picotech.com/downloads/linux
 *
 *		Place this file in the same folder as the files from the linux-build-files
 *		folder. Edit the configure.ac and Makefile.am files to use this file.
 *		In a terminal window, use the following commands to build the
 *		ps5000aBlockMSOCon application:
 *
 *			./autogen.sh <ENTER>
 *			make <ENTER>
 *
 * Copyright (C) 2018-2019 Pico Technology Ltd. See LICENSE file for terms.
 *
 ******************************************************************************/

#include <stdio.h>

 /* Headers for Windows */
#ifdef _WIN32
#include "windows.h"
#include <conio.h>
#include <math.h>
#include <vector>
#include <iostream>
#include <fstream>
#include "ps5000aApi.h"

#include "../shared/GenericMethods.h"

using namespace std;

#else
#include <sys/types.h>
#include <string.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>

#include <libps5000a-1.1/ps5000aApi.h>
#ifndef PICO_STATUS
#include <libps5000a-1.1/PicoStatus.h>
#endif

#define Sleep(a) usleep(1000*a)
#define scanf_s scanf
#define fscanf_s fscanf
#define memcpy_s(a,b,c,d) memcpy(a,c,d)

typedef enum enBOOL { FALSE, TRUE } BOOL;

/* A function to detect a keyboard press on Linux */
int32_t _getch()
{
  struct termios oldt, newt;
  int32_t ch;
  int32_t bytesWaiting;
  tcgetattr(STDIN_FILENO, &oldt);
  newt = oldt;
  newt.c_lflag &= ~(ICANON | ECHO);
  tcsetattr(STDIN_FILENO, TCSANOW, &newt);
  setbuf(stdin, NULL);
  do {
    ioctl(STDIN_FILENO, FIONREAD, &bytesWaiting);
    if (bytesWaiting)
      getchar();
  } while (bytesWaiting);

  ch = getchar();

  tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
  return ch;
}

int32_t _kbhit()
{
  struct termios oldt, newt;
  int32_t bytesWaiting;
  tcgetattr(STDIN_FILENO, &oldt);
  newt = oldt;
  newt.c_lflag &= ~(ICANON | ECHO);
  tcsetattr(STDIN_FILENO, TCSANOW, &newt);
  setbuf(stdin, NULL);
  ioctl(STDIN_FILENO, FIONREAD, &bytesWaiting);

  tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
  return bytesWaiting;
}

int32_t fopen_s(FILE** a, const int8_t* b, const int8_t* c)
{
  FILE* fp = fopen(b, c);
  *a = fp;
  return (fp > 0) ? 0 : -1;
}

/* A function to get a single character on Linux */
#define max(a,b) ((a) > (b) ? a : b)
#define min(a,b) ((a) < (b) ? a : b)
#endif

int32_t cycles = 0;

#define QUAD_SCOPE		4
#define DUAL_SCOPE		2

#define MAX_DIGITAL_PORTS 2

#define MAX_PICO_DEVICES 64
#define TIMED_LOOP_STEP 500

// int32_t     g_sampleCount;
// uint32_t		g_startIndex;

#define OBJ
#define STRUCTURED

/****************************************************************************
* main
*
***************************************************************************/
int32_t main(void)
{

  getStatusCode(67);
  getStatusCode();

  // Set the Global Variables
  PICO_STATUS status = PICO_OK;
  int16_t handle = 0;
  bool usbPowered = 0;

  const int32_t NO_OF_SAMPLES = 100;

  // Open PS5XXX unit
  status = ps5000aOpenUnit(&handle, NULL, PS5000A_DEVICE_RESOLUTION::PS5000A_DR_15BIT);
  if (PICO_OK != status) {
    std::cout << "ERROR : Open Unit : " << status << std::endl;
    getStatusCode(status);
  }

  // Manage Power Supply change
  if (PICO_POWER_SUPPLY_NOT_CONNECTED == status) {
    usbPowered = 1;
    status = ps5000aChangePowerSource(handle, status);
  }

  if (PICO_OK != status) {
    std::cout << "ERROR : Open Unit : " << status << std::endl;
    getStatusCode(status);
    return -1;
  }

  // Set the channels to be used
  status = ps5000aSetChannel(handle, PS5000A_CHANNEL_A, 1, PS5000A_DC, PS5000A_1V, 0);
  if (PICO_OK != status) {
    std::cout << "ERROR : Set Channel A : " << status << std::endl;
    return -1;
  }

  status = ps5000aSetChannel(handle, PS5000A_CHANNEL_B, 1, PS5000A_DC, PS5000A_1V, 0);
  if (PICO_OK != status) {
    std::cout << "ERROR : Set Channel B : " << status << std::endl;
    getStatusCode(status);
    return -1;
  }

  if (0 == usbPowered) {
    status = ps5000aSetChannel(handle, PS5000A_CHANNEL_C, 0, PS5000A_DC, PS5000A_1V, 0);
    if (PICO_OK != status) {
      std::cout << "ERROR : Set Channel C : " << status << std::endl;
      getStatusCode(status);
      return -1;
    }

    status = ps5000aSetChannel(handle, PS5000A_CHANNEL_D, 0, PS5000A_DC, PS5000A_1V, 0);
    if (PICO_OK != status) {
      std::cout << "ERROR : Set Channel D : " << status << std::endl;
      getStatusCode(status);
      return -1;
    }
  }

  // Set the Data Buffers for each channels
  int16_t* bufferA = (int16_t*)calloc(NO_OF_SAMPLES, sizeof(int16_t));
  int16_t* bufferB = (int16_t*)calloc(NO_OF_SAMPLES, sizeof(int16_t));
  status = ps5000aSetDataBuffer(handle, PS5000A_CHANNEL_A, bufferA, NO_OF_SAMPLES, 0, PS5000A_RATIO_MODE_NONE);
  if (PICO_OK != status) {
    std::cout << "ERROR : Set Buffer Channel A : " << status << std::endl;
    getStatusCode(status);
    return -1;
  }
  status = ps5000aSetDataBuffer(handle, PS5000A_CHANNEL_B, bufferB, NO_OF_SAMPLES, 0, PS5000A_RATIO_MODE_NONE);
  if (PICO_OK != status) {
    std::cout << "ERROR : Set Buffer Channel B : " << status << std::endl;
    getStatusCode(status);
    return -1;
  }

  // Setup the timebase
  int timeIntervalNS;
  int32_t maxSamples;
  uint32_t TIMEBASE = 4;
  status = ps5000aGetTimebase(handle, TIMEBASE, NO_OF_SAMPLES, &timeIntervalNS, &maxSamples, 0);
  if (PICO_OK != status) {
    std::cout << "ERROR : Set Trigger : " << status << std::endl;
    getStatusCode(status);
    return -1;
  }

  // Set the Trugger
  status = ps5000aSetSimpleTrigger(handle, 1, PS5000A_CHANNEL_A, 10000, PS5000A_THRESHOLD_DIRECTION::PS5000A_RISING, 0, 5000);
  if (PICO_OK != status) {
    std::cout << "ERROR : Set Trigger : " << status << std::endl;
    getStatusCode(status);
    return -1;
  }

  // Generate the signal from the AWG connected to channel A
  status = ps5000aSetSigGenBuiltInV2(handle,
    0,
    1000000,
    PS5000A_SINE,
    100,
    100,
    1,
    1,
    PS5000A_UP,
    PS5000A_ES_OFF,
    0,
    0,
    PS5000A_SIGGEN_RISING,
    PS5000A_SIGGEN_NONE,
    0);
  if (PICO_OK != status) {
    std::cout << "ERROR : AWG Signal Genertion : " << status << std::endl;
    getStatusCode(status);
    return -1;
  }

  // Execute the data acquisition.
  constexpr int32_t NUMBER_OF_CHANNELS = 1;
  auto* timeIndisposedMs = new int32_t(NUMBER_OF_CHANNELS);
  status = ps5000aRunBlock(handle, 10, NO_OF_SAMPLES - 10, TIMEBASE, timeIndisposedMs, 0, NULL, NULL);
  if (PICO_OK != status) {
    std::cout << "ERROR : RunBlock : " << status << std::endl;
    getStatusCode(status);
    return -1;
  }

  // Wait for the Data Acqusition to be completed
  int16_t isReady = 0;
  while (0 == isReady && PICO_OK == status) {
    status = ps5000aIsReady(handle, &isReady);
    std::cout << "PS3 IsReady : " << isReady << std::endl;
    if (PICO_OK != status) {
      std::cout << "Error : IsReady Issue : " << status << std::endl;
      getStatusCode(status);
      return -1;
    }
    Sleep(1);
  }

  // Extract the acquired samples
  int noSamples;
  status = ps5000aGetValues(handle, 0, (uint32_t*)&noSamples, 1, PS5000A_RATIO_MODE_NONE, 0, nullptr);
  if (PICO_OK != status) {
    std::cout << "Error : Get Values Issue : " << status << std::endl;
    getStatusCode(status);
    return -1;
  }

  // Print the extracted samples
  std::cout << "Print Buffer A : " << std::endl;
  for (auto sampleIndex = 0; sampleIndex < noSamples; sampleIndex++)
    std::cout << sampleIndex << ";" << bufferA[sampleIndex] << ";" << adc_to_mv(bufferA[sampleIndex], 7, 32767) << std::endl;

  std::cout << std::endl;
  std::cout << "Print Buffer B : " << std::endl;
  for (auto sampleIndex = 0; sampleIndex < noSamples; sampleIndex++)
    std::cout << sampleIndex << ";" << bufferB[sampleIndex] << ";" << adc_to_mv(bufferB[sampleIndex], 7, 32767) << std::endl;

  // Close the unit.
  status = ps5000aCloseUnit(handle);
  if (PICO_OK != status) {
    std::cout << "Error : Close Unit : " << status << std::endl;
    getStatusCode(status);
    return -1;
  }

  return 0;
}<commit_msg>Use the enum instead of a magic number for the ranges<commit_after>/*******************************************************************************
 *
 * Filename: ps5000aBlockMSOCon.c
 *
 * Description:
 *   This is a console mode program that demonstrates how to use some of
 *	 the PicoScope 5000 Series (ps5000a) driver API functions to perform Block Mode
 *   on any PS5xxx scope
 *
 *	Supported PicoScope models:
 *
 *		PicoScope 5242D MSO & 5442D MSO
 *		PicoScope 5243D MSO & 5443D MSO
 *		PicoScope 5244D MSO & 5444D MSO
 *
 * Examples:
 *   Collect a block of samples when a trigger event occurs
 *	 Handle power source changes
 *
 *	To build this application:-
 *
 *		If Microsoft Visual Studio (including Express/Community Edition) is being used:
 *
 *			Select the solution configuration (Debug/Release) and platform (x86/x64)
 *			Ensure that the 32-/64-bit ps5000a.lib can be located
 *			Ensure that the ps5000aApi.h and PicoStatus.h files can be located
 *
 *		Otherwise:
 *
 *			 Set up a project for a 32-/64-bit console mode application
 *			 Add this file to the project
 *			 Add ps5000a.lib to the project (Microsoft C only)
 *			 Add ps5000aApi.h and PicoStatus.h to the project
 *			 Build the project
 *
 *  Linux platforms:
 *
 *		Ensure that the libps5000a driver package has been installed using the
 *		instructions from https://www.picotech.com/downloads/linux
 *
 *		Place this file in the same folder as the files from the linux-build-files
 *		folder. Edit the configure.ac and Makefile.am files to use this file.
 *		In a terminal window, use the following commands to build the
 *		ps5000aBlockMSOCon application:
 *
 *			./autogen.sh <ENTER>
 *			make <ENTER>
 *
 * Copyright (C) 2018-2019 Pico Technology Ltd. See LICENSE file for terms.
 *
 ******************************************************************************/

#include <stdio.h>

 /* Headers for Windows */
#ifdef _WIN32
#include "windows.h"
#include <conio.h>
#include <math.h>
#include <vector>
#include <iostream>
#include <fstream>
#include "ps5000aApi.h"

#include "../shared/GenericMethods.h"

using namespace std;

#else
#include <sys/types.h>
#include <string.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>

#include <libps5000a-1.1/ps5000aApi.h>
#ifndef PICO_STATUS
#include <libps5000a-1.1/PicoStatus.h>
#endif

#define Sleep(a) usleep(1000*a)
#define scanf_s scanf
#define fscanf_s fscanf
#define memcpy_s(a,b,c,d) memcpy(a,c,d)

typedef enum enBOOL { FALSE, TRUE } BOOL;

/* A function to detect a keyboard press on Linux */
int32_t _getch()
{
  struct termios oldt, newt;
  int32_t ch;
  int32_t bytesWaiting;
  tcgetattr(STDIN_FILENO, &oldt);
  newt = oldt;
  newt.c_lflag &= ~(ICANON | ECHO);
  tcsetattr(STDIN_FILENO, TCSANOW, &newt);
  setbuf(stdin, NULL);
  do {
    ioctl(STDIN_FILENO, FIONREAD, &bytesWaiting);
    if (bytesWaiting)
      getchar();
  } while (bytesWaiting);

  ch = getchar();

  tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
  return ch;
}

int32_t _kbhit()
{
  struct termios oldt, newt;
  int32_t bytesWaiting;
  tcgetattr(STDIN_FILENO, &oldt);
  newt = oldt;
  newt.c_lflag &= ~(ICANON | ECHO);
  tcsetattr(STDIN_FILENO, TCSANOW, &newt);
  setbuf(stdin, NULL);
  ioctl(STDIN_FILENO, FIONREAD, &bytesWaiting);

  tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
  return bytesWaiting;
}

int32_t fopen_s(FILE** a, const int8_t* b, const int8_t* c)
{
  FILE* fp = fopen(b, c);
  *a = fp;
  return (fp > 0) ? 0 : -1;
}

/* A function to get a single character on Linux */
#define max(a,b) ((a) > (b) ? a : b)
#define min(a,b) ((a) < (b) ? a : b)
#endif

int32_t cycles = 0;

#define QUAD_SCOPE		4
#define DUAL_SCOPE		2

#define MAX_DIGITAL_PORTS 2

#define MAX_PICO_DEVICES 64
#define TIMED_LOOP_STEP 500

// int32_t     g_sampleCount;
// uint32_t		g_startIndex;

#define OBJ
#define STRUCTURED

/****************************************************************************
* main
*
***************************************************************************/
int32_t main(void)
{

  getStatusCode(67);
  getStatusCode();

  // Set the Global Variables
  PICO_STATUS status = PICO_OK;
  int16_t handle = 0;
  bool usbPowered = 0;

  const int32_t NO_OF_SAMPLES = 100;

  // Open PS5XXX unit
  status = ps5000aOpenUnit(&handle, NULL, PS5000A_DEVICE_RESOLUTION::PS5000A_DR_15BIT);
  if (PICO_OK != status) {
    std::cout << "ERROR : Open Unit : " << status << std::endl;
    getStatusCode(status);
  }

  // Manage Power Supply change
  if (PICO_POWER_SUPPLY_NOT_CONNECTED == status) {
    usbPowered = 1;
    status = ps5000aChangePowerSource(handle, status);
  }

  if (PICO_OK != status) {
    std::cout << "ERROR : Open Unit : " << status << std::endl;
    getStatusCode(status);
    return -1;
  }

  // Set the channels to be used
  status = ps5000aSetChannel(handle, PS5000A_CHANNEL_A, 1, PS5000A_DC, PS5000A_1V, 0);
  if (PICO_OK != status) {
    std::cout << "ERROR : Set Channel A : " << status << std::endl;
    return -1;
  }

  status = ps5000aSetChannel(handle, PS5000A_CHANNEL_B, 1, PS5000A_DC, PS5000A_1V, 0);
  if (PICO_OK != status) {
    std::cout << "ERROR : Set Channel B : " << status << std::endl;
    getStatusCode(status);
    return -1;
  }

  if (0 == usbPowered) {
    status = ps5000aSetChannel(handle, PS5000A_CHANNEL_C, 0, PS5000A_DC, PS5000A_1V, 0);
    if (PICO_OK != status) {
      std::cout << "ERROR : Set Channel C : " << status << std::endl;
      getStatusCode(status);
      return -1;
    }

    status = ps5000aSetChannel(handle, PS5000A_CHANNEL_D, 0, PS5000A_DC, PS5000A_1V, 0);
    if (PICO_OK != status) {
      std::cout << "ERROR : Set Channel D : " << status << std::endl;
      getStatusCode(status);
      return -1;
    }
  }

  // Set the Data Buffers for each channels
  int16_t* bufferA = (int16_t*)calloc(NO_OF_SAMPLES, sizeof(int16_t));
  int16_t* bufferB = (int16_t*)calloc(NO_OF_SAMPLES, sizeof(int16_t));
  status = ps5000aSetDataBuffer(handle, PS5000A_CHANNEL_A, bufferA, NO_OF_SAMPLES, 0, PS5000A_RATIO_MODE_NONE);
  if (PICO_OK != status) {
    std::cout << "ERROR : Set Buffer Channel A : " << status << std::endl;
    getStatusCode(status);
    return -1;
  }
  status = ps5000aSetDataBuffer(handle, PS5000A_CHANNEL_B, bufferB, NO_OF_SAMPLES, 0, PS5000A_RATIO_MODE_NONE);
  if (PICO_OK != status) {
    std::cout << "ERROR : Set Buffer Channel B : " << status << std::endl;
    getStatusCode(status);
    return -1;
  }

  // Setup the timebase
  int timeIntervalNS;
  int32_t maxSamples;
  uint32_t TIMEBASE = 4;
  status = ps5000aGetTimebase(handle, TIMEBASE, NO_OF_SAMPLES, &timeIntervalNS, &maxSamples, 0);
  if (PICO_OK != status) {
    std::cout << "ERROR : Set Trigger : " << status << std::endl;
    getStatusCode(status);
    return -1;
  }

  // Set the Trugger
  status = ps5000aSetSimpleTrigger(handle, 1, PS5000A_CHANNEL_A, 10000, PS5000A_THRESHOLD_DIRECTION::PS5000A_RISING, 0, 5000);
  if (PICO_OK != status) {
    std::cout << "ERROR : Set Trigger : " << status << std::endl;
    getStatusCode(status);
    return -1;
  }

  // Generate the signal from the AWG connected to channel A
  status = ps5000aSetSigGenBuiltInV2(handle,
    0,
    1000000,
    PS5000A_SINE,
    100,
    100,
    1,
    1,
    PS5000A_UP,
    PS5000A_ES_OFF,
    0,
    0,
    PS5000A_SIGGEN_RISING,
    PS5000A_SIGGEN_NONE,
    0);
  if (PICO_OK != status) {
    std::cout << "ERROR : AWG Signal Genertion : " << status << std::endl;
    getStatusCode(status);
    return -1;
  }

  // Execute the data acquisition.
  constexpr int32_t NUMBER_OF_CHANNELS = 1;
  auto* timeIndisposedMs = new int32_t(NUMBER_OF_CHANNELS);
  status = ps5000aRunBlock(handle, 10, NO_OF_SAMPLES - 10, TIMEBASE, timeIndisposedMs, 0, NULL, NULL);
  if (PICO_OK != status) {
    std::cout << "ERROR : RunBlock : " << status << std::endl;
    getStatusCode(status);
    return -1;
  }

  // Wait for the Data Acqusition to be completed
  int16_t isReady = 0;
  while (0 == isReady && PICO_OK == status) {
    status = ps5000aIsReady(handle, &isReady);
    std::cout << "PS3 IsReady : " << isReady << std::endl;
    if (PICO_OK != status) {
      std::cout << "Error : IsReady Issue : " << status << std::endl;
      getStatusCode(status);
      return -1;
    }
    Sleep(1);
  }

  // Extract the acquired samples
  int noSamples;
  status = ps5000aGetValues(handle, 0, (uint32_t*)&noSamples, 1, PS5000A_RATIO_MODE_NONE, 0, nullptr);
  if (PICO_OK != status) {
    std::cout << "Error : Get Values Issue : " << status << std::endl;
    getStatusCode(status);
    return -1;
  }

  // Print the extracted samples
  std::cout << "Print Buffer A : " << std::endl;
  for (auto sampleIndex = 0; sampleIndex < noSamples; sampleIndex++)
    std::cout << sampleIndex << ";" << bufferA[sampleIndex] << ";" << adc_to_mv(bufferA[sampleIndex], PS5000A_RANGE::PS5000A_2V, 32767) << std::endl;

  std::cout << std::endl;
  std::cout << "Print Buffer B : " << std::endl;
  for (auto sampleIndex = 0; sampleIndex < noSamples; sampleIndex++)
    std::cout << sampleIndex << ";" << bufferB[sampleIndex] << ";" << adc_to_mv(bufferB[sampleIndex], PS5000A_RANGE::PS5000A_2V, 32767) << std::endl;

  // Close the unit.
  status = ps5000aCloseUnit(handle);
  if (PICO_OK != status) {
    std::cout << "Error : Close Unit : " << status << std::endl;
    getStatusCode(status);
    return -1;
  }

  return 0;
}<|endoftext|>


<commit_before>// XFAIL: hexagon
// Test this without pch.
// RUN: %clang_cc1 -include %S/cxx-typeid.h -fsyntax-only -verify %s

// RUN: %clang_cc1 -x c++-header -emit-pch -o %t.pch %S/cxx-typeid.h
// RUN: %clang_cc1 -include-pch %t.pch -fsyntax-only -verify %s

// expected-no-diagnostics

void f() {
    (void)typeid(int);
}
<commit_msg>Remove XFAIL now that the test is standalone.<commit_after>// Test this without pch.
// RUN: %clang_cc1 -include %S/cxx-typeid.h -fsyntax-only -verify %s

// RUN: %clang_cc1 -x c++-header -emit-pch -o %t.pch %S/cxx-typeid.h
// RUN: %clang_cc1 -include-pch %t.pch -fsyntax-only -verify %s

// expected-no-diagnostics

void f() {
    (void)typeid(int);
}
<|endoftext|>


<commit_before>/*********************************************************************
* Software License Agreement (BSD License)
*
*  Copyright (c) 2008, Willow Garage, Inc.
*  All rights reserved.
*
*  Redistribution and use in source and binary forms, with or without
*  modification, are permitted provided that the following conditions
*  are met:
*
*   * Redistributions of source code must retain the above copyright
*     notice, this list of conditions and the following disclaimer.
*   * Redistributions in binary form must reproduce the above
*     copyright notice, this list of conditions and the following
*     disclaimer in the documentation and/or other materials provided
*     with the distribution.
*   * Neither the name of the Willow Garage nor the names of its
*     contributors may be used to endorse or promote products derived
*     from this software without specific prior written permission.
*
*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
*  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
*  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
*  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
*  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
*  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
*  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
*  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
*  POSSIBILITY OF SUCH DAMAGE.
*********************************************************************/

/* Author: Wim Meeussen */

#ifndef KDL_PARSER_H
#define KDL_PARSER_H

#include <kdl/tree.hpp>
#include <string>
#include <urdf/model.h>

using namespace std;

namespace kdl_parser{

/** Constructs a KDL tree from a file, given the file name
 * \param file The filename from where to read the xml
 * \param tree The resulting KDL Tree
 * returns true on success, false on failure
 */
bool treeFromFile(const string& file, KDL::Tree& tree);

/** Constructs a KDL tree from a string containing xml
 * \param xml A string containting the xml description of the robot
 * \param tree The resulting KDL Tree
 * returns true on success, false on failure
 */
bool treeFromString(const string& xml, KDL::Tree& tree);

/** Constructs a KDL tree from a TiXmlDocument
 * \param xml_doc The TiXmlDocument containting the xml description of the robot
 * \param tree The resulting KDL Tree
 * returns true on success, false on failure
 */
bool treeFromXml(TiXmlDocument *xml_doc, KDL::Tree& tree);

/** Constructs a KDL tree from a URDF robot model
 * \param robot_model The URDF robot model
 * \param tree The resulting KDL Tree
 * returns true on success, false on failure
 */
bool treeFromRobotModel(const urdf::Model& robot_model, KDL::Tree& tree);

/** Constructs a KDL tree from a URDF robot model
 * \param robot_model The URDF robot model
 * \param tree The resulting KDL Tree
 * returns true on success, false on failure
 */
bool treeFromUrdfModel(const urdf::Model& robot_model, KDL::Tree& tree);
}

#endif
<commit_msg>function deprectation warning at compile time<commit_after>/*********************************************************************
* Software License Agreement (BSD License)
*
*  Copyright (c) 2008, Willow Garage, Inc.
*  All rights reserved.
*
*  Redistribution and use in source and binary forms, with or without
*  modification, are permitted provided that the following conditions
*  are met:
*
*   * Redistributions of source code must retain the above copyright
*     notice, this list of conditions and the following disclaimer.
*   * Redistributions in binary form must reproduce the above
*     copyright notice, this list of conditions and the following
*     disclaimer in the documentation and/or other materials provided
*     with the distribution.
*   * Neither the name of the Willow Garage nor the names of its
*     contributors may be used to endorse or promote products derived
*     from this software without specific prior written permission.
*
*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
*  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
*  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
*  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
*  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
*  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
*  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
*  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
*  POSSIBILITY OF SUCH DAMAGE.
*********************************************************************/

/* Author: Wim Meeussen */

#ifndef KDL_PARSER_H
#define KDL_PARSER_H

#include <kdl/tree.hpp>
#include <string>
#include <urdf/model.h>

using namespace std;

namespace kdl_parser{

/** Constructs a KDL tree from a file, given the file name
 * \param file The filename from where to read the xml
 * \param tree The resulting KDL Tree
 * returns true on success, false on failure
 */
bool treeFromFile(const string& file, KDL::Tree& tree);

/** Constructs a KDL tree from a string containing xml
 * \param xml A string containting the xml description of the robot
 * \param tree The resulting KDL Tree
 * returns true on success, false on failure
 */
bool treeFromString(const string& xml, KDL::Tree& tree);

/** Constructs a KDL tree from a TiXmlDocument
 * \param xml_doc The TiXmlDocument containting the xml description of the robot
 * \param tree The resulting KDL Tree
 * returns true on success, false on failure
 */
bool treeFromXml(TiXmlDocument *xml_doc, KDL::Tree& tree);

/** Constructs a KDL tree from a URDF robot model
 * \param robot_model The URDF robot model
 * \param tree The resulting KDL Tree
 * returns true on success, false on failure
 */
bool treeFromRobotModel(const urdf::Model& robot_model, KDL::Tree& tree) __attribute__((deprecated));;

/** Constructs a KDL tree from a URDF robot model
 * \param robot_model The URDF robot model
 * \param tree The resulting KDL Tree
 * returns true on success, false on failure
 */
bool treeFromUrdfModel(const urdf::Model& robot_model, KDL::Tree& tree);
}

#endif
<|endoftext|>


<commit_before>//
// Created by SGuzman on 3/19/2015.
//
#include <iostream>

#include "pascal.hxx"
#include "../../include/pretty_print.hxx"

using namespace std;

int main(void) {
	Solution sol;

	for (int i = 0; i < 10; ++i) {
		cout << sol.generate(i) << endl;
	}

	return 0;
}
<commit_msg>fix include directory<commit_after>//
// Created by SGuzman on 3/19/2015.
//
#include <iostream>

#include "pascal.hxx"
#include "../../../include/pretty_print.hxx"

using namespace std;

int main(void) {
	Solution sol;

	for (int i = 0; i < 10; ++i) {
		cout << sol.generate(i) << endl;
	}

	return 0;
}
<|endoftext|>