<commit_before>/**
 * @file
 */
#pragma once
#if ENABLE_LAZY_DEEP_CLONE

#include "libbirch/LazyAny.hpp"
#include "libbirch/LazyLabel.hpp"
#include "libbirch/Nil.hpp"
#include "libbirch/thread.hpp"

namespace libbirch {
/**
 * Wraps another pointer type to apply lazy deep clone semantics.
 *
 * @ingroup libbirch
 *
 * @tparam P Pointer type.
 */
template<class P>
class LazyPtr {
  template<class U> friend class LazyPtr;
public:
  using pointer_type = P;
  using value_type = typename P::value_type;

  LazyPtr& operator=(const LazyPtr&) = delete;
  LazyPtr& operator=(LazyPtr&&) = delete;

  /**
   * Constructor.
   */
  LazyPtr(const Nil& = nil) :
    object(),
    label(0),
    cross(false) {
    //
  }

  /**
   * Constructor.
   */
  LazyPtr(Label* context, const Nil& = nil) :
      object(),
      label(0),
      cross(false) {
    //
  }

  /**
   * Constructor.
   */
  LazyPtr(Label* context, value_type* object) :
      object(object),
      label(reinterpret_cast<intptr_t>(context)),
      cross(false) {
    //
  }

  /**
   * Constructor.
   */
  LazyPtr(Label* context, const P& object) :
      object(object),
      label(reinterpret_cast<intptr_t>(context)),
      cross(false) {
    //
  }

  /**
   * Copy constructor.
   */
  LazyPtr(const LazyPtr<P>& o) :
      object(o.get()),
      label(o.label),
      cross(o.cross) {
    if (isCross()) {
      getLabel()->incShared();
    }
  }

  /**
   * Copy constructor.
   */
  template<class Q, IS_CONVERTIBLE(Q,P)>
  LazyPtr(const LazyPtr<Q>& o) :
      object(o.get()),
      label(o.label),
      cross(o.cross) {
    if (isCross()) {
      getLabel()->incShared();
    }
  }

  /**
   * Copy constructor.
   */
  LazyPtr(Label* context, const LazyPtr<P>& o) :
      object(o.get()),
      label(0),
      cross(false) {
    if (object) {
      setLabel(o.getLabel(), o.getLabel() != context);
    }
  }

  /**
   * Copy constructor.
   */
  template<class Q, IS_CONVERTIBLE(Q,P)>
  LazyPtr(Label* context, const LazyPtr<Q>& o) :
      object(o.get()),
      label(0),
      cross(false) {
    if (object) {
      setLabel(o.getLabel(), o.getLabel() != context);
    }
  }

  /**
   * Move constructor.
   */
  LazyPtr(LazyPtr<P>&& o) :
      object(std::move(o.object)),
      label(o.label),
      cross(o.cross) {
    o.label = 0;
    o.cross = false;
  }

  /**
   * Move constructor.
   */
  template<class Q, IS_CONVERTIBLE(Q,P)>
  LazyPtr(LazyPtr<Q>&& o) :
      object(std::move(o.object)),
      label(o.label),
      cross(o.cross) {
    o.label = 0;
    o.cross = false;
  }

  /**
   * Move constructor.
   */
  LazyPtr(Label* context, LazyPtr<P>&& o) :
      object(std::move(o.object)),
      label(0),
      cross(false) {
    if (object) {
      setLabel(o.getLabel(), o.getLabel() != context);
    }
  }

  /**
   * Move constructor.
   */
  template<class Q, IS_CONVERTIBLE(Q,P)>
  LazyPtr(Label* context, LazyPtr<Q>&& o) :
      object(std::move(o.object)),
      label(0),
      cross(false) {
    if (object) {
      setLabel(o.getLabel(), o.getLabel() != context);
    }
  }

  /**
   * Deep copy constructor.
   */
  LazyPtr(Label* context, Label* label, const LazyPtr<P>& o) :
      object(),
      label(0),
      cross(false) {
    assert(context == label);
    if (o.object) {
      if (o.isCross()) {
        o.finish();
        o.freeze();
      }
      object = o.object;
      setLabel(label, false);
    }
  }

  /**
   * Destructor.
   */
  ~LazyPtr() {
    releaseLabel();
  }

  /**
   * Copy assignment.
   */
  template<class Q>
  LazyPtr& assign(Label* context, const LazyPtr<Q>& o) {
    object = o.get();
    if (object) {
      replaceLabel(o.getLabel(), o.getLabel() != context);
    } else {
      releaseLabel();
    }
    return *this;
  }

  /**
   * Move assignment.
   */
  template<class Q>
  LazyPtr& assign(Label* context, LazyPtr<Q>&& o) {
    object = std::move(o.get());
    if (object) {
      replaceLabel(o.getLabel(), o.getLabel() != context);
    } else {
      releaseLabel();
    }
    return *this;
  }

  /**
   * Value assignment.
   */
  template<class U, typename = std::enable_if_t<is_value<U>::value>>
  LazyPtr<P>& assign(Label* context, const U& o) {
    *get() = o;
    return *this;
  }

  /**
   * Release the pointer.
   */
  void release() {
    object.release();
    releaseLabel();
  }

  /**
   * Value conversion.
   */
  template<class U, IS_CONVERTIBLE(value_type,U)>
  operator U() const {
    return static_cast<U>(*get());
  }

  /**
   * Is the pointer not null?
   */
  bool query() const {
    return static_cast<bool>(object);
  }

  /**
   * Get the raw pointer, with lazy cloning.
   */
  P& get() {
    auto raw = object.get();
    if (raw && raw->isFrozen()) {
      raw = static_cast<value_type*>(getLabel()->get(raw));
      object.replace(raw);
      assert(object);
    }
    return object;
  }

  /**
   * Get the raw pointer, with lazy cloning.
   */
  auto get() const {
    return const_cast<LazyPtr<P>*>(this)->get();
  }

  /**
   * Get the raw pointer for read-only use, without cloning.
   */
  P& pull() {
    auto raw = object.get();
    if (raw && raw->isFrozen()) {
      raw = static_cast<value_type*>(getLabel()->pull(raw));
      object.replace(raw);
      assert(object);
    }
    return object;
  }

  /**
   * Get the raw pointer for read-only use, without cloning.
   */
  auto pull() const {
    return const_cast<LazyPtr<P>*>(this)->pull();
  }

  /**
   * Start lazy deep clone.
   */
  LazyPtr<P> clone(Label* context) const {
    assert(object);
    pull();
    startFreeze();
    return LazyPtr<P>(context, getLabel()->fork(), object);
  }

  /**
   * Start a freeze operation. This is just like freeze(), but manages thread
   * safety on entry and exit.
   */
  void startFreeze() {
    if (object) {
      freezeLock.enter();
      freeze();
      freezeLock.exit();
    }
  }

  /**
   * Start a freeze operation. This is just like freeze(), but manages thread
   * safety on entry and exit.
   */
  void startFreeze() const {
    return const_cast<LazyPtr<P>*>(this)->startFreeze();
  }

  /**
   * Freeze.
   */
  void freeze() {
    if (object) {
      object->freeze();
      getLabel()->freeze();
    }
  }

  /**
   * Freeze.
   */
  void freeze() const {
    return const_cast<LazyPtr<P>*>(this)->freeze();
  }

  /**
   * Thaw.
   */
  void thaw(LazyLabel* label) {
    if (isCross()) {
      startFinish();
      startFreeze();
    }
    if (object) {
      this->label = reinterpret_cast<intptr_t>(label);
    }
  }

  /**
   * Thaw.
   */
  void thaw(LazyLabel* label) const {
    return const_cast<LazyPtr<P>*>(this)->thaw(label);
  }

  /**
   * Start a finish operation. This is just like finish(), but manages thread
   * safety on entry and exit.
   */
  void startFinish() {
    if (object) {
      finishLock.enter();
      finish();
      finishLock.exit();
    }
  }

  /**
   * Start a freeze operation. This is just like finish(), but manages thread
   * safety on entry and exit.
   */
  void startFinish() const {
    return const_cast<LazyPtr<P>*>(this)->startFinish();
  }

  /**
   * Finish.
   */
  void finish() {
    if (object) {
      get();
      object->finish();
    }
  }

  /**
   * Finish.
   */
  void finish() const {
    return const_cast<LazyPtr<P>*>(this)->finish();
  }

  /**
   * Dereference.
   */
  auto& operator*() const {
    return *get();
  }

  /**
   * Member access.
   */
  auto operator->() const {
    return get();
  }

  /**
   * Equal comparison.
   */
  template<class U>
  bool operator==(const LazyPtr<U>& o) const {
    return get() == o.get();
  }

  /**
   * Not equal comparison.
   */
  template<class U>
  bool operator!=(const LazyPtr<U>& o) const {
    return get() != o.get();
  }

  /**
   * Dynamic cast.
   */
  template<class U>
  auto dynamic_pointer_cast(Label* context) const {
    auto cast = object.template dynamic_pointer_cast<typename U::pointer_type>();
    return LazyPtr<decltype(cast)>(getLabel(), cast);
  }

  /**
   * Static cast.
   */
  template<class U>
  auto static_pointer_cast(Label* context) const {
    auto cast = object.template static_pointer_cast<typename U::pointer_type>();
    return LazyPtr<decltype(cast)>(getLabel(), cast);
  }

private:
  /**
   * Constructor.
   */
  LazyPtr(Label* context, Label* label, const P& object) :
      object(object),
      label(0),
      cross(false) {
    if (object) {
      setLabel(label, label != context);
    }
  }

  /**
   * Get the label.
   */
  Label* getLabel() const {
    return reinterpret_cast<Label*>(this->label);
  }

  /**
   * Is this pointer crossed? A crossed pointer is to a context different to
   * that of the context in which it was created (e.g. the context of the
   * object to which it belongs).
   */
  bool isCross() const {
    return cross;
  }

  /**
   * Set the label.
   */
  void setLabel(Label* label, bool cross) {
    assert(this->label == 0);
    assert(!this->cross);
    this->label = reinterpret_cast<intptr_t>(label);
    this->cross = cross;
    if (label && cross) {
      label->incShared();
    }
  }

  /**
   * Replace the label.
   */
  void replaceLabel(Label* label, bool cross) {
    auto oldLabel = this->getLabel();
    auto oldCross = this->isCross();
    this->label = reinterpret_cast<intptr_t>(label);
    this->cross = cross;
    if (label && cross) {
      label->incShared();
    }
    if (oldLabel && oldCross) {
      oldLabel->decShared();
    }
  }

  /**
   * Release the label.
   */
  void releaseLabel() {
    auto label = getLabel();
    auto cross = isCross();
    if (label && cross) {
      label->decShared();
    }
    this->label = 0;
    this->cross = false;
  }

  /**
   * Object.
   */
  P object;

  /**
   * Raw pointer.
   */
  intptr_t label:63;

  /**
   * Is this pointer crossed? A crossed pointer is to a context different to
   * that of the context in which it was created (e.g. the context of the
   * object to which it belongs).
   */
  bool cross:1;
};
}

#endif
<commit_msg>Fix for casting, requires pull of object.<commit_after>/**
 * @file
 */
#pragma once
#if ENABLE_LAZY_DEEP_CLONE

#include "libbirch/LazyAny.hpp"
#include "libbirch/LazyLabel.hpp"
#include "libbirch/Nil.hpp"
#include "libbirch/thread.hpp"

namespace libbirch {
/**
 * Wraps another pointer type to apply lazy deep clone semantics.
 *
 * @ingroup libbirch
 *
 * @tparam P Pointer type.
 */
template<class P>
class LazyPtr {
  template<class U> friend class LazyPtr;
public:
  using pointer_type = P;
  using value_type = typename P::value_type;

  LazyPtr& operator=(const LazyPtr&) = delete;
  LazyPtr& operator=(LazyPtr&&) = delete;

  /**
   * Constructor.
   */
  LazyPtr(const Nil& = nil) :
      object(),
      label(0),
      cross(false) {
    //
  }

  /**
   * Constructor.
   */
  LazyPtr(Label* context, const Nil& = nil) :
      object(),
      label(0),
      cross(false) {
    //
  }

  /**
   * Constructor.
   */
  LazyPtr(Label* context, value_type* object) :
      object(object),
      label(reinterpret_cast<intptr_t>(context)),
      cross(false) {
    //
  }

  /**
   * Constructor.
   */
  LazyPtr(Label* context, const P& object) :
      object(object),
      label(reinterpret_cast<intptr_t>(context)),
      cross(false) {
    //
  }

  /**
   * Copy constructor.
   */
  LazyPtr(const LazyPtr<P>& o) :
      object(o.get()),
      label(o.label),
      cross(o.cross) {
    if (isCross()) {
      getLabel()->incShared();
    }
  }

  /**
   * Copy constructor.
   */
  template<class Q, IS_CONVERTIBLE(Q,P)>
  LazyPtr(const LazyPtr<Q>& o) :
      object(o.get()),
      label(o.label),
      cross(o.cross) {
    if (isCross()) {
      getLabel()->incShared();
    }
  }

  /**
   * Copy constructor.
   */
  LazyPtr(Label* context, const LazyPtr<P>& o) :
      object(o.get()),
      label(0),
      cross(false) {
    if (object) {
      setLabel(o.getLabel(), o.getLabel() != context);
    }
  }

  /**
   * Copy constructor.
   */
  template<class Q, IS_CONVERTIBLE(Q,P)>
  LazyPtr(Label* context, const LazyPtr<Q>& o) :
      object(o.get()),
      label(0),
      cross(false) {
    if (object) {
      setLabel(o.getLabel(), o.getLabel() != context);
    }
  }

  /**
   * Move constructor.
   */
  LazyPtr(LazyPtr<P>&& o) :
      object(std::move(o.object)),
      label(o.label),
      cross(o.cross) {
    o.label = 0;
    o.cross = false;
  }

  /**
   * Move constructor.
   */
  template<class Q, IS_CONVERTIBLE(Q,P)>
  LazyPtr(LazyPtr<Q>&& o) :
      object(std::move(o.object)),
      label(o.label),
      cross(o.cross) {
    o.label = 0;
    o.cross = false;
  }

  /**
   * Move constructor.
   */
  LazyPtr(Label* context, LazyPtr<P>&& o) :
      object(std::move(o.object)),
      label(0),
      cross(false) {
    if (object) {
      setLabel(o.getLabel(), o.getLabel() != context);
    }
  }

  /**
   * Move constructor.
   */
  template<class Q, IS_CONVERTIBLE(Q,P)>
  LazyPtr(Label* context, LazyPtr<Q>&& o) :
      object(std::move(o.object)),
      label(0),
      cross(false) {
    if (object) {
      setLabel(o.getLabel(), o.getLabel() != context);
    }
  }

  /**
   * Deep copy constructor.
   */
  LazyPtr(Label* context, Label* label, const LazyPtr<P>& o) :
      object(),
      label(0),
      cross(false) {
    assert(context == label);
    if (o.object) {
      if (o.isCross()) {
        o.finish();
        o.freeze();
      }
      object = o.object;
      setLabel(label, false);
    }
  }

  /**
   * Destructor.
   */
  ~LazyPtr() {
    releaseLabel();
  }

  /**
   * Copy assignment.
   */
  template<class Q>
  LazyPtr& assign(Label* context, const LazyPtr<Q>& o) {
    object = o.get();
    if (object) {
      replaceLabel(o.getLabel(), o.getLabel() != context);
    } else {
      releaseLabel();
    }
    return *this;
  }

  /**
   * Move assignment.
   */
  template<class Q>
  LazyPtr& assign(Label* context, LazyPtr<Q>&& o) {
    object = std::move(o.get());
    if (object) {
      replaceLabel(o.getLabel(), o.getLabel() != context);
    } else {
      releaseLabel();
    }
    return *this;
  }

  /**
   * Value assignment.
   */
  template<class U, typename = std::enable_if_t<is_value<U>::value>>
  LazyPtr<P>& assign(Label* context, const U& o) {
    *get() = o;
    return *this;
  }

  /**
   * Release the pointer.
   */
  void release() {
    object.release();
    releaseLabel();
  }

  /**
   * Value conversion.
   */
  template<class U, IS_CONVERTIBLE(value_type,U)>
  operator U() const {
    return static_cast<U>(*get());
  }

  /**
   * Is the pointer not null?
   */
  bool query() const {
    return static_cast<bool>(object);
  }

  /**
   * Get the raw pointer, with lazy cloning.
   */
  P& get() {
    auto raw = object.get();
    if (raw && raw->isFrozen()) {
      raw = static_cast<value_type*>(getLabel()->get(raw));
      object.replace(raw);
      assert(object);
    }
    return object;
  }

  /**
   * Get the raw pointer, with lazy cloning.
   */
  auto get() const {
    return const_cast<LazyPtr<P>*>(this)->get();
  }

  /**
   * Get the raw pointer for read-only use, without cloning.
   */
  P& pull() {
    auto raw = object.get();
    if (raw && raw->isFrozen()) {
      raw = static_cast<value_type*>(getLabel()->pull(raw));
      object.replace(raw);
      assert(object);
    }
    return object;
  }

  /**
   * Get the raw pointer for read-only use, without cloning.
   */
  auto pull() const {
    return const_cast<LazyPtr<P>*>(this)->pull();
  }

  /**
   * Start lazy deep clone.
   */
  LazyPtr<P> clone(Label* context) const {
    assert(object);
    pull();
    startFreeze();
    return LazyPtr<P>(context, getLabel()->fork(), object);
  }

  /**
   * Start a freeze operation. This is just like freeze(), but manages thread
   * safety on entry and exit.
   */
  void startFreeze() {
    if (object) {
      freezeLock.enter();
      freeze();
      freezeLock.exit();
    }
  }

  /**
   * Start a freeze operation. This is just like freeze(), but manages thread
   * safety on entry and exit.
   */
  void startFreeze() const {
    return const_cast<LazyPtr<P>*>(this)->startFreeze();
  }

  /**
   * Freeze.
   */
  void freeze() {
    if (object) {
      object->freeze();
      getLabel()->freeze();
    }
  }

  /**
   * Freeze.
   */
  void freeze() const {
    return const_cast<LazyPtr<P>*>(this)->freeze();
  }

  /**
   * Thaw.
   */
  void thaw(LazyLabel* label) {
    if (isCross()) {
      startFinish();
      startFreeze();
    }
    if (object) {
      this->label = reinterpret_cast<intptr_t>(label);
    }
  }

  /**
   * Thaw.
   */
  void thaw(LazyLabel* label) const {
    return const_cast<LazyPtr<P>*>(this)->thaw(label);
  }

  /**
   * Start a finish operation. This is just like finish(), but manages thread
   * safety on entry and exit.
   */
  void startFinish() {
    if (object) {
      finishLock.enter();
      finish();
      finishLock.exit();
    }
  }

  /**
   * Start a freeze operation. This is just like finish(), but manages thread
   * safety on entry and exit.
   */
  void startFinish() const {
    return const_cast<LazyPtr<P>*>(this)->startFinish();
  }

  /**
   * Finish.
   */
  void finish() {
    if (object) {
      get();
      object->finish();
    }
  }

  /**
   * Finish.
   */
  void finish() const {
    return const_cast<LazyPtr<P>*>(this)->finish();
  }

  /**
   * Dereference.
   */
  auto& operator*() const {
    return *get();
  }

  /**
   * Member access.
   */
  auto operator->() const {
    return get();
  }

  /**
   * Equal comparison.
   */
  template<class U>
  bool operator==(const LazyPtr<U>& o) const {
    return get() == o.get();
  }

  /**
   * Not equal comparison.
   */
  template<class U>
  bool operator!=(const LazyPtr<U>& o) const {
    return get() != o.get();
  }

  /**
   * Dynamic cast.
   */
  template<class U>
  auto dynamic_pointer_cast(Label* context) const {
    auto cast = get().template dynamic_pointer_cast<typename U::pointer_type>();
    return LazyPtr<decltype(cast)>(getLabel(), cast);
  }

  /**
   * Static cast.
   */
  template<class U>
  auto static_pointer_cast(Label* context) const {
    auto cast = get().template static_pointer_cast<typename U::pointer_type>();
    return LazyPtr<decltype(cast)>(getLabel(), cast);
  }

private:
  /**
   * Constructor.
   */
  LazyPtr(Label* context, Label* label, const P& object) :
      object(object),
      label(0),
      cross(false) {
    if (object) {
      setLabel(label, label != context);
    }
  }

  /**
   * Get the label.
   */
  Label* getLabel() const {
    return reinterpret_cast<Label*>(this->label);
  }

  /**
   * Is this pointer crossed? A crossed pointer is to a context different to
   * that of the context in which it was created (e.g. the context of the
   * object to which it belongs).
   */
  bool isCross() const {
    return cross;
  }

  /**
   * Set the label.
   */
  void setLabel(Label* label, bool cross) {
    assert(this->label == 0);
    assert(!this->cross);
    this->label = reinterpret_cast<intptr_t>(label);
    this->cross = cross;
    if (label && cross) {
      label->incShared();
    }
  }

  /**
   * Replace the label.
   */
  void replaceLabel(Label* label, bool cross) {
    auto oldLabel = this->getLabel();
    auto oldCross = this->isCross();
    this->label = reinterpret_cast<intptr_t>(label);
    this->cross = cross;
    if (label && cross) {
      label->incShared();
    }
    if (oldLabel && oldCross) {
      oldLabel->decShared();
    }
  }

  /**
   * Release the label.
   */
  void releaseLabel() {
    auto label = getLabel();
    auto cross = isCross();
    if (label && cross) {
      label->decShared();
    }
    this->label = 0;
    this->cross = false;
  }

  /**
   * Object.
   */
  P object;

  /**
   * Raw pointer.
   */
  intptr_t label:63;

  /**
   * Is this pointer crossed? A crossed pointer is to a context different to
   * that of the context in which it was created (e.g. the context of the
   * object to which it belongs).
   */
  bool cross:1;
};
}

#endif
<|endoftext|>


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

/**
 * @file
 * Declaration of a request, the overall memory request consisting of
 the parts of the request that are persistent throughout the transaction.
 */

#ifndef __MEM_REQUEST_HH__
#define __MEM_REQUEST_HH__

#include <cassert>

#include "base/fast_alloc.hh"
#include "base/flags.hh"
#include "base/misc.hh"
#include "sim/host.hh"
#include "sim/core.hh"

class Request;

typedef Request* RequestPtr;

class Request : public FastAlloc
{
  public:
    typedef uint32_t FlagsType;
    typedef ::Flags<FlagsType> Flags;

    /** ASI information for this request if it exists. */
    static const FlagsType ASI_BITS                    = 0x000000FF;
    /** The request is a Load locked/store conditional. */
    static const FlagsType LLSC                        = 0x00000100;
    /** The virtual address is also the physical address. */
    static const FlagsType PHYSICAL                    = 0x00000200;
    /** The request is an ALPHA VPTE pal access (hw_ld). */
    static const FlagsType VPTE                        = 0x00000400;
    /** Use the alternate mode bits in ALPHA. */
    static const FlagsType ALTMODE                     = 0x00000800;
    /** The request is to an uncacheable address. */
    static const FlagsType UNCACHEABLE                 = 0x00001000;
    /** The request should not cause a page fault. */
    static const FlagsType NO_FAULT                    = 0x00002000;
    /** The request should not cause a memory access. */
    static const FlagsType NO_ACCESS                   = 0x00004000;
    /** This request will lock or unlock the accessed memory. When used with
     * a load, the access locks the particular chunk of memory. When used
     * with a store, it unlocks. The rule is that locked accesses have to be
     * made up of a locked load, some operation on the data, and then a locked
     * store.
     */
    static const FlagsType LOCKED                      = 0x00008000;
    /** The request should be prefetched into the exclusive state. */
    static const FlagsType PF_EXCLUSIVE                = 0x00010000;
    /** The request should be marked as LRU. */
    static const FlagsType EVICT_NEXT                  = 0x00020000;
    /** The request should ignore unaligned access faults */
    static const FlagsType NO_ALIGN_FAULT              = 0x00040000;
    /** The request was an instruction fetch. */
    static const FlagsType INST_FETCH                  = 0x00080000;
    /** This request is for a memory swap. */
    static const FlagsType MEM_SWAP                    = 0x00100000;
    static const FlagsType MEM_SWAP_COND               = 0x00200000;
    /** The request should ignore unaligned access faults */
    static const FlagsType NO_HALF_WORD_ALIGN_FAULT    = 0x00400000;
    /** This request is to a memory mapped register. */
    static const FlagsType MMAPED_IPR                  = 0x00800000;

    /** These flags are *not* cleared when a Request object is reused
       (assigned a new address). */
    static const FlagsType STICKY_FLAGS = INST_FETCH;

  private:
    typedef uint8_t PrivateFlagsType;
    typedef ::Flags<PrivateFlagsType> PrivateFlags;

    /** Whether or not the size is valid. */
    static const PrivateFlagsType VALID_SIZE           = 0x00000001;
    /** Whether or not paddr is valid (has been written yet). */
    static const PrivateFlagsType VALID_PADDR          = 0x00000002;
    /** Whether or not the vaddr & asid are valid. */
    static const PrivateFlagsType VALID_VADDR          = 0x00000004;
    /** Whether or not the pc is valid. */
    static const PrivateFlagsType VALID_PC             = 0x00000010;
    /** Whether or not the context ID is valid. */
    static const PrivateFlagsType VALID_CONTEXT_ID     = 0x00000020;
    static const PrivateFlagsType VALID_THREAD_ID      = 0x00000040;
    /** Whether or not the sc result is valid. */
    static const PrivateFlagsType VALID_EXTRA_DATA     = 0x00000080;

    /** These flags are *not* cleared when a Request object is reused
       (assigned a new address). */
    static const PrivateFlagsType STICKY_PRIVATE_FLAGS =
        VALID_CONTEXT_ID | VALID_THREAD_ID;

  private:
    /**
     * The physical address of the request. Valid only if validPaddr
     * is set.
     */
    Addr paddr;

    /**
     * The size of the request. This field must be set when vaddr or
     * paddr is written via setVirt() or setPhys(), so it is always
     * valid as long as one of the address fields is valid.
     */
    int size;

    /** Flag structure for the request. */
    Flags flags;

    /** Private flags for field validity checking. */
    PrivateFlags privateFlags;

    /**
     * The time this request was started. Used to calculate
     * latencies. This field is set to curTick any time paddr or vaddr
     * is written.
     */
    Tick time;

    /** The address space ID. */
    int asid;

    /** The virtual address of the request. */
    Addr vaddr;

    /**
     * Extra data for the request, such as the return value of
     * store conditional or the compare value for a CAS. */
    uint64_t extraData;

    /** The context ID (for statistics, typically). */
    int _contextId;
    /** The thread ID (id within this CPU) */
    int _threadId;

    /** program counter of initiating access; for tracing/debugging */
    Addr pc;

  public:
    /** Minimal constructor.  No fields are initialized. */
    Request()
    {}

    /**
     * Constructor for physical (e.g. device) requests.  Initializes
     * just physical address, size, flags, and timestamp (to curTick).
     * These fields are adequate to perform a request.
     */
    Request(Addr paddr, int size, Flags flags)
    {
        setPhys(paddr, size, flags);
    }

    Request(int asid, Addr vaddr, int size, Flags flags, Addr pc,
            int cid, int tid)
    {
        setVirt(asid, vaddr, size, flags, pc);
        setThreadContext(cid, tid);
    }

    ~Request() {}  // for FastAlloc

    /**
     * Set up CPU and thread numbers.
     */
    void
    setThreadContext(int context_id, int thread_id)
    {
        _contextId = context_id;
        _threadId = thread_id;
        privateFlags.set(VALID_CONTEXT_ID|VALID_THREAD_ID);
    }

    /**
     * Set up a physical (e.g. device) request in a previously
     * allocated Request object.
     */
    void
    setPhys(Addr _paddr, int _size, Flags _flags)
    {
        assert(_size >= 0);
        paddr = _paddr;
        size = _size;
        time = curTick;

        flags.clear(~STICKY_FLAGS);
        flags.set(_flags);
        privateFlags.clear(~STICKY_PRIVATE_FLAGS);
        privateFlags.set(VALID_PADDR|VALID_SIZE);
    }

    /**
     * Set up a virtual (e.g., CPU) request in a previously
     * allocated Request object.
     */
    void
    setVirt(int _asid, Addr _vaddr, int _size, Flags _flags, Addr _pc)
    {
        assert(_size >= 0);
        asid = _asid;
        vaddr = _vaddr;
        size = _size;
        flags = _flags;
        pc = _pc;
        time = curTick;

        flags.clear(~STICKY_FLAGS);
        flags.set(_flags);
        privateFlags.clear(~STICKY_PRIVATE_FLAGS);
        privateFlags.set(VALID_VADDR|VALID_SIZE|VALID_PC);
    }

    /**
     * Set just the physical address.  This should only be used to
     * record the result of a translation, and thus the vaddr must be
     * valid before this method is called.  Otherwise, use setPhys()
     * to guarantee that the size and flags are also set.
     */
    void
    setPaddr(Addr _paddr)
    {
        assert(privateFlags.isSet(VALID_VADDR));
        paddr = _paddr;
        privateFlags.set(VALID_PADDR);
    }

    /**
     * Generate two requests as if this request had been split into two
     * pieces. The original request can't have been translated already.
     */
    void splitOnVaddr(Addr split_addr, RequestPtr &req1, RequestPtr &req2)
    {
        assert(privateFlags.isSet(VALID_VADDR));
        assert(privateFlags.noneSet(VALID_PADDR));
        assert(split_addr > vaddr && split_addr < vaddr + size);
        req1 = new Request;
        *req1 = *this;
        req2 = new Request;
        *req2 = *this;
        req1->size = split_addr - vaddr;
        req2->vaddr = split_addr;
        req2->size = size - req1->size;
    }

    /**
     * Accessor for paddr.
     */
    bool
    hasPaddr()
    {
        return privateFlags.isSet(VALID_PADDR);
    }

    Addr
    getPaddr()
    {
        assert(privateFlags.isSet(VALID_PADDR));
        return paddr;
    }

    /**
     *  Accessor for size.
     */
    bool
    hasSize()
    {
        return privateFlags.isSet(VALID_SIZE);
    }

    int
    getSize()
    {
        assert(privateFlags.isSet(VALID_SIZE));
        return size;
    }

    /** Accessor for time. */
    Tick
    getTime()
    {
        assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
        return time;
    }

    /** Accessor for flags. */
    Flags
    getFlags()
    {
        assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
        return flags;
    }

    void
    setFlags(Flags _flags)
    {
        assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
        flags.set(_flags);
    }

    /** Accessor function for vaddr.*/
    Addr
    getVaddr()
    {
        assert(privateFlags.isSet(VALID_VADDR));
        return vaddr;
    }

    /** Accessor function for asid.*/
    int
    getAsid()
    {
        assert(privateFlags.isSet(VALID_VADDR));
        return asid;
    }

    /** Accessor function for asi.*/
    uint8_t
    getAsi()
    {
        assert(privateFlags.isSet(VALID_VADDR));
        return flags & ASI_BITS;
    }

    /** Accessor function for MMAPED_IPR flag. */
    bool
    isMmapedIpr()
    {
        assert(privateFlags.isSet(VALID_PADDR));
        return flags.isSet(MMAPED_IPR);
    }

    void
    setMmapedIpr(bool r)
    {
        assert(VALID_VADDR);
        flags.set(MMAPED_IPR);
    }

    /** Accessor function to check if sc result is valid. */
    bool
    extraDataValid()
    {
        return privateFlags.isSet(VALID_EXTRA_DATA);
    }

    /** Accessor function for store conditional return value.*/
    uint64_t
    getExtraData() const
    {
        assert(privateFlags.isSet(VALID_EXTRA_DATA));
        return extraData;
    }

    /** Accessor function for store conditional return value.*/
    void
    setExtraData(uint64_t _extraData)
    {
        extraData = _extraData;
        privateFlags.set(VALID_EXTRA_DATA);
    }

    bool
    hasContextId() const
    {
        return privateFlags.isSet(VALID_CONTEXT_ID);
    }

    /** Accessor function for context ID.*/
    int
    contextId() const
    {
        assert(privateFlags.isSet(VALID_CONTEXT_ID));
        return _contextId;
    }

    /** Accessor function for thread ID. */
    int
    threadId() const
    {
        assert(privateFlags.isSet(VALID_THREAD_ID));
        return _threadId;
    }

    bool
    hasPC() const
    {
        return privateFlags.isSet(VALID_PC);
    }

    /** Accessor function for pc.*/
    Addr
    getPC() const
    {
        assert(privateFlags.isSet(VALID_PC));
        return pc;
    }

    /** Accessor Function to Check Cacheability. */
    bool isUncacheable() const { return flags.isSet(UNCACHEABLE); }
    bool isInstFetch() const { return flags.isSet(INST_FETCH); }
    bool isLLSC() const { return flags.isSet(LLSC); }
    bool isLocked() const { return flags.isSet(LOCKED); }
    bool isSwap() const { return flags.isSet(MEM_SWAP|MEM_SWAP_COND); }
    bool isCondSwap() const { return flags.isSet(MEM_SWAP_COND); }

    bool
    isMisaligned() const
    {
        if (flags.isSet(NO_ALIGN_FAULT))
            return false;

        if ((vaddr & 0x1))
            return true;

        if (flags.isSet(NO_HALF_WORD_ALIGN_FAULT))
            return false;

        if ((vaddr & 0x2))
            return true;

        return false;
    }
};

#endif // __MEM_REQUEST_HH__
<commit_msg>request: add PREFETCH flag.<commit_after>/*
 * Copyright (c) 2002-2005 The Regents of The University of Michigan
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met: redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer;
 * redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution;
 * neither the name of the copyright holders nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Authors: Ron Dreslinski
 *          Steve Reinhardt
 *          Ali Saidi
 */

/**
 * @file
 * Declaration of a request, the overall memory request consisting of
 the parts of the request that are persistent throughout the transaction.
 */

#ifndef __MEM_REQUEST_HH__
#define __MEM_REQUEST_HH__

#include <cassert>

#include "base/fast_alloc.hh"
#include "base/flags.hh"
#include "base/misc.hh"
#include "sim/host.hh"
#include "sim/core.hh"

class Request;

typedef Request* RequestPtr;

class Request : public FastAlloc
{
  public:
    typedef uint32_t FlagsType;
    typedef ::Flags<FlagsType> Flags;

    /** ASI information for this request if it exists. */
    static const FlagsType ASI_BITS                    = 0x000000FF;
    /** The request is a Load locked/store conditional. */
    static const FlagsType LLSC                        = 0x00000100;
    /** The virtual address is also the physical address. */
    static const FlagsType PHYSICAL                    = 0x00000200;
    /** The request is an ALPHA VPTE pal access (hw_ld). */
    static const FlagsType VPTE                        = 0x00000400;
    /** Use the alternate mode bits in ALPHA. */
    static const FlagsType ALTMODE                     = 0x00000800;
    /** The request is to an uncacheable address. */
    static const FlagsType UNCACHEABLE                 = 0x00001000;
    /** The request should not cause a page fault. */
    static const FlagsType NO_FAULT                    = 0x00002000;
    /** The request should not cause a memory access. */
    static const FlagsType NO_ACCESS                   = 0x00004000;
    /** This request will lock or unlock the accessed memory. When used with
     * a load, the access locks the particular chunk of memory. When used
     * with a store, it unlocks. The rule is that locked accesses have to be
     * made up of a locked load, some operation on the data, and then a locked
     * store.
     */
    static const FlagsType LOCKED                      = 0x00008000;
    /** The request should be prefetched into the exclusive state. */
    static const FlagsType PF_EXCLUSIVE                = 0x00010000;
    /** The request should be marked as LRU. */
    static const FlagsType EVICT_NEXT                  = 0x00020000;
    /** The request should ignore unaligned access faults */
    static const FlagsType NO_ALIGN_FAULT              = 0x00040000;
    /** The request was an instruction fetch. */
    static const FlagsType INST_FETCH                  = 0x00080000;
    /** This request is for a memory swap. */
    static const FlagsType MEM_SWAP                    = 0x00100000;
    static const FlagsType MEM_SWAP_COND               = 0x00200000;
    /** The request should ignore unaligned access faults */
    static const FlagsType NO_HALF_WORD_ALIGN_FAULT    = 0x00400000;
    /** This request is to a memory mapped register. */
    static const FlagsType MMAPED_IPR                  = 0x00800000;
    /** The request is a prefetch. */
    static const FlagsType PREFETCH                    = 0x01000000;

    /** These flags are *not* cleared when a Request object is reused
       (assigned a new address). */
    static const FlagsType STICKY_FLAGS = INST_FETCH;

  private:
    typedef uint8_t PrivateFlagsType;
    typedef ::Flags<PrivateFlagsType> PrivateFlags;

    /** Whether or not the size is valid. */
    static const PrivateFlagsType VALID_SIZE           = 0x00000001;
    /** Whether or not paddr is valid (has been written yet). */
    static const PrivateFlagsType VALID_PADDR          = 0x00000002;
    /** Whether or not the vaddr & asid are valid. */
    static const PrivateFlagsType VALID_VADDR          = 0x00000004;
    /** Whether or not the pc is valid. */
    static const PrivateFlagsType VALID_PC             = 0x00000010;
    /** Whether or not the context ID is valid. */
    static const PrivateFlagsType VALID_CONTEXT_ID     = 0x00000020;
    static const PrivateFlagsType VALID_THREAD_ID      = 0x00000040;
    /** Whether or not the sc result is valid. */
    static const PrivateFlagsType VALID_EXTRA_DATA     = 0x00000080;

    /** These flags are *not* cleared when a Request object is reused
       (assigned a new address). */
    static const PrivateFlagsType STICKY_PRIVATE_FLAGS =
        VALID_CONTEXT_ID | VALID_THREAD_ID;

  private:
    /**
     * The physical address of the request. Valid only if validPaddr
     * is set.
     */
    Addr paddr;

    /**
     * The size of the request. This field must be set when vaddr or
     * paddr is written via setVirt() or setPhys(), so it is always
     * valid as long as one of the address fields is valid.
     */
    int size;

    /** Flag structure for the request. */
    Flags flags;

    /** Private flags for field validity checking. */
    PrivateFlags privateFlags;

    /**
     * The time this request was started. Used to calculate
     * latencies. This field is set to curTick any time paddr or vaddr
     * is written.
     */
    Tick time;

    /** The address space ID. */
    int asid;

    /** The virtual address of the request. */
    Addr vaddr;

    /**
     * Extra data for the request, such as the return value of
     * store conditional or the compare value for a CAS. */
    uint64_t extraData;

    /** The context ID (for statistics, typically). */
    int _contextId;
    /** The thread ID (id within this CPU) */
    int _threadId;

    /** program counter of initiating access; for tracing/debugging */
    Addr pc;

  public:
    /** Minimal constructor.  No fields are initialized. */
    Request()
    {}

    /**
     * Constructor for physical (e.g. device) requests.  Initializes
     * just physical address, size, flags, and timestamp (to curTick).
     * These fields are adequate to perform a request.
     */
    Request(Addr paddr, int size, Flags flags)
    {
        setPhys(paddr, size, flags);
    }

    Request(int asid, Addr vaddr, int size, Flags flags, Addr pc,
            int cid, int tid)
    {
        setVirt(asid, vaddr, size, flags, pc);
        setThreadContext(cid, tid);
    }

    ~Request() {}  // for FastAlloc

    /**
     * Set up CPU and thread numbers.
     */
    void
    setThreadContext(int context_id, int thread_id)
    {
        _contextId = context_id;
        _threadId = thread_id;
        privateFlags.set(VALID_CONTEXT_ID|VALID_THREAD_ID);
    }

    /**
     * Set up a physical (e.g. device) request in a previously
     * allocated Request object.
     */
    void
    setPhys(Addr _paddr, int _size, Flags _flags)
    {
        assert(_size >= 0);
        paddr = _paddr;
        size = _size;
        time = curTick;

        flags.clear(~STICKY_FLAGS);
        flags.set(_flags);
        privateFlags.clear(~STICKY_PRIVATE_FLAGS);
        privateFlags.set(VALID_PADDR|VALID_SIZE);
    }

    /**
     * Set up a virtual (e.g., CPU) request in a previously
     * allocated Request object.
     */
    void
    setVirt(int _asid, Addr _vaddr, int _size, Flags _flags, Addr _pc)
    {
        assert(_size >= 0);
        asid = _asid;
        vaddr = _vaddr;
        size = _size;
        flags = _flags;
        pc = _pc;
        time = curTick;

        flags.clear(~STICKY_FLAGS);
        flags.set(_flags);
        privateFlags.clear(~STICKY_PRIVATE_FLAGS);
        privateFlags.set(VALID_VADDR|VALID_SIZE|VALID_PC);
    }

    /**
     * Set just the physical address.  This should only be used to
     * record the result of a translation, and thus the vaddr must be
     * valid before this method is called.  Otherwise, use setPhys()
     * to guarantee that the size and flags are also set.
     */
    void
    setPaddr(Addr _paddr)
    {
        assert(privateFlags.isSet(VALID_VADDR));
        paddr = _paddr;
        privateFlags.set(VALID_PADDR);
    }

    /**
     * Generate two requests as if this request had been split into two
     * pieces. The original request can't have been translated already.
     */
    void splitOnVaddr(Addr split_addr, RequestPtr &req1, RequestPtr &req2)
    {
        assert(privateFlags.isSet(VALID_VADDR));
        assert(privateFlags.noneSet(VALID_PADDR));
        assert(split_addr > vaddr && split_addr < vaddr + size);
        req1 = new Request;
        *req1 = *this;
        req2 = new Request;
        *req2 = *this;
        req1->size = split_addr - vaddr;
        req2->vaddr = split_addr;
        req2->size = size - req1->size;
    }

    /**
     * Accessor for paddr.
     */
    bool
    hasPaddr()
    {
        return privateFlags.isSet(VALID_PADDR);
    }

    Addr
    getPaddr()
    {
        assert(privateFlags.isSet(VALID_PADDR));
        return paddr;
    }

    /**
     *  Accessor for size.
     */
    bool
    hasSize()
    {
        return privateFlags.isSet(VALID_SIZE);
    }

    int
    getSize()
    {
        assert(privateFlags.isSet(VALID_SIZE));
        return size;
    }

    /** Accessor for time. */
    Tick
    getTime()
    {
        assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
        return time;
    }

    /** Accessor for flags. */
    Flags
    getFlags()
    {
        assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
        return flags;
    }

    void
    setFlags(Flags _flags)
    {
        assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
        flags.set(_flags);
    }

    /** Accessor function for vaddr.*/
    Addr
    getVaddr()
    {
        assert(privateFlags.isSet(VALID_VADDR));
        return vaddr;
    }

    /** Accessor function for asid.*/
    int
    getAsid()
    {
        assert(privateFlags.isSet(VALID_VADDR));
        return asid;
    }

    /** Accessor function for asi.*/
    uint8_t
    getAsi()
    {
        assert(privateFlags.isSet(VALID_VADDR));
        return flags & ASI_BITS;
    }

    /** Accessor function for MMAPED_IPR flag. */
    bool
    isMmapedIpr()
    {
        assert(privateFlags.isSet(VALID_PADDR));
        return flags.isSet(MMAPED_IPR);
    }

    void
    setMmapedIpr(bool r)
    {
        assert(VALID_VADDR);
        flags.set(MMAPED_IPR);
    }

    /** Accessor function to check if sc result is valid. */
    bool
    extraDataValid()
    {
        return privateFlags.isSet(VALID_EXTRA_DATA);
    }

    /** Accessor function for store conditional return value.*/
    uint64_t
    getExtraData() const
    {
        assert(privateFlags.isSet(VALID_EXTRA_DATA));
        return extraData;
    }

    /** Accessor function for store conditional return value.*/
    void
    setExtraData(uint64_t _extraData)
    {
        extraData = _extraData;
        privateFlags.set(VALID_EXTRA_DATA);
    }

    bool
    hasContextId() const
    {
        return privateFlags.isSet(VALID_CONTEXT_ID);
    }

    /** Accessor function for context ID.*/
    int
    contextId() const
    {
        assert(privateFlags.isSet(VALID_CONTEXT_ID));
        return _contextId;
    }

    /** Accessor function for thread ID. */
    int
    threadId() const
    {
        assert(privateFlags.isSet(VALID_THREAD_ID));
        return _threadId;
    }

    bool
    hasPC() const
    {
        return privateFlags.isSet(VALID_PC);
    }

    /** Accessor function for pc.*/
    Addr
    getPC() const
    {
        assert(privateFlags.isSet(VALID_PC));
        return pc;
    }

    /** Accessor Function to Check Cacheability. */
    bool isUncacheable() const { return flags.isSet(UNCACHEABLE); }
    bool isInstFetch() const { return flags.isSet(INST_FETCH); }
    bool isPrefetch() const { return flags.isSet(PREFETCH); }
    bool isLLSC() const { return flags.isSet(LLSC); }
    bool isLocked() const { return flags.isSet(LOCKED); }
    bool isSwap() const { return flags.isSet(MEM_SWAP|MEM_SWAP_COND); }
    bool isCondSwap() const { return flags.isSet(MEM_SWAP_COND); }

    bool
    isMisaligned() const
    {
        if (flags.isSet(NO_ALIGN_FAULT))
            return false;

        if ((vaddr & 0x1))
            return true;

        if (flags.isSet(NO_HALF_WORD_ALIGN_FAULT))
            return false;

        if ((vaddr & 0x2))
            return true;

        return false;
    }
};

#endif // __MEM_REQUEST_HH__
<|endoftext|>


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

#include "git_command.h"

int GitCommand::parseFileSystem(pp::VarDictionary message, std::string name,
    pp::FileSystem& system) {
  pp::Var var_filesystem = message.Get(name);

  if (!var_filesystem.is_resource()) {
    //TODO(grv): return error code;
     return 1;
  }

  pp::Resource resource_filesystem = var_filesystem.AsResource();
  fileSystem = pp::FileSystem(resource_filesystem);
  return 0;
}

int GitCommand::parseArgs() {

  int error = 0;

  if ((error = parseFileSystem(_args, kFileSystem, fileSystem))) {

  }

  if ((error = parseString(_args, kFullPath,  fullPath))) {

  }

  if ((error = parseString(_args, kUrl,  url))) {

  }
  return 0;
}

int GitClone::runCommand() {
  // mount the folder as a filesystem.
  ChromefsInit();

  git_threads_init();

  std::string message = "clone successful";

  if (!url.length()) {
    git_repository_open(&repo, "/chromefs");
    message = "repository load successful";
  } else {
    git_clone(&repo, url.c_str(), "/chromefs", NULL);
  }

  const git_error *a = giterr_last();

  if (a != NULL) {
    printf("giterror: %s\n", a->message);
  }

  pp::VarDictionary arg;
  arg.Set(kMessage, message);

  pp::VarDictionary response;
  response.Set(kRegarding, subject);
  response.Set(kArg, arg);
  response.Set(kName, kResult);

  _gitSalt->PostMessage(response);
  return 0;
}

void GitClone::ChromefsInit() {
  int32_t r = (int32_t) fileSystem.pp_resource();
  char fs_resource[100] = "filesystem_resource=";
  sprintf(&fs_resource[20], "%d", r);
  mount(fullPath.c_str(),                     /* source */
      "/chromefs",                            /* target */
      "html5fs",                              /* filesystemtype */
      0,                                      /* mountflags */
      fs_resource);                           /* data */
}

int GitCommit::runCommand() {
  //TODO(grv): implement.
  char message[100];
  sprintf(message, "%s", subject.c_str());
  _gitSalt->PostMessage(pp::Var(message));
  printf("GitCommit: to be implemented");
  return 0;
}

int GitCurrentBranch::parseArgs() {
  return 0;
}

int GitCurrentBranch::runCommand() {

  git_reference* ref = NULL;
  char buf[100] = "(head detached)";
  char *branch = buf;
  int x = git_repository_head(&ref, repo);
  if (x == 0) {
    git_branch_name((const char**)&branch, ref);
  }

  const git_error *a = giterr_last();

  if (a != NULL) {
    printf("giterror: %s\n", a->message);
  }

  pp::VarDictionary arg;
  arg.Set(kBranch, branch);

  pp::VarDictionary response;
  response.Set(kRegarding, subject);
  response.Set(kArg, arg);
  response.Set(kName, kResult);

  _gitSalt->PostMessage(response);
  git_reference_free(ref);
  return 0;
}
<commit_msg>remove unused buffer.<commit_after>// Copyright (c) 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "git_command.h"

int GitCommand::parseFileSystem(pp::VarDictionary message, std::string name,
    pp::FileSystem& system) {
  pp::Var var_filesystem = message.Get(name);

  if (!var_filesystem.is_resource()) {
    //TODO(grv): return error code;
     return 1;
  }

  pp::Resource resource_filesystem = var_filesystem.AsResource();
  fileSystem = pp::FileSystem(resource_filesystem);
  return 0;
}

int GitCommand::parseArgs() {

  int error = 0;

  if ((error = parseFileSystem(_args, kFileSystem, fileSystem))) {

  }

  if ((error = parseString(_args, kFullPath,  fullPath))) {

  }

  if ((error = parseString(_args, kUrl,  url))) {

  }
  return 0;
}

int GitClone::runCommand() {
  // mount the folder as a filesystem.
  ChromefsInit();

  git_threads_init();

  std::string message = "clone successful";

  if (!url.length()) {
    git_repository_open(&repo, "/chromefs");
    message = "repository load successful";
  } else {
    git_clone(&repo, url.c_str(), "/chromefs", NULL);
  }

  const git_error *a = giterr_last();

  if (a != NULL) {
    printf("giterror: %s\n", a->message);
  }

  pp::VarDictionary arg;
  arg.Set(kMessage, message);

  pp::VarDictionary response;
  response.Set(kRegarding, subject);
  response.Set(kArg, arg);
  response.Set(kName, kResult);

  _gitSalt->PostMessage(response);
  return 0;
}

void GitClone::ChromefsInit() {
  int32_t r = (int32_t) fileSystem.pp_resource();
  char fs_resource[100] = "filesystem_resource=";
  sprintf(&fs_resource[20], "%d", r);
  mount(fullPath.c_str(),                     /* source */
      "/chromefs",                            /* target */
      "html5fs",                              /* filesystemtype */
      0,                                      /* mountflags */
      fs_resource);                           /* data */
}

int GitCommit::runCommand() {
  //TODO(grv): implement.
  char message[100];
  sprintf(message, "%s", subject.c_str());
  _gitSalt->PostMessage(pp::Var(message));
  printf("GitCommit: to be implemented");
  return 0;
}

int GitCurrentBranch::parseArgs() {
  return 0;
}

int GitCurrentBranch::runCommand() {

  git_reference* ref = NULL;
  char *branch = NULL;
  int r= git_repository_head(&ref, repo);
  if (r == 0) {
    git_branch_name((const char**)&branch, ref);
  }

  const git_error *a = giterr_last();

  if (a != NULL) {
    printf("giterror: %s\n", a->message);
  }

  pp::VarDictionary arg;
  arg.Set(kBranch, branch);

  pp::VarDictionary response;
  response.Set(kRegarding, subject);
  response.Set(kArg, arg);
  response.Set(kName, kResult);

  _gitSalt->PostMessage(response);
  git_reference_free(ref);
  return 0;
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: unoforou.cxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: cl $ $Date: 2001-08-08 11:08:14 $
 *
 *  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): _______________________________________
 *
 *
 ************************************************************************/

#pragma hdrstop

#ifndef _SFXSTYLE_HXX
#include <svtools/style.hxx>
#endif

#include <svtools/itemset.hxx>
#include <editeng.hxx>
#include <outliner.hxx>

#ifndef _SFXPOOLITEM_HXX
#include <svtools/poolitem.hxx>
#endif

#ifndef _SV_WRKWIN_HXX //autogen
#include <vcl/wrkwin.hxx>
#endif

#ifndef _EEITEM_HXX //autogen
#include "eeitem.hxx"
#endif

#include "unoforou.hxx"
#include "unofored.hxx"

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

SvxOutlinerForwarder::SvxOutlinerForwarder( Outliner& rOutl ) :
    rOutliner( rOutl )
{
}

SvxOutlinerForwarder::~SvxOutlinerForwarder()
{
    //  der Outliner muss ggf. von aussen geloescht werden
}

USHORT SvxOutlinerForwarder::GetParagraphCount() const
{
    return (USHORT)rOutliner.GetParagraphCount();
}

USHORT SvxOutlinerForwarder::GetTextLen( USHORT nParagraph ) const
{
    return rOutliner.GetEditEngine().GetTextLen( nParagraph );
}

String SvxOutlinerForwarder::GetText( const ESelection& rSel ) const
{
    //! GetText(ESelection) sollte es wohl auch mal am Outliner geben
    //  solange den Hack fuer die EditEngine uebernehmen:
    EditEngine* pEditEngine = (EditEngine*)&rOutliner.GetEditEngine();
    return pEditEngine->GetText( rSel, LINEEND_LF );
}

SfxItemSet SvxOutlinerForwarder::GetAttribs( const ESelection& rSel, BOOL bOnlyHardAttrib ) const
{
    //! gibt's das nicht am Outliner ???
    //! und warum ist GetAttribs an der EditEngine nicht const?
    EditEngine& rEditEngine = (EditEngine&)rOutliner.GetEditEngine();

    SfxItemSet aSet( rEditEngine.GetAttribs( rSel, bOnlyHardAttrib ) );

    SfxStyleSheet* pStyle = rEditEngine.GetStyleSheet( rSel.nStartPara );
    if( pStyle )
        aSet.SetParent( &(pStyle->GetItemSet() ) );

    return aSet;
}

SfxItemSet SvxOutlinerForwarder::GetParaAttribs( USHORT nPara ) const
{
    SfxItemSet aSet( rOutliner.GetParaAttribs( nPara ) );

    EditEngine& rEditEngine = (EditEngine&)rOutliner.GetEditEngine();

    USHORT nWhich = EE_PARA_START;
    while( nWhich <= EE_PARA_END )
    {
        if( aSet.GetItemState( nWhich, TRUE ) != SFX_ITEM_ON )
        {
            if( rEditEngine.HasParaAttrib( nPara, nWhich ) )
                aSet.Put( rEditEngine.GetParaAttrib( nPara, nWhich ) );
        }
        nWhich++;
    }

    SfxStyleSheet* pStyle = rEditEngine.GetStyleSheet( nPara );
    if( pStyle )
        aSet.SetParent( &(pStyle->GetItemSet() ) );

    return aSet;
}

void SvxOutlinerForwarder::SetParaAttribs( USHORT nPara, const SfxItemSet& rSet )
{
    rOutliner.SetParaAttribs( nPara, rSet );
}

SfxItemPool* SvxOutlinerForwarder::GetPool() const
{
    return rOutliner.GetEmptyItemSet().GetPool();
}

void SvxOutlinerForwarder::GetPortions( USHORT nPara, SvUShorts& rList ) const
{
    ((EditEngine&)rOutliner.GetEditEngine()).GetPortions( nPara, rList );
}

void SvxOutlinerForwarder::QuickInsertText( const String& rText, const ESelection& rSel )
{
    if( rText.Len() == 0 )
    {
        rOutliner.QuickDelete( rSel );
    }
    else
    {
        rOutliner.QuickInsertText( rText, rSel );
    }
}

void SvxOutlinerForwarder::QuickInsertLineBreak( const ESelection& rSel )
{
    rOutliner.QuickInsertLineBreak( rSel );
}

void SvxOutlinerForwarder::QuickInsertField( const SvxFieldItem& rFld, const ESelection& rSel )
{
    rOutliner.QuickInsertField( rFld, rSel );
}

void SvxOutlinerForwarder::QuickSetAttribs( const SfxItemSet& rSet, const ESelection& rSel )
{
    rOutliner.QuickSetAttribs( rSet, rSel );
}

XubString SvxOutlinerForwarder::CalcFieldValue( const SvxFieldItem& rField, USHORT nPara, USHORT nPos, Color*& rpTxtColor, Color*& rpFldColor )
{
    return rOutliner.CalcFieldValue( rField, nPara, nPos, rpTxtColor, rpFldColor );
}

extern USHORT GetSvxEditEngineItemState( EditEngine& rEditEngine, const ESelection& rSel, USHORT nWhich );

USHORT SvxOutlinerForwarder::GetItemState( const ESelection& rSel, USHORT nWhich ) const
{
    return GetSvxEditEngineItemState( (EditEngine&)rOutliner.GetEditEngine(), rSel, nWhich );
}

USHORT SvxOutlinerForwarder::GetItemState( USHORT nPara, USHORT nWhich ) const
{
    const SfxItemSet& rSet = rOutliner.GetParaAttribs( nPara );
    return rSet.GetItemState( nWhich );
}

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

<commit_msg>#90884# remove parent of itemset before setting para attribs<commit_after>/*************************************************************************
 *
 *  $RCSfile: unoforou.cxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: cl $ $Date: 2001-08-22 14:30:53 $
 *
 *  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): _______________________________________
 *
 *
 ************************************************************************/

#pragma hdrstop

#ifndef _SFXSTYLE_HXX
#include <svtools/style.hxx>
#endif

#include <svtools/itemset.hxx>
#include <editeng.hxx>
#include <outliner.hxx>

#ifndef _SFXPOOLITEM_HXX
#include <svtools/poolitem.hxx>
#endif

#ifndef _SV_WRKWIN_HXX //autogen
#include <vcl/wrkwin.hxx>
#endif

#ifndef _EEITEM_HXX //autogen
#include "eeitem.hxx"
#endif

#include "unoforou.hxx"
#include "unofored.hxx"

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

SvxOutlinerForwarder::SvxOutlinerForwarder( Outliner& rOutl ) :
    rOutliner( rOutl )
{
}

SvxOutlinerForwarder::~SvxOutlinerForwarder()
{
    //  der Outliner muss ggf. von aussen geloescht werden
}

USHORT SvxOutlinerForwarder::GetParagraphCount() const
{
    return (USHORT)rOutliner.GetParagraphCount();
}

USHORT SvxOutlinerForwarder::GetTextLen( USHORT nParagraph ) const
{
    return rOutliner.GetEditEngine().GetTextLen( nParagraph );
}

String SvxOutlinerForwarder::GetText( const ESelection& rSel ) const
{
    //! GetText(ESelection) sollte es wohl auch mal am Outliner geben
    //  solange den Hack fuer die EditEngine uebernehmen:
    EditEngine* pEditEngine = (EditEngine*)&rOutliner.GetEditEngine();
    return pEditEngine->GetText( rSel, LINEEND_LF );
}

SfxItemSet SvxOutlinerForwarder::GetAttribs( const ESelection& rSel, BOOL bOnlyHardAttrib ) const
{
    //! gibt's das nicht am Outliner ???
    //! und warum ist GetAttribs an der EditEngine nicht const?
    EditEngine& rEditEngine = (EditEngine&)rOutliner.GetEditEngine();

    SfxItemSet aSet( rEditEngine.GetAttribs( rSel, bOnlyHardAttrib ) );

    SfxStyleSheet* pStyle = rEditEngine.GetStyleSheet( rSel.nStartPara );
    if( pStyle )
        aSet.SetParent( &(pStyle->GetItemSet() ) );

    return aSet;
}

SfxItemSet SvxOutlinerForwarder::GetParaAttribs( USHORT nPara ) const
{
    SfxItemSet aSet( rOutliner.GetParaAttribs( nPara ) );

    EditEngine& rEditEngine = (EditEngine&)rOutliner.GetEditEngine();

    SfxStyleSheet* pStyle = rEditEngine.GetStyleSheet( nPara );
    if( pStyle )
        aSet.SetParent( &(pStyle->GetItemSet() ) );

    return aSet;
}

void SvxOutlinerForwarder::SetParaAttribs( USHORT nPara, const SfxItemSet& rSet )
{
    const SfxItemSet* pOldParent = rSet.GetParent();
    if( pOldParent )
        ((SfxItemSet*)&rSet)->SetParent( NULL );

    rOutliner.SetParaAttribs( nPara, rSet );

    if( pOldParent )
        ((SfxItemSet*)&rSet)->SetParent( pOldParent );
}

SfxItemPool* SvxOutlinerForwarder::GetPool() const
{
    return rOutliner.GetEmptyItemSet().GetPool();
}

void SvxOutlinerForwarder::GetPortions( USHORT nPara, SvUShorts& rList ) const
{
    ((EditEngine&)rOutliner.GetEditEngine()).GetPortions( nPara, rList );
}

void SvxOutlinerForwarder::QuickInsertText( const String& rText, const ESelection& rSel )
{
    if( rText.Len() == 0 )
    {
        rOutliner.QuickDelete( rSel );
    }
    else
    {
        rOutliner.QuickInsertText( rText, rSel );
    }
}

void SvxOutlinerForwarder::QuickInsertLineBreak( const ESelection& rSel )
{
    rOutliner.QuickInsertLineBreak( rSel );
}

void SvxOutlinerForwarder::QuickInsertField( const SvxFieldItem& rFld, const ESelection& rSel )
{
    rOutliner.QuickInsertField( rFld, rSel );
}

void SvxOutlinerForwarder::QuickSetAttribs( const SfxItemSet& rSet, const ESelection& rSel )
{
    rOutliner.QuickSetAttribs( rSet, rSel );
}

XubString SvxOutlinerForwarder::CalcFieldValue( const SvxFieldItem& rField, USHORT nPara, USHORT nPos, Color*& rpTxtColor, Color*& rpFldColor )
{
    return rOutliner.CalcFieldValue( rField, nPara, nPos, rpTxtColor, rpFldColor );
}

extern USHORT GetSvxEditEngineItemState( EditEngine& rEditEngine, const ESelection& rSel, USHORT nWhich );

USHORT SvxOutlinerForwarder::GetItemState( const ESelection& rSel, USHORT nWhich ) const
{
    return GetSvxEditEngineItemState( (EditEngine&)rOutliner.GetEditEngine(), rSel, nWhich );
}

USHORT SvxOutlinerForwarder::GetItemState( USHORT nPara, USHORT nWhich ) const
{
    const SfxItemSet& rSet = rOutliner.GetParaAttribs( nPara );
    return rSet.GetItemState( nWhich );
}

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

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: bookmrk.cxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-09 03:02:22 $
 *
 *  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
 *
 ************************************************************************/

#pragma hdrstop

#ifndef _SWTYPES_HXX
#include <swtypes.hxx>
#endif
#ifndef _DOC_HXX
#include <doc.hxx>
#endif
#ifndef _PAM_HXX
#include <pam.hxx>
#endif
#ifndef _BOOKMRK_HXX
#include <bookmrk.hxx>
#endif
#ifndef _SWSERV_HXX
#include <swserv.hxx>
#endif

#ifndef _ERRHDL_HXX //autogen
#include <errhdl.hxx>
#endif

SV_IMPL_REF( SwServerObject )

TYPEINIT1( SwBookmark, SwModify );  //rtti

SwBookmark::SwBookmark(const SwPosition& aPos)
    : SwModify( 0 ),
    pPos2( 0 ),
    aStartMacro( aEmptyStr, aEmptyStr ),
    aEndMacro  ( aEmptyStr, aEmptyStr ),
    eMarkType( BOOKMARK )
{
    pPos1 = new SwPosition( aPos );
}

SwBookmark::SwBookmark(const SwPosition& aPos, const KeyCode& rCode,
                        const String& rName, const String& rShortName )
    : SwModify( 0 ),
    pPos2( 0 ),
    aStartMacro( aEmptyStr, aEmptyStr ),
    aEndMacro  ( aEmptyStr, aEmptyStr ),
    aName(rName),
    aShortName(rShortName),
    aCode(rCode),
    eMarkType( BOOKMARK )
{
    pPos1 = new SwPosition(aPos);
}

// Beim Loeschen von Text werden Bookmarks mitgeloescht!

SwBookmark::~SwBookmark()
{
    // falls wir noch der DDE-Bookmark sind, dann muss der aus dem
    // Clipboard ausgetragen werden. Wird automatisch ueber DataChanged
    // ausgeloest.
    if( refObj.Is() )
    {
        if( DDE_BOOKMARK == eMarkType && refObj->HasDataLinks() )
        {
            ::sfx2::SvLinkSource* p = &refObj;
            p->SendDataChanged();
        }
        refObj->SetNoServer();
    }

    delete pPos1;
    if( pPos2 )
        delete pPos2;
}

// Vergleiche auf Basis der Dokumentposition

BOOL SwBookmark::operator<(const SwBookmark &rBM) const
{
    const SwPosition* pThisPos = ( !pPos2 || *pPos1 <= *pPos2 ) ? pPos1 : pPos2;
    const SwPosition* pBMPos = ( !rBM.pPos2 || *rBM.pPos1 <= *rBM.pPos2 )
                                        ? rBM.pPos1 : rBM.pPos2;

    return *pThisPos < *pBMPos;
}

BOOL SwBookmark::operator==(const SwBookmark &rBM) const
{
    return (this == &rBM);
}

BOOL SwBookmark::IsEqualPos( const SwBookmark &rBM ) const
{
    const SwPosition* pThisPos = ( !pPos2 || *pPos1 <= *pPos2 ) ? pPos1 : pPos2;
    const SwPosition* pBMPos = ( !rBM.pPos2 || *rBM.pPos1 <= *rBM.pPos2 )
                                        ? rBM.pPos1 : rBM.pPos2;

    return *pThisPos == *pBMPos;
}

void SwBookmark::SetRefObject( SwServerObject* pObj )
{
    refObj = pObj;
}

SwMark::SwMark( const SwPosition& aPos,
                const KeyCode& rCode,
                const String& rName,
                const String& rShortName )
    : SwBookmark( aPos, rCode, rName, rShortName )
{
    eMarkType = MARK;
}

SwUNOMark::SwUNOMark( const SwPosition& aPos,
                const KeyCode& rCode,
                const String& rName,
                const String& rShortName )
    : SwBookmark( aPos, rCode, rName, rShortName )
{
    eMarkType = UNO_BOOKMARK;
}

<commit_msg>INTEGRATION: CWS writercorehandoff (1.6.444); FILE MERGED 2006/05/08 11:21:10 fme 1.6.444.3: #i50348# Make SwDoc accessible via interfaces 2005/09/13 13:09:18 tra 1.6.444.2: RESYNC: (1.6-1.7); FILE MERGED 2005/07/19 08:42:52 tra 1.6.444.1: #i50348#make SwDoc interface based<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: bookmrk.cxx,v $
 *
 *  $Revision: 1.8 $
 *
 *  last change: $Author: hr $ $Date: 2006-08-14 15:50:26 $
 *
 *  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
 *
 ************************************************************************/

#pragma hdrstop

#ifndef _BOOKMRK_HXX
#include <bookmrk.hxx>
#endif
#ifndef _SWTYPES_HXX
#include <swtypes.hxx>
#endif
#ifndef _PAM_HXX
#include <pam.hxx>
#endif
#ifndef _SWSERV_HXX
#include <swserv.hxx>
#endif
#ifndef _ERRHDL_HXX //autogen
#include <errhdl.hxx>
#endif
#include <IDocumentBookmarkAccess.hxx>

SV_IMPL_REF( SwServerObject )

TYPEINIT1( SwBookmark, SwModify );  //rtti

SwBookmark::SwBookmark(const SwPosition& aPos)
    : SwModify( 0 ),
    pPos2( 0 ),
    aStartMacro( aEmptyStr, aEmptyStr ),
    aEndMacro  ( aEmptyStr, aEmptyStr ),
    eMarkType( IDocumentBookmarkAccess::BOOKMARK )
{
    pPos1 = new SwPosition( aPos );
}

SwBookmark::SwBookmark(const SwPosition& aPos, const KeyCode& rCode,
                        const String& rName, const String& rShortName )
    : SwModify( 0 ),
    pPos2( 0 ),
    aStartMacro( aEmptyStr, aEmptyStr ),
    aEndMacro  ( aEmptyStr, aEmptyStr ),
    aName(rName),
    aShortName(rShortName),
    aCode(rCode),
    eMarkType( IDocumentBookmarkAccess::BOOKMARK )
{
    pPos1 = new SwPosition(aPos);
}

// Beim Loeschen von Text werden Bookmarks mitgeloescht!

SwBookmark::~SwBookmark()
{
    // falls wir noch der DDE-Bookmark sind, dann muss der aus dem
    // Clipboard ausgetragen werden. Wird automatisch ueber DataChanged
    // ausgeloest.
    if( refObj.Is() )
    {
        if( IDocumentBookmarkAccess::DDE_BOOKMARK == eMarkType && refObj->HasDataLinks() )
        {
            ::sfx2::SvLinkSource* p = &refObj;
            p->SendDataChanged();
        }
        refObj->SetNoServer();
    }

    delete pPos1;
    if( pPos2 )
        delete pPos2;
}

// Vergleiche auf Basis der Dokumentposition

BOOL SwBookmark::operator<(const SwBookmark &rBM) const
{
    const SwPosition* pThisPos = ( !pPos2 || *pPos1 <= *pPos2 ) ? pPos1 : pPos2;
    const SwPosition* pBMPos = ( !rBM.pPos2 || *rBM.pPos1 <= *rBM.pPos2 )
                                        ? rBM.pPos1 : rBM.pPos2;

    return *pThisPos < *pBMPos;
}

BOOL SwBookmark::operator==(const SwBookmark &rBM) const
{
    return (this == &rBM);
}

BOOL SwBookmark::IsEqualPos( const SwBookmark &rBM ) const
{
    const SwPosition* pThisPos = ( !pPos2 || *pPos1 <= *pPos2 ) ? pPos1 : pPos2;
    const SwPosition* pBMPos = ( !rBM.pPos2 || *rBM.pPos1 <= *rBM.pPos2 )
                                        ? rBM.pPos1 : rBM.pPos2;

    return *pThisPos == *pBMPos;
}

void SwBookmark::SetRefObject( SwServerObject* pObj )
{
    refObj = pObj;
}

SwMark::SwMark( const SwPosition& aPos,
                const KeyCode& rCode,
                const String& rName,
                const String& rShortName )
    : SwBookmark( aPos, rCode, rName, rShortName )
{
    eMarkType = IDocumentBookmarkAccess::MARK;
}

SwUNOMark::SwUNOMark( const SwPosition& aPos,
                const KeyCode& rCode,
                const String& rName,
                const String& rShortName )
    : SwBookmark( aPos, rCode, rName, rShortName )
{
    eMarkType = IDocumentBookmarkAccess::UNO_BOOKMARK;
}

<|endoftext|>