<commit_before>/*
 * Copyright(c) Sophist Solutions, Inc. 1990-2013.  All rights reserved
 */
#ifndef _Stroika_Foundation_Containers_Private_PatchingDataStructures_STLContainerWrapper_inl_
#define _Stroika_Foundation_Containers_Private_PatchingDataStructures_STLContainerWrapper_inl_   1

#include    <algorithm>

#include    "../../../Debug/Assertions.h"

namespace   Stroika {
    namespace   Foundation {
        namespace   Containers {
            namespace Private {
                namespace   PatchingDataStructures {

                    /*
                     ********************************************************************************
                     ******************* STLContainerWrapper<STL_CONTAINER_OF_T> ********************
                     ********************************************************************************
                     */
                    template    <typename STL_CONTAINER_OF_T>
                    inline  STLContainerWrapper<STL_CONTAINER_OF_T>::STLContainerWrapper ()
                        : inherited ()
                        , fActiveIteratorsListHead_ (nullptr)
                    {
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    inline  STLContainerWrapper<STL_CONTAINER_OF_T>::STLContainerWrapper (const STLContainerWrapper<STL_CONTAINER_OF_T>& from)
                        : inherited (from)
                        , fActiveIteratorsListHead_ (nullptr)
                    {
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    inline  STLContainerWrapper<STL_CONTAINER_OF_T>::~STLContainerWrapper ()
                    {
                        Require (not HasActiveIterators ()); // cannot destroy container with active iterators
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    inline  STLContainerWrapper<STL_CONTAINER_OF_T>&   STLContainerWrapper<STL_CONTAINER_OF_T>::operator= (const STLContainerWrapper<STL_CONTAINER_OF_T>& rhs)
                    {
                        /*
                         * Don't copy the rhs iterators, and don't do assignments when we have active iterators.
                         * If this is to be supported at some future date, well need to work on our patching.
                         */
                        Require (not HasActiveIterators ()); // cannot overwrite container with active iterators
                        inherited::operator= (rhs);
                        return *this;
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    inline  bool    STLContainerWrapper<STL_CONTAINER_OF_T>::HasActiveIterators () const
                    {
                        return fActiveIteratorsListHead_ != nullptr;
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    template    <typename INSERT_VALUE_TYPE>
                    void    STLContainerWrapper<STL_CONTAINER_OF_T>::insert_toVector_WithPatching (typename STL_CONTAINER_OF_T::iterator i, INSERT_VALUE_TYPE v)
                    {
                        Invariant ();
                        insert (i, v);
                        /// WRONG!!!! - must be more sophisticated. Must map all iteraotrs to OFFSETS, and then replace with new iteartors based on old offsets!!!
#if 0
                        // USE TwoPhaseIteratorPatcherPass1 - to captch all - and capture their offsets - need new overload - adn then new overload to patch back...
                        for (auto ai = fActiveIteratorsListHead_; ai != nullptr; ai = ai->fNextActiveIterator) {
                            ai->PatchAfter_insert (i);
                        }
#endif
                        Invariant ();
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    void    STLContainerWrapper<STL_CONTAINER_OF_T>::erase_WithPatching (typename STL_CONTAINER_OF_T::iterator i)
                    {
                        Invariant ();
                        Memory::SmallStackBuffer<ForwardIterator*>   items2Patch (0);
                        TwoPhaseIteratorPatcherPass1 (i, &items2Patch);
                        auto newI = this->erase (i);
                        TwoPhaseIteratorPatcherPass2 (&items2Patch, newI);
                        Invariant ();
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    void    STLContainerWrapper<STL_CONTAINER_OF_T>::clear_WithPatching ()
                    {
                        Invariant ();
                        this->clear ();
                        for (auto ai = fActiveIteratorsListHead_; ai != nullptr; ai = ai->fNextActiveIterator) {
                            ai->TwoPhaseIteratorPatcherPass2 (this->end ());
                        }
                        Invariant ();
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    inline  void    STLContainerWrapper<STL_CONTAINER_OF_T>::TwoPhaseIteratorPatcherPass1 (typename STL_CONTAINER_OF_T::iterator oldI, Memory::SmallStackBuffer<ForwardIterator*>* items2Patch) const
                    {
                        for (auto ai = fActiveIteratorsListHead_; ai != nullptr; ai = ai->fNextActiveIterator) {
                            ai->TwoPhaseIteratorPatcherPass1 (oldI, items2Patch);
                        }
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    inline  void    STLContainerWrapper<STL_CONTAINER_OF_T>::TwoPhaseIteratorPatcherPass2 (const Memory::SmallStackBuffer<ForwardIterator*>* items2Patch, typename STL_CONTAINER_OF_T::iterator newI)
                    {
                        for (size_t i = 0; i < items2Patch->GetSize (); ++i) {
                            (*items2Patch)[i]->TwoPhaseIteratorPatcherPass2 (newI);
                        }
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    inline  void    STLContainerWrapper<STL_CONTAINER_OF_T>::Invariant () const
                    {
#if     qDebug
                        _Invariant ();
#endif
                    }
#if     qDebug
                    template    <typename STL_CONTAINER_OF_T>
                    void    STLContainerWrapper<STL_CONTAINER_OF_T>::_Invariant () const
                    {
                        for (auto ai = fActiveIteratorsListHead_; ai != nullptr; ai = ai->fNextActiveIterator) {
                            ai->Invariant ();
                        }
                    }
#endif

                    /*
                     ********************************************************************************
                     ************ STLContainerWrapper<STL_CONTAINER_OF_T>::ForwardIterator **********
                     ********************************************************************************
                     */
                    template    <typename STL_CONTAINER_OF_T>
                    STLContainerWrapper<STL_CONTAINER_OF_T>::ForwardIterator::ForwardIterator (CONTAINER_TYPE* data)
                        : inherited (data)
                        , fData (data)
                        , fNextActiveIterator (data->fActiveIteratorsListHead_)
                        , fSuppressMore (true)
                    {
                        RequireNotNull (data);
                        fData->fActiveIteratorsListHead_ = this;
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    STLContainerWrapper<STL_CONTAINER_OF_T>::ForwardIterator::ForwardIterator (const ForwardIterator& from)
                        : inherited (from)
                        , fData (from.fData)
                        , fNextActiveIterator (from.fData->fActiveIteratorsListHead_)
                        , fSuppressMore (from.fSuppressMore)
                    {
                        RequireNotNull (fData);
                        fData->fActiveIteratorsListHead_ = this;
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    STLContainerWrapper<STL_CONTAINER_OF_T>::ForwardIterator::~ForwardIterator ()
                    {
                        AssertNotNull (fData);
                        if (fData->fActiveIteratorsListHead_ == this) {
                            fData->fActiveIteratorsListHead_ = fNextActiveIterator;
                        }
                        else {
                            auto v = fData->fActiveIteratorsListHead_;
                            for (; v->fNextActiveIterator != this; v = v->fNextActiveIterator) {
                                AssertNotNull (v);
                                AssertNotNull (v->fNextActiveIterator);
                            }
                            AssertNotNull (v);
                            Assert (v->fNextActiveIterator == this);
                            v->fNextActiveIterator = fNextActiveIterator;
                        }
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    typename  STLContainerWrapper<STL_CONTAINER_OF_T>::ForwardIterator&   STLContainerWrapper<STL_CONTAINER_OF_T>::ForwardIterator::operator= (const ForwardIterator& rhs)
                    {
                        /*
                         *      If the fData field has not changed, then we can leave alone our iterator linkage.
                         *  Otherwise, we must remove ourselves from the old, and add ourselves to the new.
                         */
                        if (fData != rhs.fData) {
                            AssertNotNull (fData);
                            AssertNotNull (rhs.fData);

                            /*
                             * Remove from old.
                             */
                            if (fData->fIterators == this) {
                                fData->fIterators = fNextActiveIterator;
                            }
                            else {
                                auto v = fData->fIterators;
                                for (; v->fNextActiveIterator != this; v = v->fNextActiveIterator) {
                                    AssertNotNull (v);
                                    AssertNotNull (v->fNextActiveIterator);
                                }
                                AssertNotNull (v);
                                Assert (v->fNextActiveIterator == this);
                                v->fNextActiveIterator = fNextActiveIterator;
                            }

                            /*
                             * Add to new.
                             */
                            fData = rhs.fData;
                            fNextActiveIterator = rhs.fData->fIterators;
                            fData->fIterators = this;
                            inherited::operator= (rhs);
                        }
                        return *this;
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    template    <typename VALUE_TYPE>
                    inline  bool    STLContainerWrapper<STL_CONTAINER_OF_T>::ForwardIterator::More (VALUE_TYPE* current, bool advance)
                    {
                        if (advance and fSuppressMore) {
                            advance = false;
                            fSuppressMore = false;
                        }
                        return inherited::More (current, advance);
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    inline  void    STLContainerWrapper<STL_CONTAINER_OF_T>::ForwardIterator::RemoveCurrent ()
                    {
                        AssertNotNull (fData);
                        fData->erase_WithPatching (this->fStdIterator);
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    void    STLContainerWrapper<STL_CONTAINER_OF_T>::ForwardIterator::TwoPhaseIteratorPatcherPass1 (typename STL_CONTAINER_OF_T::iterator oldI, Memory::SmallStackBuffer<ForwardIterator*>* items2Patch)
                    {
                        if (this->fStdIterator == oldI) {
                            items2Patch->push_back (this);
                        }
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    void    STLContainerWrapper<STL_CONTAINER_OF_T>::ForwardIterator::TwoPhaseIteratorPatcherPass2 (typename STL_CONTAINER_OF_T::iterator newI)
                    {
                        fSuppressMore = true;
                        this->fStdIterator = newI;
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    inline  void    STLContainerWrapper<STL_CONTAINER_OF_T>::ForwardIterator::Invariant () const
                    {
#if     qDebug
                        _Invariant ();
#endif
                    }
#if     qDebug
                    template    <typename STL_CONTAINER_OF_T>
                    void    STLContainerWrapper<STL_CONTAINER_OF_T>::ForwardIterator::_Invariant () const
                    {
                        AssertNotNull (fData);
                        // apparently pointless test is just to force triggering any check code in iterator classes for valid iterators
                        Assert (this->fStdIterator == fData->end () or this->fStdIterator != fData->end ());
                        // Find some way to check iterator traits to see if random access and do this test if possible
                        //Assert ((fCurrent >= fStart) and (fCurrent <= fEnd));   // ANSI C requires this is always TRUE
                    }
#endif

                }
            }
        }
    }
}
#endif /* _Stroika_Foundation_Containers_Private_PatchingDataStructures_STLContainerWrapper_inl_ */
<commit_msg>fixed  STLContainerWrapper<STL_CONTAINER_OF_T>::insert_toVector_WithPatching for finickier GCC<commit_after>/*
 * Copyright(c) Sophist Solutions, Inc. 1990-2013.  All rights reserved
 */
#ifndef _Stroika_Foundation_Containers_Private_PatchingDataStructures_STLContainerWrapper_inl_
#define _Stroika_Foundation_Containers_Private_PatchingDataStructures_STLContainerWrapper_inl_   1

#include    <algorithm>

#include    "../../../Debug/Assertions.h"

namespace   Stroika {
    namespace   Foundation {
        namespace   Containers {
            namespace Private {
                namespace   PatchingDataStructures {

                    /*
                     ********************************************************************************
                     ******************* STLContainerWrapper<STL_CONTAINER_OF_T> ********************
                     ********************************************************************************
                     */
                    template    <typename STL_CONTAINER_OF_T>
                    inline  STLContainerWrapper<STL_CONTAINER_OF_T>::STLContainerWrapper ()
                        : inherited ()
                        , fActiveIteratorsListHead_ (nullptr)
                    {
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    inline  STLContainerWrapper<STL_CONTAINER_OF_T>::STLContainerWrapper (const STLContainerWrapper<STL_CONTAINER_OF_T>& from)
                        : inherited (from)
                        , fActiveIteratorsListHead_ (nullptr)
                    {
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    inline  STLContainerWrapper<STL_CONTAINER_OF_T>::~STLContainerWrapper ()
                    {
                        Require (not HasActiveIterators ()); // cannot destroy container with active iterators
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    inline  STLContainerWrapper<STL_CONTAINER_OF_T>&   STLContainerWrapper<STL_CONTAINER_OF_T>::operator= (const STLContainerWrapper<STL_CONTAINER_OF_T>& rhs)
                    {
                        /*
                         * Don't copy the rhs iterators, and don't do assignments when we have active iterators.
                         * If this is to be supported at some future date, well need to work on our patching.
                         */
                        Require (not HasActiveIterators ()); // cannot overwrite container with active iterators
                        inherited::operator= (rhs);
                        return *this;
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    inline  bool    STLContainerWrapper<STL_CONTAINER_OF_T>::HasActiveIterators () const
                    {
                        return fActiveIteratorsListHead_ != nullptr;
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    template    <typename INSERT_VALUE_TYPE>
                    void    STLContainerWrapper<STL_CONTAINER_OF_T>::insert_toVector_WithPatching (typename STL_CONTAINER_OF_T::iterator i, INSERT_VALUE_TYPE v)
                    {
                        Invariant ();
                        this->insert (i, v);
                        /// WRONG!!!! - must be more sophisticated. Must map all iteraotrs to OFFSETS, and then replace with new iteartors based on old offsets!!!
#if 0
                        // USE TwoPhaseIteratorPatcherPass1 - to captch all - and capture their offsets - need new overload - adn then new overload to patch back...
                        for (auto ai = fActiveIteratorsListHead_; ai != nullptr; ai = ai->fNextActiveIterator) {
                            ai->PatchAfter_insert (i);
                        }
#endif
                        Invariant ();
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    void    STLContainerWrapper<STL_CONTAINER_OF_T>::erase_WithPatching (typename STL_CONTAINER_OF_T::iterator i)
                    {
                        Invariant ();
                        Memory::SmallStackBuffer<ForwardIterator*>   items2Patch (0);
                        TwoPhaseIteratorPatcherPass1 (i, &items2Patch);
                        auto newI = this->erase (i);
                        TwoPhaseIteratorPatcherPass2 (&items2Patch, newI);
                        Invariant ();
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    void    STLContainerWrapper<STL_CONTAINER_OF_T>::clear_WithPatching ()
                    {
                        Invariant ();
                        this->clear ();
                        for (auto ai = fActiveIteratorsListHead_; ai != nullptr; ai = ai->fNextActiveIterator) {
                            ai->TwoPhaseIteratorPatcherPass2 (this->end ());
                        }
                        Invariant ();
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    inline  void    STLContainerWrapper<STL_CONTAINER_OF_T>::TwoPhaseIteratorPatcherPass1 (typename STL_CONTAINER_OF_T::iterator oldI, Memory::SmallStackBuffer<ForwardIterator*>* items2Patch) const
                    {
                        for (auto ai = fActiveIteratorsListHead_; ai != nullptr; ai = ai->fNextActiveIterator) {
                            ai->TwoPhaseIteratorPatcherPass1 (oldI, items2Patch);
                        }
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    inline  void    STLContainerWrapper<STL_CONTAINER_OF_T>::TwoPhaseIteratorPatcherPass2 (const Memory::SmallStackBuffer<ForwardIterator*>* items2Patch, typename STL_CONTAINER_OF_T::iterator newI)
                    {
                        for (size_t i = 0; i < items2Patch->GetSize (); ++i) {
                            (*items2Patch)[i]->TwoPhaseIteratorPatcherPass2 (newI);
                        }
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    inline  void    STLContainerWrapper<STL_CONTAINER_OF_T>::Invariant () const
                    {
#if     qDebug
                        _Invariant ();
#endif
                    }
#if     qDebug
                    template    <typename STL_CONTAINER_OF_T>
                    void    STLContainerWrapper<STL_CONTAINER_OF_T>::_Invariant () const
                    {
                        for (auto ai = fActiveIteratorsListHead_; ai != nullptr; ai = ai->fNextActiveIterator) {
                            ai->Invariant ();
                        }
                    }
#endif

                    /*
                     ********************************************************************************
                     ************ STLContainerWrapper<STL_CONTAINER_OF_T>::ForwardIterator **********
                     ********************************************************************************
                     */
                    template    <typename STL_CONTAINER_OF_T>
                    STLContainerWrapper<STL_CONTAINER_OF_T>::ForwardIterator::ForwardIterator (CONTAINER_TYPE* data)
                        : inherited (data)
                        , fData (data)
                        , fNextActiveIterator (data->fActiveIteratorsListHead_)
                        , fSuppressMore (true)
                    {
                        RequireNotNull (data);
                        fData->fActiveIteratorsListHead_ = this;
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    STLContainerWrapper<STL_CONTAINER_OF_T>::ForwardIterator::ForwardIterator (const ForwardIterator& from)
                        : inherited (from)
                        , fData (from.fData)
                        , fNextActiveIterator (from.fData->fActiveIteratorsListHead_)
                        , fSuppressMore (from.fSuppressMore)
                    {
                        RequireNotNull (fData);
                        fData->fActiveIteratorsListHead_ = this;
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    STLContainerWrapper<STL_CONTAINER_OF_T>::ForwardIterator::~ForwardIterator ()
                    {
                        AssertNotNull (fData);
                        if (fData->fActiveIteratorsListHead_ == this) {
                            fData->fActiveIteratorsListHead_ = fNextActiveIterator;
                        }
                        else {
                            auto v = fData->fActiveIteratorsListHead_;
                            for (; v->fNextActiveIterator != this; v = v->fNextActiveIterator) {
                                AssertNotNull (v);
                                AssertNotNull (v->fNextActiveIterator);
                            }
                            AssertNotNull (v);
                            Assert (v->fNextActiveIterator == this);
                            v->fNextActiveIterator = fNextActiveIterator;
                        }
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    typename  STLContainerWrapper<STL_CONTAINER_OF_T>::ForwardIterator&   STLContainerWrapper<STL_CONTAINER_OF_T>::ForwardIterator::operator= (const ForwardIterator& rhs)
                    {
                        /*
                         *      If the fData field has not changed, then we can leave alone our iterator linkage.
                         *  Otherwise, we must remove ourselves from the old, and add ourselves to the new.
                         */
                        if (fData != rhs.fData) {
                            AssertNotNull (fData);
                            AssertNotNull (rhs.fData);

                            /*
                             * Remove from old.
                             */
                            if (fData->fIterators == this) {
                                fData->fIterators = fNextActiveIterator;
                            }
                            else {
                                auto v = fData->fIterators;
                                for (; v->fNextActiveIterator != this; v = v->fNextActiveIterator) {
                                    AssertNotNull (v);
                                    AssertNotNull (v->fNextActiveIterator);
                                }
                                AssertNotNull (v);
                                Assert (v->fNextActiveIterator == this);
                                v->fNextActiveIterator = fNextActiveIterator;
                            }

                            /*
                             * Add to new.
                             */
                            fData = rhs.fData;
                            fNextActiveIterator = rhs.fData->fIterators;
                            fData->fIterators = this;
                            inherited::operator= (rhs);
                        }
                        return *this;
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    template    <typename VALUE_TYPE>
                    inline  bool    STLContainerWrapper<STL_CONTAINER_OF_T>::ForwardIterator::More (VALUE_TYPE* current, bool advance)
                    {
                        if (advance and fSuppressMore) {
                            advance = false;
                            fSuppressMore = false;
                        }
                        return inherited::More (current, advance);
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    inline  void    STLContainerWrapper<STL_CONTAINER_OF_T>::ForwardIterator::RemoveCurrent ()
                    {
                        AssertNotNull (fData);
                        fData->erase_WithPatching (this->fStdIterator);
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    void    STLContainerWrapper<STL_CONTAINER_OF_T>::ForwardIterator::TwoPhaseIteratorPatcherPass1 (typename STL_CONTAINER_OF_T::iterator oldI, Memory::SmallStackBuffer<ForwardIterator*>* items2Patch)
                    {
                        if (this->fStdIterator == oldI) {
                            items2Patch->push_back (this);
                        }
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    void    STLContainerWrapper<STL_CONTAINER_OF_T>::ForwardIterator::TwoPhaseIteratorPatcherPass2 (typename STL_CONTAINER_OF_T::iterator newI)
                    {
                        fSuppressMore = true;
                        this->fStdIterator = newI;
                    }
                    template    <typename STL_CONTAINER_OF_T>
                    inline  void    STLContainerWrapper<STL_CONTAINER_OF_T>::ForwardIterator::Invariant () const
                    {
#if     qDebug
                        _Invariant ();
#endif
                    }
#if     qDebug
                    template    <typename STL_CONTAINER_OF_T>
                    void    STLContainerWrapper<STL_CONTAINER_OF_T>::ForwardIterator::_Invariant () const
                    {
                        AssertNotNull (fData);
                        // apparently pointless test is just to force triggering any check code in iterator classes for valid iterators
                        Assert (this->fStdIterator == fData->end () or this->fStdIterator != fData->end ());
                        // Find some way to check iterator traits to see if random access and do this test if possible
                        //Assert ((fCurrent >= fStart) and (fCurrent <= fEnd));   // ANSI C requires this is always TRUE
                    }
#endif

                }
            }
        }
    }
}
#endif /* _Stroika_Foundation_Containers_Private_PatchingDataStructures_STLContainerWrapper_inl_ */
<|endoftext|>


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

 Program:   BlueBerry Platform
 Language:  C++
 Date:      $Date: 2009-10-23 02:59:36 +0200 (Fri, 23 Oct 2009) $
 Version:   $Revision$

 Copyright (c) German Cancer Research Center, Division of Medical and
 Biological Informatics. All rights reserved.
 See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.

 This software is distributed WITHOUT ANY WARRANTY; without even
 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 PURPOSE.  See the above copyright notices for more information.

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

#include "QmitkDiffusionImagingAppWorkbenchAdvisor.h"

#include "internal/mitkPluginActivator.h"

#include <berryPlatform.h>
#include <berryIPreferencesService.h>
#include <berryWorkbenchPreferenceConstants.h>
#include <berryQtAssistantUtil.h>
#include <QmitkExtWorkbenchWindowAdvisor.h>

#include <QApplication>

const std::string QmitkDiffusionImagingAppWorkbenchAdvisor::WELCOME_PERSPECTIVE_ID = "org.mitk.diffusionimagingapp.perspectives.welcome";

void
QmitkDiffusionImagingAppWorkbenchAdvisor::Initialize(berry::IWorkbenchConfigurer::Pointer configurer)
{
  berry::QtWorkbenchAdvisor::Initialize(configurer);

  configurer->SetSaveAndRestore(true);

  // TODO This should go into the products plugin_customization.ini file (when
  // the product and branding support is finished, see bug 2146).
  // This will not work anymore, if bug 2822 is fixed.
  berry::IPreferencesService::Pointer prefService = berry::Platform::GetServiceRegistry().GetServiceById<berry::IPreferencesService>(berry::IPreferencesService::ID);
  prefService->GetSystemPreferences()->Put(berry::WorkbenchPreferenceConstants::PREFERRED_SASH_LAYOUT, berry::WorkbenchPreferenceConstants::RIGHT);

  QString collectionFile = mitkPluginActivator::GetDefault()->GetQtHelpCollectionFile();
  if (!collectionFile.isEmpty())
  {
//    berry::QtAssistantUtil::SetHelpCollectionFile(collectionFile);
//    berry::QtAssistantUtil::SetDefaultHelpUrl("qthelp://org.mitk.gui.qt.diffusionimagingapp/bundle/index.html");

    typedef std::vector<berry::IBundle::Pointer> BundleContainer;
    BundleContainer bundles = berry::Platform::GetBundles();
    berry::QtAssistantUtil::RegisterQCHFiles(bundles);
  }

}

berry::WorkbenchWindowAdvisor*
QmitkDiffusionImagingAppWorkbenchAdvisor::CreateWorkbenchWindowAdvisor(
        berry::IWorkbenchWindowConfigurer::Pointer configurer)
{
  std::vector<std::string> perspExcludeList;
  perspExcludeList.push_back( std::string("org.blueberry.uitest.util.EmptyPerspective") );
  perspExcludeList.push_back( std::string("org.blueberry.uitest.util.EmptyPerspective2") );
  perspExcludeList.push_back( std::string("org.mitk.coreapp.defaultperspective") );
  perspExcludeList.push_back( std::string("org.mitk.extapp.defaultperspective") );
  perspExcludeList.push_back( std::string("org.mitk.perspectives.publicdiffusionimaging") );
  perspExcludeList.push_back( std::string("org.mitk.perspectives.diffusionimaginginternal") );

  std::vector<std::string> viewExcludeList;
//  viewExcludeList.push_back( std::string("org.mitk.views.partialvolumeanalysis") );
//  viewExcludeList.push_back( std::string("org.mitk.views.globalfibertracking") );
//  viewExcludeList.push_back( std::string("org.mitk.views.tractbasedspatialstatistics") );
//  viewExcludeList.push_back( std::string("org.mitk.views.fibertracking") );
//  viewExcludeList.push_back( std::string("org.mitk.views.ivim") );
//  viewExcludeList.push_back( std::string("org.mitk.views.qballreconstruction") );
//  viewExcludeList.push_back( std::string("org.mitk.views.diffusiondicomimport") );
//  viewExcludeList.push_back( std::string("org.mitk.views.diffusionpreprocessing") );
//  viewExcludeList.push_back( std::string("org.mitk.views.diffusionquantification") );
//  viewExcludeList.push_back( std::string("org.mitk.views.tensorreconstruction") );
//  viewExcludeList.push_back( std::string("org.mitk.views.perspectiveswitcher") );
//  viewExcludeList.push_back( std::string("org.mitk.views.basicimageprocessing") );
//  viewExcludeList.push_back( std::string("org.mitk.views.fiberbundleoperations") );
//  viewExcludeList.push_back( std::string("org.mitk.views.measurement") );
//  viewExcludeList.push_back( std::string("org.mitk.views.moviemaker") );
//  viewExcludeList.push_back( std::string("org.mitk.views.odfdetails") );
//  viewExcludeList.push_back( std::string("org.mitk.views.propertylistview") );
//  viewExcludeList.push_back( std::string("org.mitk.views.screenshotmaker") );
//  viewExcludeList.push_back( std::string("org.mitk.views.segmentation") );
//  viewExcludeList.push_back( std::string("org.mitk.views.imagestatistics") );
//  viewExcludeList.push_back( std::string("org.mitk.views.controlvisualizationpropertiesview") );
//  viewExcludeList.push_back( std::string("org.mitk.views.volumevisualization") );
//  viewExcludeList.push_back( std::string("org.mitk.views.simplemeasurement") );

  configurer->SetShowPerspectiveBar(true);
  configurer->SetInitialSize(berry::Point(1000,770));

  QmitkExtWorkbenchWindowAdvisor* advisor = new QmitkExtWorkbenchWindowAdvisor(this, configurer);
  advisor->SetPerspectiveExcludeList(perspExcludeList);
  advisor->SetViewExcludeList(viewExcludeList);
  advisor->ShowViewToolbar(false);
  advisor->ShowVersionInfo(false);
  advisor->ShowMitkVersionInfo(false);
  advisor->SetProductName("MITK Diffusion Imaging App");
  advisor->SetWindowIcon(":/org.mitk.gui.qt.diffusionimagingapp/app-icon.png");
  return advisor;
}

std::string QmitkDiffusionImagingAppWorkbenchAdvisor::GetInitialWindowPerspectiveId()
{
  return WELCOME_PERSPECTIVE_ID;
}
<commit_msg>Changed perspective bar<commit_after>/*=========================================================================

 Program:   BlueBerry Platform
 Language:  C++
 Date:      $Date: 2009-10-23 02:59:36 +0200 (Fri, 23 Oct 2009) $
 Version:   $Revision$

 Copyright (c) German Cancer Research Center, Division of Medical and
 Biological Informatics. All rights reserved.
 See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.

 This software is distributed WITHOUT ANY WARRANTY; without even
 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 PURPOSE.  See the above copyright notices for more information.

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

#include "QmitkDiffusionImagingAppWorkbenchAdvisor.h"

#include "internal/mitkPluginActivator.h"

#include <berryPlatform.h>
#include <berryIPreferencesService.h>
#include <berryWorkbenchPreferenceConstants.h>
#include <berryQtAssistantUtil.h>
#include <QmitkExtWorkbenchWindowAdvisor.h>

#include <QApplication>

const std::string QmitkDiffusionImagingAppWorkbenchAdvisor::WELCOME_PERSPECTIVE_ID = "org.mitk.diffusionimagingapp.perspectives.welcome";

void
QmitkDiffusionImagingAppWorkbenchAdvisor::Initialize(berry::IWorkbenchConfigurer::Pointer configurer)
{
  berry::QtWorkbenchAdvisor::Initialize(configurer);

  configurer->SetSaveAndRestore(true);

  // TODO This should go into the products plugin_customization.ini file (when
  // the product and branding support is finished, see bug 2146).
  // This will not work anymore, if bug 2822 is fixed.
  berry::IPreferencesService::Pointer prefService = berry::Platform::GetServiceRegistry().GetServiceById<berry::IPreferencesService>(berry::IPreferencesService::ID);
  prefService->GetSystemPreferences()->Put(berry::WorkbenchPreferenceConstants::PREFERRED_SASH_LAYOUT, berry::WorkbenchPreferenceConstants::RIGHT);

  QString collectionFile = mitkPluginActivator::GetDefault()->GetQtHelpCollectionFile();
  if (!collectionFile.isEmpty())
  {
//    berry::QtAssistantUtil::SetHelpCollectionFile(collectionFile);
//    berry::QtAssistantUtil::SetDefaultHelpUrl("qthelp://org.mitk.gui.qt.diffusionimagingapp/bundle/index.html");

    typedef std::vector<berry::IBundle::Pointer> BundleContainer;
    BundleContainer bundles = berry::Platform::GetBundles();
    berry::QtAssistantUtil::RegisterQCHFiles(bundles);
  }

}

berry::WorkbenchWindowAdvisor*
QmitkDiffusionImagingAppWorkbenchAdvisor::CreateWorkbenchWindowAdvisor(
        berry::IWorkbenchWindowConfigurer::Pointer configurer)
{
  std::vector<std::string> perspExcludeList;
  perspExcludeList.push_back( std::string("org.blueberry.uitest.util.EmptyPerspective") );
  perspExcludeList.push_back( std::string("org.blueberry.uitest.util.EmptyPerspective2") );
  perspExcludeList.push_back( std::string("org.mitk.coreapp.defaultperspective") );
  perspExcludeList.push_back( std::string("org.mitk.extapp.defaultperspective") );
  perspExcludeList.push_back( std::string("org.mitk.perspectives.publicdiffusionimaging") );
  perspExcludeList.push_back( std::string("org.mitk.perspectives.diffusionimaginginternal") );

  std::vector<std::string> viewExcludeList;
//  viewExcludeList.push_back( std::string("org.mitk.views.partialvolumeanalysis") );
//  viewExcludeList.push_back( std::string("org.mitk.views.globalfibertracking") );
//  viewExcludeList.push_back( std::string("org.mitk.views.tractbasedspatialstatistics") );
//  viewExcludeList.push_back( std::string("org.mitk.views.fibertracking") );
//  viewExcludeList.push_back( std::string("org.mitk.views.ivim") );
//  viewExcludeList.push_back( std::string("org.mitk.views.qballreconstruction") );
//  viewExcludeList.push_back( std::string("org.mitk.views.diffusiondicomimport") );
//  viewExcludeList.push_back( std::string("org.mitk.views.diffusionpreprocessing") );
//  viewExcludeList.push_back( std::string("org.mitk.views.diffusionquantification") );
//  viewExcludeList.push_back( std::string("org.mitk.views.tensorreconstruction") );
//  viewExcludeList.push_back( std::string("org.mitk.views.perspectiveswitcher") );
//  viewExcludeList.push_back( std::string("org.mitk.views.basicimageprocessing") );
//  viewExcludeList.push_back( std::string("org.mitk.views.fiberbundleoperations") );
//  viewExcludeList.push_back( std::string("org.mitk.views.measurement") );
//  viewExcludeList.push_back( std::string("org.mitk.views.moviemaker") );
//  viewExcludeList.push_back( std::string("org.mitk.views.odfdetails") );
//  viewExcludeList.push_back( std::string("org.mitk.views.propertylistview") );
//  viewExcludeList.push_back( std::string("org.mitk.views.screenshotmaker") );
//  viewExcludeList.push_back( std::string("org.mitk.views.segmentation") );
//  viewExcludeList.push_back( std::string("org.mitk.views.imagestatistics") );
//  viewExcludeList.push_back( std::string("org.mitk.views.controlvisualizationpropertiesview") );
//  viewExcludeList.push_back( std::string("org.mitk.views.volumevisualization") );
//  viewExcludeList.push_back( std::string("org.mitk.views.simplemeasurement") );

  configurer->SetInitialSize(berry::Point(1000,770));

  QmitkExtWorkbenchWindowAdvisor* advisor = new QmitkExtWorkbenchWindowAdvisor(this, configurer);
  advisor->SetPerspectiveExcludeList(perspExcludeList);
  advisor->SetViewExcludeList(viewExcludeList);
  advisor->ShowViewToolbar(false);
  advisor->ShowPerspectiveToolbar(true);
  advisor->ShowVersionInfo(false);
  advisor->ShowMitkVersionInfo(false);
  advisor->SetProductName("MITK Diffusion Imaging App");
  advisor->SetWindowIcon(":/org.mitk.gui.qt.diffusionimagingapp/app-icon.png");
  return advisor;
}

std::string QmitkDiffusionImagingAppWorkbenchAdvisor::GetInitialWindowPerspectiveId()
{
  return WELCOME_PERSPECTIVE_ID;
}
<|endoftext|>


<commit_before>#include "filehandler.h"

/**
 * @brief FileHandler::FileHandler
 */
FileHandler::FileHandler()
{
    this->m_pid = 0; // zero out counter ids
    this->m_fid = 0;
    this->m_did = 0;
    this->lastError = 0;

}
/**
 * @brief FileHandler::create_project
 * creates project and associated files.
 * @param std::string name
 * @return Project* created project
 */
Project* FileHandler::create_project(std::string projName){
    Project* proj =  new Project(this->m_pid, projName);
    this->m_projects.insert(std::make_pair(proj->m_id, proj));
    save_project(proj);
    this->m_pid++;
    return proj;
}
/**
 * @brief FileHandler::create_directory
 * @param dirpath
 * @return unique directory ID
 */
ID FileHandler::create_directory(std::string dirpath){
    this->lastError = make_dir(dirpath); //varying implementation, OS dependant
    ID id = this->add_dir(dirpath);
    return id;
}

/**
 * @brief FileHandler::delete_directory
 * @param id
 * @return errorcode, if deletion was done code is 0;
 * otherwise see OS relevant directoryfile.
 */
FH_ERROR FileHandler::delete_directory(ID id){
    FH_ERROR err = remove_dir(this->get_dir(id)); //varying implementation, OS dependant
    return err;
}
/**
 * @brief FileHandler::save_project
 * @param id
 */
void FileHandler::save_project(ID id){
    save_project(get_project(id));
}

/**
 * @todo unfinished, needs full project structure
 * and program to file parser to finish
 * @brief FileHandler::save_project
 * @param Project* name
 * Creates project and associated files.
 * @return void
 */
void FileHandler::save_project(Project* proj){
    std::string projFile = proj->m_name + std::string(".txt"); //filename
    if(!proj->saved){
        ID dirID = create_directory(std::string(WORKSPACE) + "/"+ proj->m_name);//project directory

        proj->files->dir = dirID;

        proj->files->f_proj = create_file(projFile, dirID); //create project file

        std::string vidFile = proj->m_name + "_videos.txt";
        proj->files->f_videos = create_file(vidFile, dirID); //create video file

        std::string analysisFile = proj->m_name + "_analyses.txt";
        proj->files->f_analysis = create_file(analysisFile, dirID); //create analysis file

        std::string drawingFile = proj->m_name + "_drawings.txt";
        proj->files->f_drawings =create_file(drawingFile, dirID); //create drawings file
    }
    update_proj_files(proj);

}
/**
 * @todo unfinished, will be released with parser
 * however, is needed for creating
 * @brief FileHandler::save_project
 * @param Project* name
 * Creates project and associated files.
 * @return void
 */
void FileHandler::update_proj_files(Project* proj){
    ProjectStream ps;
    ps << *proj;
    write_file(proj->files->f_proj, ps.projFile.str(), WRITE_OPTION::OVERWRITE);
    write_file(proj->files->f_videos, ps.videos.str(), WRITE_OPTION::OVERWRITE);
    write_file(proj->files->f_analysis, ps.analyzes.str(), WRITE_OPTION::OVERWRITE);
    write_file(proj->files->f_drawings, ps.drawings.str(), WRITE_OPTION::OVERWRITE);
}
void FileHandler::load_proj_files(std::string str){
    ID id;
    std::string filepath;
    std::stringstream sstr;
    sstr << str;
    //read files until empty
    while(sstr >> id >> filepath){
        add_file(id, filepath);
    }
}
/**
 * @brief FileHandler::load_project
 * @param dirpath
 * @return
 */
Project* FileHandler::load_project(std::string fullProjectPath){
    std::string reverse (fullProjectPath.rbegin(), fullProjectPath.rend());
    std::string emaNjorp = reverse.substr(0, reverse.find("/"));
    std::string projName (emaNjorp.rbegin(), emaNjorp.rend());
    std::string dirpath = fullProjectPath.substr(0, fullProjectPath.find("/" + projName));
    projName = projName.substr(0, projName.find(".txt"));
    return load_project(projName, dirpath);
}
/**
 * @todo load analyses (in project <</>> operators)
 * @todo load drawings (in project <</>> operators)
 * @brief FileHandler::load_project
 * @param projname
 * @param dirpath
 * @return project
 */
Project* FileHandler::load_project(std::string projname, std::string dirpath){
    Project* proj = new Project();
    add_project(std::make_pair(this->m_pid++, proj));
    ProjectStream projStream;

    proj->saved = true;
//    Read project file
    std::string projFilePath = dirpath + "/" + projname + ".txt";
    proj->files->f_proj = load_project_file(projFilePath, projStream.projFile);

//    Read video file
    std::string videoFilePath = dirpath + "/" + projname + "_videos.txt";
    proj->files->f_videos = load_project_file(videoFilePath, projStream.videos);
//    Read Analyzes
    std::string analysesFilePath = dirpath + "/" + projname + "_analyses.txt";
    proj->files->f_analysis = load_project_file(analysesFilePath, projStream.videos);
//    Read Drawings
    std::string drawingsFilePath = dirpath + "/" + projname + "_drawings.txt";
    proj->files->f_drawings = load_project_file(drawingsFilePath, projStream.drawings);
//    Read project from projstream
    projStream >> *proj;
    return proj;
}
ID FileHandler::load_project_file(std::string filePath, std::stringstream& projFileStream){
    std::string buf;
    ID projFileID = add_file(filePath);
    read_file(projFileID, buf);
    projFileStream << buf; // Read project name
    return projFileID;
}

/**
 * @brief FileHandler::delete_project
 * Deletes project, its associated files and contents.
 * OBS! This operation is as of now irreversible
 * @param Project*
 * @return FH_ERROR errorcode
 */
FH_ERROR FileHandler::delete_project(Project* proj){
    ProjFiles* pf = proj->files;
    delete_file(pf->f_proj);
    delete_file(pf->f_videos);
    delete_file(pf->f_analysis);
    delete_file(pf->f_drawings);
    return delete_directory(proj->files->dir);

}
/**
 * @todo make threadsafe
 * @brief FileHandler::add_video
 * @param Project*,string filepath
 *
 * string
 * Add a video filepath to a given project.
 * Creates Video object which is accessed further by returned id.
 */
void FileHandler::add_video(Project* proj, std::string filePath){
    Video* v = new Video(filePath);
    proj->add_video(v);
    this->add_file(filePath);
}

 /**
  * @brief FileHandler::create_file
  * create a file by given name in already excisting
  * application tracked directory
  * @param std::string file name, ID directory id
  */

ID FileHandler::create_file(std::string filename, ID dirID){
    std::ofstream f;
    std::string filePath = this->get_dir(dirID)+"/"+filename;
    f.open(filePath.c_str());
    return this->add_file(filePath);
  }
/**
 * @todo make threadsafe
 * @brief FileHandler::delete_file
 * delete application tracked file
 * @param ID file id
 */
 FH_ERROR FileHandler::delete_file(ID id){
    std::string file = this->get_file(id);
    return std::remove(file.c_str());
 }
 /**
  * @todo make threadsafe
  * @brief FileHandler::write_file
  *  Write given text to an application tracked file
  * @param ID file id, std::string text
  * @return void
  */
 void FileHandler::write_file(ID id, std::string text, WRITE_OPTION opt){
    std::string fileName = this->get_file(id);
    std::ofstream f;
    switch(opt){
    case WRITE_OPTION::OVERWRITE:
        f.open(fileName.c_str(), std::ios::in | std::ios::out);
        break;
    case WRITE_OPTION::APPEND:
        f.open(fileName.c_str(), std::ios::in | std::ios::out | std::ios::ate);
        break;
    default:
        return; // no open file
        break;
    }
    if(f.is_open()) f << text.c_str() << std::endl;
 }

 /**
  * @brief FileHandler::read_file
  *  Read given lenght of lines to buffer from application
  *  tracked file. OBS! If number of lines exceeds =>
  *  reads to end of file (EOF)
  *  @param ID file id, std::string text
  *  @return voi
  */
 void FileHandler::read_file(ID id,  std::string& buf, int linesToRead){
     std::ifstream f(this->get_file(id));
     std::string temp;
     if(f.is_open()){
         while(linesToRead-- && std::getline(f, temp)){
            buf += temp;
         }
     }
 }
 /**
  * @brief FileHandler::get_project
  * Getter
  * @param ID project id
  * @return Project*
  */
 Project* FileHandler::get_project(ID pid){
    this->projMapLock.lock();
    Project* p = this->m_projects.at(pid);
    this->projMapLock.unlock();
    return p;
 }
 /**
  * @brief FileHandler::get_file
  * Getter
  * @param ID project file id
  * @return std::string filepath
  */
 std::string FileHandler::get_file(ID id){
    this->fileMapLock.lock();
    std::string file = this->m_fileMap.at(id);
    this->fileMapLock.unlock();
    return file;
 }
 /**
  * @brief FileHandler::get_dir
  * @param ID directory id
  * @return directory path
  */
 std::string FileHandler::get_dir(ID id){
    this->dirMapLock.lock();
    std::string dir = this->m_dirMap.at(id);
    this->dirMapLock.unlock();
    return dir;
 }

 /**
  * @brief FileHandler::add_projectr
  * @param std::pari<<ID, Project*> pair
  * @return void
  */
 void FileHandler::add_project(std::pair<ID,Project*> pair){
    this->projMapLock.lock();
    this->m_projects.insert(pair);
    this->projMapLock.unlock();

 }
 /**
  * @brief FileHandler::add_file
  * @param std::string filepath
  * @return unique file identifier
  */
ID FileHandler::add_file(std::string filepath){
    add_file(this->m_fid, filepath);
    return this->m_fid++;
 }
/**
 * @brief FileHandler::add_file
 * @param id
 * @param filepath
 */
void FileHandler::add_file(ID id ,std::string filepath){
    std::pair<ID,std::string> pair = std::make_pair(id, filepath);
    this->fileMapLock.lock();
    this->m_fileMap.insert(pair);
    this->fileMapLock.unlock();
}
 /**
  * @brief FileHandler::add_dir
  * @param std::string dirpath
  * @return unique directory identifier
  */
ID FileHandler::add_dir(std::string dirpath){
    std::pair<ID,std::string> pair = std::make_pair(this->m_did, dirpath);
    this->dirMapLock.lock();
    this->m_dirMap.insert(pair);
    this->dirMapLock.unlock();
    return this->m_did++;
 }

<commit_msg>sets project id and not just in filehandler on load<commit_after>#include "filehandler.h"

/**
 * @brief FileHandler::FileHandler
 */
FileHandler::FileHandler()
{
    this->m_pid = 0; // zero out counter ids
    this->m_fid = 0;
    this->m_did = 0;
    this->lastError = 0;

}
/**
 * @brief FileHandler::create_project
 * creates project and associated files.
 * @param std::string name
 * @return Project* created project
 */
Project* FileHandler::create_project(std::string projName){
    Project* proj =  new Project(this->m_pid, projName);
    this->m_projects.insert(std::make_pair(proj->m_id, proj));
    save_project(proj);
    this->m_pid++;
    return proj;
}
/**
 * @brief FileHandler::create_directory
 * @param dirpath
 * @return unique directory ID
 */
ID FileHandler::create_directory(std::string dirpath){
    this->lastError = make_dir(dirpath); //varying implementation, OS dependant
    ID id = this->add_dir(dirpath);
    return id;
}

/**
 * @brief FileHandler::delete_directory
 * @param id
 * @return errorcode, if deletion was done code is 0;
 * otherwise see OS relevant directoryfile.
 */
FH_ERROR FileHandler::delete_directory(ID id){
    FH_ERROR err = remove_dir(this->get_dir(id)); //varying implementation, OS dependant
    return err;
}
/**
 * @brief FileHandler::save_project
 * @param id
 */
void FileHandler::save_project(ID id){
    save_project(get_project(id));
}

/**
 * @todo unfinished, needs full project structure
 * and program to file parser to finish
 * @brief FileHandler::save_project
 * @param Project* name
 * Creates project and associated files.
 * @return void
 */
void FileHandler::save_project(Project* proj){
    std::string projFile = proj->m_name + std::string(".txt"); //filename
    if(!proj->saved){
        ID dirID = create_directory(std::string(WORKSPACE) + "/"+ proj->m_name);//project directory

        proj->files->dir = dirID;

        proj->files->f_proj = create_file(projFile, dirID); //create project file

        std::string vidFile = proj->m_name + "_videos.txt";
        proj->files->f_videos = create_file(vidFile, dirID); //create video file

        std::string analysisFile = proj->m_name + "_analyses.txt";
        proj->files->f_analysis = create_file(analysisFile, dirID); //create analysis file

        std::string drawingFile = proj->m_name + "_drawings.txt";
        proj->files->f_drawings =create_file(drawingFile, dirID); //create drawings file
    }
    update_proj_files(proj);

}
/**
 * @todo unfinished, will be released with parser
 * however, is needed for creating
 * @brief FileHandler::save_project
 * @param Project* name
 * Creates project and associated files.
 * @return void
 */
void FileHandler::update_proj_files(Project* proj){
    ProjectStream ps;
    ps << *proj;
    write_file(proj->files->f_proj, ps.projFile.str(), WRITE_OPTION::OVERWRITE);
    write_file(proj->files->f_videos, ps.videos.str(), WRITE_OPTION::OVERWRITE);
    write_file(proj->files->f_analysis, ps.analyzes.str(), WRITE_OPTION::OVERWRITE);
    write_file(proj->files->f_drawings, ps.drawings.str(), WRITE_OPTION::OVERWRITE);
}
void FileHandler::load_proj_files(std::string str){
    ID id;
    std::string filepath;
    std::stringstream sstr;
    sstr << str;
    //read files until empty
    while(sstr >> id >> filepath){
        add_file(id, filepath);
    }
}
/**
 * @brief FileHandler::load_project
 * @param dirpath
 * @return
 */
Project* FileHandler::load_project(std::string fullProjectPath){
    std::string reverse (fullProjectPath.rbegin(), fullProjectPath.rend());
    std::string emaNjorp = reverse.substr(0, reverse.find("/"));
    std::string projName (emaNjorp.rbegin(), emaNjorp.rend());
    std::string dirpath = fullProjectPath.substr(0, fullProjectPath.find("/" + projName));
    projName = projName.substr(0, projName.find(".txt"));
    return load_project(projName, dirpath);
}
/**
 * @todo load analyses (in project <</>> operators)
 * @todo load drawings (in project <</>> operators)
 * @brief FileHandler::load_project
 * @param projname
 * @param dirpath
 * @return project
 */
Project* FileHandler::load_project(std::string projname, std::string dirpath){
    Project* proj = new Project();
    proj->m_id = this->m_pid;
    add_project(std::make_pair(this->m_pid++, proj));

    ProjectStream projStream;

    proj->saved = true;
//    Read project file
    std::string projFilePath = dirpath + "/" + projname + ".txt";
    proj->files->f_proj = load_project_file(projFilePath, projStream.projFile);

//    Read video file
    std::string videoFilePath = dirpath + "/" + projname + "_videos.txt";
    proj->files->f_videos = load_project_file(videoFilePath, projStream.videos);
//    Read Analyzes
    std::string analysesFilePath = dirpath + "/" + projname + "_analyses.txt";
    proj->files->f_analysis = load_project_file(analysesFilePath, projStream.videos);
//    Read Drawings
    std::string drawingsFilePath = dirpath + "/" + projname + "_drawings.txt";
    proj->files->f_drawings = load_project_file(drawingsFilePath, projStream.drawings);
//    Read project from projstream
    projStream >> *proj;
    return proj;
}
ID FileHandler::load_project_file(std::string filePath, std::stringstream& projFileStream){
    std::string buf;
    ID projFileID = add_file(filePath);
    read_file(projFileID, buf);
    projFileStream << buf; // Read project name
    return projFileID;
}

/**
 * @brief FileHandler::delete_project
 * Deletes project, its associated files and contents.
 * OBS! This operation is as of now irreversible
 * @param Project*
 * @return FH_ERROR errorcode
 */
FH_ERROR FileHandler::delete_project(Project* proj){
    ProjFiles* pf = proj->files;
    delete_file(pf->f_proj);
    delete_file(pf->f_videos);
    delete_file(pf->f_analysis);
    delete_file(pf->f_drawings);
    return delete_directory(proj->files->dir);

}
/**
 * @todo make threadsafe
 * @brief FileHandler::add_video
 * @param Project*,string filepath
 *
 * string
 * Add a video filepath to a given project.
 * Creates Video object which is accessed further by returned id.
 */
void FileHandler::add_video(Project* proj, std::string filePath){
    Video* v = new Video(filePath);
    proj->add_video(v);
    this->add_file(filePath);
}

 /**
  * @brief FileHandler::create_file
  * create a file by given name in already excisting
  * application tracked directory
  * @param std::string file name, ID directory id
  */

ID FileHandler::create_file(std::string filename, ID dirID){
    std::ofstream f;
    std::string filePath = this->get_dir(dirID)+"/"+filename;
    f.open(filePath.c_str());
    return this->add_file(filePath);
  }
/**
 * @todo make threadsafe
 * @brief FileHandler::delete_file
 * delete application tracked file
 * @param ID file id
 */
 FH_ERROR FileHandler::delete_file(ID id){
    std::string file = this->get_file(id);
    return std::remove(file.c_str());
 }
 /**
  * @todo make threadsafe
  * @brief FileHandler::write_file
  *  Write given text to an application tracked file
  * @param ID file id, std::string text
  * @return void
  */
 void FileHandler::write_file(ID id, std::string text, WRITE_OPTION opt){
    std::string fileName = this->get_file(id);
    std::ofstream f;
    switch(opt){
    case WRITE_OPTION::OVERWRITE:
        f.open(fileName.c_str(), std::ios::in | std::ios::out);
        break;
    case WRITE_OPTION::APPEND:
        f.open(fileName.c_str(), std::ios::in | std::ios::out | std::ios::ate);
        break;
    default:
        return; // no open file
        break;
    }
    if(f.is_open()) f << text.c_str() << std::endl;
 }

 /**
  * @brief FileHandler::read_file
  *  Read given lenght of lines to buffer from application
  *  tracked file. OBS! If number of lines exceeds =>
  *  reads to end of file (EOF)
  *  @param ID file id, std::string text
  *  @return voi
  */
 void FileHandler::read_file(ID id,  std::string& buf, int linesToRead){
     std::ifstream f(this->get_file(id));
     std::string temp;
     if(f.is_open()){
         while(linesToRead-- && std::getline(f, temp)){
            buf += temp;
         }
     }
 }
 /**
  * @brief FileHandler::get_project
  * Getter
  * @param ID project id
  * @return Project*
  */
 Project* FileHandler::get_project(ID pid){
    this->projMapLock.lock();
    Project* p = this->m_projects.at(pid);
    this->projMapLock.unlock();
    return p;
 }
 /**
  * @brief FileHandler::get_file
  * Getter
  * @param ID project file id
  * @return std::string filepath
  */
 std::string FileHandler::get_file(ID id){
    this->fileMapLock.lock();
    std::string file = this->m_fileMap.at(id);
    this->fileMapLock.unlock();
    return file;
 }
 /**
  * @brief FileHandler::get_dir
  * @param ID directory id
  * @return directory path
  */
 std::string FileHandler::get_dir(ID id){
    this->dirMapLock.lock();
    std::string dir = this->m_dirMap.at(id);
    this->dirMapLock.unlock();
    return dir;
 }

 /**
  * @brief FileHandler::add_projectr
  * @param std::pari<<ID, Project*> pair
  * @return void
  */
 void FileHandler::add_project(std::pair<ID,Project*> pair){
    this->projMapLock.lock();
    this->m_projects.insert(pair);
    this->projMapLock.unlock();

 }
 /**
  * @brief FileHandler::add_file
  * @param std::string filepath
  * @return unique file identifier
  */
ID FileHandler::add_file(std::string filepath){
    add_file(this->m_fid, filepath);
    return this->m_fid++;
 }
/**
 * @brief FileHandler::add_file
 * @param id
 * @param filepath
 */
void FileHandler::add_file(ID id ,std::string filepath){
    std::pair<ID,std::string> pair = std::make_pair(id, filepath);
    this->fileMapLock.lock();
    this->m_fileMap.insert(pair);
    this->fileMapLock.unlock();
}
 /**
  * @brief FileHandler::add_dir
  * @param std::string dirpath
  * @return unique directory identifier
  */
ID FileHandler::add_dir(std::string dirpath){
    std::pair<ID,std::string> pair = std::make_pair(this->m_did, dirpath);
    this->dirMapLock.lock();
    this->m_dirMap.insert(pair);
    this->dirMapLock.unlock();
    return this->m_did++;
 }

<|endoftext|>


<commit_before>// implementation for APPLY

#include <utils/array1d.h>
#include <list>
#include <map>

#include <adaptive/compression.h>

using MathTL::Array1D;

namespace WaveletTL
{
  template <class PROBLEM>
  void APPLY(const PROBLEM& P,
	     const InfiniteVector<double, typename PROBLEM::Index>& v,
	     const double eta,
	     InfiniteVector<double, typename PROBLEM::Index>& w,
	     const int jmax,
	     const CompressionStrategy strategy)
  {
    typedef typename PROBLEM::Index Index;

    w.clear();
    // Binary Binning variant of APPLY from [S],[B]
    // Remark: it is possible to perform binary binning without actually assembling
    // the bins, however, in this first version we do setup the bins to avoid
    // unnecessary difficulties
    if (v.size() > 0) {
      // compute the number of bins V_0,...,V_q
      const double norm_v_sqr = l2_norm_sqr(v);
      const double norm_v = sqrt(norm_v_sqr);
      const double norm_A = P.norm_A();

      const unsigned int q = (unsigned int) std::max(ceil(log(sqrt((double)v.size())*norm_v*norm_A*2/eta)/M_LN2), 0.);

      // Setup the bins: The i-th bin contains the entries of v with modulus in the interval
      // (2^{-(i+1)}||v||,2^{-i}||v||], 0 <= i <= q-1, the remaining elements (with even smaller modulus)
      // are collected in the q-th bin.
      Array1D<std::list<std::pair<Index, double> > > bins(q+1);
      for (typename InfiniteVector<double,Index>::const_iterator it(v.begin());
 	   it != v.end(); ++it) {
 	const unsigned int i = std::min(q, (unsigned int)floor(-log(fabs(*it)/norm_v)/M_LN2));
	bins[i].push_back(std::make_pair(it.index(), *it));
      }
      // glue all the bins together
      Array1D<std::pair<Index, double> > v_binned(v.size());
      for (unsigned int bin = 0, id = 0; bin <= q; bin++)
	for (typename std::list<std::pair<Index, double> >::const_iterator it(bins[bin].begin());
	     it != bins[bin].end(); ++it, ++id)
	  v_binned[id] = *it;

      const double theta = 0.5;

      // setup the segments v_{[0]},...,v_{[\ell]},
      // \ell being the smallest number such that
      //   ||A||*||v-\sum_{k=0}^\ell v_{[k]}|| <= theta * eta
      // i.e.
      //   ||v-\sum_{k=0}^\ell v_{[k]}||^2 <= eta^2 * theta^2 / ||A||^2
      // see [S, (3.9)]
      const double threshold = eta*eta*theta*theta/(norm_A*norm_A);
      unsigned int id = 0, k = 0;
      double error_sqr = norm_v_sqr;
      typename std::list<std::list<std::pair<Index, double> > > vks;
      typename std::list<double> vks_norm;
      while (true) {
	// setup the k-th segment v_{[k]}
	std::list<std::pair<Index, double> > vk;
	double vk_norm_sqr = 0;
	for (unsigned int n = 1; error_sqr > threshold && id < v.size() && n <= ldexp(1.0, k)-floor(ldexp(1.0, k-1)); n++, id++) {
	  vk.push_back(v_binned[id]);
	  const double help = v_binned[id].second * v_binned[id].second;
	  error_sqr -= help;
	  vk_norm_sqr += help;
	}
	vks.push_back(vk);
	vks_norm.push_back(sqrt(vk_norm_sqr));

	if (error_sqr <= threshold || id >= v.size()) break; // in this case, ell=k
	k++;
      }
      const unsigned int ell = k;

      // compute the smallest J >= ell, such that
      //   \sum_{k=0}^{\ell} alpha_{J-k}*2^{-s(J-k)}*||v_{[k]}|| <= (1-theta) * eta
      unsigned int J = ell;
      const double s = P.s_star();
      while (true) {
	double check = 0.0;
	unsigned int k = 0;
	for (std::list<double>::const_iterator it(vks_norm.begin()); k <= ell; ++it, ++k)
	  check += P.alphak(J-k) * pow(ldexp(1.0,J-k),-s) * (*it);
	if (check <= (1-theta)*eta) break;
	J++;
      }

      // compute w = \sum_{k=0}^\ell A_{J-k}v_{[k]}
      k = 0;
      for (typename std::list<std::list<std::pair<Index, double> > >::const_iterator it(vks.begin());
	   k <= ell; ++it, ++k) {
	for (typename std::list<std::pair<Index, double> >::const_iterator itk(it->begin());
	     itk != it->end(); ++itk) {
	  add_compressed_column(P, itk->second, itk->first, J-k, w, jmax, strategy);
	}
      }
    }
  }

  static int its = 0; // DIRTY HACK, REMOVE THIS SOON!!!

  template <class PROBLEM>
  void RES(const PROBLEM& P,
	   const InfiniteVector<double, typename PROBLEM::Index>& w,
	   const double xi,
	   const double delta,
	   const double epsilon,
	   const int jmax,
	   InfiniteVector<double, typename PROBLEM::Index>& tilde_r,
	   double& nu,
	   const CompressionStrategy strategy)
  {
    unsigned int k = 0;
    double zeta = 2.*xi;
    //double zeta = 2.*epsilon;
    double l2n = 0.;

//     its++;

//     if (its > 100) {
//       InfiniteVector<double, typename PROBLEM::Index> help;
//       zeta *= 1.0 / (1 << 9);
//       P.RHS (zeta/2., tilde_r);
//       cout << "zeta half = " << zeta/2. << endl;
//       APPLY_COARSE(P, w, zeta/2., help, 0.00000001, jmax, strategy);
//       tilde_r -= help;
//       l2n = l2_norm(tilde_r);
//       nu = l2n + zeta;
//     }
//    else
//      {
	do {
	  zeta /= 2.;
	  P.RHS (zeta/2., tilde_r);
	  //cout << tilde_r << endl;
	  InfiniteVector<double, typename PROBLEM::Index> help;
	  //cout << w << endl;
	  cout << "zeta halbe = " << zeta/2. << endl;
	  //cout << "before aply in RES " << endl;
	  //APPLY(P, w, zeta/2., help, jmax, strategy);
	  cout << ++k << "calls of APPlY in RES" << endl;
	  APPLY_COARSE(P, w, zeta/2., help, 0.00000001, jmax, strategy);
	  //cout << "after apply in RES " << endl;
	  tilde_r -= help;
	  l2n = l2_norm(tilde_r);
	  nu = l2n + zeta;
	  //cout << "zeta = " << zeta << endl;
	  //cout << delta*l2n << endl;
	  //cout << "delta = " << delta << endl;
	  //if(k == 10)
	  //	break;
	}
 	while ( (nu > epsilon) && (zeta > delta*l2n) );
	//}
  }

}
<commit_msg>commented out unused declaration of "its"<commit_after>// implementation for APPLY

#include <utils/array1d.h>
#include <list>
#include <map>

#include <adaptive/compression.h>

using MathTL::Array1D;

namespace WaveletTL
{
  template <class PROBLEM>
  void APPLY(const PROBLEM& P,
	     const InfiniteVector<double, typename PROBLEM::Index>& v,
	     const double eta,
	     InfiniteVector<double, typename PROBLEM::Index>& w,
	     const int jmax,
	     const CompressionStrategy strategy)
  {
    typedef typename PROBLEM::Index Index;

    w.clear();
    // Binary Binning variant of APPLY from [S],[B]
    // Remark: it is possible to perform binary binning without actually assembling
    // the bins, however, in this first version we do setup the bins to avoid
    // unnecessary difficulties
    if (v.size() > 0) {
      // compute the number of bins V_0,...,V_q
      const double norm_v_sqr = l2_norm_sqr(v);
      const double norm_v = sqrt(norm_v_sqr);
      const double norm_A = P.norm_A();

      const unsigned int q = (unsigned int) std::max(ceil(log(sqrt((double)v.size())*norm_v*norm_A*2/eta)/M_LN2), 0.);

      // Setup the bins: The i-th bin contains the entries of v with modulus in the interval
      // (2^{-(i+1)}||v||,2^{-i}||v||], 0 <= i <= q-1, the remaining elements (with even smaller modulus)
      // are collected in the q-th bin.
      Array1D<std::list<std::pair<Index, double> > > bins(q+1);
      for (typename InfiniteVector<double,Index>::const_iterator it(v.begin());
 	   it != v.end(); ++it) {
 	const unsigned int i = std::min(q, (unsigned int)floor(-log(fabs(*it)/norm_v)/M_LN2));
	bins[i].push_back(std::make_pair(it.index(), *it));
      }
      // glue all the bins together
      Array1D<std::pair<Index, double> > v_binned(v.size());
      for (unsigned int bin = 0, id = 0; bin <= q; bin++)
	for (typename std::list<std::pair<Index, double> >::const_iterator it(bins[bin].begin());
	     it != bins[bin].end(); ++it, ++id)
	  v_binned[id] = *it;

      const double theta = 0.5;

      // setup the segments v_{[0]},...,v_{[\ell]},
      // \ell being the smallest number such that
      //   ||A||*||v-\sum_{k=0}^\ell v_{[k]}|| <= theta * eta
      // i.e.
      //   ||v-\sum_{k=0}^\ell v_{[k]}||^2 <= eta^2 * theta^2 / ||A||^2
      // see [S, (3.9)]
      const double threshold = eta*eta*theta*theta/(norm_A*norm_A);
      unsigned int id = 0, k = 0;
      double error_sqr = norm_v_sqr;
      typename std::list<std::list<std::pair<Index, double> > > vks;
      typename std::list<double> vks_norm;
      while (true) {
	// setup the k-th segment v_{[k]}
	std::list<std::pair<Index, double> > vk;
	double vk_norm_sqr = 0;
	for (unsigned int n = 1; error_sqr > threshold && id < v.size() && n <= ldexp(1.0, k)-floor(ldexp(1.0, k-1)); n++, id++) {
	  vk.push_back(v_binned[id]);
	  const double help = v_binned[id].second * v_binned[id].second;
	  error_sqr -= help;
	  vk_norm_sqr += help;
	}
	vks.push_back(vk);
	vks_norm.push_back(sqrt(vk_norm_sqr));

	if (error_sqr <= threshold || id >= v.size()) break; // in this case, ell=k
	k++;
      }
      const unsigned int ell = k;

      // compute the smallest J >= ell, such that
      //   \sum_{k=0}^{\ell} alpha_{J-k}*2^{-s(J-k)}*||v_{[k]}|| <= (1-theta) * eta
      unsigned int J = ell;
      const double s = P.s_star();
      while (true) {
	double check = 0.0;
	unsigned int k = 0;
	for (std::list<double>::const_iterator it(vks_norm.begin()); k <= ell; ++it, ++k)
	  check += P.alphak(J-k) * pow(ldexp(1.0,J-k),-s) * (*it);
	if (check <= (1-theta)*eta) break;
	J++;
      }

      // compute w = \sum_{k=0}^\ell A_{J-k}v_{[k]}
      k = 0;
      for (typename std::list<std::list<std::pair<Index, double> > >::const_iterator it(vks.begin());
	   k <= ell; ++it, ++k) {
	for (typename std::list<std::pair<Index, double> >::const_iterator itk(it->begin());
	     itk != it->end(); ++itk) {
	  add_compressed_column(P, itk->second, itk->first, J-k, w, jmax, strategy);
	}
      }
    }
  }

//   static int its = 0; // DIRTY HACK, REMOVE THIS SOON!!!

  template <class PROBLEM>
  void RES(const PROBLEM& P,
	   const InfiniteVector<double, typename PROBLEM::Index>& w,
	   const double xi,
	   const double delta,
	   const double epsilon,
	   const int jmax,
	   InfiniteVector<double, typename PROBLEM::Index>& tilde_r,
	   double& nu,
	   const CompressionStrategy strategy)
  {
    unsigned int k = 0;
    double zeta = 2.*xi;
    //double zeta = 2.*epsilon;
    double l2n = 0.;

//     its++;

//     if (its > 100) {
//       InfiniteVector<double, typename PROBLEM::Index> help;
//       zeta *= 1.0 / (1 << 9);
//       P.RHS (zeta/2., tilde_r);
//       cout << "zeta half = " << zeta/2. << endl;
//       APPLY_COARSE(P, w, zeta/2., help, 0.00000001, jmax, strategy);
//       tilde_r -= help;
//       l2n = l2_norm(tilde_r);
//       nu = l2n + zeta;
//     }
//    else
//      {
	do {
	  zeta /= 2.;
	  P.RHS (zeta/2., tilde_r);
	  //cout << tilde_r << endl;
	  InfiniteVector<double, typename PROBLEM::Index> help;
	  //cout << w << endl;
	  cout << "zeta halbe = " << zeta/2. << endl;
	  //cout << "before aply in RES " << endl;
	  //APPLY(P, w, zeta/2., help, jmax, strategy);
	  cout << ++k << "calls of APPlY in RES" << endl;
	  APPLY_COARSE(P, w, zeta/2., help, 0.00000001, jmax, strategy);
	  //cout << "after apply in RES " << endl;
	  tilde_r -= help;
	  l2n = l2_norm(tilde_r);
	  nu = l2n + zeta;
	  //cout << "zeta = " << zeta << endl;
	  //cout << delta*l2n << endl;
	  //cout << "delta = " << delta << endl;
	  //if(k == 10)
	  //	break;
	}
 	while ( (nu > epsilon) && (zeta > delta*l2n) );
	//}
  }

}
<|endoftext|>


<commit_before>#ifndef UCI_H
#define UCI_H

#include <string>
#include "Board.hpp"

using namespace std;

class UCI
{
    private:
        Board currentBoard = Board("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
        int currentColor = 1;
    public:
        bool quit = 0;
        bool waitForInput();
        void outputBestMove(string moveString); //string like e2e4
        void identification();
        bool sentPosition(string input);
        bool startCalculating(string input);
        void sendInfo(string info);
};

#endif // UCI_H
<commit_msg>Documentation<commit_after>#ifndef UCI_H
#define UCI_H

#include <string>
#include "Board.hpp"

using namespace std;

/**
 * @class UCI
 * @brief Handles the UCI communication protocol
 *
 */

class UCI
{
    private:
        Board currentBoard = Board("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"); /**< The board set-up with the position command */
        int currentColor = 1; /**< The player who is next to move. 1 for white, -1 for black */
    public:
        bool quit = 0; /**< A flag to be set to true when the quit command is received */
        /**
		 * @fn WaitForInput
		 * @brief Waits to receive input via stdin
		 * @return bool Returns true if the command is recognised, false if not
		 */
        bool waitForInput();
        /**
		 * @fn outputBestMove
		 * @brief Outputs the best move
		 * @param moveString A string giving the best move in algebraic notation
		 * @return void
		 */
        void outputBestMove(string moveString); //string like e2e4
        /**
		 * @fn identification
		 * @brief Outputs the name of the engine and the authors
		 * @return void
		 */
        void identification();
        /**
		 * @fn sentPosition
		 * @brief Sets up a position in response to the position UCI command
		 * @param input A string containing the input from stdin
		 * @return bool Returns true if the position can be set up and false if not
		 */
        bool sentPosition(string input);
        /**
		 * @fn startCalculating
		 * @brief Starts searching for the best move at the current position
		 * @param input A string containing the input from stdin
		 * @return bool Returns true if the command is valid and false if not
		 */
        bool startCalculating(string input);
        /**
		 * @fn sendInfo
		 * @brief Used for outputting information during calculation
		 * @param info A string containing the information to output
		 * @return void
		 */
        void sendInfo(string info);
};

#endif // UCI_H
<|endoftext|>