<commit_before>// Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "adaptive_sequenced_executor.h"

namespace vespalib {

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

AdaptiveSequencedExecutor::Strand::Strand()
    : state(State::IDLE),
      queue()
{
}

AdaptiveSequencedExecutor::Strand::~Strand()
{
    assert(queue.empty());
}

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

AdaptiveSequencedExecutor::Worker::Worker()
    : cond(),
      state(State::RUNNING),
      strand(nullptr)
{
}

AdaptiveSequencedExecutor::Worker::~Worker()
{
    assert(state == State::DONE);
    assert(strand == nullptr);
}

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

AdaptiveSequencedExecutor::Self::Self()
    : cond(),
      state(State::OPEN),
      waiting_tasks(0),
      pending_tasks(0)
{
}

AdaptiveSequencedExecutor::Self::~Self()
{
    assert(state == State::CLOSED);
    assert(waiting_tasks == 0);
    assert(pending_tasks == 0);
}

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

AdaptiveSequencedExecutor::ThreadTools::ThreadTools(AdaptiveSequencedExecutor &parent_in)
    : parent(parent_in),
      pool(std::make_unique<FastOS_ThreadPool>(STACK_SIZE)),
      allow_worker_exit()
{
}

AdaptiveSequencedExecutor::ThreadTools::~ThreadTools()
{
    assert(pool->isClosed());
}

void
AdaptiveSequencedExecutor::ThreadTools::Run(FastOS_ThreadInterface *, void *)
{
    parent.worker_main();
}

void
AdaptiveSequencedExecutor::ThreadTools::start(size_t num_threads)
{
    for (size_t i = 0; i < num_threads; ++i) {
        FastOS_ThreadInterface *thread = pool->NewThread(this);
        assert(thread != nullptr);
        (void)thread;
    }
}

void
AdaptiveSequencedExecutor::ThreadTools::close()
{
    allow_worker_exit.countDown();
    pool->Close();
}

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

void
AdaptiveSequencedExecutor::maybe_block_self(std::unique_lock<std::mutex> &lock)
{
    while (_self.state == Self::State::BLOCKED) {
        _self.cond.wait(lock);
    }
    while ((_self.state == Self::State::OPEN) && (_self.pending_tasks >= _cfg.max_pending)) {
        _self.state = Self::State::BLOCKED;
        while (_self.state == Self::State::BLOCKED) {
            _self.cond.wait(lock);
        }
    }
}

bool
AdaptiveSequencedExecutor::maybe_unblock_self(const std::unique_lock<std::mutex> &)
{
    if ((_self.state == Self::State::BLOCKED) && (_self.pending_tasks < _cfg.wakeup_limit)) {
        _self.state = Self::State::OPEN;
        return true;
    }
    return false;
}

AdaptiveSequencedExecutor::Worker *
AdaptiveSequencedExecutor::get_worker_to_wake(const std::unique_lock<std::mutex> &)
{
    if ((_self.waiting_tasks > _cfg.max_waiting) && (!_worker_stack.empty())) {
        assert(!_wait_queue.empty());
        Worker *worker = _worker_stack.back();
        _worker_stack.popBack();
        assert(worker->state == Worker::State::BLOCKED);
        assert(worker->strand == nullptr);
        worker->state = Worker::State::RUNNING;
        worker->strand = _wait_queue.front();
        _wait_queue.pop();
        assert(worker->strand->state == Strand::State::WAITING);
        assert(!worker->strand->queue.empty());
        worker->strand->state = Strand::State::ACTIVE;
        assert(_self.waiting_tasks >= worker->strand->queue.size());
        _self.waiting_tasks -= worker->strand->queue.size();
        return worker;
    }
    return nullptr;
}

bool
AdaptiveSequencedExecutor::obtain_strand(Worker &worker, std::unique_lock<std::mutex> &lock)
{
    assert(worker.strand == nullptr);
    if (!_wait_queue.empty()) {
        worker.strand = _wait_queue.front();
        _wait_queue.pop();
        assert(worker.strand->state == Strand::State::WAITING);
        assert(!worker.strand->queue.empty());
        worker.strand->state = Strand::State::ACTIVE;
        assert(_self.waiting_tasks >= worker.strand->queue.size());
        _self.waiting_tasks -= worker.strand->queue.size();
    } else if (_self.state == Self::State::CLOSED) {
        worker.state = Worker::State::DONE;
    } else {
        worker.state = Worker::State::BLOCKED;
        _worker_stack.push(&worker);
        while (worker.state == Worker::State::BLOCKED) {
            worker.cond.wait(lock);
        }
    }
    return (worker.state == Worker::State::RUNNING);
}

bool
AdaptiveSequencedExecutor::exchange_strand(Worker &worker, std::unique_lock<std::mutex> &lock)
{
    if (worker.strand == nullptr) {
        return obtain_strand(worker, lock);
    }
    if (worker.strand->queue.empty()) {
        worker.strand->state = Strand::State::IDLE;
        worker.strand = nullptr;
        return obtain_strand(worker, lock);
    }
    if (!_wait_queue.empty()) {
        worker.strand->state = Strand::State::WAITING;
        _self.waiting_tasks += worker.strand->queue.size();
        _wait_queue.push(worker.strand);
        worker.strand = nullptr;
        return obtain_strand(worker, lock);
    }
    return true;
}

AdaptiveSequencedExecutor::TaggedTask
AdaptiveSequencedExecutor::next_task(Worker &worker, std::optional<uint32_t> prev_token)
{
    TaggedTask task;
    Worker *worker_to_wake = nullptr;
    auto guard = std::unique_lock(_mutex);
    if (prev_token.has_value()) {
        _barrier.completeEvent(prev_token.value());
    }
    if (exchange_strand(worker, guard)) {
        assert(worker.state == Worker::State::RUNNING);
        assert(worker.strand != nullptr);
        assert(!worker.strand->queue.empty());
        task = std::move(worker.strand->queue.front());
        worker.strand->queue.pop();
        _stats.queueSize.add(--_self.pending_tasks);
        worker_to_wake = get_worker_to_wake(guard);
    } else {
        assert(worker.state == Worker::State::DONE);
        assert(worker.strand == nullptr);
    }
    bool signal_self = maybe_unblock_self(guard);
    guard.unlock(); // UNLOCK
    if (worker_to_wake != nullptr) {
        worker_to_wake->cond.notify_one();
    }
    if (signal_self) {
        _self.cond.notify_all();
    }
    return task;
}

void
AdaptiveSequencedExecutor::worker_main()
{
    Worker worker;
    std::optional<uint32_t> prev_token = std::nullopt;
    while (TaggedTask my_task = next_task(worker, prev_token)) {
        my_task.task->run();
        prev_token = my_task.token;
    }
    _thread_tools->allow_worker_exit.await();
}

AdaptiveSequencedExecutor::AdaptiveSequencedExecutor(size_t num_strands, size_t num_threads,
                                                     size_t max_waiting, size_t max_pending)
    : ISequencedTaskExecutor(num_strands),
      _thread_tools(std::make_unique<ThreadTools>(*this)),
      _mutex(),
      _strands(num_strands),
      _wait_queue(num_strands),
      _worker_stack(num_threads),
      _self(),
      _stats(),
      _cfg(num_threads, max_waiting, max_pending)
{
    _stats.queueSize.add(_self.pending_tasks);
    _thread_tools->start(num_threads);
}

AdaptiveSequencedExecutor::~AdaptiveSequencedExecutor()
{
    sync();
    {
        auto guard = std::unique_lock(_mutex);
        assert(_self.state == Self::State::OPEN);
        _self.state = Self::State::CLOSED;
        while (!_worker_stack.empty()) {
            Worker *worker = _worker_stack.back();
            _worker_stack.popBack();
            assert(worker->state == Worker::State::BLOCKED);
            assert(worker->strand == nullptr);
            worker->state = Worker::State::DONE;
            worker->cond.notify_one();
        }
        _self.cond.notify_all();
    }
    _thread_tools->close();
    assert(_wait_queue.empty());
    assert(_worker_stack.empty());
}

ISequencedTaskExecutor::ExecutorId
AdaptiveSequencedExecutor::getExecutorId(uint64_t component) const {
    return ExecutorId(component % _strands.size());
}

void
AdaptiveSequencedExecutor::executeTask(ExecutorId id, Task::UP task)
{
    assert(id.getId() < _strands.size());
    Strand &strand = _strands[id.getId()];
    auto guard = std::unique_lock(_mutex);
    assert(_self.state != Self::State::CLOSED);
    maybe_block_self(guard);
    strand.queue.push(TaggedTask(std::move(task), _barrier.startEvent()));
    _stats.queueSize.add(++_self.pending_tasks);
    ++_stats.acceptedTasks;
    if (strand.state == Strand::State::WAITING) {
        ++_self.waiting_tasks;
    } else if (strand.state == Strand::State::IDLE) {
        if (_worker_stack.size() < _cfg.num_threads) {
            strand.state = Strand::State::WAITING;
            _wait_queue.push(&strand);
            _self.waiting_tasks += strand.queue.size();
        } else {
            strand.state = Strand::State::ACTIVE;
            assert(_wait_queue.empty());
            Worker *worker = _worker_stack.back();
            _worker_stack.popBack();
            assert(worker->state == Worker::State::BLOCKED);
            assert(worker->strand == nullptr);
            worker->state = Worker::State::RUNNING;
            worker->strand = &strand;
            guard.unlock(); // UNLOCK
            worker->cond.notify_one();
        }
    }
}

void
AdaptiveSequencedExecutor::sync()
{
    BarrierCompletion barrierCompletion;
    {
        auto guard = std::scoped_lock(_mutex);
        if (!_barrier.startBarrier(barrierCompletion)) {
            return;
        }
    }
    barrierCompletion.gate.await();
}

void
AdaptiveSequencedExecutor::setTaskLimit(uint32_t task_limit)
{
    auto guard = std::unique_lock(_mutex);
    _cfg.set_max_pending(task_limit);
    bool signal_self = maybe_unblock_self(guard);
    guard.unlock(); // UNLOCK
    if (signal_self) {
        _self.cond.notify_all();
    }
}

AdaptiveSequencedExecutor::Stats
AdaptiveSequencedExecutor::getStats()
{
    auto guard = std::lock_guard(_mutex);
    Stats stats = _stats;
    _stats = Stats();
    _stats.queueSize.add(_self.pending_tasks);
    return stats;
}

}
<commit_msg>use appropriate lock<commit_after>// Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "adaptive_sequenced_executor.h"

namespace vespalib {

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

AdaptiveSequencedExecutor::Strand::Strand()
    : state(State::IDLE),
      queue()
{
}

AdaptiveSequencedExecutor::Strand::~Strand()
{
    assert(queue.empty());
}

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

AdaptiveSequencedExecutor::Worker::Worker()
    : cond(),
      state(State::RUNNING),
      strand(nullptr)
{
}

AdaptiveSequencedExecutor::Worker::~Worker()
{
    assert(state == State::DONE);
    assert(strand == nullptr);
}

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

AdaptiveSequencedExecutor::Self::Self()
    : cond(),
      state(State::OPEN),
      waiting_tasks(0),
      pending_tasks(0)
{
}

AdaptiveSequencedExecutor::Self::~Self()
{
    assert(state == State::CLOSED);
    assert(waiting_tasks == 0);
    assert(pending_tasks == 0);
}

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

AdaptiveSequencedExecutor::ThreadTools::ThreadTools(AdaptiveSequencedExecutor &parent_in)
    : parent(parent_in),
      pool(std::make_unique<FastOS_ThreadPool>(STACK_SIZE)),
      allow_worker_exit()
{
}

AdaptiveSequencedExecutor::ThreadTools::~ThreadTools()
{
    assert(pool->isClosed());
}

void
AdaptiveSequencedExecutor::ThreadTools::Run(FastOS_ThreadInterface *, void *)
{
    parent.worker_main();
}

void
AdaptiveSequencedExecutor::ThreadTools::start(size_t num_threads)
{
    for (size_t i = 0; i < num_threads; ++i) {
        FastOS_ThreadInterface *thread = pool->NewThread(this);
        assert(thread != nullptr);
        (void)thread;
    }
}

void
AdaptiveSequencedExecutor::ThreadTools::close()
{
    allow_worker_exit.countDown();
    pool->Close();
}

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

void
AdaptiveSequencedExecutor::maybe_block_self(std::unique_lock<std::mutex> &lock)
{
    while (_self.state == Self::State::BLOCKED) {
        _self.cond.wait(lock);
    }
    while ((_self.state == Self::State::OPEN) && (_self.pending_tasks >= _cfg.max_pending)) {
        _self.state = Self::State::BLOCKED;
        while (_self.state == Self::State::BLOCKED) {
            _self.cond.wait(lock);
        }
    }
}

bool
AdaptiveSequencedExecutor::maybe_unblock_self(const std::unique_lock<std::mutex> &)
{
    if ((_self.state == Self::State::BLOCKED) && (_self.pending_tasks < _cfg.wakeup_limit)) {
        _self.state = Self::State::OPEN;
        return true;
    }
    return false;
}

AdaptiveSequencedExecutor::Worker *
AdaptiveSequencedExecutor::get_worker_to_wake(const std::unique_lock<std::mutex> &)
{
    if ((_self.waiting_tasks > _cfg.max_waiting) && (!_worker_stack.empty())) {
        assert(!_wait_queue.empty());
        Worker *worker = _worker_stack.back();
        _worker_stack.popBack();
        assert(worker->state == Worker::State::BLOCKED);
        assert(worker->strand == nullptr);
        worker->state = Worker::State::RUNNING;
        worker->strand = _wait_queue.front();
        _wait_queue.pop();
        assert(worker->strand->state == Strand::State::WAITING);
        assert(!worker->strand->queue.empty());
        worker->strand->state = Strand::State::ACTIVE;
        assert(_self.waiting_tasks >= worker->strand->queue.size());
        _self.waiting_tasks -= worker->strand->queue.size();
        return worker;
    }
    return nullptr;
}

bool
AdaptiveSequencedExecutor::obtain_strand(Worker &worker, std::unique_lock<std::mutex> &lock)
{
    assert(worker.strand == nullptr);
    if (!_wait_queue.empty()) {
        worker.strand = _wait_queue.front();
        _wait_queue.pop();
        assert(worker.strand->state == Strand::State::WAITING);
        assert(!worker.strand->queue.empty());
        worker.strand->state = Strand::State::ACTIVE;
        assert(_self.waiting_tasks >= worker.strand->queue.size());
        _self.waiting_tasks -= worker.strand->queue.size();
    } else if (_self.state == Self::State::CLOSED) {
        worker.state = Worker::State::DONE;
    } else {
        worker.state = Worker::State::BLOCKED;
        _worker_stack.push(&worker);
        while (worker.state == Worker::State::BLOCKED) {
            worker.cond.wait(lock);
        }
    }
    return (worker.state == Worker::State::RUNNING);
}

bool
AdaptiveSequencedExecutor::exchange_strand(Worker &worker, std::unique_lock<std::mutex> &lock)
{
    if (worker.strand == nullptr) {
        return obtain_strand(worker, lock);
    }
    if (worker.strand->queue.empty()) {
        worker.strand->state = Strand::State::IDLE;
        worker.strand = nullptr;
        return obtain_strand(worker, lock);
    }
    if (!_wait_queue.empty()) {
        worker.strand->state = Strand::State::WAITING;
        _self.waiting_tasks += worker.strand->queue.size();
        _wait_queue.push(worker.strand);
        worker.strand = nullptr;
        return obtain_strand(worker, lock);
    }
    return true;
}

AdaptiveSequencedExecutor::TaggedTask
AdaptiveSequencedExecutor::next_task(Worker &worker, std::optional<uint32_t> prev_token)
{
    TaggedTask task;
    Worker *worker_to_wake = nullptr;
    auto guard = std::unique_lock(_mutex);
    if (prev_token.has_value()) {
        _barrier.completeEvent(prev_token.value());
    }
    if (exchange_strand(worker, guard)) {
        assert(worker.state == Worker::State::RUNNING);
        assert(worker.strand != nullptr);
        assert(!worker.strand->queue.empty());
        task = std::move(worker.strand->queue.front());
        worker.strand->queue.pop();
        _stats.queueSize.add(--_self.pending_tasks);
        worker_to_wake = get_worker_to_wake(guard);
    } else {
        assert(worker.state == Worker::State::DONE);
        assert(worker.strand == nullptr);
    }
    bool signal_self = maybe_unblock_self(guard);
    guard.unlock(); // UNLOCK
    if (worker_to_wake != nullptr) {
        worker_to_wake->cond.notify_one();
    }
    if (signal_self) {
        _self.cond.notify_all();
    }
    return task;
}

void
AdaptiveSequencedExecutor::worker_main()
{
    Worker worker;
    std::optional<uint32_t> prev_token = std::nullopt;
    while (TaggedTask my_task = next_task(worker, prev_token)) {
        my_task.task->run();
        prev_token = my_task.token;
    }
    _thread_tools->allow_worker_exit.await();
}

AdaptiveSequencedExecutor::AdaptiveSequencedExecutor(size_t num_strands, size_t num_threads,
                                                     size_t max_waiting, size_t max_pending)
    : ISequencedTaskExecutor(num_strands),
      _thread_tools(std::make_unique<ThreadTools>(*this)),
      _mutex(),
      _strands(num_strands),
      _wait_queue(num_strands),
      _worker_stack(num_threads),
      _self(),
      _stats(),
      _cfg(num_threads, max_waiting, max_pending)
{
    _stats.queueSize.add(_self.pending_tasks);
    _thread_tools->start(num_threads);
}

AdaptiveSequencedExecutor::~AdaptiveSequencedExecutor()
{
    sync();
    {
        auto guard = std::unique_lock(_mutex);
        assert(_self.state == Self::State::OPEN);
        _self.state = Self::State::CLOSED;
        while (!_worker_stack.empty()) {
            Worker *worker = _worker_stack.back();
            _worker_stack.popBack();
            assert(worker->state == Worker::State::BLOCKED);
            assert(worker->strand == nullptr);
            worker->state = Worker::State::DONE;
            worker->cond.notify_one();
        }
        _self.cond.notify_all();
    }
    _thread_tools->close();
    assert(_wait_queue.empty());
    assert(_worker_stack.empty());
}

ISequencedTaskExecutor::ExecutorId
AdaptiveSequencedExecutor::getExecutorId(uint64_t component) const {
    return ExecutorId(component % _strands.size());
}

void
AdaptiveSequencedExecutor::executeTask(ExecutorId id, Task::UP task)
{
    assert(id.getId() < _strands.size());
    Strand &strand = _strands[id.getId()];
    auto guard = std::unique_lock(_mutex);
    assert(_self.state != Self::State::CLOSED);
    maybe_block_self(guard);
    strand.queue.push(TaggedTask(std::move(task), _barrier.startEvent()));
    _stats.queueSize.add(++_self.pending_tasks);
    ++_stats.acceptedTasks;
    if (strand.state == Strand::State::WAITING) {
        ++_self.waiting_tasks;
    } else if (strand.state == Strand::State::IDLE) {
        if (_worker_stack.size() < _cfg.num_threads) {
            strand.state = Strand::State::WAITING;
            _wait_queue.push(&strand);
            _self.waiting_tasks += strand.queue.size();
        } else {
            strand.state = Strand::State::ACTIVE;
            assert(_wait_queue.empty());
            Worker *worker = _worker_stack.back();
            _worker_stack.popBack();
            assert(worker->state == Worker::State::BLOCKED);
            assert(worker->strand == nullptr);
            worker->state = Worker::State::RUNNING;
            worker->strand = &strand;
            guard.unlock(); // UNLOCK
            worker->cond.notify_one();
        }
    }
}

void
AdaptiveSequencedExecutor::sync()
{
    BarrierCompletion barrierCompletion;
    {
        auto guard = std::lock_guard(_mutex);
        if (!_barrier.startBarrier(barrierCompletion)) {
            return;
        }
    }
    barrierCompletion.gate.await();
}

void
AdaptiveSequencedExecutor::setTaskLimit(uint32_t task_limit)
{
    auto guard = std::unique_lock(_mutex);
    _cfg.set_max_pending(task_limit);
    bool signal_self = maybe_unblock_self(guard);
    guard.unlock(); // UNLOCK
    if (signal_self) {
        _self.cond.notify_all();
    }
}

AdaptiveSequencedExecutor::Stats
AdaptiveSequencedExecutor::getStats()
{
    auto guard = std::lock_guard(_mutex);
    Stats stats = _stats;
    _stats = Stats();
    _stats.queueSize.add(_self.pending_tasks);
    return stats;
}

}
<|endoftext|>


<commit_before>/**
 * Copyright (c) 2011-2015 libbitcoin developers (see AUTHORS)
 *
 * This file is part of libbitcoin.
 *
 * libbitcoin is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License with
 * additional permissions to the one published by the Free Software
 * Foundation, either version 3 of the License, or (at your option)
 * any later version. For more information see LICENSE.
 *
 * This program 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
#include <bitcoin/bitcoin/network/timeout.hpp>

#include <cstdint>
#include <boost/asio.hpp>
#include <boost/date_time.hpp>
#include <boost/system/error_code.hpp>

namespace libbitcoin {
namespace network {

using boost::posix_time::seconds;
using boost::posix_time::minutes;

const timeout timeout::defaults;

timeout::timeout(
    uint32_t connect_timeout_seconds,
    uint32_t channel_handshake_minutes,
    uint32_t channel_revival_minutes,
    uint32_t channel_heartbeat_minutes,
    uint32_t channel_inactivity_minutes,
    uint32_t channel_expiration_minutes)
  : connect(0, 0, connect_timeout_seconds),
    handshake(0, channel_handshake_minutes, 0),
    revival(0, channel_revival_minutes, 0),
    heartbeat(0, channel_heartbeat_minutes, 0),
    inactivity(0, channel_inactivity_minutes, 0),
    expiration(0, channel_expiration_minutes, 0)
{
}

bool timeout::canceled(const boost::system::error_code& ec)
{
    return ec == boost::asio::error::operation_aborted;
}

} // namespace network
} // namespace libbitcoin
<commit_msg>Comment.<commit_after>/**
 * Copyright (c) 2011-2015 libbitcoin developers (see AUTHORS)
 *
 * This file is part of libbitcoin.
 *
 * libbitcoin is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License with
 * additional permissions to the one published by the Free Software
 * Foundation, either version 3 of the License, or (at your option)
 * any later version. For more information see LICENSE.
 *
 * This program 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
#include <bitcoin/bitcoin/network/timeout.hpp>

#include <cstdint>
#include <boost/asio.hpp>
#include <boost/date_time.hpp>
#include <boost/system/error_code.hpp>

namespace libbitcoin {
namespace network {

using boost::posix_time::seconds;
using boost::posix_time::minutes;

const timeout timeout::defaults;

timeout::timeout(
    uint32_t connect_timeout_seconds,
    uint32_t channel_handshake_minutes,
    uint32_t channel_revival_minutes,
    uint32_t channel_heartbeat_minutes,
    uint32_t channel_inactivity_minutes,
    uint32_t channel_expiration_minutes)
  : connect(0, 0, connect_timeout_seconds),
    handshake(0, channel_handshake_minutes, 0),
    revival(0, channel_revival_minutes, 0),
    heartbeat(0, channel_heartbeat_minutes, 0),
    inactivity(0, channel_inactivity_minutes, 0),
    expiration(0, channel_expiration_minutes, 0)
{
}

// TODO: wrap boost timers with our own and map error codes internally.
bool timeout::canceled(const boost::system::error_code& ec)
{
    return ec == boost::asio::error::operation_aborted;
}

} // namespace network
} // namespace libbitcoin
<|endoftext|>


<commit_before>#include <algorithm>
#include <random>
#include <vector>

#include "aim.hpp"
#include "maze.hpp"

// Algorithm to be tested

void generate_maze(char** maze, Dimension const& dim, Point const& start_pt, Point const& end_pt, unsigned seed)
{
  auto const& width = dim.width;
  auto const& height = dim.height;
  std::mt19937 g(seed);

  // Reset the map
  for (std::size_t j {} ; j != height ; ++j)
  {
    for (std::size_t i {} ; i != width ; ++i)
    {
      maze[j][i] = to_char(MazeElement::Wall);
    }
  }

  // Put start and end
  maze[start_pt.y][start_pt.x] = to_char(MazeElement::Start);
  maze[end_pt.y  ][end_pt.x  ] = to_char(MazeElement::End);

  // Random journey in the grid
  std::vector<Point> toscan;

  auto is_end = [width,height,maze](Point const& pt) { return pt.x < width && pt.y < height && maze[pt.y][pt.x] == to_char(MazeElement::End); };
  auto is_notwall = [width,height,maze](Point const& pt) { return pt.x < width && pt.y < height && maze[pt.y][pt.x] != to_char(MazeElement::Wall); };

  auto is_next_to_end = [&is_end](Point const& pt) { return is_end(Point{pt.x, pt.y-1}) || is_end(Point{pt.x, pt.y+1}) || is_end(Point{pt.x-1, pt.y}) || is_end(Point{pt.x+1, pt.y}); };

  auto append_if_wall = [&toscan,width,height,maze](Point const& pt) { if (pt.x < width && pt.y < height && maze[pt.y][pt.x] == to_char(MazeElement::Wall)) { toscan.push_back(pt); } };
  auto append_neighboors = [&append_if_wall,&g,&toscan,maze](Point const& pt) {
      auto before = toscan.size();
      append_if_wall(Point{pt.x-1,   pt.y});
      append_if_wall(Point{pt.x+1,   pt.y});
      append_if_wall(Point{pt.x  , pt.y-1});
      append_if_wall(Point{pt.x  , pt.y+1});
      std::shuffle(toscan.rbegin(), std::next(toscan.rbegin(), toscan.size() - before), g);
  };
  append_neighboors(start_pt);

  bool reached_end { is_next_to_end(start_pt) };
  while (! toscan.empty())
  {
    Point last = toscan.back();
    toscan.pop_back();

    if (maze[last.y][last.x] != to_char(MazeElement::Wall)) { continue; }

    unsigned num_roads {};
    if (is_notwall(Point{last.x  , last.y-1})) { ++num_roads; }
    if (is_notwall(Point{last.x  , last.y+1})) { ++num_roads; }
    if (is_notwall(Point{last.x-1,   last.y})) { ++num_roads; }
    if (is_notwall(Point{last.x+1,   last.y})) { ++num_roads; }

    bool invalid_choice = (num_roads > 2);
    if (num_roads == 2)
    {
      if (reached_end) invalid_choice = true;
      else
      {
        reached_end = is_next_to_end(last);
        invalid_choice = !reached_end;
      }
    }

    if (invalid_choice)
    {// we reach the end of ongoing path -- cleaning and shuffling of previously possible points
      toscan.erase(
          std::remove_if(toscan.begin(), toscan.end(), [maze](auto const& pt) { return maze[pt.y][pt.x] != to_char(MazeElement::Wall); })
          , toscan.end());
      std::shuffle(toscan.begin(), toscan.end(), g);
      continue;
    }

    maze[last.y][last.x] = to_char(MazeElement::Road);
    append_neighboors(last);
  }
}

<commit_msg>[graph/maze-generator] Fixed #6: mazes with no path to end<commit_after>#include <algorithm>
#include <random>
#include <vector>

#include "aim.hpp"
#include "maze.hpp"

// Algorithm to be tested

template <class RandGen> bool generate_maze_helper(char** maze, Dimension const& dim, Point const& start_pt, Point const& end_pt, RandGen& g)
{
  auto const& width = dim.width;
  auto const& height = dim.height;

  // Reset the map
  for (std::size_t j {} ; j != height ; ++j)
  {
    for (std::size_t i {} ; i != width ; ++i)
    {
      maze[j][i] = to_char(MazeElement::Wall);
    }
  }

  // Put start and end
  maze[start_pt.y][start_pt.x] = to_char(MazeElement::Start);
  maze[end_pt.y  ][end_pt.x  ] = to_char(MazeElement::End);

  // Random journey in the grid
  std::vector<Point> toscan;

  auto is_end = [width,height,maze](Point const& pt) { return pt.x < width && pt.y < height && maze[pt.y][pt.x] == to_char(MazeElement::End); };
  auto is_notwall = [width,height,maze](Point const& pt) { return pt.x < width && pt.y < height && maze[pt.y][pt.x] != to_char(MazeElement::Wall); };

  auto is_next_to_end = [&is_end](Point const& pt) { return is_end(Point{pt.x, pt.y-1}) || is_end(Point{pt.x, pt.y+1}) || is_end(Point{pt.x-1, pt.y}) || is_end(Point{pt.x+1, pt.y}); };

  auto append_if_wall = [&toscan,width,height,maze](Point const& pt) { if (pt.x < width && pt.y < height && maze[pt.y][pt.x] == to_char(MazeElement::Wall)) { toscan.push_back(pt); } };
  auto append_neighboors = [&append_if_wall,&g,&toscan,maze](Point const& pt) {
      auto before = toscan.size();
      append_if_wall(Point{pt.x-1,   pt.y});
      append_if_wall(Point{pt.x+1,   pt.y});
      append_if_wall(Point{pt.x  , pt.y-1});
      append_if_wall(Point{pt.x  , pt.y+1});
      std::shuffle(toscan.rbegin(), std::next(toscan.rbegin(), toscan.size() - before), g);
  };
  append_neighboors(start_pt);

  bool reached_end { is_next_to_end(start_pt) };
  while (! toscan.empty())
  {
    Point last = toscan.back();
    toscan.pop_back();

    if (maze[last.y][last.x] != to_char(MazeElement::Wall)) { continue; }

    unsigned num_roads {};
    if (is_notwall(Point{last.x  , last.y-1})) { ++num_roads; }
    if (is_notwall(Point{last.x  , last.y+1})) { ++num_roads; }
    if (is_notwall(Point{last.x-1,   last.y})) { ++num_roads; }
    if (is_notwall(Point{last.x+1,   last.y})) { ++num_roads; }

    bool invalid_choice = (num_roads > 2);
    if (num_roads == 2)
    {
      if (reached_end) invalid_choice = true;
      else
      {
        reached_end = is_next_to_end(last);
        invalid_choice = !reached_end;
      }
    }

    if (invalid_choice)
    {// we reach the end of ongoing path -- cleaning and shuffling of previously possible points
      toscan.erase(
          std::remove_if(toscan.begin(), toscan.end(), [maze](auto const& pt) { return maze[pt.y][pt.x] != to_char(MazeElement::Wall); })
          , toscan.end());
      std::shuffle(toscan.begin(), toscan.end(), g);
      continue;
    }

    maze[last.y][last.x] = to_char(MazeElement::Road);
    append_neighboors(last);
  }
  return reached_end;
}

void generate_maze(char** maze, Dimension const& dim, Point const& start_pt, Point const& end_pt, unsigned seed)
{
  std::mt19937 g(seed);

  bool correct {};
  while (! correct) { correct = generate_maze_helper(maze, dim, start_pt, end_pt, g); }
}

<|endoftext|>


<commit_before>#include <iostream>
#include <ncurses.h>

#include "../src/newmove.hh"
#include "UnitTest++/UnitTest++.h"
#include "../src/configuration.hh"

TEST(mvsot) {
    contents contents;
    contents.push_back("    hello");

    initscr();
    mvsot(contents);
    endwin();

    CHECK_EQUAL(0,contents.get_y());
    CHECK_EQUAL(4,contents.get_x());
}

TEST(mvcol) {
    contents contents;
    contents.push_back("asert");

    initscr();
    mvcol(contents,3);
    int y1 = contents.get_y(),
        x1 = contents.get_x();

    mvcol(contents,10); //doesn't do anything
    int y2 = contents.get_y(),
        x2 = contents.get_x();

    mvcol(contents,0);
    int y3 = contents.get_y(),
        x3 = contents.get_x();
    endwin();

    CHECK_EQUAL(0,y1);
    CHECK_EQUAL(0,y2);
    CHECK_EQUAL(0,y3);
    CHECK_EQUAL(3,x1);
    CHECK_EQUAL(3,x2);
    CHECK_EQUAL(0,x3);
}

TEST(mvsol) {
    contents contents (0,5);
    contents.push_back("    assert");

    initscr();
    mvsol(contents);
    int y = contents.get_y(),
        x = contents.get_x();
    endwin();

    CHECK_EQUAL(0,y);
    CHECK_EQUAL(0,x);
}

TEST(mvd) {
    contents contents;
    contents.push_back("assert");
    contents.push_back("hello");
    contents.push_back("aseuirpo");

    initscr();
    mvd(contents,2);
    int y = contents.get_y(),
        x = contents.get_x();
    mvd(contents);
    int y1 = contents.get_y(),
        x1 = contents.get_x();
    endwin();

    CHECK_EQUAL(0,x);
    CHECK_EQUAL(0,x1);
    CHECK_EQUAL(2,y);
    CHECK_EQUAL(2,y1);
}

TEST(mvf) {
    contents contents;
    contents.push_back("assert");
    contents.push_back("hello");

    initscr();
    mvf(contents,3);
    int y = contents.get_y(),
        x = contents.get_x();
    mvf(contents,4);
    int y1 = contents.get_y(),
        x1 = contents.get_x();
    endwin();

    CHECK_EQUAL(0,y);
    CHECK_EQUAL(3,x);
    CHECK_EQUAL(1,y1);
    CHECK_EQUAL(1,x1);
}

TEST(mvb) {
    contents contents (1,0);
    contents.push_back("assert");
    contents.push_back("back");

    initscr();
    mvb(contents,2);
    int y = contents.get_y(),
        x = contents.get_x();
    endwin();

    CHECK_EQUAL(0,y);
    CHECK_EQUAL(4,x);
}

TEST(mvf_2) {
    contents contents;
    contents.push_back("CFLAGS=-lncurses -Wall");
    contents.push_back("O=out");
    contents.push_back("S=src");
    contents.push_back("T=test");
    contents.push_back("TO=testout");
    contents.push_back("CC=g++");

    initscr();
    mveol(contents);
    int y = contents.get_y(),
        x = contents.get_x();
    mvf(contents,2);
    int y1 = contents.get_y(),
        x1 = contents.get_x();
    endwin();

    CHECK_EQUAL(0,y);
    CHECK_EQUAL(21,x);
    CHECK_EQUAL(1,y1);
    CHECK_EQUAL(1,x1);
}

TEST(mveol) {
    contents contents;
    contents.push_back("Aesop");

    initscr();
    mveol(contents);
    int y = contents.get_y(),
        x = contents.get_x();
    endwin();

    CHECK_EQUAL(4,x);
    CHECK_EQUAL(0,y);
}

TEST(mvu) {
    contents contents (1,6);
    contents.push_back("hi");
    contents.push_back("Alabama");

    initscr();
    mvu(contents);
    int y1 = contents.get_y(),
        x1 = contents.get_x();
    endwin();

    CHECK_EQUAL(0,y1);
    CHECK_EQUAL(1,x1);
    CHECK_EQUAL(true,contents.get_waiting_for_desired());
    CHECK_EQUAL(6,contents.get_desired_x());
}

TEST(mvd_2) {
    contents contents;
    contents.push_back("CFLAGS=-lncurses -Wall");
    contents.push_back("O=out");
    contents.push_back("S=src");
    contents.push_back("T=test");

    initscr();
    mveol(contents);
    int y = contents.get_y(),
        x = contents.get_x();
    mvd(contents);
    int y1 = contents.get_y(),
        x1 = contents.get_x();
    int d1 = contents.get_desired_x();
    bool w1 = contents.get_waiting_for_desired();
    mvd(contents);
    int y2 = contents.get_y(),
        x2 = contents.get_x();
    int d2 = contents.get_desired_x();
    bool w2 = contents.get_waiting_for_desired();
    endwin();

    CHECK_EQUAL(0,y);
    CHECK_EQUAL(21,x);

    CHECK_EQUAL(1,y1);
    CHECK_EQUAL(4,x1);
    CHECK_EQUAL(21,d1);
    CHECK_EQUAL(true,w1);

    CHECK_EQUAL(2,y2);
    CHECK_EQUAL(4,x2);
    CHECK_EQUAL(21,d2);
    CHECK_EQUAL(true,w2);
}

TEST(mvf_over_empty_lines) {
    contents contents (0,1);
    contents.push_back("hi");
    contents.push_back("");
    contents.push_back("hi");

    initscr();
    mvf(contents);
    endwin();

    CHECK_EQUAL(0,contents.get_x());
    CHECK_EQUAL(1,contents.get_y());
}

TEST(mvf_over_tabs) {
    contents contents (0,25);
    contents.push_back("testVI: ${files} $O/main.o");
    contents.push_back("\t${CC} -o testVI $^ $(CFLAGS)");

    initscr();
    mvf(contents);
    int vis_y,vis_x,y,x;
    getyx(stdscr,vis_y,vis_x);
    y = contents.get_y();
    x = contents.get_x();
    mvf(contents);
    int vis_y1,vis_x1,y1,x1;
    getyx(stdscr,vis_y1,vis_x1);
    y1= contents.get_y();
    x1= contents.get_x();
    endwin();

    CHECK_EQUAL(1,y);
    CHECK_EQUAL(0,x);
    CHECK_EQUAL(1,vis_y);
    CHECK_EQUAL(6,vis_x);

    std::cout << "break\n";
    CHECK_EQUAL(1,y1);
    CHECK_EQUAL(1,x1);
    CHECK_EQUAL(1,vis_y1);
    CHECK_EQUAL(7,vis_x1);
}

TEST(to_visual) {
    std::string first("\thi");
    CHECK_EQUAL(TAB_SIZE() - 1, to_visual(first,0));
}
<commit_msg>Test for ``from_visual''<commit_after>#include <iostream>
#include <ncurses.h>

#include "../src/newmove.hh"
#include "UnitTest++/UnitTest++.h"
#include "../src/configuration.hh"

TEST(mvsot) {
    contents contents;
    contents.push_back("    hello");

    initscr();
    mvsot(contents);
    endwin();

    CHECK_EQUAL(0,contents.get_y());
    CHECK_EQUAL(4,contents.get_x());
}

TEST(mvcol) {
    contents contents;
    contents.push_back("asert");

    initscr();
    mvcol(contents,3);
    int y1 = contents.get_y(),
        x1 = contents.get_x();

    mvcol(contents,10); //doesn't do anything
    int y2 = contents.get_y(),
        x2 = contents.get_x();

    mvcol(contents,0);
    int y3 = contents.get_y(),
        x3 = contents.get_x();
    endwin();

    CHECK_EQUAL(0,y1);
    CHECK_EQUAL(0,y2);
    CHECK_EQUAL(0,y3);
    CHECK_EQUAL(3,x1);
    CHECK_EQUAL(3,x2);
    CHECK_EQUAL(0,x3);
}

TEST(mvsol) {
    contents contents (0,5);
    contents.push_back("    assert");

    initscr();
    mvsol(contents);
    int y = contents.get_y(),
        x = contents.get_x();
    endwin();

    CHECK_EQUAL(0,y);
    CHECK_EQUAL(0,x);
}

TEST(mvd) {
    contents contents;
    contents.push_back("assert");
    contents.push_back("hello");
    contents.push_back("aseuirpo");

    initscr();
    mvd(contents,2);
    int y = contents.get_y(),
        x = contents.get_x();
    mvd(contents);
    int y1 = contents.get_y(),
        x1 = contents.get_x();
    endwin();

    CHECK_EQUAL(0,x);
    CHECK_EQUAL(0,x1);
    CHECK_EQUAL(2,y);
    CHECK_EQUAL(2,y1);
}

TEST(mvf) {
    contents contents;
    contents.push_back("assert");
    contents.push_back("hello");

    initscr();
    mvf(contents,3);
    int y = contents.get_y(),
        x = contents.get_x();
    mvf(contents,4);
    int y1 = contents.get_y(),
        x1 = contents.get_x();
    endwin();

    CHECK_EQUAL(0,y);
    CHECK_EQUAL(3,x);
    CHECK_EQUAL(1,y1);
    CHECK_EQUAL(1,x1);
}

TEST(mvb) {
    contents contents (1,0);
    contents.push_back("assert");
    contents.push_back("back");

    initscr();
    mvb(contents,2);
    int y = contents.get_y(),
        x = contents.get_x();
    endwin();

    CHECK_EQUAL(0,y);
    CHECK_EQUAL(4,x);
}

TEST(mvf_2) {
    contents contents;
    contents.push_back("CFLAGS=-lncurses -Wall");
    contents.push_back("O=out");
    contents.push_back("S=src");
    contents.push_back("T=test");
    contents.push_back("TO=testout");
    contents.push_back("CC=g++");

    initscr();
    mveol(contents);
    int y = contents.get_y(),
        x = contents.get_x();
    mvf(contents,2);
    int y1 = contents.get_y(),
        x1 = contents.get_x();
    endwin();

    CHECK_EQUAL(0,y);
    CHECK_EQUAL(21,x);
    CHECK_EQUAL(1,y1);
    CHECK_EQUAL(1,x1);
}

TEST(mveol) {
    contents contents;
    contents.push_back("Aesop");

    initscr();
    mveol(contents);
    int y = contents.get_y(),
        x = contents.get_x();
    endwin();

    CHECK_EQUAL(4,x);
    CHECK_EQUAL(0,y);
}

TEST(mvu) {
    contents contents (1,6);
    contents.push_back("hi");
    contents.push_back("Alabama");

    initscr();
    mvu(contents);
    int y1 = contents.get_y(),
        x1 = contents.get_x();
    endwin();

    CHECK_EQUAL(0,y1);
    CHECK_EQUAL(1,x1);
    CHECK_EQUAL(true,contents.get_waiting_for_desired());
    CHECK_EQUAL(6,contents.get_desired_x());
}

TEST(mvd_2) {
    contents contents;
    contents.push_back("CFLAGS=-lncurses -Wall");
    contents.push_back("O=out");
    contents.push_back("S=src");
    contents.push_back("T=test");

    initscr();
    mveol(contents);
    int y = contents.get_y(),
        x = contents.get_x();
    mvd(contents);
    int y1 = contents.get_y(),
        x1 = contents.get_x();
    int d1 = contents.get_desired_x();
    bool w1 = contents.get_waiting_for_desired();
    mvd(contents);
    int y2 = contents.get_y(),
        x2 = contents.get_x();
    int d2 = contents.get_desired_x();
    bool w2 = contents.get_waiting_for_desired();
    endwin();

    CHECK_EQUAL(0,y);
    CHECK_EQUAL(21,x);

    CHECK_EQUAL(1,y1);
    CHECK_EQUAL(4,x1);
    CHECK_EQUAL(21,d1);
    CHECK_EQUAL(true,w1);

    CHECK_EQUAL(2,y2);
    CHECK_EQUAL(4,x2);
    CHECK_EQUAL(21,d2);
    CHECK_EQUAL(true,w2);
}

TEST(mvf_over_empty_lines) {
    contents contents (0,1);
    contents.push_back("hi");
    contents.push_back("");
    contents.push_back("hi");

    initscr();
    mvf(contents);
    endwin();

    CHECK_EQUAL(0,contents.get_x());
    CHECK_EQUAL(1,contents.get_y());
}

TEST(mvf_over_tabs) {
    contents contents (0,25);
    contents.push_back("testVI: ${files} $O/main.o");
    contents.push_back("\t${CC} -o testVI $^ $(CFLAGS)");

    initscr();
    mvf(contents);
    int vis_y,vis_x,y,x;
    getyx(stdscr,vis_y,vis_x);
    y = contents.get_y();
    x = contents.get_x();
    mvf(contents);
    int vis_y1,vis_x1,y1,x1;
    getyx(stdscr,vis_y1,vis_x1);
    y1= contents.get_y();
    x1= contents.get_x();
    endwin();

    CHECK_EQUAL(1,y);
    CHECK_EQUAL(0,x);
    CHECK_EQUAL(1,vis_y);
    CHECK_EQUAL(7,vis_x);
    CHECK_EQUAL(1,y1);
    CHECK_EQUAL(1,x1);
    CHECK_EQUAL(1,vis_y1);
    CHECK_EQUAL(8,vis_x1);
}

TEST(to_visual) {
    std::string first("\thi");
    CHECK_EQUAL(TAB_SIZE() - 1, to_visual(first,0));
}

TEST(from_visual) {
    std::string
        first("\thi"),
        second("\t\thi");
    for(int i = 0; i < TAB_SIZE() - 1; i++) {
        if(0 != from_visual(first,TAB_SIZE() - i))
            std::cout << i << std::endl;
        CHECK_EQUAL(0, from_visual(first, TAB_SIZE() - i));
    }
    CHECK_EQUAL(1, from_visual(first,TAB_SIZE()));
    CHECK_EQUAL(3, from_visual(first,to_visual(second,3)));
    CHECK_EQUAL(3, to_visual(first,from_visual(second,3)));
}
<|endoftext|>


<commit_before>#ifndef PROTON_REF_HEADER
#define PROTON_REF_HEADER

/** @file ref.hpp
 *  @brief the core header for reference support.
 */

#include <memory>
#include <utility>
#include <functional>
#include <tuple>
#include <type_traits>
#include <proton/pool.hpp>

namespace proton{

namespace detail{

class refc_t {
private:
    long __r;
public:
    refc_t():__r(0)
    {}

    refc_t(const refc_t& r):__r(0)
    {}

    refc_t& operator=(const refc_t& r)
    {
        return *this;
    }

    bool operator<(long i)const
    {
        return __r < i;
    }

    bool operator==(long i)const
    {
        return __r == i;
    }

    void enter()
    {
        ++__r;
    }

    long release()
    {
        return --__r;
    }

    long count() const
    {
        return __r;
    }
};

} // ns detail

/** @defgroup ref 1 Smart reference
 * Provide core reference support for proton.
 * @{
 */

class init_alloc{};
extern init_alloc alloc; ///< explicitly demand to initialize an object.

class init_alloc_inner{};
extern init_alloc_inner alloc_inner; //< for inner use of ref_.

/** test a ref null or not.
 * @param x the ref to be checked
 * @return true: x doesn't refer to any object, false: x refers to an object.
 */
template<typename refT> bool is_null(const refT& x)
{
    return &x.__o()==NULL;
}

/** test a ref valid or not.
 * @param x the ref to be checked
 * @return true: x refers to an object, false: x doesn't refer to any object.
 */
template<typename refT> bool is_valid(const refT& x)
{
    return &x.__o()!=NULL;
}

/** declare copy_to().
 * For object classes which need to support copy().
 */
#define PROTON_COPY_DECL(type)\
    virtual void copy_to(void* p)const\
    {\
        new (p) type(*this);\
    }

/** declare copy_to() without virtual.
 * For object classes which need to support copy(), without inheritance.
 */
#define PROTON_COPY_DECL_NV(type)\
    void copy_to(void* p)const\
    {\
        new (p) type(*this);\
    }

/** Generate a copy of object.
 * Note: the alloc_t of refT must support duplicate() like smart_allocator.
 * @param x a ref to an obj supporting the method: void copy_to(void* new_addr)const.
 *          You can use PROTON_COPY_DECL() or PROTON_COPY_DECL_NV() to declare copy_to()
 *          in the obj class.
 * @return a cloned obj of x
 */
template<typename refT> refT copy(const refT& x)
{
    if(is_null(x))
        return refT();
    typedef typename refT::alloc_t alloc_t;
    detail::refc_t* p=(detail::refc_t*)alloc_t::duplicate(x._rp);
    new (p) detail::refc_t();
    typename refT::obj_t* q=(typename refT::obj_t *)(p+1);
    x->copy_to((void*)q);
    return refT(alloc_inner,p,q);
}

/** reset a ref to release its object if any.
 * @param x the ref to be resetted.
 */
template<typename refT> void reset(refT& x)
{
    x.release();
}

/** get the reference count of the object.
 * @param x refers to the object
 * @return the reference count.
 */
template<typename refT> long ref_count(const refT& x)
{
    if(x._rp)
        return x._rp->count();
    else
        return 0;
}

/** cast from a ref type to another.
 * if casting fails, throw std::bad_cast().
 * @param x the original ref
 * @return the casted one
 */
template<typename T, typename refT> T cast(const refT& x)
{
    static_assert(std::is_class<typename T::proton_ref_self_t>(), "The target type is not a ref_ type");
    typedef typename T::obj_t target_t;
    if(std::is_base_of<target_t, typename refT::obj_t>())
        return T(alloc_inner, x._rp, static_cast<target_t*>(x._p));
    else{
        target_t* p=dynamic_cast<target_t*>(x._p);
        if(p)
            return T(alloc_inner, x._rp, p);
        else
            throw std::bad_cast();
    }
}

/** The core reference support template.
 * @param allocator It must support confiscate(), and allocator::allocate() must be static.
 *                  See smart_allocator in <proton/pool.hpp>
 */
template<typename objT, typename allocator=smart_allocator<objT> > struct ref_ {
friend void reset<ref_>(ref_& x);
friend ref_ copy<ref_>(const ref_& x);
friend long ref_count<ref_>(const ref_& x);
template<typename T, typename ref_>friend  T cast(const ref_& x);

public:
    typedef ref_ proton_ref_self_t;
    typedef std::ostream proton_ostream_t;
    typedef objT obj_t;
    typedef allocator alloc_t;

protected:
    detail::refc_t * _rp;
    objT*    _p;

protected:
    void enter(detail::refc_t* rp)
    {
        _rp=rp;
        if(_rp)
            _rp->enter();
    }

    void assign(detail::refc_t* rp, objT* p)
    {
        if(rp!=_rp){
            detail::refc_t* rp_old=_rp;
            objT* p_old=_p;

            _rp=rp;
            _p=p;

            if(rp_old){
                long r=rp_old->release();
                if(!r){
                    p_old->~objT(); // may throw
                    alloc_t::confiscate(rp_old);
                }
            }
        }
    }

    void release()
    {
        if(_rp){
            long r=_rp->release();
            if(!r){
                _p->~objT();
                alloc_t::confiscate(_rp);
            }
            _rp=NULL;
            _p=NULL;
        }
    }

public:
    /** default ctor.
     * Doesn't refer to any object.
     */
    ref_():_rp(NULL), _p(NULL)
    {}

    // inner use
    ref_(init_alloc_inner, detail::refc_t* rp, objT* p):_rp(rp), _p(p)
    {
        if(_rp)
            _rp->enter();
    }

    template<typename ...argT> explicit ref_(init_alloc, argT&& ...a)
    {
        struct ref_obj_t{
            detail::refc_t r;
            obj_t o;
        };
        typedef typename alloc_t::template rebind<ref_obj_t>::other real_alloc;
        ref_obj_t* p=real_alloc::allocate(1);
        if(p){
            new (&(p->r)) detail::refc_t();
            new (&p->o) obj_t(a...);
            _p=&(p->o);
            enter(&(p->r));
        }
    }

    template<typename ...argT> explicit ref_(argT&& ...a)
    {
        struct ref_obj_t{
            detail::refc_t r;
            obj_t o;
        };
        typedef typename alloc_t::template rebind<ref_obj_t>::other real_alloc;
        ref_obj_t* p=real_alloc::allocate(1);
        if(p){
            new (&(p->r)) detail::refc_t();
            new (&(p->o)) obj_t(a...);
            _p=&(p->o);
            enter(&(p->r));
        }
    }

    /** const copy ctor.
     */
    ref_(const ref_& r):_p(r._p)
    {
        enter(r._rp);
    }

    /** copy ctor.
     */
    ref_(ref_& r):_p(r._p)
    {
        enter(r._rp);
    }

    /** move ctor.
     */
    ref_(ref_&& r):_p(r._p)
    {
        _rp=r._rp;
        r._rp=NULL;
        r._p=NULL;
    }

    /** assign operator.
     */
    ref_& operator=(ref_ r)
    {
        assign(r._rp,r._p);
        r._rp=NULL;
        r._p=NULL;
        return *this;
    }

    /** dtor.
     */
    ~ref_()
    {
        release();
    }

public:
    /** conversion to const baseT&.
     * Notice! NEVER convert to a non-const ref from here!
     */
    template<typename baseT> operator const baseT& () const
	{
		static_assert(std::is_class<typename baseT::proton_ref_self_t>(), "The target type is not a ref_ type");
		static_assert(std::is_base_of<typename baseT::obj_t, obj_t>(), "The target type is not a base type of obj_t");
		static_assert(static_cast<typename baseT::obj_t*>((obj_t*)4096)==(typename baseT::obj_t*)4096, "can not convert to a non-first-base ref_");
		return reinterpret_cast<const baseT&>(*this);
	}

    /** conversion to baseT.
     */
	template<typename baseT> operator baseT () const
	{
		static_assert(std::is_class<typename baseT::proton_ref_self_t>(), "The target type is not a ref_ type");
		static_assert(std::is_base_of<typename baseT::obj_t, obj_t>(), "The target type is not a base type of obj_t");
		return baseT(alloc_inner, _rp, static_cast<typename baseT::obj_t*>(_p));
	}

public:
    const objT& __o()const
    {
        return *_p;
    }

    objT& __o()
    {
        return *_p;
    }

    objT& operator *()
    {
        return __o();
    }

    const objT& operator *()const
    {
        return __o();
    }

    /** operator-> points to the object refered.
     */
    objT* operator->()
    {
        return &__o();
    }

    /** operator-> points to the object refered.
     */
    const objT* operator->()const
    {
        return &__o();
    }

    /** general operator== for refs.
     * Need T::obj_t to implenment operator==.
     */
    template<typename T> bool operator==(const T& x)const
    {
        static_assert(std::is_class<typename T::proton_ref_self_t>(),
                      "The target type is not a ref_ type");
        if((void*)&(__o())==(void*)&(x.__o()))
            return true;
        if(is_null(*this)||is_null(x))
            return false;
        return __o() == x.__o();
    }

    /** general operator< for refs.
     * Need T::obj_t to implenment operator<.
     */
    template<typename T> bool operator<(const T& x)const
    {
        static_assert(std::is_class<typename T::proton_ref_self_t>(),
                      "The target type is not a ref_ type");
        if((void*)&(x.__o())==(void*)&(__o()))
            return false;
        if(is_null(*this))
            return true;
        if(is_null(x))
            return false;
        return __o() < x.__o();
    }
};

/** general output for refs.
 * Need T::obj_t to implenment the method: void output(std::ostream& s)const.
 * Don't forget virtual when needed.
 */
template<typename T>std::ostream& operator<<(typename T::proton_ostream_t& s,
                                   const T& y)
{
    if(is_null(y)){
        s << "<>" ;
        return s;
    }
    y->output(s);
    return s;
}

/** general operator< & operator== for objects.
 * Need obj_t to implenment T1 key()const.
 * Don't forget virtual when needed.
 * [TODO] need an example.
 */
#define PROTON_KEY_DECL(type)\
    bool operator<(const type& y)const\
    {\
        return key()<y.key();\
    }\
    \
    bool operator==(const type& y)const\
    {\
        return key()==y.key();\
    }\

/** general key_hash for refs.
 * Need T::obj_t to implenment T1 key()const, and T1 must support std::hash.
 * Don't forget virtual when needed.
 * [TODO] need an example.
 */
template<typename T>struct key_hash{
public:
    size_t operator()(const T& x)const
    {
        if(is_null(x))
            return 0;
        else{
            typedef decltype(x->key()) ref_t;
            typedef typename std::remove_reference<ref_t>::type const_key_t;
            typedef typename std::remove_cv<const_key_t>::type key_t;
            return std::hash<key_t>()(x->key());
        }
    }
};

/** general subkey_hash for refs.
 * Need T::obj_t to implenment T1 key()const, and T1 is a tuple,
 * and the key_seq item of T1 must support std::hash.
 * Don't forget virtual when needed.
 * [TODO] need an example.
 */
template<typename T, int key_seq=0>struct subkey_hash{
public:
    size_t operator()(const T& x)const
    {
        typedef decltype(std::get<key_seq>(x->key())) ref_t;
        typedef typename std::remove_reference<ref_t>::type const_key_t;
        typedef typename std::remove_cv<const_key_t>::type key_t;
        if(is_null(x))
            return 0;
        else
            return std::hash<key_t>()(std::get<key_seq>(x->key()));
    }
};

/**
 * @}
 */
};

using namespace std::rel_ops;

#endif // PROTON_REF_HEADER
<commit_msg>fix remarks<commit_after>#ifndef PROTON_REF_HEADER
#define PROTON_REF_HEADER

/** @file ref.hpp
 *  @brief the core header for reference support.
 */

#include <memory>
#include <utility>
#include <functional>
#include <tuple>
#include <type_traits>
#include <proton/pool.hpp>

namespace proton{

namespace detail{

class refc_t {
private:
    long __r;
public:
    refc_t():__r(0)
    {}

    refc_t(const refc_t& r):__r(0)
    {}

    refc_t& operator=(const refc_t& r)
    {
        return *this;
    }

    bool operator<(long i)const
    {
        return __r < i;
    }

    bool operator==(long i)const
    {
        return __r == i;
    }

    void enter()
    {
        ++__r;
    }

    long release()
    {
        return --__r;
    }

    long count() const
    {
        return __r;
    }
};

} // ns detail

/** @defgroup ref 1 Smart reference
 * Provide core reference support for proton.
 * @{
 */

class init_alloc{};
extern init_alloc alloc; ///< explicitly demand to initialize an object.

class init_alloc_inner{};
extern init_alloc_inner alloc_inner; //< for inner use of ref_.

/** test a ref null or not.
 * @param x the ref to be checked
 * @return true: x doesn't refer to any object, false: x refers to an object.
 */
template<typename refT> bool is_null(const refT& x)
{
    return &x.__o()==NULL;
}

/** test a ref valid or not.
 * @param x the ref to be checked
 * @return true: x refers to an object, false: x doesn't refer to any object.
 */
template<typename refT> bool is_valid(const refT& x)
{
    return &x.__o()!=NULL;
}

/** declare copy_to().
 * For object classes which need to support copy().
 */
#define PROTON_COPY_DECL(type)\
    virtual void copy_to(void* p)const\
    {\
        new (p) type(*this);\
    }

/** declare copy_to() without virtual.
 * For object classes which need to support copy(), without inheritance.
 */
#define PROTON_COPY_DECL_NV(type)\
    void copy_to(void* p)const\
    {\
        new (p) type(*this);\
    }

/** Generate a copy of object.
 * Note: the alloc_t of refT must support duplicate() like smart_allocator.
 * @param x a ref to an obj supporting the method: void copy_to(void* new_addr)const.
 *          You can use PROTON_COPY_DECL() or PROTON_COPY_DECL_NV() to declare copy_to()
 *          in the obj class.
 * @return a cloned obj of x
 */
template<typename refT> refT copy(const refT& x)
{
    if(is_null(x))
        return refT();
    typedef typename refT::alloc_t alloc_t;
    detail::refc_t* p=(detail::refc_t*)alloc_t::duplicate(x._rp);
    new (p) detail::refc_t();
    typename refT::obj_t* q=(typename refT::obj_t *)(p+1);
    x->copy_to((void*)q);
    return refT(alloc_inner,p,q);
}

/** reset a ref to release its object if any.
 * @param x the ref to be resetted.
 */
template<typename refT> void reset(refT& x)
{
    x.release();
}

/** get the reference count of the object.
 * @param x refers to the object
 * @return the reference count.
 */
template<typename refT> long ref_count(const refT& x)
{
    if(x._rp)
        return x._rp->count();
    else
        return 0;
}

/** cast from a ref type to another.
 * if casting fails, throw std::bad_cast().
 * @param x the original ref
 * @return the casted one
 */
template<typename T, typename refT> T cast(const refT& x)
{
    static_assert(std::is_class<typename T::proton_ref_self_t>(), "The target type is not a ref_ type");
    typedef typename T::obj_t target_t;
    if(std::is_base_of<target_t, typename refT::obj_t>())
        return T(alloc_inner, x._rp, static_cast<target_t*>(x._p));
    else{
        target_t* p=dynamic_cast<target_t*>(x._p);
        if(p)
            return T(alloc_inner, x._rp, p);
        else
            throw std::bad_cast();
    }
}

/** The core reference support template.
 * @param allocator It must support confiscate(), and allocator::allocate() must be static.
 *                  See smart_allocator in <proton/pool.hpp>
 */
template<typename objT, typename allocator=smart_allocator<objT> > struct ref_ {
friend void reset<ref_>(ref_& x);
friend ref_ copy<ref_>(const ref_& x);
friend long ref_count<ref_>(const ref_& x);
template<typename T, typename ref_>friend  T cast(const ref_& x);

public:
    typedef ref_ proton_ref_self_t;
    typedef std::ostream proton_ostream_t;
    typedef objT obj_t;
    typedef allocator alloc_t;

protected:
    detail::refc_t * _rp;
    objT*    _p;

protected:
    void enter(detail::refc_t* rp)
    {
        _rp=rp;
        if(_rp)
            _rp->enter();
    }

    void assign(detail::refc_t* rp, objT* p)
    {
        if(rp!=_rp){
            detail::refc_t* rp_old=_rp;
            objT* p_old=_p;

            _rp=rp;
            _p=p;

            if(rp_old){
                long r=rp_old->release();
                if(!r){
                    p_old->~objT(); // may throw
                    alloc_t::confiscate(rp_old);
                }
            }
        }
    }

    void release()
    {
        if(_rp){
            long r=_rp->release();
            if(!r){
                _p->~objT();
                alloc_t::confiscate(_rp);
            }
            _rp=NULL;
            _p=NULL;
        }
    }

public:
    /** default ctor.
     * Doesn't refer to any object.
     */
    ref_():_rp(NULL), _p(NULL)
    {}

    // inner use
    ref_(init_alloc_inner, detail::refc_t* rp, objT* p):_rp(rp), _p(p)
    {
        if(_rp)
            _rp->enter();
    }

    template<typename ...argT> explicit ref_(init_alloc, argT&& ...a)
    {
        struct ref_obj_t{
            detail::refc_t r;
            obj_t o;
        };
        typedef typename alloc_t::template rebind<ref_obj_t>::other real_alloc;
        ref_obj_t* p=real_alloc::allocate(1);
        if(p){
            new (&(p->r)) detail::refc_t();
            new (&p->o) obj_t(a...);
            _p=&(p->o);
            enter(&(p->r));
        }
    }

    template<typename ...argT> explicit ref_(argT&& ...a)
    {
        struct ref_obj_t{
            detail::refc_t r;
            obj_t o;
        };
        typedef typename alloc_t::template rebind<ref_obj_t>::other real_alloc;
        ref_obj_t* p=real_alloc::allocate(1);
        if(p){
            new (&(p->r)) detail::refc_t();
            new (&(p->o)) obj_t(a...);
            _p=&(p->o);
            enter(&(p->r));
        }
    }

    /** const copy ctor.
     */
    ref_(const ref_& r):_p(r._p)
    {
        enter(r._rp);
    }

    /** copy ctor.
     */
    ref_(ref_& r):_p(r._p)
    {
        enter(r._rp);
    }

    /** move ctor.
     */
    ref_(ref_&& r):_p(r._p)
    {
        _rp=r._rp;
        r._rp=NULL;
        r._p=NULL;
    }

    /** assign operator.
     */
    ref_& operator=(ref_ r)
    {
        assign(r._rp,r._p);
        r._rp=NULL;
        r._p=NULL;
        return *this;
    }

    /** dtor.
     */
    ~ref_()
    {
        release();
    }

public:
    /** conversion to const baseT&.
     * Notice! NEVER convert to a non-const ref from here!
     */
    template<typename baseT> operator const baseT& () const
	{
		static_assert(std::is_class<typename baseT::proton_ref_self_t>(), "The target type is not a ref_ type");
		static_assert(std::is_base_of<typename baseT::obj_t, obj_t>(), "The target type is not a base type of obj_t");
		static_assert(static_cast<typename baseT::obj_t*>((obj_t*)4096)==(typename baseT::obj_t*)4096, "can not convert to a non-first-base ref_");
		return reinterpret_cast<const baseT&>(*this);
	}

    /** conversion to baseT.
     */
	template<typename baseT> operator baseT () const
	{
		static_assert(std::is_class<typename baseT::proton_ref_self_t>(), "The target type is not a ref_ type");
		static_assert(std::is_base_of<typename baseT::obj_t, obj_t>(), "The target type is not a base type of obj_t");
		return baseT(alloc_inner, _rp, static_cast<typename baseT::obj_t*>(_p));
	}

public:
    const objT& __o()const
    {
        return *_p;
    }

    objT& __o()
    {
        return *_p;
    }

    objT& operator *()
    {
        return __o();
    }

    const objT& operator *()const
    {
        return __o();
    }

    /** operator-> points to the object refered.
     */
    objT* operator->()
    {
        return &__o();
    }

    /** operator-> points to the object refered.
     */
    const objT* operator->()const
    {
        return &__o();
    }

    /** general operator== for refs.
     * Need to implement obj_t == T::obj_t.
     */
    template<typename T> bool operator==(const T& x)const
    {
        static_assert(std::is_class<typename T::proton_ref_self_t>(),
                      "The target type is not a ref_ type");
        if((void*)&(__o())==(void*)&(x.__o()))
            return true;
        if(is_null(*this)||is_null(x))
            return false;
        return __o() == x.__o();
    }

    /** general operator< for refs.
     * Need to implement obj_t < T::obj_t.
     */
    template<typename T> bool operator<(const T& x)const
    {
        static_assert(std::is_class<typename T::proton_ref_self_t>(),
                      "The target type is not a ref_ type");
        if((void*)&(x.__o())==(void*)&(__o()))
            return false;
        if(is_null(*this))
            return true;
        if(is_null(x))
            return false;
        return __o() < x.__o();
    }
};

/** general output for refs.
 * Need T::obj_t to implenment the method: void output(std::ostream& s)const.
 * Don't forget virtual when needed.
 */
template<typename T>std::ostream& operator<<(typename T::proton_ostream_t& s,
                                   const T& y)
{
    if(is_null(y)){
        s << "<>" ;
        return s;
    }
    y->output(s);
    return s;
}

/** general operator< & operator== for objects.
 * Need obj_t to implenment T1 key()const.
 * Don't forget virtual when needed.
 * [TODO] need an example.
 */
#define PROTON_KEY_DECL(type)\
    bool operator<(const type& y)const\
    {\
        return key()<y.key();\
    }\
    \
    bool operator==(const type& y)const\
    {\
        return key()==y.key();\
    }\

/** general key_hash for refs.
 * Need T::obj_t to implenment T1 key()const, and T1 must support std::hash.
 * Don't forget virtual when needed.
 * [TODO] need an example.
 */
template<typename T>struct key_hash{
public:
    size_t operator()(const T& x)const
    {
        if(is_null(x))
            return 0;
        else{
            typedef decltype(x->key()) ref_t;
            typedef typename std::remove_reference<ref_t>::type const_key_t;
            typedef typename std::remove_cv<const_key_t>::type key_t;
            return std::hash<key_t>()(x->key());
        }
    }
};

/** general subkey_hash for refs.
 * Need T::obj_t to implenment T1 key()const, and T1 is a tuple,
 * and the key_seq item of T1 must support std::hash.
 * Don't forget virtual when needed.
 * [TODO] need an example.
 */
template<typename T, int key_seq=0>struct subkey_hash{
public:
    size_t operator()(const T& x)const
    {
        typedef decltype(std::get<key_seq>(x->key())) ref_t;
        typedef typename std::remove_reference<ref_t>::type const_key_t;
        typedef typename std::remove_cv<const_key_t>::type key_t;
        if(is_null(x))
            return 0;
        else
            return std::hash<key_t>()(std::get<key_seq>(x->key()));
    }
};

/**
 * @}
 */
};

using namespace std::rel_ops;

#endif // PROTON_REF_HEADER
<|endoftext|>


<commit_before>#pragma once
#include <boss.h>

#include "boss_integration_opencv-3.1.0.h"
#include <addon/opencv-3.1.0_for_boss/include/opencv2/opencv.hpp>
extern "C"
{
    #include <addon/opencv-3.1.0_for_boss/include/opencv/cv.h>
    #include <addon/opencv-3.1.0_for_boss/include/opencv/highgui.h>
}

#include <boss.hpp>
#include <element/boss_point.hpp>
#include <element/boss_rect.hpp>

class CVObject
{
public:
    CVObject();
    ~CVObject();

public:
    // MOG2
    bool mEnableMOG2;
    sint32 mOldHistory;
    double mOldThreshold;
    bool mOldShadows;
    cv::Mat mMOG2Mask;
    cv::Mat mMOG2Image;
    cv::Ptr<cv::BackgroundSubtractor> mMOG2;
    // Canny
    bool mEnableCanny;
    double mLow;
    double mHigh;
    sint32 mAperture;
    cv::Mat mCannyImage;

    // Result
    cv::Mat mGrayImage;
    cv::Mat* mResult;
};
<commit_msg>1.1.3<commit_after>#pragma once
#include <boss.h>

#if !BOSS_WINDOWS
    #define _CTYPE_U 0x01
    #define _CTYPE_L 0x02
    #define _CTYPE_D 0x04
    #define _CTYPE_S 0x08
    #define _CTYPE_P 0x10
    #define _CTYPE_C 0x20
    #define _CTYPE_X 0x40
    #define _CTYPE_B 0x80
    #define _CTYPE_R (_CTYPE_P|_CTYPE_U|_CTYPE_L|_CTYPE_D|_CTYPE_B)
    #define _CTYPE_A (_CTYPE_L|_CTYPE_U)
    #define _CTYPE_N _CTYPE_D
    #define _U _CTYPE_U
    #define _L _CTYPE_L
    #define _N _CTYPE_N
    #define _S _CTYPE_S
    #define _P _CTYPE_P
    #define _C _CTYPE_C
    #define _X _CTYPE_X
    #define _B _CTYPE_B
#endif

#include "boss_integration_opencv-3.1.0.h"
#include <addon/opencv-3.1.0_for_boss/include/opencv2/opencv.hpp>
extern "C"
{
    #include <addon/opencv-3.1.0_for_boss/include/opencv/cv.h>
    #include <addon/opencv-3.1.0_for_boss/include/opencv/highgui.h>
}

#include <boss.hpp>
#include <element/boss_point.hpp>
#include <element/boss_rect.hpp>

class CVObject
{
public:
    CVObject();
    ~CVObject();

public:
    // MOG2
    bool mEnableMOG2;
    sint32 mOldHistory;
    double mOldThreshold;
    bool mOldShadows;
    cv::Mat mMOG2Mask;
    cv::Mat mMOG2Image;
    cv::Ptr<cv::BackgroundSubtractor> mMOG2;
    // Canny
    bool mEnableCanny;
    double mLow;
    double mHigh;
    sint32 mAperture;
    cv::Mat mCannyImage;

    // Result
    cv::Mat mGrayImage;
    cv::Mat* mResult;
};
<|endoftext|>


<commit_before>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */
#ifndef INCLUDED_SVX_NBDTMG_HXX
#define INCLUDED_SVX_NBDTMG_HXX
#include <svx/svxdllapi.h>
#include <boost/shared_ptr.hpp>
#include <vector>
#include <editeng/numitem.hxx>
#include <vcl/font.hxx>

namespace svx { namespace sidebar {

#define DEFAULT_BULLET_TYPES                            8
#define DEFAULT_NONE                                    10
#define DEFAULT_NUM_TYPE_MEMBER                         5
#define DEFAULT_NUM_VALUSET_COUNT                       8
#define DEFAULT_NUMBERING_CACHE_FORMAT_VERSION          0x10

typedef sal_uInt16 NBOType;
namespace eNBOType
{
    const NBOType BULLETS = 0x01;
    const NBOType GRAPHICBULLETS = 0x02;
    const NBOType NUMBERING = 0x03;
    const NBOType OUTLINE = 0x04;
    const NBOType MIXBULLETS = 0x05;
}

typedef sal_uInt16 NBType;
namespace eNBType
{
    const NBOType BULLETS = 0x01;
    const NBOType GRAPHICBULLETS = 0x02;
}

class  SVX_DLLPUBLIC NumSettings_Impl
{
    public:
        short       nNumberType;
        short       nParentNumbering;
        SvxNumberFormat::LabelFollowedBy eLabelFollowedBy;
        long        nTabValue;
        SvxAdjust   eNumAlign;
        long            nNumAlignAt;
        long            nNumIndentAt;
        rtl::OUString   sPrefix;
        rtl::OUString   sSuffix;
        rtl::OUString   sBulletChar;
        rtl::OUString   sBulletFont;
        SvxBrushItem   *pBrushItem;
        Size            aSize;

    public:
        NumSettings_Impl()
            : nNumberType(0)
            , nParentNumbering(0)
            , pBrushItem(0)
            , aSize(0,0)
        {}
        ~NumSettings_Impl(){}
};

typedef NumSettings_Impl* NumSettings_ImplPtr;
typedef std::vector< boost::shared_ptr<NumSettings_Impl> > NumSettingsArr_Impl;

class  SVX_DLLPUBLIC BulletsSettings
{
    public:
        sal_Bool        bIsCustomized;
        rtl::OUString   sDescription;
        NBType      eType;
    public:
        BulletsSettings(NBType eTy) :
            bIsCustomized(sal_False),
            eType(eTy)
            {}
        virtual ~BulletsSettings(){}
};

class  SVX_DLLPUBLIC BulletsSettings_Impl:public BulletsSettings
{
    public:
        sal_Unicode cBulletChar;
        Font            aFont;

    public:
        BulletsSettings_Impl(NBType eTy)
            : BulletsSettings(eTy)
            , cBulletChar(0)
            {}
        virtual ~BulletsSettings_Impl(){}
};

class  SVX_DLLPUBLIC GrfBulDataRelation: public BulletsSettings
{
    public:
        OUString    sGrfName;
        sal_uInt16  nTabIndex;
        sal_uInt16  nGallaryIndex;
        const Graphic*  pGrfObj;
        Size aSize;
    GrfBulDataRelation(NBType eTy):
        BulletsSettings(eTy),
        nTabIndex((sal_uInt16)0xFFFF),
        nGallaryIndex((sal_uInt16)0xFFFF),
        pGrfObj(0),
        aSize(0,0)
    {}
    virtual ~GrfBulDataRelation(){}
};

class  SVX_DLLPUBLIC MixBulletsSettings_Impl
{
    public:
        NBType          eType;
        sal_uInt16          nIndex; //index in the tab page display
        sal_uInt16          nIndexDefault;
        BulletsSettings*    pBullets;
    public:
        MixBulletsSettings_Impl(NBType eTy) :
            eType(eTy),
            nIndex((sal_uInt16)0xFFFF),
            nIndexDefault((sal_uInt16)0xFFFF),
            pBullets(0)
            {}
        ~MixBulletsSettings_Impl(){}
};

class  SVX_DLLPUBLIC NumberSettings_Impl
{
    public:
        sal_Bool        bIsCustomized;
        rtl::OUString   sDescription;
        sal_uInt16      nIndex; //index in the tab page display
        sal_uInt16      nIndexDefault;
        NumSettings_Impl    *pNumSetting;
    public:
        NumberSettings_Impl() :
            bIsCustomized(sal_False),
            nIndex((sal_uInt16)0xFFFF),
            nIndexDefault((sal_uInt16)0xFFFF),
            pNumSetting(NULL)
            {}
        ~NumberSettings_Impl(){}
};

typedef NumberSettings_Impl* NumberSettings_ImplPtr;
typedef std::vector< boost::shared_ptr<NumberSettings_Impl> > NumberSettingsArr_Impl;

class  SVX_DLLPUBLIC OutlineSettings_Impl
{
    public:
        sal_Bool        bIsCustomized;
        rtl::OUString   sDescription;
        NumSettingsArr_Impl *pNumSettingsArr;
    public:
        OutlineSettings_Impl() :
            bIsCustomized(sal_False),
            pNumSettingsArr(NULL)
            {}
        ~OutlineSettings_Impl(){
        }
};

class SVX_DLLPUBLIC NBOTypeMgrBase
{
    public:
        NBOType         eType;
    private:
        const SfxItemSet*   pSet;
        SfxMapUnit      eCoreUnit;
        // store the attributes passed from pSet
        OUString        aNumCharFmtName;
        void            StoreBulCharFmtName_impl();
        void            StoreMapUnit_impl();

    public:
        NBOTypeMgrBase(const NBOType aType)
            : eType(aType)
            , pSet(0)
            , eCoreUnit(SFX_MAPUNIT_TWIP)
            , aNumCharFmtName(OUString())
            , bIsLoading(false)
        {}
        NBOTypeMgrBase(const NBOType aType,const SfxItemSet* pArg)
            : eType(aType)
            , pSet(pArg)
            , eCoreUnit(SFX_MAPUNIT_TWIP)
            , aNumCharFmtName(OUString())
            , bIsLoading(false)
        {}
        NBOTypeMgrBase(const NBOTypeMgrBase& aTypeMgr)
        {
            eType = aTypeMgr.eType;
            pSet = aTypeMgr.pSet;
            eCoreUnit = aTypeMgr.eCoreUnit;
            aNumCharFmtName = aTypeMgr.aNumCharFmtName;
            bIsLoading = false;
        }
        virtual ~NBOTypeMgrBase() {}
        virtual void Init()=0;
        virtual sal_uInt16 GetNBOIndexForNumRule(SvxNumRule& aNum,sal_uInt16 mLevel,sal_uInt16 nFromIndex=0)=0;
        virtual sal_Bool RelplaceNumRule(SvxNumRule& aNum,sal_uInt16 nIndex,sal_uInt16 mLevel=(sal_uInt16)0xFFFF)=0;
        virtual sal_Bool ApplyNumRule(SvxNumRule& aNum,sal_uInt16 nIndex,sal_uInt16 mLevel=(sal_uInt16)0xFFFF, sal_Bool isDefault=false,sal_Bool isResetSize=false)=0;
        virtual OUString GetDescription(sal_uInt16 nIndex,sal_Bool isDefault=false)=0;
        virtual sal_Bool IsCustomized(sal_uInt16 nIndex)=0;
        sal_uInt16 IsSingleLevel(sal_uInt16 nCurLevel);
        const SfxItemSet* GetItems() { return pSet;}
        // store the attributes passed from pSet
        void SetItems(const SfxItemSet* pArg) { pSet = pArg;StoreBulCharFmtName_impl();StoreMapUnit_impl();}
    protected:
        OUString GetBulCharFmtName();
        SfxMapUnit GetMapUnit();
    protected:
        bool    bIsLoading;
        void    ImplLoad(OUString filename);
        void    ImplStore(OUString filename);

};

class SVX_DLLPUBLIC BulletsTypeMgr: public NBOTypeMgrBase
{
    friend class OutlineTypeMgr;
    friend class NumberingTypeMgr;
    public:
        static sal_Unicode aDynamicBulletTypes[DEFAULT_BULLET_TYPES];
        static sal_Unicode aDynamicRTLBulletTypes[DEFAULT_BULLET_TYPES];
        static BulletsSettings_Impl* pActualBullets[DEFAULT_BULLET_TYPES];
    public:
        BulletsTypeMgr();
        BulletsTypeMgr(const BulletsTypeMgr& aTypeMgr);
        virtual ~BulletsTypeMgr() {}
        virtual void Init();
        virtual sal_uInt16 GetNBOIndexForNumRule(SvxNumRule& aNum,sal_uInt16 mLevel,sal_uInt16 nFromIndex=0);
        virtual sal_Bool RelplaceNumRule(SvxNumRule& aNum,sal_uInt16 nIndex,sal_uInt16 mLevel=(sal_uInt16)0xFFFF);
        virtual sal_Bool ApplyNumRule(SvxNumRule& aNum,sal_uInt16 nIndex,sal_uInt16 mLevel=(sal_uInt16)0xFFFF,sal_Bool isDefault=false,sal_Bool isResetSize=false);
        virtual OUString GetDescription(sal_uInt16 nIndex,sal_Bool isDefault=false);
        virtual sal_Bool IsCustomized(sal_uInt16 nIndex);
        sal_Unicode GetBulChar(sal_uInt16 nIndex);
        Font GetBulCharFont(sal_uInt16 nIndex);
        static BulletsTypeMgr& GetInstance();
};

class SVX_DLLPUBLIC GraphyicBulletsTypeMgr: public NBOTypeMgrBase
{
    friend class OutlineTypeMgr;
    friend class NumberingTypeMgr;
    public:
        typedef std::vector<GrfBulDataRelation*> ListType;
        ListType aGrfDataLst;
    public:
        GraphyicBulletsTypeMgr();
        GraphyicBulletsTypeMgr(const GraphyicBulletsTypeMgr& aTypeMgr);
        virtual ~GraphyicBulletsTypeMgr();
        virtual void Init();
        virtual sal_uInt16 GetNBOIndexForNumRule(SvxNumRule& aNum,sal_uInt16 mLevel,sal_uInt16 nFromIndex=0);
        virtual sal_Bool RelplaceNumRule(SvxNumRule& aNum,sal_uInt16 nIndex,sal_uInt16 mLevel=(sal_uInt16)0xFFFF);
        virtual sal_Bool ApplyNumRule(SvxNumRule& aNum,sal_uInt16 nIndex,sal_uInt16 mLevel=(sal_uInt16)0xFFFF,sal_Bool isDefault=false,sal_Bool isResetSize=false);
        virtual OUString GetDescription(sal_uInt16 nIndex,sal_Bool isDefault=false);
        virtual sal_Bool IsCustomized(sal_uInt16 nIndex);
        OUString GetGrfName(sal_uInt16 nIndex);
        static GraphyicBulletsTypeMgr& GetInstance();
};

class SVX_DLLPUBLIC MixBulletsTypeMgr: public NBOTypeMgrBase
{
    friend class OutlineTypeMgr;
    friend class NumberingTypeMgr;
    public:
        static MixBulletsSettings_Impl* pActualBullets[DEFAULT_BULLET_TYPES];
        static MixBulletsSettings_Impl* pDefaultActualBullets[DEFAULT_BULLET_TYPES];
    public:
        MixBulletsTypeMgr();
        MixBulletsTypeMgr(const MixBulletsTypeMgr& aTypeMgr);
        virtual ~MixBulletsTypeMgr() {}
        virtual void Init();
        virtual sal_uInt16 GetNBOIndexForNumRule(SvxNumRule& aNum,sal_uInt16 mLevel,sal_uInt16 nFromIndex=0);
        virtual sal_Bool RelplaceNumRule(SvxNumRule& aNum,sal_uInt16 nIndex,sal_uInt16 mLevel=(sal_uInt16)0xFFFF);
        virtual sal_Bool ApplyNumRule(SvxNumRule& aNum,sal_uInt16 nIndex,sal_uInt16 mLevel=(sal_uInt16)0xFFFF,sal_Bool isDefault=false,sal_Bool isResetSize=false);
        virtual OUString GetDescription(sal_uInt16 nIndex,sal_Bool isDefault=false);
        virtual sal_Bool IsCustomized(sal_uInt16 nIndex);
        static MixBulletsTypeMgr& GetInstance();
};

class SVX_DLLPUBLIC NumberingTypeMgr: public NBOTypeMgrBase
{
    public:
        NumberSettingsArr_Impl*     pNumberSettingsArr;
        NumberSettingsArr_Impl*     pDefaultNumberSettingsArr;
    public:
        NumberingTypeMgr();
        NumberingTypeMgr(const NumberingTypeMgr& aTypeMgr);
        virtual ~NumberingTypeMgr();
        virtual void Init();
        virtual sal_uInt16 GetNBOIndexForNumRule(SvxNumRule& aNum,sal_uInt16 mLevel,sal_uInt16 nFromIndex=0);
        virtual sal_Bool RelplaceNumRule(SvxNumRule& aNum,sal_uInt16 nIndex,sal_uInt16 mLevel=(sal_uInt16)0xFFFF);
        virtual sal_Bool ApplyNumRule(SvxNumRule& aNum,sal_uInt16 nIndex,sal_uInt16 mLevel=(sal_uInt16)0xFFFF,sal_Bool isDefault=false,sal_Bool isResetSize=false);
        virtual OUString GetDescription(sal_uInt16 nIndex,sal_Bool isDefault=false);
        virtual sal_Bool IsCustomized(sal_uInt16 nIndex);
        static NumberingTypeMgr& GetInstance();
};

class SVX_DLLPUBLIC OutlineTypeMgr: public NBOTypeMgrBase
{
    public:
        OutlineSettings_Impl*       pOutlineSettingsArrs[DEFAULT_NUM_VALUSET_COUNT];
        OutlineSettings_Impl*       pDefaultOutlineSettingsArrs[DEFAULT_NUM_VALUSET_COUNT];
    public:
        OutlineTypeMgr();
        OutlineTypeMgr(const OutlineTypeMgr& aTypeMgr);
        virtual ~OutlineTypeMgr() {}
        virtual void Init();
        virtual sal_uInt16 GetNBOIndexForNumRule(SvxNumRule& aNum,sal_uInt16 mLevel,sal_uInt16 nFromIndex=0);
        virtual sal_Bool RelplaceNumRule(SvxNumRule& aNum,sal_uInt16 nIndex,sal_uInt16 mLevel=(sal_uInt16)0xFFFF);
        virtual sal_Bool ApplyNumRule(SvxNumRule& aNum,sal_uInt16 nIndex,sal_uInt16 mLevel=(sal_uInt16)0xFFFF,sal_Bool isDefault=false,sal_Bool isResetSize=false);
        virtual OUString GetDescription(sal_uInt16 nIndex,sal_Bool isDefault=false);
        virtual sal_Bool IsCustomized(sal_uInt16 nIndex);
        static OutlineTypeMgr& GetInstance();
};
}}
#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<commit_msg>coverity#1028570 : Uninitialized scalar field<commit_after>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */
#ifndef INCLUDED_SVX_NBDTMG_HXX
#define INCLUDED_SVX_NBDTMG_HXX
#include <svx/svxdllapi.h>
#include <boost/shared_ptr.hpp>
#include <vector>
#include <editeng/numitem.hxx>
#include <vcl/font.hxx>

namespace svx { namespace sidebar {

#define DEFAULT_BULLET_TYPES                            8
#define DEFAULT_NONE                                    10
#define DEFAULT_NUM_TYPE_MEMBER                         5
#define DEFAULT_NUM_VALUSET_COUNT                       8
#define DEFAULT_NUMBERING_CACHE_FORMAT_VERSION          0x10

typedef sal_uInt16 NBOType;
namespace eNBOType
{
    const NBOType BULLETS = 0x01;
    const NBOType GRAPHICBULLETS = 0x02;
    const NBOType NUMBERING = 0x03;
    const NBOType OUTLINE = 0x04;
    const NBOType MIXBULLETS = 0x05;
}

typedef sal_uInt16 NBType;
namespace eNBType
{
    const NBOType BULLETS = 0x01;
    const NBOType GRAPHICBULLETS = 0x02;
}

class  SVX_DLLPUBLIC NumSettings_Impl
{
    public:
        short       nNumberType;
        short       nParentNumbering;
        SvxNumberFormat::LabelFollowedBy eLabelFollowedBy;
        long        nTabValue;
        SvxAdjust   eNumAlign;
        long            nNumAlignAt;
        long            nNumIndentAt;
        rtl::OUString   sPrefix;
        rtl::OUString   sSuffix;
        rtl::OUString   sBulletChar;
        rtl::OUString   sBulletFont;
        SvxBrushItem   *pBrushItem;
        Size            aSize;

    public:
        NumSettings_Impl()
            : nNumberType(0)
            , nParentNumbering(0)
            , eLabelFollowedBy(SvxNumberFormat::NOTHING)
            , nTabValue (0)
            , eNumAlign(SVX_ADJUST_LEFT)
            , nNumAlignAt(0)
            , nNumIndentAt(0)
            , pBrushItem(0)
            , aSize(0,0)
        {}
        ~NumSettings_Impl(){}
};

typedef NumSettings_Impl* NumSettings_ImplPtr;
typedef std::vector< boost::shared_ptr<NumSettings_Impl> > NumSettingsArr_Impl;

class  SVX_DLLPUBLIC BulletsSettings
{
    public:
        sal_Bool        bIsCustomized;
        rtl::OUString   sDescription;
        NBType      eType;
    public:
        BulletsSettings(NBType eTy) :
            bIsCustomized(sal_False),
            eType(eTy)
            {}
        virtual ~BulletsSettings(){}
};

class  SVX_DLLPUBLIC BulletsSettings_Impl:public BulletsSettings
{
    public:
        sal_Unicode cBulletChar;
        Font            aFont;

    public:
        BulletsSettings_Impl(NBType eTy)
            : BulletsSettings(eTy)
            , cBulletChar(0)
            {}
        virtual ~BulletsSettings_Impl(){}
};

class  SVX_DLLPUBLIC GrfBulDataRelation: public BulletsSettings
{
    public:
        OUString    sGrfName;
        sal_uInt16  nTabIndex;
        sal_uInt16  nGallaryIndex;
        const Graphic*  pGrfObj;
        Size aSize;
    GrfBulDataRelation(NBType eTy):
        BulletsSettings(eTy),
        nTabIndex((sal_uInt16)0xFFFF),
        nGallaryIndex((sal_uInt16)0xFFFF),
        pGrfObj(0),
        aSize(0,0)
    {}
    virtual ~GrfBulDataRelation(){}
};

class  SVX_DLLPUBLIC MixBulletsSettings_Impl
{
    public:
        NBType          eType;
        sal_uInt16          nIndex; //index in the tab page display
        sal_uInt16          nIndexDefault;
        BulletsSettings*    pBullets;
    public:
        MixBulletsSettings_Impl(NBType eTy) :
            eType(eTy),
            nIndex((sal_uInt16)0xFFFF),
            nIndexDefault((sal_uInt16)0xFFFF),
            pBullets(0)
            {}
        ~MixBulletsSettings_Impl(){}
};

class  SVX_DLLPUBLIC NumberSettings_Impl
{
    public:
        sal_Bool        bIsCustomized;
        rtl::OUString   sDescription;
        sal_uInt16      nIndex; //index in the tab page display
        sal_uInt16      nIndexDefault;
        NumSettings_Impl    *pNumSetting;
    public:
        NumberSettings_Impl() :
            bIsCustomized(sal_False),
            nIndex((sal_uInt16)0xFFFF),
            nIndexDefault((sal_uInt16)0xFFFF),
            pNumSetting(NULL)
            {}
        ~NumberSettings_Impl(){}
};

typedef NumberSettings_Impl* NumberSettings_ImplPtr;
typedef std::vector< boost::shared_ptr<NumberSettings_Impl> > NumberSettingsArr_Impl;

class  SVX_DLLPUBLIC OutlineSettings_Impl
{
    public:
        sal_Bool        bIsCustomized;
        rtl::OUString   sDescription;
        NumSettingsArr_Impl *pNumSettingsArr;
    public:
        OutlineSettings_Impl() :
            bIsCustomized(sal_False),
            pNumSettingsArr(NULL)
            {}
        ~OutlineSettings_Impl(){
        }
};

class SVX_DLLPUBLIC NBOTypeMgrBase
{
    public:
        NBOType         eType;
    private:
        const SfxItemSet*   pSet;
        SfxMapUnit      eCoreUnit;
        // store the attributes passed from pSet
        OUString        aNumCharFmtName;
        void            StoreBulCharFmtName_impl();
        void            StoreMapUnit_impl();

    public:
        NBOTypeMgrBase(const NBOType aType)
            : eType(aType)
            , pSet(0)
            , eCoreUnit(SFX_MAPUNIT_TWIP)
            , aNumCharFmtName(OUString())
            , bIsLoading(false)
        {}
        NBOTypeMgrBase(const NBOType aType,const SfxItemSet* pArg)
            : eType(aType)
            , pSet(pArg)
            , eCoreUnit(SFX_MAPUNIT_TWIP)
            , aNumCharFmtName(OUString())
            , bIsLoading(false)
        {}
        NBOTypeMgrBase(const NBOTypeMgrBase& aTypeMgr)
        {
            eType = aTypeMgr.eType;
            pSet = aTypeMgr.pSet;
            eCoreUnit = aTypeMgr.eCoreUnit;
            aNumCharFmtName = aTypeMgr.aNumCharFmtName;
            bIsLoading = false;
        }
        virtual ~NBOTypeMgrBase() {}
        virtual void Init()=0;
        virtual sal_uInt16 GetNBOIndexForNumRule(SvxNumRule& aNum,sal_uInt16 mLevel,sal_uInt16 nFromIndex=0)=0;
        virtual sal_Bool RelplaceNumRule(SvxNumRule& aNum,sal_uInt16 nIndex,sal_uInt16 mLevel=(sal_uInt16)0xFFFF)=0;
        virtual sal_Bool ApplyNumRule(SvxNumRule& aNum,sal_uInt16 nIndex,sal_uInt16 mLevel=(sal_uInt16)0xFFFF, sal_Bool isDefault=false,sal_Bool isResetSize=false)=0;
        virtual OUString GetDescription(sal_uInt16 nIndex,sal_Bool isDefault=false)=0;
        virtual sal_Bool IsCustomized(sal_uInt16 nIndex)=0;
        sal_uInt16 IsSingleLevel(sal_uInt16 nCurLevel);
        const SfxItemSet* GetItems() { return pSet;}
        // store the attributes passed from pSet
        void SetItems(const SfxItemSet* pArg) { pSet = pArg;StoreBulCharFmtName_impl();StoreMapUnit_impl();}
    protected:
        OUString GetBulCharFmtName();
        SfxMapUnit GetMapUnit();
    protected:
        bool    bIsLoading;
        void    ImplLoad(OUString filename);
        void    ImplStore(OUString filename);

};

class SVX_DLLPUBLIC BulletsTypeMgr: public NBOTypeMgrBase
{
    friend class OutlineTypeMgr;
    friend class NumberingTypeMgr;
    public:
        static sal_Unicode aDynamicBulletTypes[DEFAULT_BULLET_TYPES];
        static sal_Unicode aDynamicRTLBulletTypes[DEFAULT_BULLET_TYPES];
        static BulletsSettings_Impl* pActualBullets[DEFAULT_BULLET_TYPES];
    public:
        BulletsTypeMgr();
        BulletsTypeMgr(const BulletsTypeMgr& aTypeMgr);
        virtual ~BulletsTypeMgr() {}
        virtual void Init();
        virtual sal_uInt16 GetNBOIndexForNumRule(SvxNumRule& aNum,sal_uInt16 mLevel,sal_uInt16 nFromIndex=0);
        virtual sal_Bool RelplaceNumRule(SvxNumRule& aNum,sal_uInt16 nIndex,sal_uInt16 mLevel=(sal_uInt16)0xFFFF);
        virtual sal_Bool ApplyNumRule(SvxNumRule& aNum,sal_uInt16 nIndex,sal_uInt16 mLevel=(sal_uInt16)0xFFFF,sal_Bool isDefault=false,sal_Bool isResetSize=false);
        virtual OUString GetDescription(sal_uInt16 nIndex,sal_Bool isDefault=false);
        virtual sal_Bool IsCustomized(sal_uInt16 nIndex);
        sal_Unicode GetBulChar(sal_uInt16 nIndex);
        Font GetBulCharFont(sal_uInt16 nIndex);
        static BulletsTypeMgr& GetInstance();
};

class SVX_DLLPUBLIC GraphyicBulletsTypeMgr: public NBOTypeMgrBase
{
    friend class OutlineTypeMgr;
    friend class NumberingTypeMgr;
    public:
        typedef std::vector<GrfBulDataRelation*> ListType;
        ListType aGrfDataLst;
    public:
        GraphyicBulletsTypeMgr();
        GraphyicBulletsTypeMgr(const GraphyicBulletsTypeMgr& aTypeMgr);
        virtual ~GraphyicBulletsTypeMgr();
        virtual void Init();
        virtual sal_uInt16 GetNBOIndexForNumRule(SvxNumRule& aNum,sal_uInt16 mLevel,sal_uInt16 nFromIndex=0);
        virtual sal_Bool RelplaceNumRule(SvxNumRule& aNum,sal_uInt16 nIndex,sal_uInt16 mLevel=(sal_uInt16)0xFFFF);
        virtual sal_Bool ApplyNumRule(SvxNumRule& aNum,sal_uInt16 nIndex,sal_uInt16 mLevel=(sal_uInt16)0xFFFF,sal_Bool isDefault=false,sal_Bool isResetSize=false);
        virtual OUString GetDescription(sal_uInt16 nIndex,sal_Bool isDefault=false);
        virtual sal_Bool IsCustomized(sal_uInt16 nIndex);
        OUString GetGrfName(sal_uInt16 nIndex);
        static GraphyicBulletsTypeMgr& GetInstance();
};

class SVX_DLLPUBLIC MixBulletsTypeMgr: public NBOTypeMgrBase
{
    friend class OutlineTypeMgr;
    friend class NumberingTypeMgr;
    public:
        static MixBulletsSettings_Impl* pActualBullets[DEFAULT_BULLET_TYPES];
        static MixBulletsSettings_Impl* pDefaultActualBullets[DEFAULT_BULLET_TYPES];
    public:
        MixBulletsTypeMgr();
        MixBulletsTypeMgr(const MixBulletsTypeMgr& aTypeMgr);
        virtual ~MixBulletsTypeMgr() {}
        virtual void Init();
        virtual sal_uInt16 GetNBOIndexForNumRule(SvxNumRule& aNum,sal_uInt16 mLevel,sal_uInt16 nFromIndex=0);
        virtual sal_Bool RelplaceNumRule(SvxNumRule& aNum,sal_uInt16 nIndex,sal_uInt16 mLevel=(sal_uInt16)0xFFFF);
        virtual sal_Bool ApplyNumRule(SvxNumRule& aNum,sal_uInt16 nIndex,sal_uInt16 mLevel=(sal_uInt16)0xFFFF,sal_Bool isDefault=false,sal_Bool isResetSize=false);
        virtual OUString GetDescription(sal_uInt16 nIndex,sal_Bool isDefault=false);
        virtual sal_Bool IsCustomized(sal_uInt16 nIndex);
        static MixBulletsTypeMgr& GetInstance();
};

class SVX_DLLPUBLIC NumberingTypeMgr: public NBOTypeMgrBase
{
    public:
        NumberSettingsArr_Impl*     pNumberSettingsArr;
        NumberSettingsArr_Impl*     pDefaultNumberSettingsArr;
    public:
        NumberingTypeMgr();
        NumberingTypeMgr(const NumberingTypeMgr& aTypeMgr);
        virtual ~NumberingTypeMgr();
        virtual void Init();
        virtual sal_uInt16 GetNBOIndexForNumRule(SvxNumRule& aNum,sal_uInt16 mLevel,sal_uInt16 nFromIndex=0);
        virtual sal_Bool RelplaceNumRule(SvxNumRule& aNum,sal_uInt16 nIndex,sal_uInt16 mLevel=(sal_uInt16)0xFFFF);
        virtual sal_Bool ApplyNumRule(SvxNumRule& aNum,sal_uInt16 nIndex,sal_uInt16 mLevel=(sal_uInt16)0xFFFF,sal_Bool isDefault=false,sal_Bool isResetSize=false);
        virtual OUString GetDescription(sal_uInt16 nIndex,sal_Bool isDefault=false);
        virtual sal_Bool IsCustomized(sal_uInt16 nIndex);
        static NumberingTypeMgr& GetInstance();
};

class SVX_DLLPUBLIC OutlineTypeMgr: public NBOTypeMgrBase
{
    public:
        OutlineSettings_Impl*       pOutlineSettingsArrs[DEFAULT_NUM_VALUSET_COUNT];
        OutlineSettings_Impl*       pDefaultOutlineSettingsArrs[DEFAULT_NUM_VALUSET_COUNT];
    public:
        OutlineTypeMgr();
        OutlineTypeMgr(const OutlineTypeMgr& aTypeMgr);
        virtual ~OutlineTypeMgr() {}
        virtual void Init();
        virtual sal_uInt16 GetNBOIndexForNumRule(SvxNumRule& aNum,sal_uInt16 mLevel,sal_uInt16 nFromIndex=0);
        virtual sal_Bool RelplaceNumRule(SvxNumRule& aNum,sal_uInt16 nIndex,sal_uInt16 mLevel=(sal_uInt16)0xFFFF);
        virtual sal_Bool ApplyNumRule(SvxNumRule& aNum,sal_uInt16 nIndex,sal_uInt16 mLevel=(sal_uInt16)0xFFFF,sal_Bool isDefault=false,sal_Bool isResetSize=false);
        virtual OUString GetDescription(sal_uInt16 nIndex,sal_Bool isDefault=false);
        virtual sal_Bool IsCustomized(sal_uInt16 nIndex);
        static OutlineTypeMgr& GetInstance();
};
}}
#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<|endoftext|>