<commit_before>/*=============================================================================

  Library: CTK

  Copyright (c) German Cancer Research Center,
    Division of Medical and Biological Informatics

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

=============================================================================*/

// Qt includes
#include <QtPlugin>
#include <QRect>
#include <QDebug>
#include <QPushButton>
#include <QApplication>
#include <QLabel>

// CTK includes
#include "ctkDICOMImage.h"
#include "ctkExampleDicomAppLogic_p.h"
#include "ctkExampleDicomAppPlugin_p.h"

// DCMTK includes
#include <dcmimage.h>

//----------------------------------------------------------------------------
ctkExampleDicomAppLogic::ctkExampleDicomAppLogic():
ctkDicomAbstractApp(ctkExampleDicomAppPlugin::getPluginContext()), Button(0)
{

  connect(this, SIGNAL(startProgress()), this, SLOT(onStartProgress()), Qt::QueuedConnection);
  connect(this, SIGNAL(resumeProgress()), this, SLOT(onResumeProgress()), Qt::QueuedConnection);
  connect(this, SIGNAL(suspendProgress()), this, SLOT(onSuspendProgress()), Qt::QueuedConnection);
  connect(this, SIGNAL(cancelProgress()), this, SLOT(onCancelProgress()), Qt::QueuedConnection);
  connect(this, SIGNAL(exitHostedApp()), this, SLOT(onExitHostedApp()), Qt::QueuedConnection);

  //notify Host we are ready.
  getHostInterface()->notifyStateChanged(ctkDicomAppHosting::IDLE);
}

//----------------------------------------------------------------------------
ctkExampleDicomAppLogic::~ctkExampleDicomAppLogic()
{
  ctkPluginContext* context = ctkExampleDicomAppPlugin::getPluginContext();
  QList <QSharedPointer<ctkPlugin> > plugins = context->getPlugins();
  for (int i = 0; i < plugins.size(); ++i)
  {
    qDebug() << plugins.at(i)->getSymbolicName ();
  }
}

//----------------------------------------------------------------------------
bool ctkExampleDicomAppLogic::bringToFront(const QRect& /*requestedScreenArea*/)
{
  return false;
}

//----------------------------------------------------------------------------
void ctkExampleDicomAppLogic::do_something()
{
  this->Button = new QPushButton("Button from App");
  connect(this->Button, SIGNAL(clicked()), this, SLOT(buttonClicked()));
  try
    {
    QRect preferred(50,50,100,100);
    qDebug() << "  Asking:getAvailableScreen";
    QRect rect = getHostInterface()->getAvailableScreen(preferred);
    qDebug() << "  got sth:" << rect.top();
    this->Button->move(rect.topLeft());
    this->Button->resize(rect.size());
    }
  catch (const std::runtime_error& e)
    {
    qCritical() << e.what();
    return;
    }
  this->Button->show();
}

//----------------------------------------------------------------------------
void ctkExampleDicomAppLogic::onStartProgress()
{
  setInternalState(ctkDicomAppHosting::INPROGRESS);
  getHostInterface()->notifyStateChanged(ctkDicomAppHosting::INPROGRESS);

  do_something();
}

//----------------------------------------------------------------------------
void ctkExampleDicomAppLogic::onResumeProgress()
{
  //reclame all resources.

  //notify state changed
  setInternalState(ctkDicomAppHosting::INPROGRESS);
  getHostInterface()->notifyStateChanged(ctkDicomAppHosting::INPROGRESS);
  //we're rolling
  //do something else normally, but this is an example
  this->Button->setEnabled(true);
}

//----------------------------------------------------------------------------
void ctkExampleDicomAppLogic::onSuspendProgress()
{
  //release resources it can reclame later to resume work
  this->Button->setEnabled(false);
  //notify state changed
  setInternalState(ctkDicomAppHosting::SUSPENDED);
  getHostInterface()->notifyStateChanged(ctkDicomAppHosting::SUSPENDED);
  //we're rolling
  //do something else normally, but this is an example
}

//----------------------------------------------------------------------------
void ctkExampleDicomAppLogic::onCancelProgress()
{
  //release all resources
  onReleaseResources();
  //update state
  setInternalState(ctkDicomAppHosting::IDLE);
  getHostInterface()->notifyStateChanged(ctkDicomAppHosting::IDLE);
}

//----------------------------------------------------------------------------
void ctkExampleDicomAppLogic::onExitHostedApp()
{
  //useless move, but correct:
  setInternalState(ctkDicomAppHosting::EXIT);
  getHostInterface()->notifyStateChanged(ctkDicomAppHosting::EXIT);
  //die
  qApp->exit(0);
}

//----------------------------------------------------------------------------
void ctkExampleDicomAppLogic::onReleaseResources()
{
  this->Button->hide();
  delete (this->Button);
  this->Button = 0 ;
}

//----------------------------------------------------------------------------
bool ctkExampleDicomAppLogic::notifyDataAvailable(const ctkDicomAppHosting::AvailableData& data, bool lastData)
{
  Q_UNUSED(lastData)
  QString s;
  if(this->Button == 0)
    {
    qCritical() << "Button is null!";
    return false;
    }
  s = "Received notifyDataAvailable with patients.count()= " + QString().setNum(data.patients.count());
  if(data.patients.count()>0)
    {
    s=s+" name:"+data.patients.begin()->name+" studies.count(): "+QString().setNum(data.patients.begin()->studies.count());
    if(data.patients.begin()->studies.count()>0)
    {
      s=s+" series.count():" + QString().setNum(data.patients.begin()->studies.begin()->series.count());
      if(data.patients.begin()->studies.begin()->series.count()>0)
      {
        s=s+" uid:" + data.patients.begin()->studies.begin()->series.begin()->seriesUID;
//        QUuid uuid("93097dc1-caf9-43a3-a814-51a57f8d861d");//data.patients.begin()->studies.begin()->series.begin()->seriesUID);
        uuid = data.patients.begin()->studies.begin()->series.begin()->objectDescriptors.begin()->descriptorUUID;
        s=s+" uuid:"+uuid.toString();
      }
    }
  }
  this->Button->setText(s);
  return false;
}

//----------------------------------------------------------------------------
QList<ctkDicomAppHosting::ObjectLocator> ctkExampleDicomAppLogic::getData(
  const QList<QUuid>& objectUUIDs,
  const QList<QString>& acceptableTransferSyntaxUIDs,
  bool includeBulkData)
{
  Q_UNUSED(objectUUIDs)
  Q_UNUSED(acceptableTransferSyntaxUIDs)
  Q_UNUSED(includeBulkData)
  return QList<ctkDicomAppHosting::ObjectLocator>();
}

//----------------------------------------------------------------------------
void ctkExampleDicomAppLogic::releaseData(const QList<QUuid>& objectUUIDs)
{
  Q_UNUSED(objectUUIDs)
}

void ctkExampleDicomAppLogic::buttonClicked()
{
  QList<QUuid> uuidlist;
  uuidlist.append(uuid);
  QString transfersyntax("1.2.840.10008.1.2.1");
  QList<QString> transfersyntaxlist;
  transfersyntaxlist.append(transfersyntax);
  QList<ctkDicomAppHosting::ObjectLocator> locators;
  locators = getHostInterface()->getData(uuidlist, transfersyntaxlist, false);
  qDebug() << "got locators! " << QString().setNum(locators.count());

  QString s;
  s=s+" loc.count:"+QString().setNum(locators.count());
  if(locators.count()>0)
  {
    s=s+" URI: "+locators.begin()->URI;
    qDebug() << "URI: " << locators.begin()->URI;
    QString filename = locators.begin()->URI;
    if(filename.startsWith("file:/",Qt::CaseInsensitive))
      filename=filename.remove(0,6);
    qDebug()<<filename;
    DicomImage dcmtkImage(filename.toLatin1().data());
    ctkDICOMImage ctkImage(&dcmtkImage);

    QLabel* qtImage = new QLabel;
    qtImage->setPixmap(ctkImage.getPixmap(0));
    qtImage->show();
  }
  this->Button->setText(s);
}
<commit_msg>Comply with changed interface of ctkDICOMImage<commit_after>/*=============================================================================

  Library: CTK

  Copyright (c) German Cancer Research Center,
    Division of Medical and Biological Informatics

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

=============================================================================*/

// Qt includes
#include <QtPlugin>
#include <QRect>
#include <QDebug>
#include <QPushButton>
#include <QApplication>
#include <QLabel>

// CTK includes
#include "ctkDICOMImage.h"
#include "ctkExampleDicomAppLogic_p.h"
#include "ctkExampleDicomAppPlugin_p.h"

// DCMTK includes
#include <dcmimage.h>

//----------------------------------------------------------------------------
ctkExampleDicomAppLogic::ctkExampleDicomAppLogic():
ctkDicomAbstractApp(ctkExampleDicomAppPlugin::getPluginContext()), Button(0)
{

  connect(this, SIGNAL(startProgress()), this, SLOT(onStartProgress()), Qt::QueuedConnection);
  connect(this, SIGNAL(resumeProgress()), this, SLOT(onResumeProgress()), Qt::QueuedConnection);
  connect(this, SIGNAL(suspendProgress()), this, SLOT(onSuspendProgress()), Qt::QueuedConnection);
  connect(this, SIGNAL(cancelProgress()), this, SLOT(onCancelProgress()), Qt::QueuedConnection);
  connect(this, SIGNAL(exitHostedApp()), this, SLOT(onExitHostedApp()), Qt::QueuedConnection);

  //notify Host we are ready.
  getHostInterface()->notifyStateChanged(ctkDicomAppHosting::IDLE);
}

//----------------------------------------------------------------------------
ctkExampleDicomAppLogic::~ctkExampleDicomAppLogic()
{
  ctkPluginContext* context = ctkExampleDicomAppPlugin::getPluginContext();
  QList <QSharedPointer<ctkPlugin> > plugins = context->getPlugins();
  for (int i = 0; i < plugins.size(); ++i)
  {
    qDebug() << plugins.at(i)->getSymbolicName ();
  }
}

//----------------------------------------------------------------------------
bool ctkExampleDicomAppLogic::bringToFront(const QRect& /*requestedScreenArea*/)
{
  return false;
}

//----------------------------------------------------------------------------
void ctkExampleDicomAppLogic::do_something()
{
  this->Button = new QPushButton("Button from App");
  connect(this->Button, SIGNAL(clicked()), this, SLOT(buttonClicked()));
  try
    {
    QRect preferred(50,50,100,100);
    qDebug() << "  Asking:getAvailableScreen";
    QRect rect = getHostInterface()->getAvailableScreen(preferred);
    qDebug() << "  got sth:" << rect.top();
    this->Button->move(rect.topLeft());
    this->Button->resize(rect.size());
    }
  catch (const std::runtime_error& e)
    {
    qCritical() << e.what();
    return;
    }
  this->Button->show();
}

//----------------------------------------------------------------------------
void ctkExampleDicomAppLogic::onStartProgress()
{
  setInternalState(ctkDicomAppHosting::INPROGRESS);
  getHostInterface()->notifyStateChanged(ctkDicomAppHosting::INPROGRESS);

  do_something();
}

//----------------------------------------------------------------------------
void ctkExampleDicomAppLogic::onResumeProgress()
{
  //reclame all resources.

  //notify state changed
  setInternalState(ctkDicomAppHosting::INPROGRESS);
  getHostInterface()->notifyStateChanged(ctkDicomAppHosting::INPROGRESS);
  //we're rolling
  //do something else normally, but this is an example
  this->Button->setEnabled(true);
}

//----------------------------------------------------------------------------
void ctkExampleDicomAppLogic::onSuspendProgress()
{
  //release resources it can reclame later to resume work
  this->Button->setEnabled(false);
  //notify state changed
  setInternalState(ctkDicomAppHosting::SUSPENDED);
  getHostInterface()->notifyStateChanged(ctkDicomAppHosting::SUSPENDED);
  //we're rolling
  //do something else normally, but this is an example
}

//----------------------------------------------------------------------------
void ctkExampleDicomAppLogic::onCancelProgress()
{
  //release all resources
  onReleaseResources();
  //update state
  setInternalState(ctkDicomAppHosting::IDLE);
  getHostInterface()->notifyStateChanged(ctkDicomAppHosting::IDLE);
}

//----------------------------------------------------------------------------
void ctkExampleDicomAppLogic::onExitHostedApp()
{
  //useless move, but correct:
  setInternalState(ctkDicomAppHosting::EXIT);
  getHostInterface()->notifyStateChanged(ctkDicomAppHosting::EXIT);
  //die
  qApp->exit(0);
}

//----------------------------------------------------------------------------
void ctkExampleDicomAppLogic::onReleaseResources()
{
  this->Button->hide();
  delete (this->Button);
  this->Button = 0 ;
}

//----------------------------------------------------------------------------
bool ctkExampleDicomAppLogic::notifyDataAvailable(const ctkDicomAppHosting::AvailableData& data, bool lastData)
{
  Q_UNUSED(lastData)
  QString s;
  if(this->Button == 0)
    {
    qCritical() << "Button is null!";
    return false;
    }
  s = "Received notifyDataAvailable with patients.count()= " + QString().setNum(data.patients.count());
  if(data.patients.count()>0)
    {
    s=s+" name:"+data.patients.begin()->name+" studies.count(): "+QString().setNum(data.patients.begin()->studies.count());
    if(data.patients.begin()->studies.count()>0)
    {
      s=s+" series.count():" + QString().setNum(data.patients.begin()->studies.begin()->series.count());
      if(data.patients.begin()->studies.begin()->series.count()>0)
      {
        s=s+" uid:" + data.patients.begin()->studies.begin()->series.begin()->seriesUID;
//        QUuid uuid("93097dc1-caf9-43a3-a814-51a57f8d861d");//data.patients.begin()->studies.begin()->series.begin()->seriesUID);
        uuid = data.patients.begin()->studies.begin()->series.begin()->objectDescriptors.begin()->descriptorUUID;
        s=s+" uuid:"+uuid.toString();
      }
    }
  }
  this->Button->setText(s);
  return false;
}

//----------------------------------------------------------------------------
QList<ctkDicomAppHosting::ObjectLocator> ctkExampleDicomAppLogic::getData(
  const QList<QUuid>& objectUUIDs,
  const QList<QString>& acceptableTransferSyntaxUIDs,
  bool includeBulkData)
{
  Q_UNUSED(objectUUIDs)
  Q_UNUSED(acceptableTransferSyntaxUIDs)
  Q_UNUSED(includeBulkData)
  return QList<ctkDicomAppHosting::ObjectLocator>();
}

//----------------------------------------------------------------------------
void ctkExampleDicomAppLogic::releaseData(const QList<QUuid>& objectUUIDs)
{
  Q_UNUSED(objectUUIDs)
}

void ctkExampleDicomAppLogic::buttonClicked()
{
  QList<QUuid> uuidlist;
  uuidlist.append(uuid);
  QString transfersyntax("1.2.840.10008.1.2.1");
  QList<QString> transfersyntaxlist;
  transfersyntaxlist.append(transfersyntax);
  QList<ctkDicomAppHosting::ObjectLocator> locators;
  locators = getHostInterface()->getData(uuidlist, transfersyntaxlist, false);
  qDebug() << "got locators! " << QString().setNum(locators.count());

  QString s;
  s=s+" loc.count:"+QString().setNum(locators.count());
  if(locators.count()>0)
  {
    s=s+" URI: "+locators.begin()->URI;
    qDebug() << "URI: " << locators.begin()->URI;
    QString filename = locators.begin()->URI;
    if(filename.startsWith("file:/",Qt::CaseInsensitive))
      filename=filename.remove(0,6);
    qDebug()<<filename;
    DicomImage dcmtkImage(filename.toLatin1().data());
    ctkDICOMImage ctkImage(&dcmtkImage);

    QLabel* qtImage = new QLabel;
    QPixmap pixmap = QPixmap::fromImage(ctkImage.getImage(0),Qt::AvoidDither);
    if (pixmap.isNull())
    {
      qCritical() << "Failed to convert QImage to QPixmap" ;
    }
    else
    {
      qtImage->setPixmap(pixmap);
      qtImage->show();
    }
  }
  this->Button->setText(s);
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: Exception.cxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-08 06:10:27 $
 *
 *  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
 *
 ************************************************************************/
#include "java/lang/Exception.hxx"
using namespace connectivity;
//**************************************************************
//************ Class: java.lang.Exception
//**************************************************************

jclass java_lang_Exception::theClass = 0;

java_lang_Exception::~java_lang_Exception()
{}

jclass java_lang_Exception::getMyClass()
{
    // die Klasse muss nur einmal geholt werden, daher statisch
    if( !theClass ){
        SDBThreadAttach t;
        if( !t.pEnv ) return (jclass)NULL;
        jclass tempClass = t.pEnv->FindClass("java/lang/Exception"); OSL_ENSURE(tempClass,"Java : FindClass nicht erfolgreich!");
        jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass );
        t.pEnv->DeleteLocalRef( tempClass );
        saveClassRef( globClass );
    }
    return theClass;
}

void java_lang_Exception::saveClassRef( jclass pClass )
{
    if( pClass==NULL  )
        return;
    // der uebergebe Klassen-Handle ist schon global, daher einfach speichern
    theClass = pClass;
}

<commit_msg>INTEGRATION: CWS pchfix02 (1.4.166); FILE MERGED 2006/09/01 17:22:20 kaib 1.4.166.1: #i68856# Added header markers and pch files<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: Exception.cxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-17 02:46:44 $
 *
 *  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
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_connectivity.hxx"
#include "java/lang/Exception.hxx"
using namespace connectivity;
//**************************************************************
//************ Class: java.lang.Exception
//**************************************************************

jclass java_lang_Exception::theClass = 0;

java_lang_Exception::~java_lang_Exception()
{}

jclass java_lang_Exception::getMyClass()
{
    // die Klasse muss nur einmal geholt werden, daher statisch
    if( !theClass ){
        SDBThreadAttach t;
        if( !t.pEnv ) return (jclass)NULL;
        jclass tempClass = t.pEnv->FindClass("java/lang/Exception"); OSL_ENSURE(tempClass,"Java : FindClass nicht erfolgreich!");
        jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass );
        t.pEnv->DeleteLocalRef( tempClass );
        saveClassRef( globClass );
    }
    return theClass;
}

void java_lang_Exception::saveClassRef( jclass pClass )
{
    if( pClass==NULL  )
        return;
    // der uebergebe Klassen-Handle ist schon global, daher einfach speichern
    theClass = pClass;
}

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: unoedhlp.hxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: kz $ $Date: 2005-01-21 15:42:49 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 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
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef _SVX_UNOEDHLP_HXX
#define _SVX_UNOEDHLP_HXX

#include <memory>

#ifndef _SOLAR_H
#include <tools/solar.h>
#endif
#ifndef _TEXTDATA_HXX
#include <svtools/textdata.hxx>
#endif
#ifndef _SFXHINT_HXX
#include <svtools/hint.hxx>
#endif
#ifndef _SV_GEN_HXX
#include <tools/gen.hxx>
#endif

#ifndef INCLUDED_SVXDLLAPI_H
#include "svx/svxdllapi.h"
#endif

struct EENotify;
class EditEngine;

#define EDITSOURCE_HINT_PARASMOVED          20
#define EDITSOURCE_HINT_SELECTIONCHANGED    21

/** Extends TextHint by two additional parameters which are necessary
    for the EDITSOURCE_HINT_PARASMOVED hint. TextHint's value in this
    case denotes the destination position, the two parameters the
    start and the end of the moved paragraph range.
 */
class SvxEditSourceHint : public TextHint
{
private:
    ULONG   mnStart;
    ULONG   mnEnd;

public:
            TYPEINFO();
            SvxEditSourceHint( ULONG nId );
            SvxEditSourceHint( ULONG nId, ULONG nValue, ULONG nStart=0, ULONG nEnd=0 );

    ULONG   GetValue() const;
    ULONG   GetStartValue() const;
    ULONG   GetEndValue() const;
    void    SetValue( ULONG n );
    void    SetStartValue( ULONG n );
    void    SetEndValue( ULONG n );
};

/** Helper class for common functionality in edit sources
 */
class SVX_DLLPUBLIC SvxEditSourceHelper
{
public:

    /** Translates EditEngine notifications into broadcastable hints

        @param aNotify
        Notification object send by the EditEngine.

        @return the translated hint
     */
    static ::std::auto_ptr<SfxHint> EENotification2Hint( EENotify* aNotify );

    /** Calculate attribute run for EditEngines

        Please note that the range returned is half-open: [nStartIndex,nEndIndex)

        @param nStartIndex
        Herein, the start index of the range of similar attributes is returned

        @param nEndIndex
        Herein, the end index (exclusive) of the range of similar attributes is returned

        @param rEE
        The EditEngine to query for attributes

        @param nPara
        The paragraph the following index value is to be interpreted in

        @param nIndex
        The character index from which the range of similar attributed characters is requested

        @return sal_True, if the range has been successfully determined
     */
    static sal_Bool GetAttributeRun( USHORT& nStartIndex, USHORT& nEndIndex, const EditEngine& rEE, USHORT nPara, USHORT nIndex );

    /** Convert point from edit engine to user coordinate space

        As the edit engine internally keeps vertical text unrotated,
        all internal edit engine methods return their stuff unrotated,
        too. This method rotates and shifts given point appropriately,
        if vertical writing is on.

        @param rPoint
        Point to transform

        @param rEESize
        Paper size of the edit engine

        @param  bIsVertical
        Whether output text is vertical or not

        @return the possibly transformed point
     */
    static Point EEToUserSpace( const Point& rPoint, const Size& rEESize, bool bIsVertical );

    /** Convert point from user to edit engine coordinate space

        As the edit engine internally keeps vertical text unrotated,
        all internal edit engine methods return their stuff unrotated,
        too. This method rotates and shifts given point appropriately,
        if vertical writing is on.

        @param rPoint
        Point to transform

        @param rEESize
        Paper size of the edit engine

        @param  bIsVertical
        Whether output text is vertical or not

        @return the possibly transformed point
     */
    static Point UserSpaceToEE( const Point& rPoint, const Size& rEESize, bool bIsVertical );

    /** Convert rect from edit engine to user coordinate space

        As the edit engine internally keeps vertical text unrotated,
        all internal edit engine methods return their stuff unrotated,
        too. This method rotates and shifts given rect appropriately,
        if vertical writing is on.

        @param rRect
        Rectangle to transform

        @param rEESize
        Paper size of the edit engine

        @param  bIsVertical
        Whether output text is vertical or not

        @return the possibly transformed rect
     */
    static Rectangle EEToUserSpace( const Rectangle& rRect, const Size& rEESize, bool bIsVertical );

    /** Convert rect from user to edit engine coordinate space

        As the edit engine internally keeps vertical text unrotated,
        all internal edit engine methods return their stuff unrotated,
        too. This method rotates and shifts given rect appropriately,
        if vertical writing is on.

        @param rRect
        Rectangle to transform

        @param rEESize
        Paper size of the edit engine

        @param  bIsVertical
        Whether output text is vertical or not

        @return the possibly transformed rect
     */
    static Rectangle UserSpaceToEE( const Rectangle& rRect, const Size& rEESize, bool bIsVertical );

};

#endif

<commit_msg>INTEGRATION: CWS ooo19126 (1.6.430); FILE MERGED 2005/09/05 14:16:57 rt 1.6.430.1: #i54170# Change license header: remove SISSL<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: unoedhlp.hxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-08 19:23:48 $
 *
 *  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 _SVX_UNOEDHLP_HXX
#define _SVX_UNOEDHLP_HXX

#include <memory>

#ifndef _SOLAR_H
#include <tools/solar.h>
#endif
#ifndef _TEXTDATA_HXX
#include <svtools/textdata.hxx>
#endif
#ifndef _SFXHINT_HXX
#include <svtools/hint.hxx>
#endif
#ifndef _SV_GEN_HXX
#include <tools/gen.hxx>
#endif

#ifndef INCLUDED_SVXDLLAPI_H
#include "svx/svxdllapi.h"
#endif

struct EENotify;
class EditEngine;

#define EDITSOURCE_HINT_PARASMOVED          20
#define EDITSOURCE_HINT_SELECTIONCHANGED    21

/** Extends TextHint by two additional parameters which are necessary
    for the EDITSOURCE_HINT_PARASMOVED hint. TextHint's value in this
    case denotes the destination position, the two parameters the
    start and the end of the moved paragraph range.
 */
class SvxEditSourceHint : public TextHint
{
private:
    ULONG   mnStart;
    ULONG   mnEnd;

public:
            TYPEINFO();
            SvxEditSourceHint( ULONG nId );
            SvxEditSourceHint( ULONG nId, ULONG nValue, ULONG nStart=0, ULONG nEnd=0 );

    ULONG   GetValue() const;
    ULONG   GetStartValue() const;
    ULONG   GetEndValue() const;
    void    SetValue( ULONG n );
    void    SetStartValue( ULONG n );
    void    SetEndValue( ULONG n );
};

/** Helper class for common functionality in edit sources
 */
class SVX_DLLPUBLIC SvxEditSourceHelper
{
public:

    /** Translates EditEngine notifications into broadcastable hints

        @param aNotify
        Notification object send by the EditEngine.

        @return the translated hint
     */
    static ::std::auto_ptr<SfxHint> EENotification2Hint( EENotify* aNotify );

    /** Calculate attribute run for EditEngines

        Please note that the range returned is half-open: [nStartIndex,nEndIndex)

        @param nStartIndex
        Herein, the start index of the range of similar attributes is returned

        @param nEndIndex
        Herein, the end index (exclusive) of the range of similar attributes is returned

        @param rEE
        The EditEngine to query for attributes

        @param nPara
        The paragraph the following index value is to be interpreted in

        @param nIndex
        The character index from which the range of similar attributed characters is requested

        @return sal_True, if the range has been successfully determined
     */
    static sal_Bool GetAttributeRun( USHORT& nStartIndex, USHORT& nEndIndex, const EditEngine& rEE, USHORT nPara, USHORT nIndex );

    /** Convert point from edit engine to user coordinate space

        As the edit engine internally keeps vertical text unrotated,
        all internal edit engine methods return their stuff unrotated,
        too. This method rotates and shifts given point appropriately,
        if vertical writing is on.

        @param rPoint
        Point to transform

        @param rEESize
        Paper size of the edit engine

        @param  bIsVertical
        Whether output text is vertical or not

        @return the possibly transformed point
     */
    static Point EEToUserSpace( const Point& rPoint, const Size& rEESize, bool bIsVertical );

    /** Convert point from user to edit engine coordinate space

        As the edit engine internally keeps vertical text unrotated,
        all internal edit engine methods return their stuff unrotated,
        too. This method rotates and shifts given point appropriately,
        if vertical writing is on.

        @param rPoint
        Point to transform

        @param rEESize
        Paper size of the edit engine

        @param  bIsVertical
        Whether output text is vertical or not

        @return the possibly transformed point
     */
    static Point UserSpaceToEE( const Point& rPoint, const Size& rEESize, bool bIsVertical );

    /** Convert rect from edit engine to user coordinate space

        As the edit engine internally keeps vertical text unrotated,
        all internal edit engine methods return their stuff unrotated,
        too. This method rotates and shifts given rect appropriately,
        if vertical writing is on.

        @param rRect
        Rectangle to transform

        @param rEESize
        Paper size of the edit engine

        @param  bIsVertical
        Whether output text is vertical or not

        @return the possibly transformed rect
     */
    static Rectangle EEToUserSpace( const Rectangle& rRect, const Size& rEESize, bool bIsVertical );

    /** Convert rect from user to edit engine coordinate space

        As the edit engine internally keeps vertical text unrotated,
        all internal edit engine methods return their stuff unrotated,
        too. This method rotates and shifts given rect appropriately,
        if vertical writing is on.

        @param rRect
        Rectangle to transform

        @param rEESize
        Paper size of the edit engine

        @param  bIsVertical
        Whether output text is vertical or not

        @return the possibly transformed rect
     */
    static Rectangle UserSpaceToEE( const Rectangle& rRect, const Size& rEESize, bool bIsVertical );

};

#endif

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: unoedhlp.hxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-08 19:23:48 $
 *
 *  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 _SVX_UNOEDHLP_HXX
#define _SVX_UNOEDHLP_HXX

#include <memory>

#ifndef _SOLAR_H
#include <tools/solar.h>
#endif
#ifndef _TEXTDATA_HXX
#include <svtools/textdata.hxx>
#endif
#ifndef _SFXHINT_HXX
#include <svtools/hint.hxx>
#endif
#ifndef _SV_GEN_HXX
#include <tools/gen.hxx>
#endif

#ifndef INCLUDED_SVXDLLAPI_H
#include "svx/svxdllapi.h"
#endif

struct EENotify;
class EditEngine;

#define EDITSOURCE_HINT_PARASMOVED          20
#define EDITSOURCE_HINT_SELECTIONCHANGED    21

/** Extends TextHint by two additional parameters which are necessary
    for the EDITSOURCE_HINT_PARASMOVED hint. TextHint's value in this
    case denotes the destination position, the two parameters the
    start and the end of the moved paragraph range.
 */
class SvxEditSourceHint : public TextHint
{
private:
    ULONG   mnStart;
    ULONG   mnEnd;

public:
            TYPEINFO();
            SvxEditSourceHint( ULONG nId );
            SvxEditSourceHint( ULONG nId, ULONG nValue, ULONG nStart=0, ULONG nEnd=0 );

    ULONG   GetValue() const;
    ULONG   GetStartValue() const;
    ULONG   GetEndValue() const;
    void    SetValue( ULONG n );
    void    SetStartValue( ULONG n );
    void    SetEndValue( ULONG n );
};

/** Helper class for common functionality in edit sources
 */
class SVX_DLLPUBLIC SvxEditSourceHelper
{
public:

    /** Translates EditEngine notifications into broadcastable hints

        @param aNotify
        Notification object send by the EditEngine.

        @return the translated hint
     */
    static ::std::auto_ptr<SfxHint> EENotification2Hint( EENotify* aNotify );

    /** Calculate attribute run for EditEngines

        Please note that the range returned is half-open: [nStartIndex,nEndIndex)

        @param nStartIndex
        Herein, the start index of the range of similar attributes is returned

        @param nEndIndex
        Herein, the end index (exclusive) of the range of similar attributes is returned

        @param rEE
        The EditEngine to query for attributes

        @param nPara
        The paragraph the following index value is to be interpreted in

        @param nIndex
        The character index from which the range of similar attributed characters is requested

        @return sal_True, if the range has been successfully determined
     */
    static sal_Bool GetAttributeRun( USHORT& nStartIndex, USHORT& nEndIndex, const EditEngine& rEE, USHORT nPara, USHORT nIndex );

    /** Convert point from edit engine to user coordinate space

        As the edit engine internally keeps vertical text unrotated,
        all internal edit engine methods return their stuff unrotated,
        too. This method rotates and shifts given point appropriately,
        if vertical writing is on.

        @param rPoint
        Point to transform

        @param rEESize
        Paper size of the edit engine

        @param  bIsVertical
        Whether output text is vertical or not

        @return the possibly transformed point
     */
    static Point EEToUserSpace( const Point& rPoint, const Size& rEESize, bool bIsVertical );

    /** Convert point from user to edit engine coordinate space

        As the edit engine internally keeps vertical text unrotated,
        all internal edit engine methods return their stuff unrotated,
        too. This method rotates and shifts given point appropriately,
        if vertical writing is on.

        @param rPoint
        Point to transform

        @param rEESize
        Paper size of the edit engine

        @param  bIsVertical
        Whether output text is vertical or not

        @return the possibly transformed point
     */
    static Point UserSpaceToEE( const Point& rPoint, const Size& rEESize, bool bIsVertical );

    /** Convert rect from edit engine to user coordinate space

        As the edit engine internally keeps vertical text unrotated,
        all internal edit engine methods return their stuff unrotated,
        too. This method rotates and shifts given rect appropriately,
        if vertical writing is on.

        @param rRect
        Rectangle to transform

        @param rEESize
        Paper size of the edit engine

        @param  bIsVertical
        Whether output text is vertical or not

        @return the possibly transformed rect
     */
    static Rectangle EEToUserSpace( const Rectangle& rRect, const Size& rEESize, bool bIsVertical );

    /** Convert rect from user to edit engine coordinate space

        As the edit engine internally keeps vertical text unrotated,
        all internal edit engine methods return their stuff unrotated,
        too. This method rotates and shifts given rect appropriately,
        if vertical writing is on.

        @param rRect
        Rectangle to transform

        @param rEESize
        Paper size of the edit engine

        @param  bIsVertical
        Whether output text is vertical or not

        @return the possibly transformed rect
     */
    static Rectangle UserSpaceToEE( const Rectangle& rRect, const Size& rEESize, bool bIsVertical );

};

#endif

<commit_msg>INTEGRATION: CWS changefileheader (1.7.1254); FILE MERGED 2008/04/01 15:49:25 thb 1.7.1254.3: #i85898# Stripping all external header guards 2008/04/01 12:46:27 thb 1.7.1254.2: #i85898# Stripping all external header guards 2008/03/31 14:18:01 rt 1.7.1254.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: unoedhlp.hxx,v $
 * $Revision: 1.8 $
 *
 * 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 _SVX_UNOEDHLP_HXX
#define _SVX_UNOEDHLP_HXX

#include <memory>
#include <tools/solar.h>
#include <svtools/textdata.hxx>
#include <svtools/hint.hxx>
#include <tools/gen.hxx>
#include "svx/svxdllapi.h"

struct EENotify;
class EditEngine;

#define EDITSOURCE_HINT_PARASMOVED          20
#define EDITSOURCE_HINT_SELECTIONCHANGED    21

/** Extends TextHint by two additional parameters which are necessary
    for the EDITSOURCE_HINT_PARASMOVED hint. TextHint's value in this
    case denotes the destination position, the two parameters the
    start and the end of the moved paragraph range.
 */
class SvxEditSourceHint : public TextHint
{
private:
    ULONG   mnStart;
    ULONG   mnEnd;

public:
            TYPEINFO();
            SvxEditSourceHint( ULONG nId );
            SvxEditSourceHint( ULONG nId, ULONG nValue, ULONG nStart=0, ULONG nEnd=0 );

    ULONG   GetValue() const;
    ULONG   GetStartValue() const;
    ULONG   GetEndValue() const;
    void    SetValue( ULONG n );
    void    SetStartValue( ULONG n );
    void    SetEndValue( ULONG n );
};

/** Helper class for common functionality in edit sources
 */
class SVX_DLLPUBLIC SvxEditSourceHelper
{
public:

    /** Translates EditEngine notifications into broadcastable hints

        @param aNotify
        Notification object send by the EditEngine.

        @return the translated hint
     */
    static ::std::auto_ptr<SfxHint> EENotification2Hint( EENotify* aNotify );

    /** Calculate attribute run for EditEngines

        Please note that the range returned is half-open: [nStartIndex,nEndIndex)

        @param nStartIndex
        Herein, the start index of the range of similar attributes is returned

        @param nEndIndex
        Herein, the end index (exclusive) of the range of similar attributes is returned

        @param rEE
        The EditEngine to query for attributes

        @param nPara
        The paragraph the following index value is to be interpreted in

        @param nIndex
        The character index from which the range of similar attributed characters is requested

        @return sal_True, if the range has been successfully determined
     */
    static sal_Bool GetAttributeRun( USHORT& nStartIndex, USHORT& nEndIndex, const EditEngine& rEE, USHORT nPara, USHORT nIndex );

    /** Convert point from edit engine to user coordinate space

        As the edit engine internally keeps vertical text unrotated,
        all internal edit engine methods return their stuff unrotated,
        too. This method rotates and shifts given point appropriately,
        if vertical writing is on.

        @param rPoint
        Point to transform

        @param rEESize
        Paper size of the edit engine

        @param  bIsVertical
        Whether output text is vertical or not

        @return the possibly transformed point
     */
    static Point EEToUserSpace( const Point& rPoint, const Size& rEESize, bool bIsVertical );

    /** Convert point from user to edit engine coordinate space

        As the edit engine internally keeps vertical text unrotated,
        all internal edit engine methods return their stuff unrotated,
        too. This method rotates and shifts given point appropriately,
        if vertical writing is on.

        @param rPoint
        Point to transform

        @param rEESize
        Paper size of the edit engine

        @param  bIsVertical
        Whether output text is vertical or not

        @return the possibly transformed point
     */
    static Point UserSpaceToEE( const Point& rPoint, const Size& rEESize, bool bIsVertical );

    /** Convert rect from edit engine to user coordinate space

        As the edit engine internally keeps vertical text unrotated,
        all internal edit engine methods return their stuff unrotated,
        too. This method rotates and shifts given rect appropriately,
        if vertical writing is on.

        @param rRect
        Rectangle to transform

        @param rEESize
        Paper size of the edit engine

        @param  bIsVertical
        Whether output text is vertical or not

        @return the possibly transformed rect
     */
    static Rectangle EEToUserSpace( const Rectangle& rRect, const Size& rEESize, bool bIsVertical );

    /** Convert rect from user to edit engine coordinate space

        As the edit engine internally keeps vertical text unrotated,
        all internal edit engine methods return their stuff unrotated,
        too. This method rotates and shifts given rect appropriately,
        if vertical writing is on.

        @param rRect
        Rectangle to transform

        @param rEESize
        Paper size of the edit engine

        @param  bIsVertical
        Whether output text is vertical or not

        @return the possibly transformed rect
     */
    static Rectangle UserSpaceToEE( const Rectangle& rRect, const Size& rEESize, bool bIsVertical );

};

#endif

<|endoftext|>


<commit_before>#include "peripheral.h"
<commit_msg>remove trivial file.<commit_after><|endoftext|>


<commit_before>/*
	This file is part of cpp-ethereum.

	cpp-ethereum is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	cpp-ethereum is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with cpp-ethereum.  If not, see <http://www.gnu.org/licenses/>.
*/
/** @file QContractDefinition.cpp
 * @author Yann yann@ethdev.com
 * @date 2014
 */

#include <QObject>

#include "QContractDefinition.h"
#include <libsolidity/CompilerStack.h>
#include <libsolidity/AST.h>
#include <libsolidity/Scanner.h>
#include <libsolidity/Parser.h>
#include <libsolidity/Scanner.h>
#include <libsolidity/NameAndTypeResolver.h>
using namespace dev::solidity;
using namespace dev::mix;

QContractDefinition::QContractDefinition(QObject* _parent, dev::solidity::ContractDefinition const* _contract): QBasicNodeDefinition(_parent, _contract)
{
	QObject* parent = _parent ? _parent : this;
	if (_contract->getConstructor() != nullptr)
		m_constructor = new QFunctionDefinition(parent, ContractType(*_contract).getConstructorType());
	else
		m_constructor = new QFunctionDefinition(parent);

	std::vector<std::string> found;
	for (auto const& f: _contract->getDefinedFunctions())
	{
		m_functions.append(new QFunctionDefinition(parent, f));
		found.push_back(f->getName());
	}

	for (auto const& it: _contract->getInterfaceFunctions())
	{
		if (std::find(found.begin(), found.end(), it.second->getDeclaration().getName()) == found.end())
			m_functions.append(new QFunctionDefinition(parent, it.second));
	}

	for (auto const& it: _contract->getEvents())
		m_events.append(new QFunctionDefinition(parent, it));

}

QFunctionDefinition const* QContractDefinition::getFunction(dev::FixedHash<4> _hash) const
{
	for (auto const& f: m_functions)
		if (f->hash() == _hash)
			return f;

	return nullptr;
}
<commit_msg>Only store functions with external visibility in QContractDefinition.<commit_after>/*
	This file is part of cpp-ethereum.

	cpp-ethereum is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	cpp-ethereum is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with cpp-ethereum.  If not, see <http://www.gnu.org/licenses/>.
*/
/** @file QContractDefinition.cpp
 * @author Yann yann@ethdev.com
 * @date 2014
 */

#include <QObject>

#include "QContractDefinition.h"
#include <libsolidity/CompilerStack.h>
#include <libsolidity/AST.h>
#include <libsolidity/Scanner.h>
#include <libsolidity/Parser.h>
#include <libsolidity/Scanner.h>
#include <libsolidity/NameAndTypeResolver.h>
using namespace dev::solidity;
using namespace dev::mix;

QContractDefinition::QContractDefinition(QObject* _parent, dev::solidity::ContractDefinition const* _contract): QBasicNodeDefinition(_parent, _contract)
{
	QObject* parent = _parent ? _parent : this;
	if (_contract->getConstructor() != nullptr)
		m_constructor = new QFunctionDefinition(parent, ContractType(*_contract).getConstructorType());
	else
		m_constructor = new QFunctionDefinition(parent);

	for (auto const& it: _contract->getInterfaceFunctions())
		m_functions.append(new QFunctionDefinition(parent, it.second));

	for (auto const& it: _contract->getEvents())
		m_events.append(new QFunctionDefinition(parent, it));

}

QFunctionDefinition const* QContractDefinition::getFunction(dev::FixedHash<4> _hash) const
{
	for (auto const& f: m_functions)
		if (f->hash() == _hash)
			return f;

	return nullptr;
}
<|endoftext|>


<commit_before>/*****************************************************************************/
/**
 *  @file   ParallelAxisInteractor.cpp
 *  @author Naohisa Sakamoto
 */
/*****************************************************************************/
#include "ParallelAxisInteractor.h"
#include <kvs/RendererManager>
#include <kvs/IDManager>
#include <kvs/ObjectManager>
#include <kvs/Camera>

namespace kvs
{

/*===========================================================================*/
/**
 *  @brief  Constructs a new ParallelAxisInteractor class.
 *  @param  axis [in] parallel axis
 */
/*===========================================================================*/
ParallelAxisInteractor::ParallelAxisInteractor( const kvs::ParallelAxis* axis ):
    m_axis( axis )
{
    BaseClass::addEventType( kvs::EventBase::MousePressEvent );
    BaseClass::addEventType( kvs::EventBase::MouseMoveEvent );
    BaseClass::addEventType( kvs::EventBase::MouseReleaseEvent );
    BaseClass::addEventType( kvs::EventBase::MouseDoubleClickEvent );
    BaseClass::addEventType( kvs::EventBase::PaintEvent );
}

/*===========================================================================*/
/**
 *  @brief  Returns pointer to the table object.
 *  @return pointer to the table object
 */
/*===========================================================================*/
kvs::TableObject* ParallelAxisInteractor::table()
{
    if ( m_table ) { return m_table; }
    const auto rid = BaseClass::scene()->rendererManager()->rendererID( m_axis );
    const auto oid = BaseClass::scene()->IDManager()->objectID( rid )[0];
    auto* object = BaseClass::scene()->objectManager()->object( oid );
    return m_table = kvs::TableObject::DownCast( object );
}

/*===========================================================================*/
/**
 *  @brief  Returns a position of the point in viewport coordinates (origin: bottom-left)
 *  @param  p [in] position of the point in pixel coordinates (orgin: top-left)
 *  @return position of the point in viewport coordinates (origin: bottom-left)
 */
/*===========================================================================*/
kvs::Vec2i ParallelAxisInteractor::toBottomLeftOrigin( const kvs::Vec2i& p )
{
    return { p.x(), BaseClass::screen()->height() - 1 - p.y() };
}

/*===========================================================================*/
/**
 *  @brief  Mouse press event function.
 *  @param  e [in] pointer to the mouse event
 */
/*===========================================================================*/
void ParallelAxisInteractor::mousePressEvent( kvs::MouseEvent* e )
{
    auto* table = this->table();
    if ( !table ) { return; }

    const auto naxes = table->numberOfColumns();
    if ( naxes < 2 ) { return; }

    m_p0 = this->toBottomLeftOrigin( { e->x(), e->y() } );
    m_p = m_p0;

    // X_min: left side of the plot region
    // X_max: right side of the plot region
    const int X_min = m_axis->leftMargin();
    const int X_max = BaseClass::screen()->width() - m_axis->rightMargin();
    const float stride = float( X_max - X_min ) / ( naxes - 1 );

    // Select the axis and determin the action (moving or setting) for its range bar
    for ( size_t i = 0; i < naxes; ++i )
    {
        const float ex = static_cast<float>( e->x() );
        const float x = m_axis->leftMargin() + stride * i;
        const float dx = m_range_width * 0.5f;
        const float ddx = dx * 0.5f;
        if ( x - ddx < ex && ex < x + ddx )
        {
            // Moving the range
            m_selected_axis = i;
            m_range_moving = true;
        }
        else if ( x - dx < ex && ex < x + dx )
        {
            // Selecting the range
            m_selected_axis = i;
            m_range_setting = true;
        }
    }
}

/*===========================================================================*/
/**
 *  @brief  Mouse move event function.
 *  @param  e [in] pointer to the mouse event
 */
/*===========================================================================*/
void ParallelAxisInteractor::mouseMoveEvent( kvs::MouseEvent* e )
{
    auto* table = this->table();
    if ( !table ) { return; }

    const auto naxes = table->numberOfColumns();
    if ( naxes < 2 ) { return; }

    m_p1 = this->toBottomLeftOrigin( { e->x(), e->y() } );

    // Y_min: bottom side of the plot region
    // Y_max: top side of the plot region
    const int Y_min = m_axis->bottomMargin();
    const int Y_max = BaseClass::screen()->height() - m_axis->topMargin();

    // Adjust the mouse moving position.
    if ( m_p1.y() <= Y_min ) { m_p1.y() = Y_min; }
    if ( m_p1.y() >= Y_max ) { m_p1.y() = Y_max; }

    const auto axis = m_selected_axis;
    const auto y_min = table->minValue( axis );
    const auto y_max = table->maxValue( axis );

    if ( m_range_setting )
    {
        const auto Y_rect_min = kvs::Math::Min( m_p0.y(), m_p1.y() );
        const auto Y_rect_max = kvs::Math::Max( m_p0.y(), m_p1.y() );
        const auto y_rect_min = y_min + ( y_max - y_min ) * ( Y_rect_min - Y_min ) / ( Y_max - Y_min );
        const auto y_rect_max = y_min + ( y_max - y_min ) * ( Y_rect_max - Y_min ) / ( Y_max - Y_min );
        table->setMinRange( axis, y_rect_min );
        table->setMaxRange( axis, y_rect_max );
    }

    if ( m_range_moving )
    {
        const auto Y_delta = m_p1.y() - m_p.y();
        const auto y_delta = ( y_max - y_min ) * Y_delta / ( Y_max - Y_min );
        table->moveRange( axis, y_delta );
        m_p = m_p1;
    }
}

/*===========================================================================*/
/**
 *  @brief  Mouse release event function.
 *  @param  e [in] pointer to the mouse event
 */
/*===========================================================================*/
void ParallelAxisInteractor::mouseReleaseEvent( kvs::MouseEvent* e )
{
    m_range_moving = false;
    m_range_setting = false;
}

/*===========================================================================*/
/**
 *  @brief  Mouse double-click event function.
 *  @param  e [in] pointer to the mouse event
 */
/*===========================================================================*/
void ParallelAxisInteractor::mouseDoubleClickEvent( kvs::MouseEvent* e )
{
    auto* table = this->table();
    if ( !table ) { return; }

    const auto naxes = table->numberOfColumns();
    if ( naxes < 2 ) { return; }

    const auto X_min = m_axis->leftMargin();
    const auto X_max = BaseClass::screen()->width() - m_axis->rightMargin();

    const auto stride = float( X_max - X_min ) / ( naxes - 1 );
    for ( size_t i = 0; i < naxes; i++ )
    {
        const auto ex = static_cast<float>( e->x() );
        const auto x = m_axis->leftMargin() + stride * i;
        if ( x - 5 < ex && ex < x + 5 ) { table->resetRange(i); return; }
    }

    table->resetRange();

    m_range_setting = false;
    m_range_moving = false;
}

/*===========================================================================*/
/**
 *  @brief  Paint event function.
 */
/*===========================================================================*/
void ParallelAxisInteractor::paintEvent()
{
    auto* table = this->table();
    if ( !table ) { return; }

    const auto naxes = table->numberOfColumns();
    if ( naxes < 2 ) { return; }

    kvs::OpenGL::WithPushedAttrib attrib( GL_ALL_ATTRIB_BITS );
    m_painter.begin( BaseClass::screen() );
    {
        kvs::OpenGL::Enable( GL_BLEND );
        kvs::OpenGL::SetBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

        // Draw range bars for each axis.
        const auto dpr = BaseClass::scene()->camera()->devicePixelRatio();
        const auto X_min = m_axis->leftMargin();
        const auto X_max = BaseClass::screen()->width() - m_axis->rightMargin();
        const auto Y_min = m_axis->topMargin();
        const auto Y_max = BaseClass::screen()->height() - m_axis->bottomMargin();
        const auto stride = float( X_max - X_min ) / ( naxes - 1 );
        for ( size_t i = 0; i < naxes; ++i )
        {
            const auto X = m_axis->leftMargin() + stride * i;
            const auto y_min_range = table->minRange(i);
            const auto y_max_range = table->maxRange(i);
            const auto y_min_value = table->minValue(i);
            const auto y_max_value = table->maxValue(i);
            const auto Y_min_range = Y_max - ( Y_max - Y_min ) * ( y_max_range - y_min_value ) / ( y_max_value - y_min_value );
            const auto Y_max_range = Y_max - ( Y_max - Y_min ) * ( y_min_range - y_min_value ) / ( y_max_value - y_min_value );

            // Range box
            kvs::OpenGL::Begin( GL_QUADS );
            kvs::OpenGL::Color( m_range_color );
            kvs::OpenGL::Vertex( kvs::Vec2( X - 10, Y_min_range ) * dpr );
            kvs::OpenGL::Vertex( kvs::Vec2( X + 10, Y_min_range ) * dpr );
            kvs::OpenGL::Vertex( kvs::Vec2( X + 10, Y_max_range ) * dpr );
            kvs::OpenGL::Vertex( kvs::Vec2( X - 10, Y_max_range ) * dpr );
            kvs::OpenGL::End();

            // Range edge
            kvs::OpenGL::SetLineWidth( 2.0f * dpr );
            kvs::OpenGL::Begin( GL_LINE_LOOP );
            kvs::OpenGL::Color( m_range_edge_color );
            kvs::OpenGL::Vertex( kvs::Vec2( X - 10, Y_min_range ) * dpr );
            kvs::OpenGL::Vertex( kvs::Vec2( X + 10, Y_min_range ) * dpr );
            kvs::OpenGL::Vertex( kvs::Vec2( X + 10, Y_max_range ) * dpr );
            kvs::OpenGL::Vertex( kvs::Vec2( X - 10, Y_max_range ) * dpr );
            kvs::OpenGL::End();
        }
    }
    m_painter.end();
}

} // end of namespace kvs
<commit_msg>Update ParallelAxisInteractor.cpp<commit_after>/*****************************************************************************/
/**
 *  @file   ParallelAxisInteractor.cpp
 *  @author Naohisa Sakamoto
 */
/*****************************************************************************/
#include "ParallelAxisInteractor.h"
#include <kvs/RendererManager>
#include <kvs/IDManager>
#include <kvs/ObjectManager>
#include <kvs/Camera>

namespace kvs
{

/*===========================================================================*/
/**
 *  @brief  Constructs a new ParallelAxisInteractor class.
 *  @param  axis [in] parallel axis
 */
/*===========================================================================*/
ParallelAxisInteractor::ParallelAxisInteractor( const kvs::ParallelAxis* axis ):
    m_axis( axis )
{
    BaseClass::addEventType( kvs::EventBase::MousePressEvent );
    BaseClass::addEventType( kvs::EventBase::MouseMoveEvent );
    BaseClass::addEventType( kvs::EventBase::MouseReleaseEvent );
    BaseClass::addEventType( kvs::EventBase::MouseDoubleClickEvent );
    BaseClass::addEventType( kvs::EventBase::PaintEvent );
}

/*===========================================================================*/
/**
 *  @brief  Returns pointer to the table object.
 *  @return pointer to the table object
 */
/*===========================================================================*/
kvs::TableObject* ParallelAxisInteractor::table()
{
    if ( m_table ) { return m_table; }
    const auto rid = BaseClass::scene()->rendererManager()->rendererID( m_axis );
    const auto oid = BaseClass::scene()->IDManager()->objectID( rid )[0];
    auto* object = BaseClass::scene()->objectManager()->object( oid );
    return m_table = kvs::TableObject::DownCast( object );
}

/*===========================================================================*/
/**
 *  @brief  Returns a position of the point in viewport coordinates (origin: bottom-left)
 *  @param  p [in] position of the point in pixel coordinates (orgin: top-left)
 *  @return position of the point in viewport coordinates (origin: bottom-left)
 */
/*===========================================================================*/
kvs::Vec2i ParallelAxisInteractor::toBottomLeftOrigin( const kvs::Vec2i& p )
{
    return { p.x(), BaseClass::screen()->height() - 1 - p.y() };
}

/*===========================================================================*/
/**
 *  @brief  Mouse press event function.
 *  @param  e [in] pointer to the mouse event
 */
/*===========================================================================*/
void ParallelAxisInteractor::mousePressEvent( kvs::MouseEvent* e )
{
    auto* table = this->table();
    if ( !table ) { return; }

    const auto naxes = table->numberOfColumns();
    if ( naxes < 2 ) { return; }

    m_p0 = this->toBottomLeftOrigin( { e->x(), e->y() } );
    m_p = m_p0;

    // X_min: left side of the plot region
    // X_max: right side of the plot region
    const int X_min = m_axis->leftMargin();
    const int X_max = BaseClass::screen()->width() - m_axis->rightMargin();
    const float stride = float( X_max - X_min ) / ( naxes - 1 );

    // Select the axis and determin the action (moving or setting) for its range bar
    for ( size_t i = 0; i < naxes; ++i )
    {
        const float ex = static_cast<float>( e->x() );
        const float x = m_axis->leftMargin() + stride * i;
        const float dx = m_range_width * 0.5f;
        const float ddx = dx * 0.5f;
        if ( x - ddx < ex && ex < x + ddx )
        {
            // Moving the range
            m_selected_axis = i;
            m_range_moving = true;
        }
        else if ( x - dx < ex && ex < x + dx )
        {
            // Selecting the range
            m_selected_axis = i;
            m_range_setting = true;
        }
    }
}

/*===========================================================================*/
/**
 *  @brief  Mouse move event function.
 *  @param  e [in] pointer to the mouse event
 */
/*===========================================================================*/
void ParallelAxisInteractor::mouseMoveEvent( kvs::MouseEvent* e )
{
    auto* table = this->table();
    if ( !table ) { return; }

    const auto naxes = table->numberOfColumns();
    if ( naxes < 2 ) { return; }

    m_p1 = this->toBottomLeftOrigin( { e->x(), e->y() } );

    // Y_min: bottom side of the plot region
    // Y_max: top side of the plot region
    const int Y_min = m_axis->bottomMargin();
    const int Y_max = BaseClass::screen()->height() - m_axis->topMargin();

    // Adjust the mouse moving position.
    if ( m_p1.y() <= Y_min ) { m_p1.y() = Y_min; }
    if ( m_p1.y() >= Y_max ) { m_p1.y() = Y_max; }

    const auto axis = m_selected_axis;
    const auto y_min = table->minValue( axis );
    const auto y_max = table->maxValue( axis );

    if ( m_range_setting )
    {
        const auto Y_rect_min = kvs::Math::Min( m_p0.y(), m_p1.y() );
        const auto Y_rect_max = kvs::Math::Max( m_p0.y(), m_p1.y() );
        const auto y_rect_min = y_min + ( y_max - y_min ) * ( Y_rect_min - Y_min ) / ( Y_max - Y_min );
        const auto y_rect_max = y_min + ( y_max - y_min ) * ( Y_rect_max - Y_min ) / ( Y_max - Y_min );
        table->setMinRange( axis, y_rect_min );
        table->setMaxRange( axis, y_rect_max );
    }

    if ( m_range_moving )
    {
        const auto Y_delta = m_p1.y() - m_p.y();
        const auto y_delta = ( y_max - y_min ) * Y_delta / ( Y_max - Y_min );
        table->moveRange( axis, y_delta );
        m_p = m_p1;
    }
}

/*===========================================================================*/
/**
 *  @brief  Mouse release event function.
 *  @param  e [in] pointer to the mouse event
 */
/*===========================================================================*/
void ParallelAxisInteractor::mouseReleaseEvent( kvs::MouseEvent* e )
{
    m_range_moving = false;
    m_range_setting = false;
}

/*===========================================================================*/
/**
 *  @brief  Mouse double-click event function.
 *  @param  e [in] pointer to the mouse event
 */
/*===========================================================================*/
void ParallelAxisInteractor::mouseDoubleClickEvent( kvs::MouseEvent* e )
{
    auto* table = this->table();
    if ( !table ) { return; }

    const auto naxes = table->numberOfColumns();
    if ( naxes < 2 ) { return; }

    const auto X_min = m_axis->leftMargin();
    const auto X_max = BaseClass::screen()->width() - m_axis->rightMargin();

    const auto stride = float( X_max - X_min ) / ( naxes - 1 );
    for ( size_t i = 0; i < naxes; i++ )
    {
        const auto ex = static_cast<float>( e->x() );
        const auto x = m_axis->leftMargin() + stride * i;
        if ( x - 5 < ex && ex < x + 5 ) { table->resetRange(i); return; }
    }

    table->resetRange();

    m_range_setting = false;
    m_range_moving = false;
}

/*===========================================================================*/
/**
 *  @brief  Paint event function.
 */
/*===========================================================================*/
void ParallelAxisInteractor::paintEvent()
{
    auto* table = this->table();
    if ( !table ) { return; }

    const auto naxes = table->numberOfColumns();
    if ( naxes < 2 ) { return; }

    kvs::OpenGL::WithPushedAttrib attrib( GL_ALL_ATTRIB_BITS );
    m_painter.begin( BaseClass::screen() );
    {
        kvs::OpenGL::Enable( GL_BLEND );
        kvs::OpenGL::SetBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

        // Draw range bars for each axis.
        const auto dpr = BaseClass::scene()->camera()->devicePixelRatio();
        const auto X_min = m_axis->leftMargin();
        const auto X_max = BaseClass::screen()->width() - m_axis->rightMargin();
        const auto Y_min = m_axis->topMargin();
        const auto Y_max = BaseClass::screen()->height() - m_axis->bottomMargin();
        const auto stride = float( X_max - X_min ) / ( naxes - 1 );
        for ( size_t i = 0; i < naxes; ++i )
        {
            const auto X = m_axis->leftMargin() + stride * i;
            const auto y_min_range = table->minRange(i);
            const auto y_max_range = table->maxRange(i);
            const auto y_min_value = table->minValue(i);
            const auto y_max_value = table->maxValue(i);
            const auto Y_min_range = Y_max - ( Y_max - Y_min ) * ( y_max_range - y_min_value ) / ( y_max_value - y_min_value );
            const auto Y_max_range = Y_max - ( Y_max - Y_min ) * ( y_min_range - y_min_value ) / ( y_max_value - y_min_value );

            // Range box
            kvs::OpenGL::Begin( GL_QUADS );
            kvs::OpenGL::Color( m_range_color );
            kvs::OpenGL::Vertex( kvs::Vec2( X - 10, Y_min_range ) * dpr );
            kvs::OpenGL::Vertex( kvs::Vec2( X + 10, Y_min_range ) * dpr );
            kvs::OpenGL::Vertex( kvs::Vec2( X + 10, Y_max_range ) * dpr );
            kvs::OpenGL::Vertex( kvs::Vec2( X - 10, Y_max_range ) * dpr );
            kvs::OpenGL::End();

            // Range edge
            kvs::OpenGL::SetLineWidth( m_range_edge_width * dpr );
            kvs::OpenGL::Begin( GL_LINE_LOOP );
            kvs::OpenGL::Color( m_range_edge_color );
            kvs::OpenGL::Vertex( kvs::Vec2( X - 10, Y_min_range ) * dpr );
            kvs::OpenGL::Vertex( kvs::Vec2( X + 10, Y_min_range ) * dpr );
            kvs::OpenGL::Vertex( kvs::Vec2( X + 10, Y_max_range ) * dpr );
            kvs::OpenGL::Vertex( kvs::Vec2( X - 10, Y_max_range ) * dpr );
            kvs::OpenGL::End();
        }
    }
    m_painter.end();
}

} // end of namespace kvs
<|endoftext|>


<commit_before>
static const char *LC = "TEST";

#include<stdexcept>

#include<behold.h>
#include<tf.h>

using TestLog = Logger<decltype(ss_test), ss_test, false>;
using StatusLog = Logger<decltype(ss_status), ss_status, true>;

void test_const_char() {
    TestLog::devel(__FUNCTION__) << "Test";
    auto ret = remove_header(ss_test.str());
    StatusLog::devel(LC) << escape(ret);

    assert_equal(ret, "Test");
}

void test_remove_header() {
    TestLog::devel(__FUNCTION__) << "Test";
    auto ret = ss_test.str();
    assert_equal(ret, std::string("d ") + __FUNCTION__ + " | Test\n");

    ret = remove_header(ret);
    assert_equal(ret, "Test");
}

void test_integer() {
    TestLog::devel(__FUNCTION__) << 1;
    auto ret = remove_header(ss_test.str());

    assert_equal(ret, "1");
}

void test_nosp_1() {
    TestLog::devel(__FUNCTION__) << 1 << LogManip::NO_SPACE << 2;
    auto ret = remove_header(ss_test.str());

    assert_equal(ret, "12");
}

void test_nosp_2() {
    TestLog::devel(__FUNCTION__) << LogManip::NO_SPACE << 1 << 2;
    auto ret = remove_header(ss_test.str());

    assert_equal(ret, "1 2");
}

static std::vector<std::function<void()>> tests = {
    test_nosp_1,
    test_nosp_2,
    test_integer,
    test_const_char,
    test_remove_header,
};

void set_up() {

}

void tear_down() {
    ss_test.str(std::string());
    ss_test.clear();

    ss_status.str(std::string());
    ss_status.clear();
}

struct TestContext {
    TestContext() {
        set_up();
    }
    ~TestContext() {
        tear_down();
    }
};

int main(int, char **) {
    return run_tests<TestContext>(tests);
}
<commit_msg>minor<commit_after>
static const char *LC = "TEST";

#include<stdexcept>

#include<behold.h>
#include<tf.h>

using TestLog = Logger<decltype(ss_test), ss_test, false>;
using StatusLog = Logger<decltype(ss_status), ss_status, true>;

void test_const_char() {
    TestLog::devel(__FUNCTION__) << "Test";
    auto ret = remove_header(ss_test.str());
    StatusLog::devel(LC) << escape(ret);

    assert_equal(ret, "Test");
}

void test_format_remove_header() {
    TestLog::devel(__FUNCTION__) << "Test";
    auto ret = ss_test.str();
    assert_equal(ret, std::string("d ") + __FUNCTION__ + " | Test\n");

    ret = remove_header(ret);
    assert_equal(ret, "Test");
}

void test_integer() {
    TestLog::devel(__FUNCTION__) << 1;
    auto ret = remove_header(ss_test.str());

    assert_equal(ret, "1");
}

void test_nosp_1() {
    TestLog::devel(__FUNCTION__) << 1 << LogManip::NO_SPACE << 2;
    auto ret = remove_header(ss_test.str());

    assert_equal(ret, "12");
}

void test_nosp_2() {
    TestLog::devel(__FUNCTION__) << LogManip::NO_SPACE << 1 << 2;
    auto ret = remove_header(ss_test.str());

    assert_equal(ret, "1 2");
}

static std::vector<std::function<void()>> tests = {
    test_nosp_1,
    test_nosp_2,
    test_integer,
    test_const_char,
    test_format_remove_header,
};

void set_up() {

}

void tear_down() {
    ss_test.str(std::string());
    ss_test.clear();

    ss_status.str(std::string());
    ss_status.clear();
}

struct TestContext {
    TestContext() {
        set_up();
    }
    ~TestContext() {
        tear_down();
    }
};

int main(int, char **) {
    return run_tests<TestContext>(tests);
}
<|endoftext|>


<commit_before>
#include<cassert>
#include<behold.h>

void test_spaces() {

}

int main(int, char **) {
    test_spaces();
    return 0;
}
<commit_msg>make initial tests work<commit_after>
static const char *LC = "TEST";

#include<cassert>
#include<behold.h>

extern std::stringstream ss;

std::stringstream ss;

using TestLog = Logger<decltype(ss), ss, false>;

// Define user defined literal "_quoted" operator.
std::string quote(const std::string &text) {
    return "\"" + text + "\"";
}

void test_spaces() {
    TestLog::devel("TCTX") << "Falan";
    auto ret = ss.str();

    Behold(std::cerr)::info(LC) << "Log line:" << quote(ret);

    assert(ret == "d TCTX | Falan \n");
}

static std::vector<std::function<void()>> tests = {
    test_spaces,
};

void set_up() {

}

void tear_down() {
    ss.clear();
}

int main(int, char **) {

    for (auto &f: tests) {
        set_up();
        f();
        tear_down();
    }
    return 0;
}
<|endoftext|>


<commit_before>#include <NTL/mat_ZZ_p.h>
#include <NTL/ZZ_p.h>
#include <NTL/ZZ.h>
#include <NTL/vec_ZZ_p.h>
#include <NTL/vec_ZZ.h>

using namespace std;
using namespace NTL;

const ZZ w = 123456789;

vec_ZZ_p decrypt(mat_ZZ_p S, vec_ZZ_p c);

// returns c*
vec_ZZ_p getBitVector(vec_ZZ_p c);

// returns S*
mat_ZZ_p getBitMatrix(mat_ZZ_p S);

// returns S
mat_ZZ_p getSecretKey(mat_ZZ_p T);

// returns M
mat_ZZ_p keySwitchMatrix(mat_ZZ_p S, mat_ZZ_p T);

// finds c* then returns Mc*
vec_ZZ_p keySwitch(mat_ZZ_p M, vec_ZZ_p c);

// as described, treating I as the secret key and wx as ciphertext
vec_ZZ_p encrypt(mat_ZZ_p T, vec_ZZ_p x);

mat_ZZ_p getRandomMatrix(int m, int n);

int main()
{

   return 0;
}

<commit_msg>testing pushing<commit_after>#include <NTL/mat_ZZ_p.h>
#include <NTL/ZZ_p.h>
#include <NTL/ZZ.h>
#include <NTL/vec_ZZ_p.h>
#include <NTL/vec_ZZ.h>

using namespace std;
using namespace NTL;

const ZZ w = 123456789;

vec_ZZ_p decrypt(mat_ZZ_p S, vec_ZZ_p c);

// returns c*
vec_ZZ_p getBitVector(vec_ZZ_p c);
//
// returns S*
mat_ZZ_p getBitMatrix(mat_ZZ_p S);

// returns S
mat_ZZ_p getSecretKey(mat_ZZ_p T);

// returns M
mat_ZZ_p keySwitchMatrix(mat_ZZ_p S, mat_ZZ_p T);

// finds c* then returns Mc*
vec_ZZ_p keySwitch(mat_ZZ_p M, vec_ZZ_p c);

// as described, treating I as the secret key and wx as ciphertext
vec_ZZ_p encrypt(mat_ZZ_p T, vec_ZZ_p x);

mat_ZZ_p getRandomMatrix(int m, int n);

int main()
{

   return 0;
}

<|endoftext|>


<commit_before>#include <cassert>
#include <NTL/mat_ZZ_p.h>
#include <NTL/ZZ_p.h>
#include <NTL/ZZ.h>
#include <NTL/vec_ZZ_p.h>
#include <NTL/vec_ZZ.h>
#include <cmath>

using namespace std;
using namespace NTL;

const ZZ w(12345), q((1LL << 31LL) - 1LL);
const int l = 34;

vec_ZZ decrypt(mat_ZZ_p S, vec_ZZ_p c);

mat_ZZ_p hCat(mat_ZZ_p A, mat_ZZ_p B);
mat_ZZ_p vCat(mat_ZZ_p A, mat_ZZ_p B);

// returns c*
vec_ZZ_p getBitVector(vec_ZZ_p c);
//
// returns S*
mat_ZZ_p getBitMatrix(mat_ZZ_p S);

// returns S
mat_ZZ_p getSecretKey(mat_ZZ_p T);

// returns M
mat_ZZ_p keySwitchMatrix(mat_ZZ_p S, mat_ZZ_p T);

// finds c* then returns Mc*
vec_ZZ_p keySwitch(mat_ZZ_p M, vec_ZZ_p c);

// as described, treating I as the secret key and wx as ciphertext
vec_ZZ_p encrypt(mat_ZZ_p T, vec_ZZ_p x);

mat_ZZ_p getRandomMatrix(int row, int col, int bound);

// finds c* then returns Mc*
vec_ZZ_p keySwitch(mat_ZZ_p M, vec_ZZ_p c){
    vec_ZZ_p cstar = getBitVector(c);
    return M * cstar;
}

mat_ZZ_p getRandomMatrix(int row, int col, int bound){
    mat_ZZ_p A;
    A.SetDims(row, col);
    for (int i=0; i<row; ++i){
        for (int j=0; j<col; ++j){
            A[i][j] = (ZZ_p)RandomBnd((long)bound);
        }
    }
    return A;
}

// returns c*
vec_ZZ_p getBitVector(vec_ZZ_p c) {
	vec_ZZ_p result;
	int length = c.length();
	result.SetLength(length * l);
	for(int i = 0; i < length; ++i) {
		ZZ value = rep(c[i]);
		for(int j = 0; j < l; ++j) {
			result[i * l + j] = bit(value, j);
		}
	}
	return result;
}

// returns S
mat_ZZ_p getSecretKey(mat_ZZ_p T) {
	mat_ZZ_p I;
	ident(I, T.NumRows());
	return hCat(I, T);
}

mat_ZZ_p hCat(mat_ZZ_p A, mat_ZZ_p B) {
	assert(A.NumRows() == B.NumRows());

	int rows = A.NumRows(), colsA = A.NumCols(), colsB = B.NumCols();
	mat_ZZ_p result;
	result.SetDims(rows, colsA + colsB);

	// Copy A
	for(int i = 0; i < rows; ++i) {
		for(int j = 0; j < colsA; ++j) {
			result[i][j] = A[i][j];
		}
	}

	// Copy B
	for(int i = 0; i < rows; ++i) {
		for(int j = 0; j < colsB; ++j) {
			result[i][colsA + j] = B[i][j];
		}
	}

	return result;
}

mat_ZZ_p vCat(mat_ZZ_p A, mat_ZZ_p B) {
	assert(A.NumCols() == B.NumCols());

	int cols = A.NumCols(), rowsA = A.NumRows(), rowsB = B.NumRows();
	mat_ZZ_p result;
	result.SetDims(rowsA + rowsB, cols);

	// Copy A
	for(int i = 0; i < rowsA; ++i) {
		for(int j = 0; j < cols; ++j) {
			result[i][j] = A[i][j];
		}
	}

	// Copy B
	for(int i = 0; i < rowsB; ++i) {
		for(int j = 0; j < cols; ++j) {
			result[i + rowsA][j] = B[i][j];
		}
	}

	return result;
}

vec_ZZ decrypt(mat_ZZ_p S, vec_ZZ_p c) {
	vec_ZZ_p Sc = S*c;
	vec_ZZ output;
	output.SetLength(Sc.length());
	for (int i=0; i<Sc.length(); i++) {
		output[i] = (rep(Sc[i])+w/2)/w;
	}
	return output;
}

mat_ZZ_p keySwitchMatrix(mat_ZZ_p S, mat_ZZ_p T) {
	mat_ZZ_p Sstar = getBitMatrix(S);
	ZZ m = Sstar.NumRows();
	ZZ nl = Sstar.NumCols();
	mat_ZZ_p A = getRandomMatrix(T.NumCols(),nl);
	//mat_ZZ_p M = vCat(Sstar + E - T*A);
	return Sstar;
}

int main()
{
	ZZ_p::init(q);
   return 0;
}

<commit_msg>finished key switch<commit_after>#include <cassert>
#include <NTL/mat_ZZ_p.h>
#include <NTL/ZZ_p.h>
#include <NTL/ZZ.h>
#include <NTL/vec_ZZ_p.h>
#include <NTL/vec_ZZ.h>
#include <cmath>

using namespace std;
using namespace NTL;

const ZZ w(12345), q((1LL << 31LL) - 1LL);
const int l = 34;

vec_ZZ decrypt(mat_ZZ_p S, vec_ZZ_p c);

mat_ZZ_p hCat(mat_ZZ_p A, mat_ZZ_p B);
mat_ZZ_p vCat(mat_ZZ_p A, mat_ZZ_p B);

// returns c*
vec_ZZ_p getBitVector(vec_ZZ_p c);
//
// returns S*
mat_ZZ_p getBitMatrix(mat_ZZ_p S);

// returns S
mat_ZZ_p getSecretKey(mat_ZZ_p T);

// returns M
mat_ZZ_p keySwitchMatrix(mat_ZZ_p S, mat_ZZ_p T);

// finds c* then returns Mc*
vec_ZZ_p keySwitch(mat_ZZ_p M, vec_ZZ_p c);

// as described, treating I as the secret key and wx as ciphertext
vec_ZZ_p encrypt(mat_ZZ_p T, vec_ZZ_p x);

mat_ZZ_p getRandomMatrix(int row, int col, int bound);

// finds c* then returns Mc*
vec_ZZ_p keySwitch(mat_ZZ_p M, vec_ZZ_p c){
    vec_ZZ_p cstar = getBitVector(c);
    return M * cstar;
}

mat_ZZ_p getRandomMatrix(int row, int col, int bound){
    mat_ZZ_p A;
    A.SetDims(row, col);
    for (int i=0; i<row; ++i){
        for (int j=0; j<col; ++j){
            A[i][j] = (ZZ_p)RandomBnd((long)bound);
        }
    }
    return A;
}

// returns c*
vec_ZZ_p getBitVector(vec_ZZ_p c) {
	vec_ZZ_p result;
	int length = c.length();
	result.SetLength(length * l);
	for(int i = 0; i < length; ++i) {
		ZZ value = rep(c[i]);
		for(int j = 0; j < l; ++j) {
			result[i * l + j] = bit(value, j);
		}
	}
	return result;
}

// returns S
mat_ZZ_p getSecretKey(mat_ZZ_p T) {
	mat_ZZ_p I;
	ident(I, T.NumRows());
	return hCat(I, T);
}

mat_ZZ_p hCat(mat_ZZ_p A, mat_ZZ_p B) {
	assert(A.NumRows() == B.NumRows());

	int rows = A.NumRows(), colsA = A.NumCols(), colsB = B.NumCols();
	mat_ZZ_p result;
	result.SetDims(rows, colsA + colsB);

	// Copy A
	for(int i = 0; i < rows; ++i) {
		for(int j = 0; j < colsA; ++j) {
			result[i][j] = A[i][j];
		}
	}

	// Copy B
	for(int i = 0; i < rows; ++i) {
		for(int j = 0; j < colsB; ++j) {
			result[i][colsA + j] = B[i][j];
		}
	}

	return result;
}

mat_ZZ_p vCat(mat_ZZ_p A, mat_ZZ_p B) {
	assert(A.NumCols() == B.NumCols());

	int cols = A.NumCols(), rowsA = A.NumRows(), rowsB = B.NumRows();
	mat_ZZ_p result;
	result.SetDims(rowsA + rowsB, cols);

	// Copy A
	for(int i = 0; i < rowsA; ++i) {
		for(int j = 0; j < cols; ++j) {
			result[i][j] = A[i][j];
		}
	}

	// Copy B
	for(int i = 0; i < rowsB; ++i) {
		for(int j = 0; j < cols; ++j) {
			result[i + rowsA][j] = B[i][j];
		}
	}

	return result;
}

vec_ZZ decrypt(mat_ZZ_p S, vec_ZZ_p c) {
	vec_ZZ_p Sc = S*c;
	vec_ZZ output;
	output.SetLength(Sc.length());
	for (int i=0; i<Sc.length(); i++) {
		output[i] = (rep(Sc[i])+w/2)/w;
	}
	return output;
}

mat_ZZ_p keySwitchMatrix(mat_ZZ_p S, mat_ZZ_p T) {
	//TODO make bound an argument
	long Abound = 5;
	long Ebound = 5;
	mat_ZZ_p Sstar = getBitMatrix(S);
	mat_ZZ_p A = getRandomMatrix(T.NumCols(),Sstar.NumCols(),Abound);
	mat_ZZ_p E = getRandomMatrix(Sstar.NumRows(),Sstar.NumCols(),Ebound);
	mat_ZZ_p M = vCat(Sstar + E - T*A, A);
	return Sstar;
}

int main()
{
	ZZ_p::init(q);
   return 0;
}

<|endoftext|>


<commit_before>
//g++ -g test.cpp proto.cpp addressbook.pb.cc -lprotobuf -lz -std=gnu++11 -o proto -Wl,-rpath,/usr/local/lib -I/usr/local/include/
//g++ -rdynamic -std=gnu++11 -fPIC -g test.cpp proto.cpp addressbook.pb.cc -I/usr/local/include/ -Wl,-rpath,/usr/local/lib -Wl,-Bdynamic -lz -Wl,-Bstatic -lprotobuf -Wl,-Bdynamic -o proto
//g++ -rdynamic -std=gnu++11 -fPIC -O3 test.cpp proto.cpp addressbook.pb.cc -I/usr/local/include/ -Wl,-rpath,/usr/local/lib -Wl,-Bdynamic -lz -Wl,-Bstatic -lprotobuf -Wl,-Bdynamic -o proto

#include "addressbook.pb.h"
#include "proto.h"
#include <iostream>
using namespace std;

//以下部分为测试代码
void addPerson(protocol::AddressBook &address_book)
{
	protocol::Person* person = address_book.add_people();
	assert(person);
	static int32_t id = 100;
	person->set_id(id++);
	*person->mutable_name() = "huang马克黄";
	person->set_email("888888@qq.com");
	//
	protocol::Person::PhoneNumber* phone_number = person->add_phones();
    phone_number->set_number("18912345678");
	phone_number->set_type(protocol::Person::MOBILE);

	phone_number = person->add_phones();
    phone_number->set_number("075512345678");
	phone_number->set_type(protocol::Person::WORK);
}

void print_(const protocol::AddressBook *book)
{
	for(int i = 0;i < book->people_size();++i)
	{
		const protocol::Person &person = book->people(i);
		std::cout<<"id:"<<person.id()<<endl;
		std::cout<<"e-mail:"<<person.email()<<endl;
		std::cout<<"name:"<<person.name()<<endl;
		for(int k = 0;k< person.phones_size();++k)
		{
			const protocol::Person_PhoneNumber &number = person.phones(k);
			std::cout<<"number:"<<number.number()<<endl;
			std::cout<<"number type:"<<number.type()<<endl;
		}
	}
}

int main(int argc,char * argv[])
{
	GOOGLE_PROTOBUF_VERIFY_VERSION;

	protocol::AddressBook address_book;

	for(int i = 0;i< 5;++i)
	{
		addPerson(address_book);
		//addPerson(address_book);
	}
	//std::string protobuf = "";
	//assert(address_book.SerializeToString(&protobuf));

	CProtobufPacket packet;
	packet.set_proto_checksum_algorithm(true);
	packet.set_proto_format(true);
	packet.set_proto_zip(true);
	std::string buf = packet.encode(address_book);

	//std::cout<<"buf"<<buf<<endl;
	buf.append("附加测试,判定只解析需要的数据");
	protocol::AddressBook *book = dynamic_cast<protocol::AddressBook*>(packet.decode(buf));
	print_(book);

	CJsonPacket jsonpacket;
	buf = jsonpacket.encode(*book);
	std::cout<<buf.size()<<endl;
	std::cout<<buf<<endl;

	book = dynamic_cast<protocol::AddressBook*>(jsonpacket.decode(buf));
	//print_(book);
	delete book;

	// Optional:  Delete all global objects allocated by libprotobuf.
  	google::protobuf::ShutdownProtobufLibrary();

	return 0;
}
<commit_msg>释放C++资源<commit_after>
//g++ -g test.cpp proto.cpp addressbook.pb.cc -lprotobuf -lz -std=gnu++11 -o proto -Wl,-rpath,/usr/local/lib -I/usr/local/include/
//g++ -rdynamic -std=gnu++11 -fPIC -g test.cpp proto.cpp addressbook.pb.cc -I/usr/local/include/ -Wl,-rpath,/usr/local/lib -Wl,-Bdynamic -lz -Wl,-Bstatic -lprotobuf -Wl,-Bdynamic -o proto
//g++ -rdynamic -std=gnu++11 -fPIC -O3 test.cpp proto.cpp addressbook.pb.cc -I/usr/local/include/ -Wl,-rpath,/usr/local/lib -Wl,-Bdynamic -lz -Wl,-Bstatic -lprotobuf -Wl,-Bdynamic -o proto

#include "addressbook.pb.h"
#include "proto.h"
#include <iostream>
using namespace std;

//以下部分为测试代码
void addPerson(protocol::AddressBook &address_book)
{
	protocol::Person* person = address_book.add_people();
	assert(person);
	static int32_t id = 100;
	person->set_id(id++);
	*person->mutable_name() = "huang马克黄";
	person->set_email("888888@qq.com");
	//
	protocol::Person::PhoneNumber* phone_number = person->add_phones();
    phone_number->set_number("18912345678");
	phone_number->set_type(protocol::Person::MOBILE);

	phone_number = person->add_phones();
    phone_number->set_number("075512345678");
	phone_number->set_type(protocol::Person::WORK);
}

void print_(const protocol::AddressBook *book)
{
	for(int i = 0;i < book->people_size();++i)
	{
		const protocol::Person &person = book->people(i);
		std::cout<<"id:"<<person.id()<<endl;
		std::cout<<"e-mail:"<<person.email()<<endl;
		std::cout<<"name:"<<person.name()<<endl;
		for(int k = 0;k< person.phones_size();++k)
		{
			const protocol::Person_PhoneNumber &number = person.phones(k);
			std::cout<<"number:"<<number.number()<<endl;
			std::cout<<"number type:"<<number.type()<<endl;
		}
	}
}

int main(int argc,char * argv[])
{
	GOOGLE_PROTOBUF_VERIFY_VERSION;

	protocol::AddressBook address_book;

	for(int i = 0;i< 5;++i)
	{
		addPerson(address_book);
		//addPerson(address_book);
	}
	//std::string protobuf = "";
	//assert(address_book.SerializeToString(&protobuf));

	CProtobufPacket packet;
	packet.set_proto_checksum_algorithm(true);
	packet.set_proto_format(true);
	packet.set_proto_zip(true);
	std::string buf = packet.encode(address_book);

	//std::cout<<"buf"<<buf<<endl;
	buf.append("附加测试,判定只解析需要的数据");
	protocol::AddressBook *book = dynamic_cast<protocol::AddressBook*>(packet.decode(buf));
	print_(book);

	CJsonPacket jsonpacket;
	buf = jsonpacket.encode(*book);
        delete book;
	std::cout<<buf.size()<<endl;
	std::cout<<buf<<endl;

	book = dynamic_cast<protocol::AddressBook*>(jsonpacket.decode(buf));
	//print_(book);
	delete book;

	// Optional:  Delete all global objects allocated by libprotobuf.
  	google::protobuf::ShutdownProtobufLibrary();

	return 0;
}
<|endoftext|>