// Description: C++-specific utilities and constants.
//
// Orig Author: X-Midas 4.11.1 $Id: utilities.hh,v 86d07d6c929f 2011/03/09 21:07:11 sms
// NeXtMidas Mods: This is a bare bones version of xm/include/midas/utilities.hh with things
//                 that are not used/supported removed.
// Version: $Id: utilities.hh,v 1.1 2012/06/26 18:21:47 ntn Exp $

#ifndef UTILITIES_HH_

// System includes
#include <iostream>
#include <string>
#include <utility>
#include <istream>

// Midas includes
#include "midas.h"

// Forward references.  This is included by headers.h, so we cannot
// include its definition here, but we must reference it.
class CPHEADER;

namespace midas {
  // Return the appropriate X-Midas character identifier for a data type.
  // Specialized below.
  template<typename T>
  static inline char type_char ();

  template<>
  inline char type_char<real_8> () { return 'D'; }

  template<>
  inline char type_char<real_4> () { return 'F'; }

  template<>
  inline char type_char<int_8> () { return 'X'; }

  template<>
  inline char type_char<int_4> () { return 'L'; }

  template<>
  inline char type_char<int_2> () { return 'I'; }

  template<>
  inline char type_char<int_1> () { return 'B'; }

  template<>
  inline char type_char<int_u1> () { return 'O'; }


  // Convert an M_PTR or unsigned long to a typed pointer.
  template <typename T>
  inline T to_ptr (unsigned long p)
  {
    return reinterpret_cast<T>(p);
  }

  template <typename T>
  inline T to_ptr (const M_PTR& m)
  {
    return to_ptr<T>(m.p);
  }

  template <typename T>
  inline T to_ptr (M_PTR& m)
  {
    return to_ptr<T>(m.p);
  }


  // Assign a void pointer to an M_PTR (or any other type).
  template <typename T>
  inline void assign_ptr (T& f, void* p)
  {
    f = static_cast<T>(reinterpret_cast<unsigned long>(p));
  }

  inline void assign_ptr (M_PTR& m, void* p)
  {
    assign_ptr(m.p, p);
  }
} // namespace midas

#define UTILITIES_HH_
#endif // UTILITIES_HH_
