<commit_before>#ifndef TPNOWAYLEXREADER_HH
#define TPNOWAYLEXREADER_HH

#include <stdio.h>
#include <map>
#include <string>

#include "TPLexPrefixTree.hh"
#include "Vocabulary.hh"

// A class that reads the lexicon from a file and calls the lexical prefix
// tree class to create the lexical tree.
//
// FILE FORMAT:
//
// ^word(prob) phone1 phone2 ...
// ^word phone1 phone2 ...
//

class TPNowayLexReader {
public:
  TPNowayLexReader(std::map<std::string,int> &hmm_map,
                   std::vector<Hmm> &hmms,
                   TPLexPrefixTree &lex_tree,
                   Vocabulary &vocab);

  /// \brief Reads the lexicon from a file.
  ///
  /// Adds all the words to the vocabulary, and the word along with the HMMs of
  /// their phones to the lexicon.
  ///
  /// \exception UnknownHmm If a phone is not found from \ref m_hmm_map.
  ///
  void read(FILE *file, const std::string &word_boundary);

  void skip_while(FILE *file, const char *chars);
  void get_until(FILE *file, std::string &str, const char *delims);

  void set_silence_is_word(bool b) { m_silence_is_word = b; }

  // Current state for error diagnosis
  inline const std::string &word() const { return m_word; }
  inline const std::string &phone() const { return m_phone; }

  struct ReadError : public std::exception {
    virtual const char *what() const throw()
      { return "TPNowayLexReader: read error"; }
  };

  struct InvalidProbability : public std::exception {
    virtual const char *what() const throw()
      { return "TPNowayLexReader: invalid probability"; }
  };

  struct UnknownHmm : public std::exception {
	  UnknownHmm(const std::string & phone, const std::string & word) : m_phone(phone), m_word(word) {}
	  virtual ~UnknownHmm() throw () {}
    virtual const char *what() const throw()
      { return "TPNowayLexReader: unknown hmm"; }
    const std::string & phone() const
    { return m_phone; }
    const std::string & word() const
    { return m_word; }
  private:
    std::string m_phone;
    std::string m_word;
  };

protected:
  std::map<std::string,int> &m_hmm_map;
  std::vector<Hmm> &m_hmms;
  TPLexPrefixTree &m_lexicon;
  Vocabulary &m_vocabulary;
  int m_line_no;

  std::string m_word;

  // Temporary variables
  std::string m_phone;

  bool m_silence_is_word;
};

#endif /* TPNOWAYLEXREADER_HH */
<commit_msg>Documentation.<commit_after>#ifndef TPNOWAYLEXREADER_HH
#define TPNOWAYLEXREADER_HH

#include <stdio.h>
#include <map>
#include <string>

#include "TPLexPrefixTree.hh"
#include "Vocabulary.hh"

// A class that reads the lexicon from a file and calls the lexical prefix
// tree class to create the lexical tree.
//
// FILE FORMAT:
//
// ^word(prob) phone1 phone2 ...
// ^word phone1 phone2 ...
//

class TPNowayLexReader {
public:
  TPNowayLexReader(std::map<std::string,int> &hmm_map,
                   std::vector<Hmm> &hmms,
                   TPLexPrefixTree &lex_tree,
                   Vocabulary &vocab);

  /// \brief Reads the lexicon from a file.
  ///
  /// Adds all the words to the vocabulary, and the word along with the HMMs of
  /// their phones to the lexicon.
  ///
  /// \exception UnknownHmm If a phone is not found from \ref m_hmm_map.
  ///
  void read(FILE *file, const std::string &word_boundary);

  void skip_while(FILE *file, const char *chars);
  void get_until(FILE *file, std::string &str, const char *delims);

  void set_silence_is_word(bool b) { m_silence_is_word = b; }

  // Current state for error diagnosis
  inline const std::string &word() const { return m_word; }
  inline const std::string &phone() const { return m_phone; }

  struct ReadError : public std::exception {
    virtual const char *what() const throw()
      { return "TPNowayLexReader: read error"; }
  };

  struct InvalidProbability : public std::exception {
    virtual const char *what() const throw()
      { return "TPNowayLexReader: invalid probability"; }
  };

  struct UnknownHmm : public std::exception {
	  UnknownHmm(const std::string & phone, const std::string & word) : m_phone(phone), m_word(word) {}
	  virtual ~UnknownHmm() throw () {}
    virtual const char *what() const throw()
      { return "TPNowayLexReader: unknown hmm"; }
    const std::string & phone() const
    { return m_phone; }
    const std::string & word() const
    { return m_word; }
  private:
    std::string m_phone;
    std::string m_word;
  };

protected:
  /// Mapping from phones (triphones) to HMM indices.
  std::map<std::string,int> &m_hmm_map;

  /// The HMMs.
  std::vector<Hmm> &m_hmms;

  TPLexPrefixTree &m_lexicon;
  Vocabulary &m_vocabulary;
  int m_line_no;

  std::string m_word;

  // Temporary variables
  std::string m_phone;

  bool m_silence_is_word;
};

#endif /* TPNOWAYLEXREADER_HH */
<|endoftext|>


<commit_before><commit_msg>add invalid framebuffer operation to OpenGL error messages<commit_after><|endoftext|>


<commit_before><commit_msg>debug helpers<commit_after><|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: gcach_xpeer.hxx,v $
 *
 *  $Revision: 1.13 $
 *
 *  last change: $Author: hr $ $Date: 2007-06-27 20:48:54 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library 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 Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef _SV_GCACH_XPEER_HXX
#define _SV_GCACH_XPEER_HXX

#include <vcl/glyphcache.hxx>

#include <prex.h>
#include <X11/extensions/Xrender.h>
#include <postx.h>

#ifndef _VCL_DLLAPI_H
#include <vcl/dllapi.h>
#endif

class SalDisplay;
struct MultiScreenGlyph;

class X11GlyphPeer
: public GlyphCachePeer
{
public:
                        X11GlyphPeer();
    virtual            ~X11GlyphPeer();

    Pixmap              GetPixmap( ServerFont&, int nGlyphIndex, int nScreen );
    const RawBitmap*    GetRawBitmap( ServerFont&, int nGlyphIndex );
    bool                ForcedAntialiasing( const ServerFont&, int nScreen ) const;

    GlyphSet            GetGlyphSet( ServerFont&, int nScreen );
    Glyph               GetGlyphId( ServerFont&, int nGlyphIndex );

protected:
    void                InitAntialiasing();

    virtual void        RemovingFont( ServerFont& );
    virtual void        RemovingGlyph( ServerFont&, GlyphData&, int nGlyphIndex );

    MultiScreenGlyph*   PrepareForMultiscreen( ExtGlyphData& ) const;
    void                SetRenderGlyph( GlyphData&, Glyph ) const;
    void                SetRawBitmap( GlyphData&, const RawBitmap* ) const;
    void                SetPixmap( GlyphData&, Pixmap, int nScreen ) const;
    Glyph               GetRenderGlyph( const GlyphData& ) const;
    const RawBitmap*    GetRawBitmap( const GlyphData& ) const;
    Pixmap              GetPixmap( const GlyphData&, int nScreen ) const;

private:
    Display*            mpDisplay;

    // thirty-two screens should be enough for everyone...
    static const int MAX_GCACH_SCREENS = 32;
    int                 mnMaxScreens;
    int                 mnDefaultScreen;
    int                 mnExtByteCount;
    RawBitmap           maRawBitmap;
    sal_uInt32          mnForcedAA;
    sal_uInt32          mnUsingXRender;
};

class X11GlyphCache : public GlyphCache
{
public:
    X11GlyphPeer&      GetPeer() { return reinterpret_cast<X11GlyphPeer&>( mrPeer ); }
static X11GlyphCache&  GetInstance();
static void            KillInstance();

private:
                       X11GlyphCache( X11GlyphPeer& );
};

#endif // _SV_GCACH_XPEER_HXX
<commit_msg>INTEGRATION: CWS changefileheader (1.13.248); FILE MERGED 2008/04/01 13:02:00 thb 1.13.248.2: #i85898# Stripping all external header guards 2008/03/28 15:45:26 rt 1.13.248.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: gcach_xpeer.hxx,v $
 * $Revision: 1.14 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org 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 version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef _SV_GCACH_XPEER_HXX
#define _SV_GCACH_XPEER_HXX

#include <vcl/glyphcache.hxx>

#include <prex.h>
#include <X11/extensions/Xrender.h>
#include <postx.h>
#include <vcl/dllapi.h>

class SalDisplay;
struct MultiScreenGlyph;

class X11GlyphPeer
: public GlyphCachePeer
{
public:
                        X11GlyphPeer();
    virtual            ~X11GlyphPeer();

    Pixmap              GetPixmap( ServerFont&, int nGlyphIndex, int nScreen );
    const RawBitmap*    GetRawBitmap( ServerFont&, int nGlyphIndex );
    bool                ForcedAntialiasing( const ServerFont&, int nScreen ) const;

    GlyphSet            GetGlyphSet( ServerFont&, int nScreen );
    Glyph               GetGlyphId( ServerFont&, int nGlyphIndex );

protected:
    void                InitAntialiasing();

    virtual void        RemovingFont( ServerFont& );
    virtual void        RemovingGlyph( ServerFont&, GlyphData&, int nGlyphIndex );

    MultiScreenGlyph*   PrepareForMultiscreen( ExtGlyphData& ) const;
    void                SetRenderGlyph( GlyphData&, Glyph ) const;
    void                SetRawBitmap( GlyphData&, const RawBitmap* ) const;
    void                SetPixmap( GlyphData&, Pixmap, int nScreen ) const;
    Glyph               GetRenderGlyph( const GlyphData& ) const;
    const RawBitmap*    GetRawBitmap( const GlyphData& ) const;
    Pixmap              GetPixmap( const GlyphData&, int nScreen ) const;

private:
    Display*            mpDisplay;

    // thirty-two screens should be enough for everyone...
    static const int MAX_GCACH_SCREENS = 32;
    int                 mnMaxScreens;
    int                 mnDefaultScreen;
    int                 mnExtByteCount;
    RawBitmap           maRawBitmap;
    sal_uInt32          mnForcedAA;
    sal_uInt32          mnUsingXRender;
};

class X11GlyphCache : public GlyphCache
{
public:
    X11GlyphPeer&      GetPeer() { return reinterpret_cast<X11GlyphPeer&>( mrPeer ); }
static X11GlyphCache&  GetInstance();
static void            KillInstance();

private:
                       X11GlyphCache( X11GlyphPeer& );
};

#endif // _SV_GCACH_XPEER_HXX
<|endoftext|>


<commit_before>#include "Chimera_Win.h"

#include <boost/algorithm/string/replace.hpp>

#include <QtCore/qglobal.h>
#include <QtPlugin>
#include <QQmlContext.h>
#include <QtQml/QQml.h>
#include <QtEndian>

#include "QmlVlc/QmlVlcSurfacePlayerProxy.h"

#ifdef QT_STATIC
    Q_IMPORT_PLUGIN( QWindowsIntegrationPlugin );
    Q_IMPORT_PLUGIN( QtQuick2Plugin );
    Q_IMPORT_PLUGIN( QtQuickLayoutsPlugin );
#endif

static std::string qtConf_resource_data;

static const unsigned char qtConf_resource_name[] = {
  // qt
  0x0,0x2,
  0x0,0x0,0x7,0x84,
  0x0,0x71,
  0x0,0x74,
    // etc
  0x0,0x3,
  0x0,0x0,0x6c,0xa3,
  0x0,0x65,
  0x0,0x74,0x0,0x63,
    // qt.conf
  0x0,0x7,
  0x8,0x74,0xa6,0xa6,
  0x0,0x71,
  0x0,0x74,0x0,0x2e,0x0,0x63,0x0,0x6f,0x0,0x6e,0x0,0x66,
};

static const unsigned char qtConf_resource_struct[] = {
  // :
  0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x1,
  // :/qt
  0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x2,
  // :/qt/etc
  0x0,0x0,0x0,0xa,0x0,0x2,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x3,
  // :/qt/etc/qt.conf
  0x0,0x0,0x0,0x16,0x0,0x0,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x0,
};

QT_BEGIN_NAMESPACE
extern Q_CORE_EXPORT
bool qRegisterResourceData( int, const unsigned char*,
                            const unsigned char* ,
                            const unsigned char* );
extern Q_CORE_EXPORT
bool qUnregisterResourceData( int, const unsigned char*,
                              const unsigned char*,
                              const unsigned char* );
QT_END_NAMESPACE

extern std::string g_dllPath;

////////////////////////////////////////////////////////////////////////////////
//Chimera_Win class
////////////////////////////////////////////////////////////////////////////////
void Chimera_Win::StaticInitialize()
{
#ifndef _DEBUG
    if( !qApp ) {
        std::string qtPrefix = g_dllPath + "/../";
        boost::algorithm::replace_all( qtPrefix, "\\", "/" );

        qtConf_resource_data = "4321[Paths]\n";
        qtConf_resource_data += "Prefix = " + qtPrefix + "\n";
        uint32_t qtConfSize = qtConf_resource_data.size() - sizeof( qtConfSize );
        uint32_t qtConfSwappedSize = qToBigEndian( qtConfSize );
        memcpy( &qtConf_resource_data[0], &qtConfSwappedSize, sizeof( qtConfSwappedSize ) );

        qRegisterResourceData( 0x01, qtConf_resource_struct,
                               qtConf_resource_name,
                               (const unsigned char*)qtConf_resource_data.data() );
    }
#endif
    QmlChimera::StaticInitialize();
}

void Chimera_Win::StaticDeinitialize()
{
#ifndef _DEBUG
    qUnregisterResourceData(0x01, qtConf_resource_struct,
                             qtConf_resource_name,
                             (const unsigned char*)qtConf_resource_data.data() );
#endif
}

Chimera_Win::Chimera_Win()
{
#ifdef QT_STATIC
    qmlProtectModule( "QtQuick", 2 );
    qmlProtectModule( "QtQuick.Layouts", 1 );
#endif
}

Chimera_Win::~Chimera_Win()
{
}

bool Chimera_Win::onWindowAttached( FB::AttachedEvent *evt, FB::PluginWindowWin* w )
{
    vlc_open();

    m_quickViewPtr.reset( new QQuickView );
    m_quickViewPtr->setResizeMode( QQuickView::SizeRootObjectToView );
    m_quickViewPtr->setProperty( "_q_embedded_native_parent_handle", WId( w->getHWND() ) );
    m_quickViewPtr->setFlags( m_quickViewPtr->flags() | Qt::FramelessWindowHint );

    QQmlContext* context = m_quickViewPtr->rootContext();
    m_qmlVlcPlayer = new QmlVlcSurfacePlayerProxy( (vlc::player*)this, m_quickViewPtr.data() );
    m_qmlVlcPlayer->classBegin();

    //have to call apply_player_options()
    //after QmlVlcSurfacePlayerProxy::classBegin
    //to allow attach Proxy's vmem to plugin before play
    apply_player_options();

    setQml();

    //simulate resize
    onWindowResized( 0, w );

    return false;
}

bool Chimera_Win::onWindowResized( FB::ResizedEvent*, FB::PluginWindowWin* w )
{
    const int newWidth = w->getWindowWidth();
    const int newHeight = w->getWindowHeight();
    if( m_quickViewPtr && !is_fullscreen() ) {
        if( newWidth > 0 && newHeight > 0 ) {
            if( !m_quickViewPtr->isVisible() )
                m_quickViewPtr->show();
            MoveWindow( (HWND)m_quickViewPtr->winId(), 0, 0, newWidth, newHeight, TRUE );
        } else
            m_quickViewPtr->hide();
    }

    return false;
}

bool Chimera_Win::onWindowsEvent( FB::WindowsEvent* event, FB::PluginWindowWin* w )
{
    if( WM_SETCURSOR == event->uMsg )
        return true;

    return false;
}

bool Chimera_Win::is_fullscreen()
{
    if( m_quickViewPtr )
        return 0 != ( m_quickViewPtr->visibility() & QWindow::FullScreen );

    return false;
}

void Chimera_Win::set_fullscreen( bool fs )
{
    if( m_quickViewPtr ) {
        if( fs && !is_fullscreen() ) {
            ::SetParent( (HWND) m_quickViewPtr->winId(), NULL );
            m_quickViewPtr->showFullScreen();
            Q_EMIT fullscreenChanged( true );
        } else if( !fs && is_fullscreen() ) {
            FB::PluginWindowWin* w = static_cast<FB::PluginWindowWin*>( GetWindow() );
            ::SetParent( (HWND) m_quickViewPtr->winId(), w->getHWND() );
            m_quickViewPtr->showNormal();
            Q_EMIT fullscreenChanged( false );
        }
    }
}
<commit_msg>emulate window resize after fullscreen<commit_after>#include "Chimera_Win.h"

#include <boost/algorithm/string/replace.hpp>

#include <QtCore/qglobal.h>
#include <QtPlugin>
#include <QQmlContext.h>
#include <QtQml/QQml.h>
#include <QtEndian>

#include "QmlVlc/QmlVlcSurfacePlayerProxy.h"

#ifdef QT_STATIC
    Q_IMPORT_PLUGIN( QWindowsIntegrationPlugin );
    Q_IMPORT_PLUGIN( QtQuick2Plugin );
    Q_IMPORT_PLUGIN( QtQuickLayoutsPlugin );
#endif

static std::string qtConf_resource_data;

static const unsigned char qtConf_resource_name[] = {
  // qt
  0x0,0x2,
  0x0,0x0,0x7,0x84,
  0x0,0x71,
  0x0,0x74,
    // etc
  0x0,0x3,
  0x0,0x0,0x6c,0xa3,
  0x0,0x65,
  0x0,0x74,0x0,0x63,
    // qt.conf
  0x0,0x7,
  0x8,0x74,0xa6,0xa6,
  0x0,0x71,
  0x0,0x74,0x0,0x2e,0x0,0x63,0x0,0x6f,0x0,0x6e,0x0,0x66,
};

static const unsigned char qtConf_resource_struct[] = {
  // :
  0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x1,
  // :/qt
  0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x2,
  // :/qt/etc
  0x0,0x0,0x0,0xa,0x0,0x2,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x3,
  // :/qt/etc/qt.conf
  0x0,0x0,0x0,0x16,0x0,0x0,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x0,
};

QT_BEGIN_NAMESPACE
extern Q_CORE_EXPORT
bool qRegisterResourceData( int, const unsigned char*,
                            const unsigned char* ,
                            const unsigned char* );
extern Q_CORE_EXPORT
bool qUnregisterResourceData( int, const unsigned char*,
                              const unsigned char*,
                              const unsigned char* );
QT_END_NAMESPACE

extern std::string g_dllPath;

////////////////////////////////////////////////////////////////////////////////
//Chimera_Win class
////////////////////////////////////////////////////////////////////////////////
void Chimera_Win::StaticInitialize()
{
#ifndef _DEBUG
    if( !qApp ) {
        std::string qtPrefix = g_dllPath + "/../";
        boost::algorithm::replace_all( qtPrefix, "\\", "/" );

        qtConf_resource_data = "4321[Paths]\n";
        qtConf_resource_data += "Prefix = " + qtPrefix + "\n";
        uint32_t qtConfSize = qtConf_resource_data.size() - sizeof( qtConfSize );
        uint32_t qtConfSwappedSize = qToBigEndian( qtConfSize );
        memcpy( &qtConf_resource_data[0], &qtConfSwappedSize, sizeof( qtConfSwappedSize ) );

        qRegisterResourceData( 0x01, qtConf_resource_struct,
                               qtConf_resource_name,
                               (const unsigned char*)qtConf_resource_data.data() );
    }
#endif
    QmlChimera::StaticInitialize();
}

void Chimera_Win::StaticDeinitialize()
{
#ifndef _DEBUG
    qUnregisterResourceData(0x01, qtConf_resource_struct,
                             qtConf_resource_name,
                             (const unsigned char*)qtConf_resource_data.data() );
#endif
}

Chimera_Win::Chimera_Win()
{
#ifdef QT_STATIC
    qmlProtectModule( "QtQuick", 2 );
    qmlProtectModule( "QtQuick.Layouts", 1 );
#endif
}

Chimera_Win::~Chimera_Win()
{
}

bool Chimera_Win::onWindowAttached( FB::AttachedEvent *evt, FB::PluginWindowWin* w )
{
    vlc_open();

    m_quickViewPtr.reset( new QQuickView );
    m_quickViewPtr->setResizeMode( QQuickView::SizeRootObjectToView );
    m_quickViewPtr->setProperty( "_q_embedded_native_parent_handle", WId( w->getHWND() ) );
    m_quickViewPtr->setFlags( m_quickViewPtr->flags() | Qt::FramelessWindowHint );

    QQmlContext* context = m_quickViewPtr->rootContext();
    m_qmlVlcPlayer = new QmlVlcSurfacePlayerProxy( (vlc::player*)this, m_quickViewPtr.data() );
    m_qmlVlcPlayer->classBegin();

    //have to call apply_player_options()
    //after QmlVlcSurfacePlayerProxy::classBegin
    //to allow attach Proxy's vmem to plugin before play
    apply_player_options();

    setQml();

    //simulate resize
    onWindowResized( 0, w );

    return false;
}

bool Chimera_Win::onWindowResized( FB::ResizedEvent*, FB::PluginWindowWin* w )
{
    const int newWidth = w->getWindowWidth();
    const int newHeight = w->getWindowHeight();
    if( m_quickViewPtr && !is_fullscreen() ) {
        if( newWidth > 0 && newHeight > 0 ) {
            if( !m_quickViewPtr->isVisible() )
                m_quickViewPtr->show();
            MoveWindow( (HWND)m_quickViewPtr->winId(), 0, 0, newWidth, newHeight, TRUE );
        } else
            m_quickViewPtr->hide();
    }

    return false;
}

bool Chimera_Win::onWindowsEvent( FB::WindowsEvent* event, FB::PluginWindowWin* w )
{
    if( WM_SETCURSOR == event->uMsg )
        return true;

    return false;
}

bool Chimera_Win::is_fullscreen()
{
    if( m_quickViewPtr )
        return 0 != ( m_quickViewPtr->visibility() & QWindow::FullScreen );

    return false;
}

void Chimera_Win::set_fullscreen( bool fs )
{
    if( m_quickViewPtr ) {
        if( fs && !is_fullscreen() ) {
            ::SetParent( (HWND) m_quickViewPtr->winId(), NULL );
            m_quickViewPtr->showFullScreen();
            Q_EMIT fullscreenChanged( true );
        } else if( !fs && is_fullscreen() ) {
            FB::PluginWindowWin* w = static_cast<FB::PluginWindowWin*>( GetWindow() );
            ::SetParent( (HWND) m_quickViewPtr->winId(), w->getHWND() );
            m_quickViewPtr->showNormal();
            onWindowResized( 0, w );
            Q_EMIT fullscreenChanged( false );
        }
    }
}
<|endoftext|>


<commit_before>/*! \file uvar.cc
 *******************************************************************************

 File: uvar.cc\n
 Implementation of the UVar class.

 This file is part of
 %URBI Kernel, version __kernelversion__\n
 (c) Jean-Christophe Baillie, 2004-2006.

 Permission to use, copy, modify, and redistribute this software for
 non-commercial use is hereby granted.

 This software is provided "as is" without warranty of any kind,
 either expressed or implied, including but not limited to the
 implied warranties of fitness for a particular purpose.

 For more information, comments, bug reports: http://www.urbiforge.com

 **************************************************************************** */

#include "uvariable.h"
#include "userver.h"
#include "uobject.h"
using namespace urbi;

namespace urbi {

  class UVardata {
    public:
      UVardata(UVariable *v) { variable = v; };
      ~UVardata() {};

      UVariable *variable;
  };
};

// **************************************************************************
//! UVar constructor: implicit object ref (using 'lastUOjbect') + varname
UVar::UVar(const string &varname)
{
  name = varname;
  __init();
}

//! UVar constructor: object reference + var name
UVar::UVar(UObject& obj, const string &varname)
{
  name = obj.__name + "." + varname;
  __init();
}

//! UVar constructor: object name + var name
UVar::UVar(const string &objname, const string &varname)
{
  name = objname + "." + varname;
  __init();
}

//! UVar initialization
void
UVar::init(const string &objname, const string &varname)
{
  name = objname + "." + varname;
  __init();
}

//! UVar initializationvoid
void
UVar::__init()
{
  this->owned = false;
  varmap[name].push_back(this);

  HMvariabletab::iterator it = ::urbiserver->variabletab.find(name.c_str());
  if (it == ::urbiserver->variabletab.end())
    vardata = new UVardata(new UVariable(name.c_str(),new
    ::UValue(),false,false,true));  // autoupdate unless otherwise specified
  else {
    vardata = new UVardata(it->second);
    owned = !vardata->variable->autoUpdate;
  }
}

//! set own mode
void
UVar::setOwned()
{
  owned = true;
  if (vardata)
    vardata->variable->autoUpdate = false;
}

//! UVar destructor.
UVar::~UVar()
{
  UVarTable::iterator varmapfind = varmap.find(name);

  if (varmapfind != varmap.end()) {

    for (list<UVar*>::iterator it = varmapfind->second.begin();
	it != varmapfind->second.end();)
      if ((*it) == this)
	varmapfind->second.erase(it);
      else
	it++;

    if (varmapfind->second.empty())
      varmap.erase(varmapfind);
  }
}

//! UVar float assignment
void
UVar::operator = (ufloat n)
{
  if (!vardata) {
    urbi::echo("Unable to locate variable %s in hashtable. Memory problem, report bug.\n",
	name.c_str());
    return;
  }

  // type mismatch is not integrated at this stage
  vardata->variable->value->dataType = ::DATA_NUM;

  if (owned)
    in() = n;
  else
    vardata->variable->setFloat(n);
}

//! UVar string assignment
void
UVar::operator = (string s)
{
  if (!vardata) {
    urbi::echo("Unable to locate variable %s in hashtable. Memory problem, report bug.\n",
	name.c_str());
    return;
  }

  if (vardata->variable->value->dataType == ::DATA_VOID)
    vardata->variable->value->str = new UString("");

  // type mismatch is not integrated at this stage
  vardata->variable->value->dataType = ::DATA_STRING;
  ::UValue tmpv(s.c_str());
  vardata->variable->set(&tmpv);
}

//! UVar binary assignment
void
UVar::operator = (const UBinary &b)
{
  if (!vardata) {
    urbi::echo("Unable to locate variable %s in hashtable. Memory problem, report bug.\n",
	name.c_str());
    return;
  }
  *vardata->variable->value=b;
  vardata->variable->updated();
}

// UVar Casting

UVar::operator int () {
  //check of dataType is done inside in and out
  if (owned)
    return (int)out();
  else
    return (int)in();
}

UVar::operator ufloat () {
  //check of dataType is done inside in and out
  if (owned)
    return out();
  else
    return in();
}

UVar::operator string () {

  if ((vardata)  && (vardata->variable->value->dataType == ::DATA_STRING))
    return (string(vardata->variable->value->str->str()));
  else
    return string("");
}

UVar::operator UList() {
return (UList)*vardata->variable->value;

}

UVar::operator urbi::UBinary() {
  if ((vardata)  && (vardata->variable->value->dataType == ::DATA_BINARY)) {
    //simplest way is to echo our bin headers and parse again
    UBinary b;
    std::ostringstream msg;
    msg << vardata->variable->value->refBinary->ref()->bufferSize;
    UNamedParameters *param = vardata->variable->value->refBinary->ref()->parameters;
    while (param) {
      if (param->expression) {
	if (param->expression->dataType == ::DATA_NUM)
	  msg<< " "<<(int)param->expression->val;
	else if (param->expression->dataType == ::DATA_STRING)
	  msg << " "<<param->expression->str->str();
      }
      param = param->next;
    }

    std::list<urbi::BinaryData> lBin;
    lBin.push_back(urbi::BinaryData( vardata->variable->value->refBinary->ref()->buffer,  vardata->variable->value->refBinary->ref()->bufferSize));
    std::list<urbi::BinaryData>::iterator lIter = lBin.begin();
    b.parse(msg.str().c_str(), 0, lBin, lIter);
  return b;
  }
  else return UBinary();
}

UVar::operator urbi::UBinary*() {
  if ((vardata)  && (vardata->variable->value->dataType == ::DATA_BINARY)) {
    //simplest way is to echo our bin headers and parse again
    UBinary* b = new UBinary();
    std::ostringstream msg;
    msg << vardata->variable->value->refBinary->ref()->bufferSize;
    UNamedParameters *param = vardata->variable->value->refBinary->ref()->parameters;
    while (param) {
      if (param->expression) {
	if (param->expression->dataType == ::DATA_NUM)
	  msg<< " "<<(int)param->expression->val;
	else if (param->expression->dataType == ::DATA_STRING)
	  msg << " "<<param->expression->str->str();
      }
      param = param->next;
    }

    std::list<urbi::BinaryData> lBin;
    lBin.push_back(urbi::BinaryData( vardata->variable->value->refBinary->ref()->buffer,  vardata->variable->value->refBinary->ref()->bufferSize));
    std::list<urbi::BinaryData>::iterator lIter = lBin.begin();
    b->parse(msg.str().c_str(), 0, lBin, lIter);
    return b;
  }
  else return new UBinary();
}

UVar::operator UImage() {
 return (UImage)*vardata->variable->value;
}

UVar::operator USound() {
 return (USound)*vardata->variable->value;
}

//! UVar out value (read mode)
ufloat&
UVar::out()
{
  static ufloat er=0;
  if ((vardata) && (vardata->variable->value->dataType == ::DATA_NUM))
    return (vardata->variable->target);
  else return er;
}

//! UVar in value (write mode)
ufloat&
UVar::in()
{
 static ufloat er=0;
 if ((vardata) && (vardata->variable->value->dataType == ::DATA_NUM))
   return (vardata->variable->value->val);
 else return er;
}

UBlendType
UVar::blend()
{
  if (vardata)
    return ((UBlendType)vardata->variable->blendType);
  else {
    urbi::echo("Internal error on variable 'vardata', should not be zero\n");
    return (UNORMAL);
  }
}

//! UVar update
void
UVar::__update(UValue& v)
{
  value = v;
}

<commit_msg>fixed (?) a bug that prevented a plugin from using a sensor variable from an other plugin correctly<commit_after>/*! \file uvar.cc
 *******************************************************************************

 File: uvar.cc\n
 Implementation of the UVar class.

 This file is part of
 %URBI Kernel, version __kernelversion__\n
 (c) Jean-Christophe Baillie, 2004-2006.

 Permission to use, copy, modify, and redistribute this software for
 non-commercial use is hereby granted.

 This software is provided "as is" without warranty of any kind,
 either expressed or implied, including but not limited to the
 implied warranties of fitness for a particular purpose.

 For more information, comments, bug reports: http://www.urbiforge.com

 **************************************************************************** */

#include "uvariable.h"
#include "userver.h"
#include "uobject.h"
using namespace urbi;

namespace urbi {

  class UVardata {
    public:
      UVardata(UVariable *v) { variable = v; };
      ~UVardata() {};

      UVariable *variable;
  };
};

// **************************************************************************
//! UVar constructor: implicit object ref (using 'lastUOjbect') + varname
UVar::UVar(const string &varname)
{
  name = varname;
  __init();
}

//! UVar constructor: object reference + var name
UVar::UVar(UObject& obj, const string &varname)
{
  name = obj.__name + "." + varname;
  __init();
}

//! UVar constructor: object name + var name
UVar::UVar(const string &objname, const string &varname)
{
  name = objname + "." + varname;
  __init();
}

//! UVar initialization
void
UVar::init(const string &objname, const string &varname)
{
  name = objname + "." + varname;
  __init();
}

//! UVar initializationvoid
void
UVar::__init()
{
  this->owned = false;
  varmap[name].push_back(this);

  HMvariabletab::iterator it = ::urbiserver->variabletab.find(name.c_str());
  if (it == ::urbiserver->variabletab.end())
    vardata = new UVardata(new UVariable(name.c_str(),new
    ::UValue(),false,false,true));  // autoupdate unless otherwise specified
  else {
    vardata = new UVardata(it->second);
    //XXX why?? owned = !vardata->variable->autoUpdate;
  }
}

//! set own mode
void
UVar::setOwned()
{
  owned = true;
  if (vardata)
    vardata->variable->autoUpdate = false;
}

//! UVar destructor.
UVar::~UVar()
{
  UVarTable::iterator varmapfind = varmap.find(name);

  if (varmapfind != varmap.end()) {

    for (list<UVar*>::iterator it = varmapfind->second.begin();
	it != varmapfind->second.end();)
      if ((*it) == this)
	varmapfind->second.erase(it);
      else
	it++;

    if (varmapfind->second.empty())
      varmap.erase(varmapfind);
  }
}

//! UVar float assignment
void
UVar::operator = (ufloat n)
{
  if (!vardata) {
    urbi::echo("Unable to locate variable %s in hashtable. Memory problem, report bug.\n",
	name.c_str());
    return;
  }

  // type mismatch is not integrated at this stage
  vardata->variable->value->dataType = ::DATA_NUM;

  if (owned)
    in() = n;
  else
    vardata->variable->setFloat(n);
}

//! UVar string assignment
void
UVar::operator = (string s)
{
  if (!vardata) {
    urbi::echo("Unable to locate variable %s in hashtable. Memory problem, report bug.\n",
	name.c_str());
    return;
  }

  if (vardata->variable->value->dataType == ::DATA_VOID)
    vardata->variable->value->str = new UString("");

  // type mismatch is not integrated at this stage
  vardata->variable->value->dataType = ::DATA_STRING;
  ::UValue tmpv(s.c_str());
  vardata->variable->set(&tmpv);
}

//! UVar binary assignment
void
UVar::operator = (const UBinary &b)
{
  if (!vardata) {
    urbi::echo("Unable to locate variable %s in hashtable. Memory problem, report bug.\n",
	name.c_str());
    return;
  }
  *vardata->variable->value=b;
  vardata->variable->updated();
}

// UVar Casting

UVar::operator int () {
  //check of dataType is done inside in and out
  if (owned)
    return (int)out();
  else
    return (int)in();
}

UVar::operator ufloat () {
  //check of dataType is done inside in and out
  if (owned)
    return out();
  else
    return in();
}

UVar::operator string () {

  if ((vardata)  && (vardata->variable->value->dataType == ::DATA_STRING))
    return (string(vardata->variable->value->str->str()));
  else
    return string("");
}

UVar::operator UList() {
return (UList)*vardata->variable->value;

}

UVar::operator urbi::UBinary() {
  if ((vardata)  && (vardata->variable->value->dataType == ::DATA_BINARY)) {
    //simplest way is to echo our bin headers and parse again
    UBinary b;
    std::ostringstream msg;
    msg << vardata->variable->value->refBinary->ref()->bufferSize;
    UNamedParameters *param = vardata->variable->value->refBinary->ref()->parameters;
    while (param) {
      if (param->expression) {
	if (param->expression->dataType == ::DATA_NUM)
	  msg<< " "<<(int)param->expression->val;
	else if (param->expression->dataType == ::DATA_STRING)
	  msg << " "<<param->expression->str->str();
      }
      param = param->next;
    }

    std::list<urbi::BinaryData> lBin;
    lBin.push_back(urbi::BinaryData( vardata->variable->value->refBinary->ref()->buffer,  vardata->variable->value->refBinary->ref()->bufferSize));
    std::list<urbi::BinaryData>::iterator lIter = lBin.begin();
    b.parse(msg.str().c_str(), 0, lBin, lIter);
  return b;
  }
  else return UBinary();
}

UVar::operator urbi::UBinary*() {
  if ((vardata)  && (vardata->variable->value->dataType == ::DATA_BINARY)) {
    //simplest way is to echo our bin headers and parse again
    UBinary* b = new UBinary();
    std::ostringstream msg;
    msg << vardata->variable->value->refBinary->ref()->bufferSize;
    UNamedParameters *param = vardata->variable->value->refBinary->ref()->parameters;
    while (param) {
      if (param->expression) {
	if (param->expression->dataType == ::DATA_NUM)
	  msg<< " "<<(int)param->expression->val;
	else if (param->expression->dataType == ::DATA_STRING)
	  msg << " "<<param->expression->str->str();
      }
      param = param->next;
    }

    std::list<urbi::BinaryData> lBin;
    lBin.push_back(urbi::BinaryData( vardata->variable->value->refBinary->ref()->buffer,  vardata->variable->value->refBinary->ref()->bufferSize));
    std::list<urbi::BinaryData>::iterator lIter = lBin.begin();
    b->parse(msg.str().c_str(), 0, lBin, lIter);
    return b;
  }
  else return new UBinary();
}

UVar::operator UImage() {
 return (UImage)*vardata->variable->value;
}

UVar::operator USound() {
 return (USound)*vardata->variable->value;
}

//! UVar out value (read mode)
ufloat&
UVar::out()
{
  static ufloat er=0;
  if ((vardata) && (vardata->variable->value->dataType == ::DATA_NUM))
    return (vardata->variable->target);
  else return er;
}

//! UVar in value (write mode)
ufloat&
UVar::in()
{
 static ufloat er=0;
 if ((vardata) && (vardata->variable->value->dataType == ::DATA_NUM))
   return (vardata->variable->value->val);
 else return er;
}

UBlendType
UVar::blend()
{
  if (vardata)
    return ((UBlendType)vardata->variable->blendType);
  else {
    urbi::echo("Internal error on variable 'vardata', should not be zero\n");
    return (UNORMAL);
  }
}

//! UVar update
void
UVar::__update(UValue& v)
{
  value = v;
}

<|endoftext|>


<commit_before>/*
 * Copyright (c) 2009-2010 ARM Limited
 * All rights reserved.
 *
 * The license below extends only to copyright in the software and shall
 * not be construed as granting a license to any other intellectual
 * property including but not limited to intellectual property relating
 * to a hardware implementation of the functionality of the software
 * licensed hereunder.  You may use the software subject to the license
 * terms below provided that you ensure that this notice is replicated
 * unmodified and in its entirety in all distributions of the software,
 * modified or unmodified, in source code or in binary form.
 *
 * 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 copyright holders 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.
 *
 * Authors: Ali Saidi
 */

#include "arch/arm/faults.hh"
#include "arch/arm/isa_traits.hh"
#include "arch/arm/tlb.hh"
#include "arch/arm/utility.hh"
#include "arch/arm/vtophys.hh"
#include "config/use_checker.hh"
#include "cpu/thread_context.hh"
#include "mem/fs_translating_port_proxy.hh"
#include "sim/full_system.hh"

namespace ArmISA {

void
initCPU(ThreadContext *tc, int cpuId)
{
    // Reset CP15?? What does that mean -- ali

    // FPEXC.EN = 0

    static Fault reset = new Reset;
    reset->invoke(tc);
}

uint64_t
getArgument(ThreadContext *tc, int &number, uint16_t size, bool fp)
{
    if (!FullSystem) {
        panic("getArgument() only implemented for full system mode.\n");
        M5_DUMMY_RETURN
    }

    if (size == (uint16_t)(-1))
        size = ArmISA::MachineBytes;
    if (fp)
        panic("getArgument(): Floating point arguments not implemented\n");

    if (number < NumArgumentRegs) {
        // If the argument is 64 bits, it must be in an even regiser
        // number. Increment the number here if it isn't even.
        if (size == sizeof(uint64_t)) {
            if ((number % 2) != 0)
                number++;
            // Read the two halves of the data. Number is inc here to
            // get the second half of the 64 bit reg.
            uint64_t tmp;
            tmp = tc->readIntReg(number++);
            tmp |= tc->readIntReg(number) << 32;
            return tmp;
        } else {
           return tc->readIntReg(number);
        }
    } else {
        Addr sp = tc->readIntReg(StackPointerReg);
        FSTranslatingPortProxy &vp = tc->getVirtProxy();
        uint64_t arg;
        if (size == sizeof(uint64_t)) {
            // If the argument is even it must be aligned
            if ((number % 2) != 0)
                number++;
            arg = vp.read<uint64_t>(sp +
                    (number-NumArgumentRegs) * sizeof(uint32_t));
            // since two 32 bit args == 1 64 bit arg, increment number
            number++;
        } else {
            arg = vp.read<uint32_t>(sp +
                           (number-NumArgumentRegs) * sizeof(uint32_t));
        }
        return arg;
    }
}

void
skipFunction(ThreadContext *tc)
{
    TheISA::PCState newPC = tc->pcState();
    newPC.set(tc->readIntReg(ReturnAddressReg) & ~ULL(1));
#if USE_CHECKER
    tc->pcStateNoRecord(newPC);
#else
    tc->pcState(newPC);
#endif
}

void
copyRegs(ThreadContext *src, ThreadContext *dest)
{
    int i;

    int saved_mode = ((CPSR)src->readMiscReg(MISCREG_CPSR)).mode;

    // Make sure we're in user mode, so we can easily see all the registers
    // in the copy loop
    src->setMiscReg(MISCREG_CPSR_MODE, MODE_USER);
    dest->setMiscReg(MISCREG_CPSR_MODE, MODE_USER);

    for(i = 0; i < TheISA::NumIntRegs; i++)
        dest->setIntReg(i, src->readIntReg(i));

    // Restore us back to the old mode
    src->setMiscReg(MISCREG_CPSR_MODE, saved_mode);
    dest->setMiscReg(MISCREG_CPSR_MODE, saved_mode);

    for(i = 0; i < TheISA::NumFloatRegs; i++)
        dest->setFloatReg(i, src->readFloatReg(i));
    for(i = 0; i < TheISA::NumMiscRegs; i++)
        dest->setMiscRegNoEffect(i, src->readMiscRegNoEffect(i));

    // setMiscReg "with effect" will set the misc register mapping correctly.
    // e.g. updateRegMap(val)
    dest->setMiscReg(MISCREG_CPSR, src->readMiscRegNoEffect(MISCREG_CPSR));

    // Copy over the PC State
    dest->pcState(src->pcState());

    // Invalidate the tlb misc register cache
    dest->getITBPtr()->invalidateMiscReg();
    dest->getDTBPtr()->invalidateMiscReg();
}

Addr
truncPage(Addr addr)
{
    return addr & ~(PageBytes - 1);
}

Addr
roundPage(Addr addr)
{
    return (addr + PageBytes - 1) & ~(PageBytes - 1);
}

} // namespace ArmISA
<commit_msg>ARM: Don't reset CPUs that are going to be switched in.<commit_after>/*
 * Copyright (c) 2009-2010 ARM Limited
 * All rights reserved.
 *
 * The license below extends only to copyright in the software and shall
 * not be construed as granting a license to any other intellectual
 * property including but not limited to intellectual property relating
 * to a hardware implementation of the functionality of the software
 * licensed hereunder.  You may use the software subject to the license
 * terms below provided that you ensure that this notice is replicated
 * unmodified and in its entirety in all distributions of the software,
 * modified or unmodified, in source code or in binary form.
 *
 * 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 copyright holders 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.
 *
 * Authors: Ali Saidi
 */

#include "arch/arm/faults.hh"
#include "arch/arm/isa_traits.hh"
#include "arch/arm/tlb.hh"
#include "arch/arm/utility.hh"
#include "arch/arm/vtophys.hh"
#include "config/use_checker.hh"
#include "cpu/base.hh"
#include "cpu/thread_context.hh"
#include "mem/fs_translating_port_proxy.hh"
#include "params/BaseCPU.hh"
#include "sim/full_system.hh"

namespace ArmISA {

void
initCPU(ThreadContext *tc, int cpuId)
{
    // Reset CP15?? What does that mean -- ali

    // FPEXC.EN = 0
    if (tc->getCpuPtr()->params()->defer_registration)
       return;

    static Fault reset = new Reset;
    reset->invoke(tc);
}

uint64_t
getArgument(ThreadContext *tc, int &number, uint16_t size, bool fp)
{
    if (!FullSystem) {
        panic("getArgument() only implemented for full system mode.\n");
        M5_DUMMY_RETURN
    }

    if (size == (uint16_t)(-1))
        size = ArmISA::MachineBytes;
    if (fp)
        panic("getArgument(): Floating point arguments not implemented\n");

    if (number < NumArgumentRegs) {
        // If the argument is 64 bits, it must be in an even regiser
        // number. Increment the number here if it isn't even.
        if (size == sizeof(uint64_t)) {
            if ((number % 2) != 0)
                number++;
            // Read the two halves of the data. Number is inc here to
            // get the second half of the 64 bit reg.
            uint64_t tmp;
            tmp = tc->readIntReg(number++);
            tmp |= tc->readIntReg(number) << 32;
            return tmp;
        } else {
           return tc->readIntReg(number);
        }
    } else {
        Addr sp = tc->readIntReg(StackPointerReg);
        FSTranslatingPortProxy &vp = tc->getVirtProxy();
        uint64_t arg;
        if (size == sizeof(uint64_t)) {
            // If the argument is even it must be aligned
            if ((number % 2) != 0)
                number++;
            arg = vp.read<uint64_t>(sp +
                    (number-NumArgumentRegs) * sizeof(uint32_t));
            // since two 32 bit args == 1 64 bit arg, increment number
            number++;
        } else {
            arg = vp.read<uint32_t>(sp +
                           (number-NumArgumentRegs) * sizeof(uint32_t));
        }
        return arg;
    }
}

void
skipFunction(ThreadContext *tc)
{
    TheISA::PCState newPC = tc->pcState();
    newPC.set(tc->readIntReg(ReturnAddressReg) & ~ULL(1));
#if USE_CHECKER
    tc->pcStateNoRecord(newPC);
#else
    tc->pcState(newPC);
#endif
}

void
copyRegs(ThreadContext *src, ThreadContext *dest)
{
    int i;

    int saved_mode = ((CPSR)src->readMiscReg(MISCREG_CPSR)).mode;

    // Make sure we're in user mode, so we can easily see all the registers
    // in the copy loop
    src->setMiscReg(MISCREG_CPSR_MODE, MODE_USER);
    dest->setMiscReg(MISCREG_CPSR_MODE, MODE_USER);

    for(i = 0; i < TheISA::NumIntRegs; i++)
        dest->setIntReg(i, src->readIntReg(i));

    // Restore us back to the old mode
    src->setMiscReg(MISCREG_CPSR_MODE, saved_mode);
    dest->setMiscReg(MISCREG_CPSR_MODE, saved_mode);

    for(i = 0; i < TheISA::NumFloatRegs; i++)
        dest->setFloatReg(i, src->readFloatReg(i));
    for(i = 0; i < TheISA::NumMiscRegs; i++)
        dest->setMiscRegNoEffect(i, src->readMiscRegNoEffect(i));

    // setMiscReg "with effect" will set the misc register mapping correctly.
    // e.g. updateRegMap(val)
    dest->setMiscReg(MISCREG_CPSR, src->readMiscRegNoEffect(MISCREG_CPSR));

    // Copy over the PC State
    dest->pcState(src->pcState());

    // Invalidate the tlb misc register cache
    dest->getITBPtr()->invalidateMiscReg();
    dest->getDTBPtr()->invalidateMiscReg();
}

Addr
truncPage(Addr addr)
{
    return addr & ~(PageBytes - 1);
}

Addr
roundPage(Addr addr)
{
    return (addr + PageBytes - 1) & ~(PageBytes - 1);
}

} // namespace ArmISA
<|endoftext|>


<commit_before>/*
 * Copyright (c) 2007 The Hewlett-Packard Development Company
 * All rights reserved.
 *
 * Redistribution and use of this software in source and binary forms,
 * with or without modification, are permitted provided that the
 * following conditions are met:
 *
 * The software must be used only for Non-Commercial Use which means any
 * use which is NOT directed to receiving any direct monetary
 * compensation for, or commercial advantage from such use.  Illustrative
 * examples of non-commercial use are academic research, personal study,
 * teaching, education and corporate research & development.
 * Illustrative examples of commercial use are distributing products for
 * commercial advantage and providing services using the software for
 * commercial advantage.
 *
 * If you wish to use this software or functionality therein that may be
 * covered by patents for commercial use, please contact:
 *     Director of Intellectual Property Licensing
 *     Office of Strategy and Technology
 *     Hewlett-Packard Company
 *     1501 Page Mill Road
 *     Palo Alto, California  94304
 *
 * 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 COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.  No right of
 * sublicense is granted herewith.  Derivatives of the software and
 * output created using the software may be prepared, but only for
 * Non-Commercial Uses.  Derivatives of the software may be shared with
 * others provided: (i) the others agree to abide by the list of
 * conditions herein which includes the Non-Commercial Use restrictions;
 * and (ii) such Derivatives of the software include the above copyright
 * notice to acknowledge the contribution from this software where
 * applicable, this list of conditions and the disclaimer below.
 *
 * 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.
 *
 * Authors: Gabe Black
 */

#ifndef __ARCH_X86_UTILITY_HH__
#define __ARCH_X86_UTILITY_HH__

#error X86 is not yet supported!

namespace X86ISA
{
};

#endif // __ARCH_X86_UTILITY_HH__
<commit_msg>Added stub implementations or prototypes for all the functions in this file.<commit_after>/*
 * Copyright (c) 2007 The Hewlett-Packard Development Company
 * All rights reserved.
 *
 * Redistribution and use of this software in source and binary forms,
 * with or without modification, are permitted provided that the
 * following conditions are met:
 *
 * The software must be used only for Non-Commercial Use which means any
 * use which is NOT directed to receiving any direct monetary
 * compensation for, or commercial advantage from such use.  Illustrative
 * examples of non-commercial use are academic research, personal study,
 * teaching, education and corporate research & development.
 * Illustrative examples of commercial use are distributing products for
 * commercial advantage and providing services using the software for
 * commercial advantage.
 *
 * If you wish to use this software or functionality therein that may be
 * covered by patents for commercial use, please contact:
 *     Director of Intellectual Property Licensing
 *     Office of Strategy and Technology
 *     Hewlett-Packard Company
 *     1501 Page Mill Road
 *     Palo Alto, California  94304
 *
 * 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 COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.  No right of
 * sublicense is granted herewith.  Derivatives of the software and
 * output created using the software may be prepared, but only for
 * Non-Commercial Uses.  Derivatives of the software may be shared with
 * others provided: (i) the others agree to abide by the list of
 * conditions herein which includes the Non-Commercial Use restrictions;
 * and (ii) such Derivatives of the software include the above copyright
 * notice to acknowledge the contribution from this software where
 * applicable, this list of conditions and the disclaimer below.
 *
 * 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.
 *
 * Authors: Gabe Black
 */

#ifndef __ARCH_X86_UTILITY_HH__
#define __ARCH_X86_UTILITY_HH__

#include "arch/x86/types.hh"
#include "base/misc.hh"

class ThreadContext;

namespace X86ISA
{
    static inline bool
    inUserMode(ThreadContext *tc)
    {
        return false;
    }

    inline ExtMachInst
    makeExtMI(MachInst inst, ThreadContext * xc) {
        return inst;
    }

    inline bool isCallerSaveIntegerRegister(unsigned int reg) {
        panic("register classification not implemented");
        return false;
    }

    inline bool isCalleeSaveIntegerRegister(unsigned int reg) {
        panic("register classification not implemented");
        return false;
    }

    inline bool isCallerSaveFloatRegister(unsigned int reg) {
        panic("register classification not implemented");
        return false;
    }

    inline bool isCalleeSaveFloatRegister(unsigned int reg) {
        panic("register classification not implemented");
        return false;
    }

    // Instruction address compression hooks
    inline Addr realPCToFetchPC(const Addr &addr)
    {
        return addr;
    }

    inline Addr fetchPCToRealPC(const Addr &addr)
    {
        return addr;
    }

    // the size of "fetched" instructions (not necessarily the size
    // of real instructions for PISA)
    inline size_t fetchInstSize()
    {
        return sizeof(MachInst);
    }

    /**
     * Function to insure ISA semantics about 0 registers.
     * @param tc The thread context.
     */
    template <class TC>
    void zeroRegisters(TC *tc);

    inline void initCPU(ThreadContext *tc, int cpuId)
    {
        panic("initCPU not implemented!\n");
    }
};

#endif // __ARCH_X86_UTILITY_HH__
<|endoftext|>


<commit_before>/*
 * Copyright (c) 2007 The Hewlett-Packard Development Company
 * All rights reserved.
 *
 * Redistribution and use of this software in source and binary forms,
 * with or without modification, are permitted provided that the
 * following conditions are met:
 *
 * The software must be used only for Non-Commercial Use which means any
 * use which is NOT directed to receiving any direct monetary
 * compensation for, or commercial advantage from such use.  Illustrative
 * examples of non-commercial use are academic research, personal study,
 * teaching, education and corporate research & development.
 * Illustrative examples of commercial use are distributing products for
 * commercial advantage and providing services using the software for
 * commercial advantage.
 *
 * If you wish to use this software or functionality therein that may be
 * covered by patents for commercial use, please contact:
 *     Director of Intellectual Property Licensing
 *     Office of Strategy and Technology
 *     Hewlett-Packard Company
 *     1501 Page Mill Road
 *     Palo Alto, California  94304
 *
 * 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 COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.  No right of
 * sublicense is granted herewith.  Derivatives of the software and
 * output created using the software may be prepared, but only for
 * Non-Commercial Uses.  Derivatives of the software may be shared with
 * others provided: (i) the others agree to abide by the list of
 * conditions herein which includes the Non-Commercial Use restrictions;
 * and (ii) such Derivatives of the software include the above copyright
 * notice to acknowledge the contribution from this software where
 * applicable, this list of conditions and the disclaimer below.
 *
 * 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.
 *
 * Authors: Gabe Black
 */

#ifndef __ARCH_X86_VTOPHYS_HH__
#define __ARCH_X86_VTOPHYS_HH__

#error X86 is not yet supported!

namespace X86ISA
{
};

#endif // __ARCH_X86_VTOPHYS_HH__
<commit_msg>Fill out a stub version of the vtophys header file.<commit_after>/*
 * Copyright (c) 2007 The Hewlett-Packard Development Company
 * All rights reserved.
 *
 * Redistribution and use of this software in source and binary forms,
 * with or without modification, are permitted provided that the
 * following conditions are met:
 *
 * The software must be used only for Non-Commercial Use which means any
 * use which is NOT directed to receiving any direct monetary
 * compensation for, or commercial advantage from such use.  Illustrative
 * examples of non-commercial use are academic research, personal study,
 * teaching, education and corporate research & development.
 * Illustrative examples of commercial use are distributing products for
 * commercial advantage and providing services using the software for
 * commercial advantage.
 *
 * If you wish to use this software or functionality therein that may be
 * covered by patents for commercial use, please contact:
 *     Director of Intellectual Property Licensing
 *     Office of Strategy and Technology
 *     Hewlett-Packard Company
 *     1501 Page Mill Road
 *     Palo Alto, California  94304
 *
 * 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 COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.  No right of
 * sublicense is granted herewith.  Derivatives of the software and
 * output created using the software may be prepared, but only for
 * Non-Commercial Uses.  Derivatives of the software may be shared with
 * others provided: (i) the others agree to abide by the list of
 * conditions herein which includes the Non-Commercial Use restrictions;
 * and (ii) such Derivatives of the software include the above copyright
 * notice to acknowledge the contribution from this software where
 * applicable, this list of conditions and the disclaimer below.
 *
 * 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.
 *
 * Authors: Gabe Black
 */

#ifndef __ARCH_X86_VTOPHYS_HH__
#define __ARCH_X86_VTOPHYS_HH__

#include "arch/x86/isa_traits.hh"
#include "arch/x86/pagetable.hh"
#include "sim/host.hh"

class ThreadContext;
class FunctionalPort;

namespace X86ISA
{

PageTableEntry
kernel_pte_lookup(FunctionalPort *mem, Addr ptbr, X86ISA::VAddr vaddr);

Addr vtophys(Addr vaddr);
Addr vtophys(ThreadContext *tc, Addr vaddr);

};

#endif // __ARCH_X86_VTOPHYS_HH__
<|endoftext|>


<commit_before>#include "bplustreeblocks.h"

using namespace bplustree;

const TRecordType BPlusTreeBlocks::commTypes[] =
  {
    COMM + LOG + SEND,
    COMM + LOG + RECV,
    COMM + PHY + SEND,
    COMM + PHY + RECV,
    RSEND + LOG,
    RRECV + LOG,
    RSEND + PHY,
    RRECV + PHY
  };

/****************************************
 * Record blocks management methods
 ****************************************/
void BPlusTreeBlocks::newRecord()
{
  if ( currentBlock == NULL )
  {
    blocks[0] = new TRecord[blockSize];
    memset( blocks[0], 0, blockSize * sizeof( TRecord ) );
    currentBlock = blocks[0];
    currentRecord = 0;
  }
  else
  {
    currentRecord++;
    if ( currentRecord == blockSize )
    {
      blocks.push_back( new TRecord[blockSize] );
      memset( blocks[blocks.size() - 1], 0, blockSize * sizeof( TRecord ) );
      currentBlock = blocks[blocks.size() - 1];
      currentRecord = 0;
    }
  }
  lastRecords.push_back( &currentBlock[currentRecord] );
  countInserted++;
}

void BPlusTreeBlocks::setType( TRecordType whichType )
{
  currentBlock[currentRecord].type = whichType;
}

void BPlusTreeBlocks::setTime( TRecordTime whichTime )
{
  currentBlock[currentRecord].time = whichTime;
}

void BPlusTreeBlocks::setThread( TThreadOrder whichThread )
{
  currentBlock[currentRecord].thread = whichThread;
}

void BPlusTreeBlocks::setThread( TApplOrder whichAppl,
                                 TTaskOrder whichTask,
                                 TThreadOrder whichThread )
{
  currentBlock[currentRecord].thread = traceModel.getGlobalThread( whichAppl,
                                       whichTask,
                                       whichThread );
}

void BPlusTreeBlocks::setCPU( TCPUOrder whichCPU )
{
  currentBlock[currentRecord].CPU = whichCPU;
}

void BPlusTreeBlocks::setEventType( TEventType whichType )
{
  currentBlock[currentRecord].URecordInfo.eventRecord.type = whichType;
}

void BPlusTreeBlocks::setEventValue( TEventValue whichValue )
{
  currentBlock[currentRecord].URecordInfo.eventRecord.value = whichValue;
}

void BPlusTreeBlocks::setState( TState whichState )
{
  currentBlock[currentRecord].URecordInfo.stateRecord.state = whichState;
}

void BPlusTreeBlocks::setStateEndTime( TRecordTime whichTime )
{
  currentBlock[currentRecord].URecordInfo.stateRecord.endTime = whichTime;
}

void BPlusTreeBlocks::setCommIndex( TCommID whichID )
{
  currentBlock[currentRecord].URecordInfo.commRecord.index = whichID;
}

/****************************************
 * Communications management methods
 ****************************************/
void BPlusTreeBlocks::newComm( bool createRecords )
{
  communications.push_back( new TCommInfo() );
  currentComm = communications.size() - 1;
  if ( !createRecords )
  {
    for ( UINT8 i = 0; i < commTypeSize; i++ )
      commRecords[ i ] = NULL;
  }
  else
  {
    for ( UINT8 i = 0; i < commTypeSize; i++ )
    {
      newRecord();
      commRecords[i] = &currentBlock[currentRecord];
      setType( commTypes[i] );
      setCommIndex( currentComm );
    }
  }
}

void BPlusTreeBlocks::setSenderThread( TThreadOrder whichThread )
{
  communications[currentComm]->senderThread = whichThread;
  if ( commRecords[logicalSend] != NULL )
  {
    commRecords[logicalSend]->thread = whichThread;
    commRecords[physicalSend]->thread = whichThread;
    commRecords[remoteLogicalReceive]->thread = whichThread;
    commRecords[remotePhysicalReceive]->thread = whichThread;
  }
}

void BPlusTreeBlocks::setSenderThread( TApplOrder whichAppl,
                                       TTaskOrder whichTask,
                                       TThreadOrder whichThread )
{
  TThreadOrder globalThread = traceModel.getGlobalThread( whichAppl,
                              whichTask,
                              whichThread );
  communications[currentComm]->senderThread = globalThread;
  if ( commRecords[logicalSend] != NULL )
  {
    commRecords[logicalSend]->thread = globalThread;
    commRecords[physicalSend]->thread = globalThread;
    commRecords[remoteLogicalReceive]->thread = globalThread;
    commRecords[remotePhysicalReceive]->thread = globalThread;
  }
}

void BPlusTreeBlocks::setSenderCPU( TCPUOrder whichCPU )
{
  communications[currentComm]->senderCPU = whichCPU;
  if ( commRecords[logicalSend] != NULL )
  {
    commRecords[logicalSend]->CPU = whichCPU;
    commRecords[physicalSend]->CPU = whichCPU;
    commRecords[remoteLogicalReceive]->CPU = whichCPU;
    commRecords[remotePhysicalReceive]->CPU = whichCPU;
  }
}

void BPlusTreeBlocks::setReceiverThread( TThreadOrder whichThread )
{
  communications[currentComm]->receiverThread = whichThread;
  if ( commRecords[logicalReceive] != NULL )
  {
    commRecords[logicalReceive]->thread = whichThread;
    commRecords[physicalReceive]->thread = whichThread;
    commRecords[remoteLogicalSend]->thread = whichThread;
    commRecords[remotePhysicalSend]->thread = whichThread;
  }
}

void BPlusTreeBlocks::setReceiverThread( TApplOrder whichAppl,
    TTaskOrder whichTask,
    TThreadOrder whichThread )
{
  TThreadOrder globalThread = traceModel.getGlobalThread( whichAppl,
                              whichTask,
                              whichThread );
  communications[currentComm]->receiverThread = globalThread;
  if ( commRecords[logicalReceive] != NULL )
  {
    commRecords[logicalReceive]->thread = globalThread;
    commRecords[physicalReceive]->thread = globalThread;
    commRecords[remoteLogicalSend]->thread = globalThread;
    commRecords[remotePhysicalSend]->thread = globalThread;
  }
}

void BPlusTreeBlocks::setReceiverCPU( TCPUOrder whichCPU )
{
  communications[currentComm]->receiverCPU = whichCPU;
  if ( commRecords[logicalReceive] != NULL )
  {
    commRecords[logicalReceive]->CPU = whichCPU;
    commRecords[physicalReceive]->CPU = whichCPU;
    commRecords[remoteLogicalSend]->CPU = whichCPU;
    commRecords[remotePhysicalSend]->CPU = whichCPU;
  }
}

void BPlusTreeBlocks::setCommTag( TCommTag whichTag )
{
  communications[currentComm]->tag = whichTag;
}

void BPlusTreeBlocks::setCommSize( TCommSize whichSize )
{
  communications[currentComm]->size = whichSize;
}

void BPlusTreeBlocks::setLogicalSend( TRecordTime whichTime )
{
  communications[currentComm]->logicalSendTime = whichTime;
  if ( commRecords[logicalSend] != NULL )
  {
    commRecords[logicalSend]->time = whichTime;
    commRecords[remoteLogicalSend]->time = whichTime;
  }
}

void BPlusTreeBlocks::setLogicalReceive( TRecordTime whichTime )
{
  communications[currentComm]->logicalReceiveTime = whichTime;
  if ( commRecords[logicalReceive] != NULL )
  {
    commRecords[logicalReceive]->time = whichTime;
    commRecords[remoteLogicalReceive]->time = whichTime;
  }
}

void BPlusTreeBlocks::setPhysicalSend( TRecordTime whichTime )
{
  communications[currentComm]->physicalSendTime = whichTime;
  if ( commRecords[physicalSend] != NULL )
  {
    commRecords[physicalSend]->time = whichTime;
    commRecords[remotePhysicalSend]->time = whichTime;
  }
}

void BPlusTreeBlocks::setPhysicalReceive( TRecordTime whichTime )
{
  communications[currentComm]->physicalReceiveTime = whichTime;
  if ( commRecords[physicalReceive] != NULL )
  {
    commRecords[physicalReceive]->time = whichTime;
    commRecords[remotePhysicalReceive]->time = whichTime;
  }
}

TThreadOrder BPlusTreeBlocks::getSenderThread( TCommID whichComm ) const
{
  return communications[whichComm]->senderThread;
}

TCPUOrder BPlusTreeBlocks::getSenderCPU( TCommID whichComm ) const
{
  return communications[whichComm]->senderCPU;
}

TThreadOrder BPlusTreeBlocks::getReceiverThread( TCommID whichComm ) const
{
  return communications[whichComm]->receiverThread;
}

TCPUOrder BPlusTreeBlocks::getReceiverCPU( TCommID whichComm ) const
{
  return communications[whichComm]->receiverCPU;
}

TCommTag BPlusTreeBlocks::getCommTag( TCommID whichComm ) const
{
  return communications[whichComm]->tag;
}

TCommSize BPlusTreeBlocks::getCommSize( TCommID whichComm ) const
{
  return communications[whichComm]->size;
}

TRecordTime BPlusTreeBlocks::getLogicalSend( TCommID whichComm ) const
{
  return communications[whichComm]->logicalSendTime;
}

TRecordTime BPlusTreeBlocks::getLogicalReceive( TCommID whichComm ) const
{
  return communications[whichComm]->logicalReceiveTime;
}

TRecordTime BPlusTreeBlocks::getPhysicalSend( TCommID whichComm ) const
{
  return communications[whichComm]->physicalSendTime;
}

TRecordTime BPlusTreeBlocks::getPhysicalReceive( TCommID whichComm ) const
{
  return communications[whichComm]->physicalReceiveTime;
}

TRecordTime BPlusTreeBlocks::getLastRecordTime() const
{
  return currentBlock[currentRecord].time;
}
<commit_msg>*** empty log message ***<commit_after>#include <string.h>
#include "bplustreeblocks.h"

using namespace bplustree;

const TRecordType BPlusTreeBlocks::commTypes[] =
  {
    COMM + LOG + SEND,
    COMM + LOG + RECV,
    COMM + PHY + SEND,
    COMM + PHY + RECV,
    RSEND + LOG,
    RRECV + LOG,
    RSEND + PHY,
    RRECV + PHY
  };

/****************************************
 * Record blocks management methods
 ****************************************/
void BPlusTreeBlocks::newRecord()
{
  if ( currentBlock == NULL )
  {
    blocks[0] = new TRecord[blockSize];
    memset( blocks[0], 0, blockSize * sizeof( TRecord ) );
    currentBlock = blocks[0];
    currentRecord = 0;
  }
  else
  {
    currentRecord++;
    if ( currentRecord == blockSize )
    {
      blocks.push_back( new TRecord[blockSize] );
      memset( blocks[blocks.size() - 1], 0, blockSize * sizeof( TRecord ) );
      currentBlock = blocks[blocks.size() - 1];
      currentRecord = 0;
    }
  }
  lastRecords.push_back( &currentBlock[currentRecord] );
  countInserted++;
}

void BPlusTreeBlocks::setType( TRecordType whichType )
{
  currentBlock[currentRecord].type = whichType;
}

void BPlusTreeBlocks::setTime( TRecordTime whichTime )
{
  currentBlock[currentRecord].time = whichTime;
}

void BPlusTreeBlocks::setThread( TThreadOrder whichThread )
{
  currentBlock[currentRecord].thread = whichThread;
}

void BPlusTreeBlocks::setThread( TApplOrder whichAppl,
                                 TTaskOrder whichTask,
                                 TThreadOrder whichThread )
{
  currentBlock[currentRecord].thread = traceModel.getGlobalThread( whichAppl,
                                       whichTask,
                                       whichThread );
}

void BPlusTreeBlocks::setCPU( TCPUOrder whichCPU )
{
  currentBlock[currentRecord].CPU = whichCPU;
}

void BPlusTreeBlocks::setEventType( TEventType whichType )
{
  currentBlock[currentRecord].URecordInfo.eventRecord.type = whichType;
}

void BPlusTreeBlocks::setEventValue( TEventValue whichValue )
{
  currentBlock[currentRecord].URecordInfo.eventRecord.value = whichValue;
}

void BPlusTreeBlocks::setState( TState whichState )
{
  currentBlock[currentRecord].URecordInfo.stateRecord.state = whichState;
}

void BPlusTreeBlocks::setStateEndTime( TRecordTime whichTime )
{
  currentBlock[currentRecord].URecordInfo.stateRecord.endTime = whichTime;
}

void BPlusTreeBlocks::setCommIndex( TCommID whichID )
{
  currentBlock[currentRecord].URecordInfo.commRecord.index = whichID;
}

/****************************************
 * Communications management methods
 ****************************************/
void BPlusTreeBlocks::newComm( bool createRecords )
{
  communications.push_back( new TCommInfo() );
  currentComm = communications.size() - 1;
  if ( !createRecords )
  {
    for ( UINT8 i = 0; i < commTypeSize; i++ )
      commRecords[ i ] = NULL;
  }
  else
  {
    for ( UINT8 i = 0; i < commTypeSize; i++ )
    {
      newRecord();
      commRecords[i] = &currentBlock[currentRecord];
      setType( commTypes[i] );
      setCommIndex( currentComm );
    }
  }
}

void BPlusTreeBlocks::setSenderThread( TThreadOrder whichThread )
{
  communications[currentComm]->senderThread = whichThread;
  if ( commRecords[logicalSend] != NULL )
  {
    commRecords[logicalSend]->thread = whichThread;
    commRecords[physicalSend]->thread = whichThread;
    commRecords[remoteLogicalReceive]->thread = whichThread;
    commRecords[remotePhysicalReceive]->thread = whichThread;
  }
}

void BPlusTreeBlocks::setSenderThread( TApplOrder whichAppl,
                                       TTaskOrder whichTask,
                                       TThreadOrder whichThread )
{
  TThreadOrder globalThread = traceModel.getGlobalThread( whichAppl,
                              whichTask,
                              whichThread );
  communications[currentComm]->senderThread = globalThread;
  if ( commRecords[logicalSend] != NULL )
  {
    commRecords[logicalSend]->thread = globalThread;
    commRecords[physicalSend]->thread = globalThread;
    commRecords[remoteLogicalReceive]->thread = globalThread;
    commRecords[remotePhysicalReceive]->thread = globalThread;
  }
}

void BPlusTreeBlocks::setSenderCPU( TCPUOrder whichCPU )
{
  communications[currentComm]->senderCPU = whichCPU;
  if ( commRecords[logicalSend] != NULL )
  {
    commRecords[logicalSend]->CPU = whichCPU;
    commRecords[physicalSend]->CPU = whichCPU;
    commRecords[remoteLogicalReceive]->CPU = whichCPU;
    commRecords[remotePhysicalReceive]->CPU = whichCPU;
  }
}

void BPlusTreeBlocks::setReceiverThread( TThreadOrder whichThread )
{
  communications[currentComm]->receiverThread = whichThread;
  if ( commRecords[logicalReceive] != NULL )
  {
    commRecords[logicalReceive]->thread = whichThread;
    commRecords[physicalReceive]->thread = whichThread;
    commRecords[remoteLogicalSend]->thread = whichThread;
    commRecords[remotePhysicalSend]->thread = whichThread;
  }
}

void BPlusTreeBlocks::setReceiverThread( TApplOrder whichAppl,
    TTaskOrder whichTask,
    TThreadOrder whichThread )
{
  TThreadOrder globalThread = traceModel.getGlobalThread( whichAppl,
                              whichTask,
                              whichThread );
  communications[currentComm]->receiverThread = globalThread;
  if ( commRecords[logicalReceive] != NULL )
  {
    commRecords[logicalReceive]->thread = globalThread;
    commRecords[physicalReceive]->thread = globalThread;
    commRecords[remoteLogicalSend]->thread = globalThread;
    commRecords[remotePhysicalSend]->thread = globalThread;
  }
}

void BPlusTreeBlocks::setReceiverCPU( TCPUOrder whichCPU )
{
  communications[currentComm]->receiverCPU = whichCPU;
  if ( commRecords[logicalReceive] != NULL )
  {
    commRecords[logicalReceive]->CPU = whichCPU;
    commRecords[physicalReceive]->CPU = whichCPU;
    commRecords[remoteLogicalSend]->CPU = whichCPU;
    commRecords[remotePhysicalSend]->CPU = whichCPU;
  }
}

void BPlusTreeBlocks::setCommTag( TCommTag whichTag )
{
  communications[currentComm]->tag = whichTag;
}

void BPlusTreeBlocks::setCommSize( TCommSize whichSize )
{
  communications[currentComm]->size = whichSize;
}

void BPlusTreeBlocks::setLogicalSend( TRecordTime whichTime )
{
  communications[currentComm]->logicalSendTime = whichTime;
  if ( commRecords[logicalSend] != NULL )
  {
    commRecords[logicalSend]->time = whichTime;
    commRecords[remoteLogicalSend]->time = whichTime;
  }
}

void BPlusTreeBlocks::setLogicalReceive( TRecordTime whichTime )
{
  communications[currentComm]->logicalReceiveTime = whichTime;
  if ( commRecords[logicalReceive] != NULL )
  {
    commRecords[logicalReceive]->time = whichTime;
    commRecords[remoteLogicalReceive]->time = whichTime;
  }
}

void BPlusTreeBlocks::setPhysicalSend( TRecordTime whichTime )
{
  communications[currentComm]->physicalSendTime = whichTime;
  if ( commRecords[physicalSend] != NULL )
  {
    commRecords[physicalSend]->time = whichTime;
    commRecords[remotePhysicalSend]->time = whichTime;
  }
}

void BPlusTreeBlocks::setPhysicalReceive( TRecordTime whichTime )
{
  communications[currentComm]->physicalReceiveTime = whichTime;
  if ( commRecords[physicalReceive] != NULL )
  {
    commRecords[physicalReceive]->time = whichTime;
    commRecords[remotePhysicalReceive]->time = whichTime;
  }
}

TThreadOrder BPlusTreeBlocks::getSenderThread( TCommID whichComm ) const
{
  return communications[whichComm]->senderThread;
}

TCPUOrder BPlusTreeBlocks::getSenderCPU( TCommID whichComm ) const
{
  return communications[whichComm]->senderCPU;
}

TThreadOrder BPlusTreeBlocks::getReceiverThread( TCommID whichComm ) const
{
  return communications[whichComm]->receiverThread;
}

TCPUOrder BPlusTreeBlocks::getReceiverCPU( TCommID whichComm ) const
{
  return communications[whichComm]->receiverCPU;
}

TCommTag BPlusTreeBlocks::getCommTag( TCommID whichComm ) const
{
  return communications[whichComm]->tag;
}

TCommSize BPlusTreeBlocks::getCommSize( TCommID whichComm ) const
{
  return communications[whichComm]->size;
}

TRecordTime BPlusTreeBlocks::getLogicalSend( TCommID whichComm ) const
{
  return communications[whichComm]->logicalSendTime;
}

TRecordTime BPlusTreeBlocks::getLogicalReceive( TCommID whichComm ) const
{
  return communications[whichComm]->logicalReceiveTime;
}

TRecordTime BPlusTreeBlocks::getPhysicalSend( TCommID whichComm ) const
{
  return communications[whichComm]->physicalSendTime;
}

TRecordTime BPlusTreeBlocks::getPhysicalReceive( TCommID whichComm ) const
{
  return communications[whichComm]->physicalReceiveTime;
}

TRecordTime BPlusTreeBlocks::getLastRecordTime() const
{
  return currentBlock[currentRecord].time;
}
<|endoftext|>


<commit_before>//userliteral header
//Copyright (c) 2014 mmYYmmdd

#if !defined MMYYMMDD_USER_LITERAL_INCLUDED
#define MMYYMMDD_USER_LITERAL_INCLUDED

#include <ratio>

// create std::integral_constant and std::ratio from user defined literal
// ユーザー定義リテラルから std::integral_constant と std::ratio を出力する
namespace mymd	{

	namespace detail_user_literal	{

		constexpr std::size_t buncho(char x)
		{  return ('0' <= x && x <= '9')? x-'0': ('a' <= x && x <='f' )? x-'a'+10: ('A' <= x && x <='F' )? x-'A'+10: 0; }

		template <std::size_t, std::size_t, std::size_t, char...> struct digit;

		template <std::size_t L, std::size_t N, std::size_t D, char first, char... tail>
		struct digit<L, N, D, first, tail...>    {
			 static constexpr std::size_t num = digit<L, L * N + buncho(first), 10 * D, tail...>::num;
			 static constexpr std::size_t den = digit<L, L * N + buncho(first), 10 * D, tail...>::den;
		};

		template <std::size_t L, std::size_t N, std::size_t D, char... tail>
		struct digit<L, N, D, 'x', tail...>    {
			static constexpr std::size_t num = digit<16, 0, D, tail...>::num;
			static constexpr std::size_t den = digit<16, 0, D, tail...>::den;
		};

		template <std::size_t L, std::size_t N, std::size_t D, char... tail>
		struct digit<L, N, D, 'X', tail...>    {
			static constexpr std::size_t num = digit<16, 0, D, tail...>::num;
			static constexpr std::size_t den = digit<16, 0, D, tail...>::den;
		};

		template <std::size_t L, std::size_t N, std::size_t D, char... tail>
		struct digit<L, N, D, 'b', tail...>    {
			static constexpr std::size_t num = digit<2, 0, D, tail...>::num;
			static constexpr std::size_t den = digit<2, 0, D, tail...>::den;
		};

		template <std::size_t L, std::size_t N, std::size_t D, char... tail>
		struct digit<L, N, D, 'B', tail...>    {
			static constexpr std::size_t num = digit<2, 0, D, tail...>::num;
			static constexpr std::size_t den = digit<2, 0, D, tail...>::den;
		};

		template <std::size_t L, std::size_t N, std::size_t D, char... tail>
		struct digit<L, N, D, '.', tail...>    {
			static constexpr std::size_t num = digit<L, N, 1, tail...>::num;
			static constexpr std::size_t den = digit<L, N, 1, tail...>::den;
		};

		template <std::size_t L, std::size_t N, std::size_t D>
		struct digit<L, N, D>    {
			constexpr static std::size_t num = N;
			constexpr static std::size_t den = D;
		};

		template <char first, char... tail>
		constexpr int num()  { return digit<first=='0'? 8: 10, 0, 0, first, tail...>::num; }

		template <char first, char... tail>
		constexpr int den()
		{
			return digit<first=='0'? 8: 10, 0, 0, first, tail...>::den == 0? 1: digit<first=='0'? 8: 10, 0, 0, first, tail...>::den;
		}

	}	//namespace detail_user_literal

	namespace ul    {
		template <char... Char>
		constexpr auto operator "" _ic()
			->std::integral_constant<int, detail_user_literal::num<Char...>() / detail_user_literal::den<Char...>()>
		{
			return std::integral_constant<int, detail_user_literal::num<Char...>() / detail_user_literal::den<Char...>()>{};
		}

		template <char... Char>
		constexpr auto operator "" _rc()
			->std::ratio<detail_user_literal::num<Char...>(), detail_user_literal::den<Char...>()>
		{
			return std::ratio<detail_user_literal::num<Char...>(), detail_user_literal::den<Char...>()>{};
		}
    }	//	namespace ul

}	//	namespace mymd

#endif
<commit_msg>Delete userliteral.hpp<commit_after><|endoftext|>


<commit_before>// Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "chainparamsbase.h"

#include "util.h"

#include <assert.h>

#include <boost/assign/list_of.hpp>

using namespace boost::assign;

/**
 * Main network
 */
class CBaseMainParams : public CBaseChainParams
{
public:
    CBaseMainParams()
    {
        networkID = CBaseChainParams::MAIN;
        nRPCPort = 9527;
    }
};
static CBaseMainParams mainParams;

/**
 * Testnet (v3)
 */
class CBaseTestNetParams : public CBaseMainParams
{
public:
    CBaseTestNetParams()
    {
        networkID = CBaseChainParams::TESTNET;
        nRPCPort = 19527;
        strDataDir = "testnet3";
    }
};
static CBaseTestNetParams testNetParams;

/*
 * Regression test
 */
class CBaseRegTestParams : public CBaseTestNetParams
{
public:
    CBaseRegTestParams()
    {
        networkID = CBaseChainParams::REGTEST;
        strDataDir = "regtest";
    }
};
static CBaseRegTestParams regTestParams;

/*
 * Unit test
 */
class CBaseUnitTestParams : public CBaseMainParams
{
public:
    CBaseUnitTestParams()
    {
        networkID = CBaseChainParams::UNITTEST;
        strDataDir = "unittest";
    }
};
static CBaseUnitTestParams unitTestParams;

static CBaseChainParams* pCurrentBaseParams = 0;

const CBaseChainParams& BaseParams()
{
    assert(pCurrentBaseParams);
    return *pCurrentBaseParams;
}

void SelectBaseParams(CBaseChainParams::Network network)
{
    switch (network) {
    case CBaseChainParams::MAIN:
        pCurrentBaseParams = &mainParams;
        break;
    case CBaseChainParams::TESTNET:
        pCurrentBaseParams = &testNetParams;
        break;
    case CBaseChainParams::REGTEST:
        pCurrentBaseParams = &regTestParams;
        break;
    case CBaseChainParams::UNITTEST:
        pCurrentBaseParams = &unitTestParams;
        break;
    default:
        assert(false && "Unimplemented network");
        return;
    }
}

CBaseChainParams::Network NetworkIdFromCommandLine()
{
    bool fRegTest = GetBoolArg("-regtest", false);
    bool fTestNet = GetBoolArg("-testnet", false);

    if (fTestNet && fRegTest)
        return CBaseChainParams::MAX_NETWORK_TYPES;
    if (fRegTest)
        return CBaseChainParams::REGTEST;
    if (fTestNet)
        return CBaseChainParams::TESTNET;
    return CBaseChainParams::MAIN;
}

bool SelectBaseParamsFromCommandLine()
{
    CBaseChainParams::Network network = NetworkIdFromCommandLine();
    if (network == CBaseChainParams::MAX_NETWORK_TYPES)
        return false;

    SelectBaseParams(network);
    return true;
}

bool AreBaseParamsConfigured()
{
    return pCurrentBaseParams != NULL;
}
<commit_msg>Delete chainparamsbase.cpp<commit_after><|endoftext|>


<commit_before>// Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-2015 The Bitcoin Core developers
// Copyright (c) 2015-2017 The Bitcoin Unlimited developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "chainparamsbase.h"

#include "tinyformat.h"
#include "util.h"

#include <assert.h>

const std::string CBaseChainParams::MAIN = "main";
const std::string CBaseChainParams::UNL = "nol";
const std::string CBaseChainParams::TESTNET = "test";
const std::string CBaseChainParams::TESTNET4 = "test4";
const std::string CBaseChainParams::REGTEST = "regtest";

/**
 * Main network
 */
class CBaseMainParams : public CBaseChainParams
{
public:
    CBaseMainParams() { nRPCPort = 8332; }
};
static CBaseMainParams mainParams;

/**
 * Unl network
 */
class CBaseUnlParams : public CBaseChainParams
{
public:
    CBaseUnlParams()
    {
        nRPCPort = 9332;
        strDataDir = "nol";
    }
};
static CBaseUnlParams unlParams;

/**
 * Testnet (v3)
 */
class CBaseTestNetParams : public CBaseChainParams
{
public:
    CBaseTestNetParams()
    {
        nRPCPort = 18332;
        strDataDir = "testnet3";
    }
};
static CBaseTestNetParams testNetParams;

class CBaseTestNet4Params : public CBaseChainParams
{
public:
    CBaseTestNet4Params()
    {
        nRPCPort = 28333;
        strDataDir = "testnet4";
    }
};
static CBaseTestNet4Params testNet4Params;

/*
 * Regression test
 */
class CBaseRegTestParams : public CBaseChainParams
{
public:
    CBaseRegTestParams()
    {
        nRPCPort = 18332;
        strDataDir = "regtest";
    }
};
static CBaseRegTestParams regTestParams;

static CBaseChainParams *pCurrentBaseParams = 0;

const CBaseChainParams &BaseParams()
{
    assert(pCurrentBaseParams);
    return *pCurrentBaseParams;
}

CBaseChainParams &BaseParams(const std::string &chain)
{
    if (chain == CBaseChainParams::MAIN)
        return mainParams;
    else if (chain == CBaseChainParams::UNL)
        return unlParams;
    else if (chain == CBaseChainParams::TESTNET)
        return testNetParams;
    else if (chain == CBaseChainParams::TESTNET4)
        return testNet4Params;
    else if (chain == CBaseChainParams::REGTEST)
        return regTestParams;
    else
        throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
}

void SelectBaseParams(const std::string &chain) { pCurrentBaseParams = &BaseParams(chain); }
std::string ChainNameFromCommandLine()
{
    uint64_t num_selected = 0;
    bool fRegTest = GetBoolArg("-regtest", false);
    num_selected += fRegTest;
    bool fTestNet = GetBoolArg("-testnet", false);
    num_selected += fTestNet;
    bool fTestNet4 = GetBoolArg("-testnet4", false);
    num_selected += fTestNet4;
    bool fUnl = GetBoolArg("-chain_nol", false);
    num_selected += fUnl;

    if (num_selected > 1)
        throw std::runtime_error("Invalid combination of -regtest, -testnet, and -testnet4.");
    if (fRegTest)
        return CBaseChainParams::REGTEST;
    if (fTestNet)
        return CBaseChainParams::TESTNET;
    if (fTestNet4)
        return CBaseChainParams::TESTNET4;
    if (fUnl)
        return CBaseChainParams::UNL;
    return CBaseChainParams::MAIN;
}

bool AreBaseParamsConfigured() { return pCurrentBaseParams != nullptr; }
<commit_msg>Fix testnet4 RPC port<commit_after>// Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-2015 The Bitcoin Core developers
// Copyright (c) 2015-2017 The Bitcoin Unlimited developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "chainparamsbase.h"

#include "tinyformat.h"
#include "util.h"

#include <assert.h>

const std::string CBaseChainParams::MAIN = "main";
const std::string CBaseChainParams::UNL = "nol";
const std::string CBaseChainParams::TESTNET = "test";
const std::string CBaseChainParams::TESTNET4 = "test4";
const std::string CBaseChainParams::REGTEST = "regtest";

/**
 * Main network
 */
class CBaseMainParams : public CBaseChainParams
{
public:
    CBaseMainParams() { nRPCPort = 8332; }
};
static CBaseMainParams mainParams;

/**
 * Unl network
 */
class CBaseUnlParams : public CBaseChainParams
{
public:
    CBaseUnlParams()
    {
        nRPCPort = 9332;
        strDataDir = "nol";
    }
};
static CBaseUnlParams unlParams;

/**
 * Testnet (v3)
 */
class CBaseTestNetParams : public CBaseChainParams
{
public:
    CBaseTestNetParams()
    {
        nRPCPort = 18332;
        strDataDir = "testnet3";
    }
};
static CBaseTestNetParams testNetParams;

/**
 * Testnet (v4)
 */
class CBaseTestNet4Params : public CBaseChainParams
{
public:
    CBaseTestNet4Params()
    {
        nRPCPort = 28332;
        strDataDir = "testnet4";
    }
};
static CBaseTestNet4Params testNet4Params;

/*
 * Regression test
 */
class CBaseRegTestParams : public CBaseChainParams
{
public:
    CBaseRegTestParams()
    {
        nRPCPort = 18332;
        strDataDir = "regtest";
    }
};
static CBaseRegTestParams regTestParams;

static CBaseChainParams *pCurrentBaseParams = 0;

const CBaseChainParams &BaseParams()
{
    assert(pCurrentBaseParams);
    return *pCurrentBaseParams;
}

CBaseChainParams &BaseParams(const std::string &chain)
{
    if (chain == CBaseChainParams::MAIN)
        return mainParams;
    else if (chain == CBaseChainParams::UNL)
        return unlParams;
    else if (chain == CBaseChainParams::TESTNET)
        return testNetParams;
    else if (chain == CBaseChainParams::TESTNET4)
        return testNet4Params;
    else if (chain == CBaseChainParams::REGTEST)
        return regTestParams;
    else
        throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
}

void SelectBaseParams(const std::string &chain) { pCurrentBaseParams = &BaseParams(chain); }
std::string ChainNameFromCommandLine()
{
    uint64_t num_selected = 0;
    bool fRegTest = GetBoolArg("-regtest", false);
    num_selected += fRegTest;
    bool fTestNet = GetBoolArg("-testnet", false);
    num_selected += fTestNet;
    bool fTestNet4 = GetBoolArg("-testnet4", false);
    num_selected += fTestNet4;
    bool fUnl = GetBoolArg("-chain_nol", false);
    num_selected += fUnl;

    if (num_selected > 1)
        throw std::runtime_error("Invalid combination of -regtest, -testnet, and -testnet4.");
    if (fRegTest)
        return CBaseChainParams::REGTEST;
    if (fTestNet)
        return CBaseChainParams::TESTNET;
    if (fTestNet4)
        return CBaseChainParams::TESTNET4;
    if (fUnl)
        return CBaseChainParams::UNL;
    return CBaseChainParams::MAIN;
}

bool AreBaseParamsConfigured() { return pCurrentBaseParams != nullptr; }
<|endoftext|>