<commit_before>// Copyright 2014-2015 Open Source Robotics Foundation, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <ccpp_dds_dcps.h>
#include <dds_dcps.h>

#include "rmw/allocators.h"
#include "rmw/error_handling.h"
#include "rmw/impl/cpp/macros.hpp"
#include "rmw/rmw.h"
#include "rmw/types.h"

#include "identifier.hpp"
#include "types.hpp"

// The extern "C" here enforces that overloading is not used.
extern "C"
{
rmw_ret_t check_attach_condition_error(DDS::ReturnCode_t retcode)
{
  if (retcode == DDS::RETCODE_OK) {
    return RMW_RET_OK;
  }
  if (retcode == DDS::RETCODE_OUT_OF_RESOURCES) {
    RMW_SET_ERROR_MSG("failed to attach condition to waitset: out of resources");
  } else if (retcode == DDS::RETCODE_BAD_PARAMETER) {
    RMW_SET_ERROR_MSG("failed to attach condition to waitset: condition pointer was invalid");
  } else {
    RMW_SET_ERROR_MSG("failed to attach condition to waitset");
  }
  return RMW_RET_ERROR;
}

rmw_ret_t
rmw_wait(
  rmw_subscriptions_t * subscriptions,
  rmw_guard_conditions_t * guard_conditions,
  rmw_services_t * services,
  rmw_clients_t * clients,
  rmw_waitset_t * waitset,
  const rmw_time_t * wait_timeout)
{
  // To ensure that we properly clean up the wait set, we declare an
  // object whose destructor will detach what we attached (this was previously
  // being done inside the destructor of the wait set.
  struct atexit_t
  {
    ~atexit_t()
    {
      // Manually detach conditions and clear sequences, to ensure a clean wait set for next time.
      if (!waitset) {
        RMW_SET_ERROR_MSG("waitset handle is null");
        return;
      }
      RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
        waitset handle,
        waitset->implementation_identifier, opensplice_cpp_identifier,
        return )
      OpenSpliceWaitSetInfo * waitset_info = static_cast<OpenSpliceWaitSetInfo *>(waitset->data);
      if (!waitset_info) {
        RMW_SET_ERROR_MSG("WaitSet implementation struct is null");
        return;
      }

      DDS::WaitSet * dds_waitset = static_cast<DDS::WaitSet *>(waitset_info->waitset);
      if (!dds_waitset) {
        RMW_SET_ERROR_MSG("DDS waitset handle is null");
        return;
      }

      DDS::ConditionSeq * attached_conditions =
        static_cast<DDS::ConditionSeq *>(waitset_info->attached_conditions);
      if (!attached_conditions) {
        RMW_SET_ERROR_MSG("DDS condition sequence handle is null");
        return;
      }

      DDS::ReturnCode_t retcode;
      retcode = dds_waitset->get_conditions(*attached_conditions);
      if (retcode != DDS::RETCODE_OK) {
        RMW_SET_ERROR_MSG("Failed to get attached conditions for waitset");
        return;
      }

      for (uint32_t i = 0; i < attached_conditions->length(); ++i) {
        bool fixed = false;
        for (uint32_t j = 0; j < waitset->fixed_guard_conditions->guard_condition_count; ++j) {
          DDS::GuardCondition * fixed_guard_cond = static_cast<DDS::GuardCondition *>(
            waitset->fixed_guard_conditions->guard_conditions[j]);
          if (fixed_guard_cond == (*attached_conditions)[i]) {
            fixed = true;
            break;
          }
        }
        if (fixed) {
          continue;
        }

        retcode = dds_waitset->detach_condition((*attached_conditions)[i]);
        if (retcode != DDS::RETCODE_OK) {
          RMW_SET_ERROR_MSG("Failed to get detach condition from waitset");
        }
      }
    }
    rmw_waitset_t * waitset = NULL;
  } atexit;

  atexit.waitset = waitset;

  if (!waitset) {
    RMW_SET_ERROR_MSG("waitset handle is null");
    return RMW_RET_ERROR;
  }
  RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
    waitset,
    waitset->implementation_identifier, opensplice_cpp_identifier,
    return RMW_RET_ERROR);

  OpenSpliceWaitSetInfo * waitset_info = static_cast<OpenSpliceWaitSetInfo *>(waitset->data);
  if (!waitset_info) {
    RMW_SET_ERROR_MSG("WaitSet implementation struct is null");
    return RMW_RET_ERROR;
  }

  DDS::WaitSet * dds_waitset = static_cast<DDS::WaitSet *>(waitset_info->waitset);
  if (!dds_waitset) {
    RMW_SET_ERROR_MSG("DDS waitset handle is null");
    return RMW_RET_ERROR;
  }

  DDS::ConditionSeq * active_conditions =
    static_cast<DDS::ConditionSeq *>(waitset_info->active_conditions);
  if (!active_conditions) {
    RMW_SET_ERROR_MSG("DDS condition sequence handle is null");
    return RMW_RET_ERROR;
  }

  // add a condition for each subscriber
  for (size_t i = 0; i < subscriptions->subscriber_count; ++i) {
    OpenSpliceStaticSubscriberInfo * subscriber_info =
      static_cast<OpenSpliceStaticSubscriberInfo *>(subscriptions->subscribers[i]);
    if (!subscriber_info) {
      RMW_SET_ERROR_MSG("subscriber info handle is null");
      return RMW_RET_ERROR;
    }
    DDS::ReadCondition * read_condition = subscriber_info->read_condition;
    if (!read_condition) {
      RMW_SET_ERROR_MSG("read condition handle is null");
      return RMW_RET_ERROR;
    }
    rmw_ret_t status = check_attach_condition_error(
      dds_waitset->attach_condition(read_condition));
    if (status != RMW_RET_OK) {
      return status;
    }
  }

  // add a condition for each guard condition
  if (guard_conditions) {
    for (size_t i = 0; i < guard_conditions->guard_condition_count; ++i) {
      DDS::GuardCondition * guard_condition =
        static_cast<DDS::GuardCondition *>(guard_conditions->guard_conditions[i]);
      if (!guard_condition) {
        RMW_SET_ERROR_MSG("guard condition handle is null");
        return RMW_RET_ERROR;
      }
      rmw_ret_t status = check_attach_condition_error(
        dds_waitset->attach_condition(guard_condition));
      if (status != RMW_RET_OK) {
        return status;
      }
    }
  }

  // add a condition for each service
  for (size_t i = 0; i < services->service_count; ++i) {
    OpenSpliceStaticServiceInfo * service_info =
      static_cast<OpenSpliceStaticServiceInfo *>(services->services[i]);
    if (!service_info) {
      RMW_SET_ERROR_MSG("service info handle is null");
      return RMW_RET_ERROR;
    }
    DDS::ReadCondition * read_condition = service_info->read_condition_;
    if (!read_condition) {
      RMW_SET_ERROR_MSG("read condition handle is null");
      return RMW_RET_ERROR;
    }
    rmw_ret_t status = check_attach_condition_error(
      dds_waitset->attach_condition(read_condition));
    if (status != RMW_RET_OK) {
      return status;
    }
  }

  // add a condition for each client
  for (size_t i = 0; i < clients->client_count; ++i) {
    OpenSpliceStaticClientInfo * client_info =
      static_cast<OpenSpliceStaticClientInfo *>(clients->clients[i]);
    if (!client_info) {
      RMW_SET_ERROR_MSG("client info handle is null");
      return RMW_RET_ERROR;
    }
    DDS::ReadCondition * read_condition = client_info->read_condition_;
    if (!read_condition) {
      RMW_SET_ERROR_MSG("read condition handle is null");
      return RMW_RET_ERROR;
    }
    rmw_ret_t status = check_attach_condition_error(
      dds_waitset->attach_condition(read_condition));
    if (status != RMW_RET_OK) {
      return status;
    }
  }

  // invoke wait until one of the conditions triggers

  DDS::Duration_t timeout;
  if (!wait_timeout) {
    timeout = DDS::DURATION_INFINITE;
  } else {
    timeout.sec = static_cast<DDS::Long>(wait_timeout->sec);
    timeout.nanosec = static_cast<DDS::Long>(wait_timeout->nsec);
  }
  DDS::ReturnCode_t status = dds_waitset->wait(*active_conditions, timeout);

  if (status == DDS::RETCODE_TIMEOUT) {
    return RMW_RET_TIMEOUT;
  }

  if (status != DDS::RETCODE_OK) {
    RMW_SET_ERROR_MSG("failed to wait on waitset");
    return RMW_RET_ERROR;
  }

  // set subscriber handles to zero for all not triggered status conditions
  for (size_t i = 0; i < subscriptions->subscriber_count; ++i) {
    OpenSpliceStaticSubscriberInfo * subscriber_info =
      static_cast<OpenSpliceStaticSubscriberInfo *>(subscriptions->subscribers[i]);
    if (!subscriber_info) {
      RMW_SET_ERROR_MSG("subscriber info handle is null");
      return RMW_RET_ERROR;
    }
    DDS::ReadCondition * read_condition = subscriber_info->read_condition;
    if (!read_condition) {
      RMW_SET_ERROR_MSG("read condition handle is null");
      return RMW_RET_ERROR;
    }
    if (!read_condition->get_trigger_value()) {
      // if the status condition was not triggered
      // reset the subscriber handle
      subscriptions->subscribers[i] = 0;
    }
  }

  // set guard condition handles to zero for all not triggered guard conditions
  if (guard_conditions) {
    for (size_t i = 0; i < guard_conditions->guard_condition_count; ++i) {
      DDS::GuardCondition * guard_condition =
        static_cast<DDS::GuardCondition *>(guard_conditions->guard_conditions[i]);
      if (!guard_condition) {
        RMW_SET_ERROR_MSG("guard condition handle is null");
        return RMW_RET_ERROR;
      }

      if (!guard_condition->get_trigger_value()) {
        // if the guard condition was not triggered
        // reset the guard condition handle
        guard_conditions->guard_conditions[i] = 0;
      } else {
        // reset the trigger value
        if (guard_condition->set_trigger_value(false) != DDS::RETCODE_OK) {
          RMW_SET_ERROR_MSG("failed to set trigger value to false");
          return RMW_RET_ERROR;
        }
      }
    }
  }

  // set service handles to zero for all not triggered conditions
  for (size_t i = 0; i < services->service_count; ++i) {
    OpenSpliceStaticServiceInfo * service_info =
      static_cast<OpenSpliceStaticServiceInfo *>(services->services[i]);
    if (!service_info) {
      RMW_SET_ERROR_MSG("service info handle is null");
      return RMW_RET_ERROR;
    }
    DDS::ReadCondition * read_condition = service_info->read_condition_;
    if (!read_condition) {
      RMW_SET_ERROR_MSG("read condition handle is null");
      return RMW_RET_ERROR;
    }

    // search for service condition in active set
    uint32_t j = 0;
    for (; j < active_conditions->length(); ++j) {
      if ((*active_conditions)[j] == read_condition) {
        break;
      }
    }
    // if service condition is not found in the active set
    // reset the service handle
    if (!(j < active_conditions->length())) {
      services->services[i] = 0;
    }
  }

  // set client handles to zero for all not triggered conditions
  for (size_t i = 0; i < clients->client_count; ++i) {
    OpenSpliceStaticClientInfo * client_info =
      static_cast<OpenSpliceStaticClientInfo *>(clients->clients[i]);
    if (!client_info) {
      RMW_SET_ERROR_MSG("client info handle is null");
      return RMW_RET_ERROR;
    }
    DDS::ReadCondition * read_condition = client_info->read_condition_;
    if (!read_condition) {
      RMW_SET_ERROR_MSG("read condition handle is null");
      return RMW_RET_ERROR;
    }

    // search for service condition in active set
    uint32_t j = 0;
    for (; j < active_conditions->length(); ++j) {
      if ((*active_conditions)[j] == read_condition) {
        break;
      }
    }
    // if client condition is not found in the active set
    // reset the client handle
    if (!(j < active_conditions->length())) {
      clients->clients[i] = 0;
    }
  }
  return RMW_RET_OK;
}
}  // extern "C"
<commit_msg>reset fixed guard condition<commit_after>// Copyright 2014-2015 Open Source Robotics Foundation, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <ccpp_dds_dcps.h>
#include <dds_dcps.h>

#include "rmw/allocators.h"
#include "rmw/error_handling.h"
#include "rmw/impl/cpp/macros.hpp"
#include "rmw/rmw.h"
#include "rmw/types.h"

#include "identifier.hpp"
#include "types.hpp"

// The extern "C" here enforces that overloading is not used.
extern "C"
{
rmw_ret_t check_attach_condition_error(DDS::ReturnCode_t retcode)
{
  if (retcode == DDS::RETCODE_OK) {
    return RMW_RET_OK;
  }
  if (retcode == DDS::RETCODE_OUT_OF_RESOURCES) {
    RMW_SET_ERROR_MSG("failed to attach condition to waitset: out of resources");
  } else if (retcode == DDS::RETCODE_BAD_PARAMETER) {
    RMW_SET_ERROR_MSG("failed to attach condition to waitset: condition pointer was invalid");
  } else {
    RMW_SET_ERROR_MSG("failed to attach condition to waitset");
  }
  return RMW_RET_ERROR;
}

rmw_ret_t
rmw_wait(
  rmw_subscriptions_t * subscriptions,
  rmw_guard_conditions_t * guard_conditions,
  rmw_services_t * services,
  rmw_clients_t * clients,
  rmw_waitset_t * waitset,
  const rmw_time_t * wait_timeout)
{
  // To ensure that we properly clean up the wait set, we declare an
  // object whose destructor will detach what we attached (this was previously
  // being done inside the destructor of the wait set.
  struct atexit_t
  {
    ~atexit_t()
    {
      // Manually detach conditions and clear sequences, to ensure a clean wait set for next time.
      if (!waitset) {
        RMW_SET_ERROR_MSG("waitset handle is null");
        return;
      }
      RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
        waitset handle,
        waitset->implementation_identifier, opensplice_cpp_identifier,
        return )
      OpenSpliceWaitSetInfo * waitset_info = static_cast<OpenSpliceWaitSetInfo *>(waitset->data);
      if (!waitset_info) {
        RMW_SET_ERROR_MSG("WaitSet implementation struct is null");
        return;
      }

      DDS::WaitSet * dds_waitset = static_cast<DDS::WaitSet *>(waitset_info->waitset);
      if (!dds_waitset) {
        RMW_SET_ERROR_MSG("DDS waitset handle is null");
        return;
      }

      DDS::ConditionSeq * attached_conditions =
        static_cast<DDS::ConditionSeq *>(waitset_info->attached_conditions);
      if (!attached_conditions) {
        RMW_SET_ERROR_MSG("DDS condition sequence handle is null");
        return;
      }

      DDS::ReturnCode_t retcode;
      retcode = dds_waitset->get_conditions(*attached_conditions);
      if (retcode != DDS::RETCODE_OK) {
        RMW_SET_ERROR_MSG("Failed to get attached conditions for waitset");
        return;
      }

      for (uint32_t i = 0; i < attached_conditions->length(); ++i) {
        bool fixed = false;
        for (uint32_t j = 0; j < waitset->fixed_guard_conditions->guard_condition_count; ++j) {
          DDS::GuardCondition * fixed_guard_cond = static_cast<DDS::GuardCondition *>(
            waitset->fixed_guard_conditions->guard_conditions[j]);
          if (fixed_guard_cond == (*attached_conditions)[i]) {
            // Reset the fixed guard conditions to avoid being woken up
            // immediately next time.
            retcode = fixed_guard_cond->set_trigger_value(false);
            if (retcode != DDS::RETCODE_OK) {
              fprintf(stderr, "failed to set trigger value\n");
            }
            fixed = true;
            break;
          }
        }
        if (fixed) {
          continue;
        }

        retcode = dds_waitset->detach_condition((*attached_conditions)[i]);
        if (retcode != DDS::RETCODE_OK) {
          RMW_SET_ERROR_MSG("Failed to get detach condition from waitset");
        }
      }
    }
    rmw_waitset_t * waitset = NULL;
  } atexit;

  atexit.waitset = waitset;

  if (!waitset) {
    RMW_SET_ERROR_MSG("waitset handle is null");
    return RMW_RET_ERROR;
  }
  RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
    waitset,
    waitset->implementation_identifier, opensplice_cpp_identifier,
    return RMW_RET_ERROR);

  OpenSpliceWaitSetInfo * waitset_info = static_cast<OpenSpliceWaitSetInfo *>(waitset->data);
  if (!waitset_info) {
    RMW_SET_ERROR_MSG("WaitSet implementation struct is null");
    return RMW_RET_ERROR;
  }

  DDS::WaitSet * dds_waitset = static_cast<DDS::WaitSet *>(waitset_info->waitset);
  if (!dds_waitset) {
    RMW_SET_ERROR_MSG("DDS waitset handle is null");
    return RMW_RET_ERROR;
  }

  DDS::ConditionSeq * active_conditions =
    static_cast<DDS::ConditionSeq *>(waitset_info->active_conditions);
  if (!active_conditions) {
    RMW_SET_ERROR_MSG("DDS condition sequence handle is null");
    return RMW_RET_ERROR;
  }

  // add a condition for each subscriber
  for (size_t i = 0; i < subscriptions->subscriber_count; ++i) {
    OpenSpliceStaticSubscriberInfo * subscriber_info =
      static_cast<OpenSpliceStaticSubscriberInfo *>(subscriptions->subscribers[i]);
    if (!subscriber_info) {
      RMW_SET_ERROR_MSG("subscriber info handle is null");
      return RMW_RET_ERROR;
    }
    DDS::ReadCondition * read_condition = subscriber_info->read_condition;
    if (!read_condition) {
      RMW_SET_ERROR_MSG("read condition handle is null");
      return RMW_RET_ERROR;
    }
    rmw_ret_t status = check_attach_condition_error(
      dds_waitset->attach_condition(read_condition));
    if (status != RMW_RET_OK) {
      return status;
    }
  }

  // add a condition for each guard condition
  if (guard_conditions) {
    for (size_t i = 0; i < guard_conditions->guard_condition_count; ++i) {
      DDS::GuardCondition * guard_condition =
        static_cast<DDS::GuardCondition *>(guard_conditions->guard_conditions[i]);
      if (!guard_condition) {
        RMW_SET_ERROR_MSG("guard condition handle is null");
        return RMW_RET_ERROR;
      }
      rmw_ret_t status = check_attach_condition_error(
        dds_waitset->attach_condition(guard_condition));
      if (status != RMW_RET_OK) {
        return status;
      }
    }
  }

  // add a condition for each service
  for (size_t i = 0; i < services->service_count; ++i) {
    OpenSpliceStaticServiceInfo * service_info =
      static_cast<OpenSpliceStaticServiceInfo *>(services->services[i]);
    if (!service_info) {
      RMW_SET_ERROR_MSG("service info handle is null");
      return RMW_RET_ERROR;
    }
    DDS::ReadCondition * read_condition = service_info->read_condition_;
    if (!read_condition) {
      RMW_SET_ERROR_MSG("read condition handle is null");
      return RMW_RET_ERROR;
    }
    rmw_ret_t status = check_attach_condition_error(
      dds_waitset->attach_condition(read_condition));
    if (status != RMW_RET_OK) {
      return status;
    }
  }

  // add a condition for each client
  for (size_t i = 0; i < clients->client_count; ++i) {
    OpenSpliceStaticClientInfo * client_info =
      static_cast<OpenSpliceStaticClientInfo *>(clients->clients[i]);
    if (!client_info) {
      RMW_SET_ERROR_MSG("client info handle is null");
      return RMW_RET_ERROR;
    }
    DDS::ReadCondition * read_condition = client_info->read_condition_;
    if (!read_condition) {
      RMW_SET_ERROR_MSG("read condition handle is null");
      return RMW_RET_ERROR;
    }
    rmw_ret_t status = check_attach_condition_error(
      dds_waitset->attach_condition(read_condition));
    if (status != RMW_RET_OK) {
      return status;
    }
  }

  // invoke wait until one of the conditions triggers

  DDS::Duration_t timeout;
  if (!wait_timeout) {
    timeout = DDS::DURATION_INFINITE;
  } else {
    timeout.sec = static_cast<DDS::Long>(wait_timeout->sec);
    timeout.nanosec = static_cast<DDS::Long>(wait_timeout->nsec);
  }
  DDS::ReturnCode_t status = dds_waitset->wait(*active_conditions, timeout);

  if (status == DDS::RETCODE_TIMEOUT) {
    return RMW_RET_TIMEOUT;
  }

  if (status != DDS::RETCODE_OK) {
    RMW_SET_ERROR_MSG("failed to wait on waitset");
    return RMW_RET_ERROR;
  }

  // set subscriber handles to zero for all not triggered status conditions
  for (size_t i = 0; i < subscriptions->subscriber_count; ++i) {
    OpenSpliceStaticSubscriberInfo * subscriber_info =
      static_cast<OpenSpliceStaticSubscriberInfo *>(subscriptions->subscribers[i]);
    if (!subscriber_info) {
      RMW_SET_ERROR_MSG("subscriber info handle is null");
      return RMW_RET_ERROR;
    }
    DDS::ReadCondition * read_condition = subscriber_info->read_condition;
    if (!read_condition) {
      RMW_SET_ERROR_MSG("read condition handle is null");
      return RMW_RET_ERROR;
    }
    if (!read_condition->get_trigger_value()) {
      // if the status condition was not triggered
      // reset the subscriber handle
      subscriptions->subscribers[i] = 0;
    }
  }

  // set guard condition handles to zero for all not triggered guard conditions
  if (guard_conditions) {
    for (size_t i = 0; i < guard_conditions->guard_condition_count; ++i) {
      DDS::GuardCondition * guard_condition =
        static_cast<DDS::GuardCondition *>(guard_conditions->guard_conditions[i]);
      if (!guard_condition) {
        RMW_SET_ERROR_MSG("guard condition handle is null");
        return RMW_RET_ERROR;
      }

      if (!guard_condition->get_trigger_value()) {
        // if the guard condition was not triggered
        // reset the guard condition handle
        guard_conditions->guard_conditions[i] = 0;
      } else {
        // reset the trigger value
        if (guard_condition->set_trigger_value(false) != DDS::RETCODE_OK) {
          RMW_SET_ERROR_MSG("failed to set trigger value to false");
          return RMW_RET_ERROR;
        }
      }
    }
  }

  // set service handles to zero for all not triggered conditions
  for (size_t i = 0; i < services->service_count; ++i) {
    OpenSpliceStaticServiceInfo * service_info =
      static_cast<OpenSpliceStaticServiceInfo *>(services->services[i]);
    if (!service_info) {
      RMW_SET_ERROR_MSG("service info handle is null");
      return RMW_RET_ERROR;
    }
    DDS::ReadCondition * read_condition = service_info->read_condition_;
    if (!read_condition) {
      RMW_SET_ERROR_MSG("read condition handle is null");
      return RMW_RET_ERROR;
    }

    // search for service condition in active set
    uint32_t j = 0;
    for (; j < active_conditions->length(); ++j) {
      if ((*active_conditions)[j] == read_condition) {
        break;
      }
    }
    // if service condition is not found in the active set
    // reset the service handle
    if (!(j < active_conditions->length())) {
      services->services[i] = 0;
    }
  }

  // set client handles to zero for all not triggered conditions
  for (size_t i = 0; i < clients->client_count; ++i) {
    OpenSpliceStaticClientInfo * client_info =
      static_cast<OpenSpliceStaticClientInfo *>(clients->clients[i]);
    if (!client_info) {
      RMW_SET_ERROR_MSG("client info handle is null");
      return RMW_RET_ERROR;
    }
    DDS::ReadCondition * read_condition = client_info->read_condition_;
    if (!read_condition) {
      RMW_SET_ERROR_MSG("read condition handle is null");
      return RMW_RET_ERROR;
    }

    // search for service condition in active set
    uint32_t j = 0;
    for (; j < active_conditions->length(); ++j) {
      if ((*active_conditions)[j] == read_condition) {
        break;
      }
    }
    // if client condition is not found in the active set
    // reset the client handle
    if (!(j < active_conditions->length())) {
      clients->clients[i] = 0;
    }
  }
  return RMW_RET_OK;
}
}  // extern "C"
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: RTableConnectionData.hxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: hr $ $Date: 2007-09-26 14:49:51 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/
#ifndef DBAUI_RTABLECONNECTIONDATA_HXX
#define DBAUI_RTABLECONNECTIONDATA_HXX

#ifndef DBAUI_TABLECONNECTIONDATA_HXX
#include "TableConnectionData.hxx"
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
#include <com/sun/star/beans/XPropertySet.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
#include <com/sun/star/container/XNameAccess.hpp>
#endif
#ifndef DBAUI_ENUMTYPES_HXX
#include "QEnumTypes.hxx"
#endif
#ifndef _UNOTOOLS_EVENTLISTENERADAPTER_HXX_
#include <unotools/eventlisteneradapter.hxx>
#endif

namespace dbaui
{
    const UINT16 CARDINAL_UNDEFINED = 0x0000;
    const UINT16 CARDINAL_ONE_MANY  = 0x0001;
    const UINT16 CARDINAL_MANY_ONE  = 0x0002;
    const UINT16 CARDINAL_ONE_ONE   = 0x0004;

    class OConnectionLineData;
    //==================================================================
    class ORelationTableConnectionData :    public OTableConnectionData,
                                            public ::utl::OEventListenerAdapter
    {
        friend bool operator==(const ORelationTableConnectionData& lhs, const ORelationTableConnectionData& rhs);
        friend bool operator!=(const ORelationTableConnectionData& lhs, const ORelationTableConnectionData& rhs) { return !(lhs == rhs); }

        ::osl::Mutex    m_aMutex;
        ::rtl::OUString m_sDatabaseName;
        ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> m_xTables;
        ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>    m_xSource;
        ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>    m_xDest;

        // @see com.sun.star.sdbc.KeyRule
        sal_Int32 m_nUpdateRules;
        sal_Int32 m_nDeleteRules;
        sal_Int32 m_nCardinality;

        BOOL checkPrimaryKey(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xTable,EConnectionSide _eEConnectionSide) const;
        BOOL IsSourcePrimKey()  const { return checkPrimaryKey(m_xSource,JTCS_FROM);    }
        BOOL IsDestPrimKey()    const { return checkPrimaryKey(m_xDest,JTCS_TO);        }
        void addListening(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& _rxComponent);
        void removeListening(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& _rxComponent);

    protected:
        virtual OConnectionLineDataRef CreateLineDataObj();
        virtual OConnectionLineDataRef CreateLineDataObj( const OConnectionLineData& rConnLineData );

        ORelationTableConnectionData& operator=( const ORelationTableConnectionData& rConnData );
    public:
        ORelationTableConnectionData();
        ORelationTableConnectionData( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>& _xTables);
        ORelationTableConnectionData( const ORelationTableConnectionData& rConnData );
        ORelationTableConnectionData( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>& _xTables,
                                      const ::rtl::OUString& rSourceWinName,
                                      const ::rtl::OUString& rDestWinName,
                                      const ::rtl::OUString& rConnName = ::rtl::OUString() );
        virtual ~ORelationTableConnectionData();

        virtual void CopyFrom(const OTableConnectionData& rSource);
        virtual OTableConnectionData* NewInstance() const { return new ORelationTableConnectionData(); }

        ::rtl::OUString GetDatabaseName() const { return m_sDatabaseName; }

        ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> getTables() const { return m_xTables;}
        ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>    getSource() const { return m_xSource;}
        ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>    getDest() const { return m_xDest; }

        virtual void SetSourceWinName( const String& rSourceWinName );
        virtual void SetDestWinName( const String& rDestWinName );
        /** Update create a new relation

            @return true if successful
        */
        virtual BOOL Update();

        void        SetCardinality();
        void        SetUpdateRules( sal_Int32 nAttr ){ m_nUpdateRules = nAttr; }
        void        SetDeleteRules( sal_Int32 nAttr ){ m_nDeleteRules = nAttr; }

        sal_Int32   GetUpdateRules() const { return m_nUpdateRules; }
        sal_Int32   GetDeleteRules() const { return m_nDeleteRules; }
        sal_Int32   GetCardinality() const { return m_nCardinality; }

        BOOL        IsConnectionPossible();
        void        ChangeOrientation();
        BOOL        DropRelation();

        // OEventListenerAdapter
        virtual void _disposing( const ::com::sun::star::lang::EventObject& _rSource );
    };
}

#endif // DBAUI_RTABLECONNECTIONDATA_HXX

<commit_msg>INTEGRATION: CWS dba24b (1.5.308); FILE MERGED 2007/09/28 11:57:09 oj 1.5.308.2: RESYNC: (1.5-1.6); FILE MERGED 2007/08/16 06:14:43 oj 1.5.308.1: #i56898# clean up of the class structure<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: RTableConnectionData.hxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: hr $ $Date: 2007-11-01 15:17:02 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/
#ifndef DBAUI_RTABLECONNECTIONDATA_HXX
#define DBAUI_RTABLECONNECTIONDATA_HXX

#ifndef DBAUI_TABLECONNECTIONDATA_HXX
#include "TableConnectionData.hxx"
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
#include <com/sun/star/beans/XPropertySet.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
#include <com/sun/star/container/XNameAccess.hpp>
#endif
#ifndef DBAUI_ENUMTYPES_HXX
#include "QEnumTypes.hxx"
#endif

namespace dbaui
{
    const UINT16 CARDINAL_UNDEFINED = 0x0000;
    const UINT16 CARDINAL_ONE_MANY  = 0x0001;
    const UINT16 CARDINAL_MANY_ONE  = 0x0002;
    const UINT16 CARDINAL_ONE_ONE   = 0x0004;

    class OConnectionLineData;
    //==================================================================
    class ORelationTableConnectionData :    public OTableConnectionData
    {
        friend bool operator==(const ORelationTableConnectionData& lhs, const ORelationTableConnectionData& rhs);
        friend bool operator!=(const ORelationTableConnectionData& lhs, const ORelationTableConnectionData& rhs) { return !(lhs == rhs); }

        ::osl::Mutex    m_aMutex;
        ::rtl::OUString m_sDatabaseName;

        // @see com.sun.star.sdbc.KeyRule
        sal_Int32 m_nUpdateRules;
        sal_Int32 m_nDeleteRules;
        sal_Int32 m_nCardinality;

        BOOL checkPrimaryKey(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xTable,EConnectionSide _eEConnectionSide) const;
        BOOL IsSourcePrimKey()  const { return checkPrimaryKey(getReferencingTable()->getTable(),JTCS_FROM);    }
        BOOL IsDestPrimKey()    const { return checkPrimaryKey(getReferencedTable()->getTable(),JTCS_TO);       }

    protected:
        virtual OConnectionLineDataRef CreateLineDataObj();
        virtual OConnectionLineDataRef CreateLineDataObj( const OConnectionLineData& rConnLineData );

        ORelationTableConnectionData& operator=( const ORelationTableConnectionData& rConnData );
    public:
        ORelationTableConnectionData();
        ORelationTableConnectionData( const ORelationTableConnectionData& rConnData );
        ORelationTableConnectionData( const TTableWindowData::value_type& _pReferencingTable,
                                      const TTableWindowData::value_type& _pReferencedTable,
                                      const ::rtl::OUString& rConnName = ::rtl::OUString() );
        virtual ~ORelationTableConnectionData();

        virtual void CopyFrom(const OTableConnectionData& rSource);
        virtual OTableConnectionData* NewInstance() const { return new ORelationTableConnectionData(); }

        inline ::rtl::OUString GetDatabaseName() const { return m_sDatabaseName; }

        /** Update create a new relation

            @return true if successful
        */
        virtual BOOL Update();

        void        SetCardinality();
        inline void SetUpdateRules( sal_Int32 nAttr ){ m_nUpdateRules = nAttr; }
        inline void SetDeleteRules( sal_Int32 nAttr ){ m_nDeleteRules = nAttr; }

        inline sal_Int32    GetUpdateRules() const { return m_nUpdateRules; }
        inline sal_Int32    GetDeleteRules() const { return m_nDeleteRules; }
        inline sal_Int32    GetCardinality() const { return m_nCardinality; }

        BOOL        IsConnectionPossible();
        void        ChangeOrientation();
        BOOL        DropRelation();
    };
}

#endif // DBAUI_RTABLECONNECTIONDATA_HXX

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: ZipPackageStream.cxx,v $
 *
 *  $Revision: 1.16 $
 *
 *  last change: $Author: mtg $ $Date: 2001-04-27 14:56:07 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): Martin Gallwey (gallwey@sun.com)
 *
 *
 ************************************************************************/

#ifndef _ZIP_PACKAGE_STREAM_HXX
#include <ZipPackageStream.hxx>
#endif
#ifndef _ZIP_PACKAGE_HXX
#include <ZipPackage.hxx>
#endif
#ifndef _ZIP_FILE_HXX
#include <ZipFile.hxx>
#endif
#ifndef _VOS_DIAGNOSE_H_
#include <vos/diagnose.hxx>
#endif

using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace com::sun::star;
using namespace cppu;
using namespace rtl;

ZipPackageStream::ZipPackageStream (ZipPackage & rNewPackage )
: rZipPackage(rNewPackage)
, bToBeCompressed ( sal_False )
, bToBeEncrypted ( sal_False )
, bPackageMember ( sal_False )
, xEncryptionData ( new EncryptionData )
{
    aEntry.nVersion     = -1;
    aEntry.nFlag        = 0;
    aEntry.nMethod      = -1;
    aEntry.nTime        = -1;
    aEntry.nCrc         = -1;
    aEntry.nCompressedSize  = -1;
    aEntry.nSize        = -1;
    aEntry.nOffset      = -1;
}

ZipPackageStream::~ZipPackageStream( void )
{
}

void ZipPackageStream::setZipEntry( const packages::ZipEntry &rInEntry)
{
    aEntry.nVersion = rInEntry.nVersion;
    aEntry.nFlag = rInEntry.nFlag;
    aEntry.nMethod = rInEntry.nMethod;
    aEntry.nTime = rInEntry.nTime;
    aEntry.nCrc = rInEntry.nCrc;
    aEntry.nCompressedSize = rInEntry.nCompressedSize;
    aEntry.nSize = rInEntry.nSize;
    aEntry.nOffset = rInEntry.nOffset;
    aEntry.sName = rInEntry.sName;
    aEntry.extra = rInEntry.extra;
    aEntry.sComment = rInEntry.sComment;
}
    //XInterface
Any SAL_CALL ZipPackageStream::queryInterface( const Type& rType )
    throw(RuntimeException)
{
    return ( ::cppu::queryInterface (   rType                                       ,
                                                // OWeakObject interfaces
                                                reinterpret_cast< XInterface*       > ( this )  ,
                                                static_cast< XWeak*         > ( this )  ,
                                                // ZipPackageEntry interfaces
                                                static_cast< container::XNamed*     > ( this )  ,
                                                static_cast< container::XChild*     > ( this )  ,
                                                static_cast< XUnoTunnel*        > ( this )  ,
                                                // My own interfaces
                                                static_cast< io::XActiveDataSink*   > ( this )  ,
                                                static_cast< beans::XPropertySet*   > ( this ) ) );

}

void SAL_CALL ZipPackageStream::acquire(  )
    throw()
{
    OWeakObject::acquire();
}
void SAL_CALL ZipPackageStream::release(  )
    throw()
{
    OWeakObject::release();
}

    // XActiveDataSink
void SAL_CALL ZipPackageStream::setInputStream( const Reference< io::XInputStream >& aStream )
        throw(RuntimeException)
{
    xStream = aStream;
    SetPackageMember ( sal_False );
    aEntry.nTime = -1;
}

Reference< io::XInputStream > SAL_CALL ZipPackageStream::getRawStream( com::sun::star::packages::ZipEntry &rEntry )
        throw(RuntimeException)
{
    if (IsPackageMember())
    {
        try
        {
            return rZipPackage.getZipFile().getRawStream(rEntry, xEncryptionData);
        }
        catch (packages::ZipException &)//rException)
        {
            VOS_ENSURE( 0, "ZipException thrown");//rException.Message);
            return Reference < io::XInputStream > ();
        }
    }
    else
        return xStream;
}

Reference< io::XInputStream > SAL_CALL ZipPackageStream::getInputStream(  )
        throw(RuntimeException)
{
    if (IsPackageMember())
    {
        try
        {
            return rZipPackage.getZipFile().getInputStream( aEntry, xEncryptionData);
        }
        catch (packages::ZipException &)//rException)
        {
            VOS_ENSURE( 0,"ZipException thrown");//rException.Message);
            return Reference < io::XInputStream > ();
        }
    }
    else
        return xStream;
}

// XPropertySet
Sequence< sal_Int8 > ZipPackageStream::getUnoTunnelImplementationId( void )
    throw (RuntimeException)
{
    static ::cppu::OImplementationId * pId = 0;
    if (! pId)
    {
        ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
        if (! pId)
        {
            static ::cppu::OImplementationId aId;
            pId = &aId;
        }
    }
    return pId->getImplementationId();
}

sal_Int64 SAL_CALL ZipPackageStream::getSomething( const Sequence< sal_Int8 >& aIdentifier )
    throw(RuntimeException)
{
    if (aIdentifier.getLength() == 16 &&
        0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(),
                               aIdentifier.getConstArray(), 16 ) )
        return reinterpret_cast < sal_Int64 > ( this );

    return 0;
}
void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName, const Any& aValue )
        throw(beans::UnknownPropertyException, beans::PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
{
    if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("MediaType")))
    {
        aValue >>= sMediaType;

        if (sMediaType.getLength() > 0)
        {
            if ( sMediaType.indexOf (OUString( RTL_CONSTASCII_USTRINGPARAM ( "text" ) ) ) != -1)
                bToBeCompressed = sal_True;
            else
                bToBeCompressed = sal_False;
        }
    }
    else if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Size") ) )
        aValue >>= aEntry.nSize;
    else if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Encrypted") ) )
        aValue >>= bToBeEncrypted;
#if SUPD>617
    else if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Compressed") ) )
#else
    else if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Compress") ) )
#endif
        aValue >>= bToBeCompressed;
    else
        throw beans::UnknownPropertyException();
}
Any SAL_CALL ZipPackageStream::getPropertyValue( const OUString& PropertyName )
        throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException)
{
    Any aAny;
    if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) )
    {
        aAny <<= sMediaType;
        return aAny;
    }
    else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Size" ) ) )
    {
        aAny <<= aEntry.nSize;
        return aAny;
    }
    else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Encrypted" ) ) )
    {
        aAny <<= bToBeEncrypted;
        return aAny;
    }
#if SUPD>617
    else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Compressed" ) ) )
#else
    else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Compress" ) ) )
#endif
    {
        aAny <<= bToBeCompressed;
        return aAny;
    }
    else
        throw beans::UnknownPropertyException();
}

const com::sun::star::uno::Sequence < sal_Int8 >& ZipPackageStream::getEncryptionKey ()
{
    return rZipPackage.getEncryptionKey();
}
<commit_msg>set default to be compressed<commit_after>/*************************************************************************
 *
 *  $RCSfile: ZipPackageStream.cxx,v $
 *
 *  $Revision: 1.17 $
 *
 *  last change: $Author: mtg $ $Date: 2001-04-30 18:22:27 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): Martin Gallwey (gallwey@sun.com)
 *
 *
 ************************************************************************/

#ifndef _ZIP_PACKAGE_STREAM_HXX
#include <ZipPackageStream.hxx>
#endif
#ifndef _ZIP_PACKAGE_HXX
#include <ZipPackage.hxx>
#endif
#ifndef _ZIP_FILE_HXX
#include <ZipFile.hxx>
#endif
#ifndef _VOS_DIAGNOSE_H_
#include <vos/diagnose.hxx>
#endif

using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace com::sun::star;
using namespace cppu;
using namespace rtl;

ZipPackageStream::ZipPackageStream (ZipPackage & rNewPackage )
: rZipPackage(rNewPackage)
, bToBeCompressed ( sal_True )
, bToBeEncrypted ( sal_False )
, bPackageMember ( sal_False )
, xEncryptionData ( new EncryptionData )
{
    aEntry.nVersion     = -1;
    aEntry.nFlag        = 0;
    aEntry.nMethod      = -1;
    aEntry.nTime        = -1;
    aEntry.nCrc         = -1;
    aEntry.nCompressedSize  = -1;
    aEntry.nSize        = -1;
    aEntry.nOffset      = -1;
}

ZipPackageStream::~ZipPackageStream( void )
{
}

void ZipPackageStream::setZipEntry( const packages::ZipEntry &rInEntry)
{
    aEntry.nVersion = rInEntry.nVersion;
    aEntry.nFlag = rInEntry.nFlag;
    aEntry.nMethod = rInEntry.nMethod;
    aEntry.nTime = rInEntry.nTime;
    aEntry.nCrc = rInEntry.nCrc;
    aEntry.nCompressedSize = rInEntry.nCompressedSize;
    aEntry.nSize = rInEntry.nSize;
    aEntry.nOffset = rInEntry.nOffset;
    aEntry.sName = rInEntry.sName;
    aEntry.extra = rInEntry.extra;
    aEntry.sComment = rInEntry.sComment;
}
    //XInterface
Any SAL_CALL ZipPackageStream::queryInterface( const Type& rType )
    throw(RuntimeException)
{
    return ( ::cppu::queryInterface (   rType                                       ,
                                                // OWeakObject interfaces
                                                reinterpret_cast< XInterface*       > ( this )  ,
                                                static_cast< XWeak*         > ( this )  ,
                                                // ZipPackageEntry interfaces
                                                static_cast< container::XNamed*     > ( this )  ,
                                                static_cast< container::XChild*     > ( this )  ,
                                                static_cast< XUnoTunnel*        > ( this )  ,
                                                // My own interfaces
                                                static_cast< io::XActiveDataSink*   > ( this )  ,
                                                static_cast< beans::XPropertySet*   > ( this ) ) );

}

void SAL_CALL ZipPackageStream::acquire(  )
    throw()
{
    OWeakObject::acquire();
}
void SAL_CALL ZipPackageStream::release(  )
    throw()
{
    OWeakObject::release();
}

    // XActiveDataSink
void SAL_CALL ZipPackageStream::setInputStream( const Reference< io::XInputStream >& aStream )
        throw(RuntimeException)
{
    xStream = aStream;
    SetPackageMember ( sal_False );
    aEntry.nTime = -1;
}

Reference< io::XInputStream > SAL_CALL ZipPackageStream::getRawStream( com::sun::star::packages::ZipEntry &rEntry )
        throw(RuntimeException)
{
    if (IsPackageMember())
    {
        try
        {
            return rZipPackage.getZipFile().getRawStream(rEntry, xEncryptionData);
        }
        catch (packages::ZipException &)//rException)
        {
            VOS_ENSURE( 0, "ZipException thrown");//rException.Message);
            return Reference < io::XInputStream > ();
        }
    }
    else
        return xStream;
}

Reference< io::XInputStream > SAL_CALL ZipPackageStream::getInputStream(  )
        throw(RuntimeException)
{
    if (IsPackageMember())
    {
        try
        {
            return rZipPackage.getZipFile().getInputStream( aEntry, xEncryptionData);
        }
        catch (packages::ZipException &)//rException)
        {
            VOS_ENSURE( 0,"ZipException thrown");//rException.Message);
            return Reference < io::XInputStream > ();
        }
    }
    else
        return xStream;
}

// XPropertySet
Sequence< sal_Int8 > ZipPackageStream::getUnoTunnelImplementationId( void )
    throw (RuntimeException)
{
    static ::cppu::OImplementationId * pId = 0;
    if (! pId)
    {
        ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
        if (! pId)
        {
            static ::cppu::OImplementationId aId;
            pId = &aId;
        }
    }
    return pId->getImplementationId();
}

sal_Int64 SAL_CALL ZipPackageStream::getSomething( const Sequence< sal_Int8 >& aIdentifier )
    throw(RuntimeException)
{
    if (aIdentifier.getLength() == 16 &&
        0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(),
                               aIdentifier.getConstArray(), 16 ) )
        return reinterpret_cast < sal_Int64 > ( this );

    return 0;
}
void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName, const Any& aValue )
        throw(beans::UnknownPropertyException, beans::PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
{
    if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("MediaType")))
    {
        aValue >>= sMediaType;

        if (sMediaType.getLength() > 0)
        {
            if ( sMediaType.indexOf (OUString( RTL_CONSTASCII_USTRINGPARAM ( "text" ) ) ) != -1)
                bToBeCompressed = sal_True;
            else
                bToBeCompressed = sal_False;
        }
    }
    else if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Size") ) )
        aValue >>= aEntry.nSize;
    else if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Encrypted") ) )
        aValue >>= bToBeEncrypted;
#if SUPD>617
    else if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Compressed") ) )
#else
    else if (aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Compress") ) )
#endif
        aValue >>= bToBeCompressed;
    else
        throw beans::UnknownPropertyException();
}
Any SAL_CALL ZipPackageStream::getPropertyValue( const OUString& PropertyName )
        throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException)
{
    Any aAny;
    if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) )
    {
        aAny <<= sMediaType;
        return aAny;
    }
    else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Size" ) ) )
    {
        aAny <<= aEntry.nSize;
        return aAny;
    }
    else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Encrypted" ) ) )
    {
        aAny <<= bToBeEncrypted;
        return aAny;
    }
#if SUPD>617
    else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Compressed" ) ) )
#else
    else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Compress" ) ) )
#endif
    {
        aAny <<= bToBeCompressed;
        return aAny;
    }
    else
        throw beans::UnknownPropertyException();
}

const com::sun::star::uno::Sequence < sal_Int8 >& ZipPackageStream::getEncryptionKey ()
{
    return rZipPackage.getEncryptionKey();
}
<|endoftext|>


<commit_before><commit_msg>[rdrawable] introduce RDisplayContext class for RDrawable<commit_after><|endoftext|>


<commit_before><commit_msg>Add proper nlohmann::json forward declaration into REveElement<commit_after><|endoftext|>


<commit_before>/*************************************************************************
> File Name: BasicCardsGen.cpp
> Project Name: Hearthstone++
> Author: Chan-Ho Chris Ohk
> Purpose: BasicCardsGen class that stores the power of basic cards.
> Created Time: 2018/06/23
> Copyright (c) 2018, Chan-Ho Chris Ohk
*************************************************************************/
#include <CardSets/BasicCardsGen.h>

namespace Hearthstonepp
{
void BasicCardsGen::AddHeroes(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddHeroPowers(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddDruid(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddDruidNonCollect(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddHunter(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddHunterNonCollect(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddMage(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddMageNonCollect(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddPaladin(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddPaladinNonCollect(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddPriest(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddPriestNonCollect(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddRogue(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddRogueNonCollect(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddShaman(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddShamanNonCollect(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddWarlock(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddWarlockNonCollect(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddWarrior(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddWarriorNonCollect(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddNeutral(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddNeutralNonCollect(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddAll(std::map<std::string, Power> cards)
{
}
}<commit_msg>[ci skip] Add EX1_066 card power<commit_after>/*************************************************************************
> File Name: BasicCardsGen.cpp
> Project Name: Hearthstone++
> Author: Chan-Ho Chris Ohk
> Purpose: BasicCardsGen class that stores the power of basic cards.
> Created Time: 2018/06/23
> Copyright (c) 2018, Chan-Ho Chris Ohk
*************************************************************************/
#include <CardSets/BasicCardsGen.h>

namespace Hearthstonepp
{
void BasicCardsGen::AddHeroes(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddHeroPowers(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddDruid(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddDruidNonCollect(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddHunter(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddHunterNonCollect(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddMage(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddMageNonCollect(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddPaladin(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddPaladinNonCollect(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddPriest(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddPriestNonCollect(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddRogue(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddRogueNonCollect(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddShaman(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddShamanNonCollect(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddWarlock(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddWarlockNonCollect(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddWarrior(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddWarriorNonCollect(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddNeutral(std::map<std::string, Power> cards)
{
    // --------------------------------------- MINION - NEUTRAL
    // [EX1_066] Acidic Swamp Ooze - COST:2 [ATK:3/HP:2]
    // - Fac: alliance, Set: core, Rarity: free
    // --------------------------------------------------------
    // Text: <b>Battlecry:</b> Destroy your opponent's weapon.
    // --------------------------------------------------------
    // GameTag:
    // - BATTLECRY = 1
    // --------------------------------------------------------
    cards.emplace("EX1_066", Power());
}

void BasicCardsGen::AddNeutralNonCollect(std::map<std::string, Power> cards)
{
}

void BasicCardsGen::AddAll(std::map<std::string, Power> cards)
{
}
}<|endoftext|>


<commit_before>// This file is part of the dune-stuff project:
//   https://users.dune-project.org/projects/dune-stuff
// Copyright holders: Rene Milk, Felix Schindler
// License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)

#include <boost/config.hpp>

#if BOOST_CLANG
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wunused-parameter"
# pragma GCC diagnostic ignored "-Wdeprecated-register"
# pragma GCC diagnostic ignored "-Wignored-qualifiers"
# pragma GCC diagnostic ignored "-Wextra"
# pragma GCC diagnostic ignored "-Wmissing-field-initializers"
# pragma GCC diagnostic ignored "-Wtype-limits"
# pragma GCC diagnostic ignored "-Wshadow"
# pragma GCC diagnostic ignored "-Wreorder"
# pragma GCC diagnostic ignored "-Wuninitialized"
# pragma GCC diagnostic ignored "-Wunused-local-typedefs"
# pragma GCC diagnostic ignored "-Wused-but-marked-unused"
# pragma GCC diagnostic ignored "-Wlogical-not-parentheses"
#elif BOOST_GCC
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wunused-parameter"
# pragma GCC diagnostic ignored "-Wignored-qualifiers"
# pragma GCC diagnostic ignored "-Wextra"
# pragma GCC diagnostic ignored "-Wmissing-field-initializers"
# pragma GCC diagnostic ignored "-Wtype-limits"
# pragma GCC diagnostic ignored "-Wshadow"
# pragma GCC diagnostic ignored "-Wreorder"
# pragma GCC diagnostic ignored "-Wuninitialized"
# pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#endif
<commit_msg>Revert "[common.disable_warnings] add -Wunused-local-typedefs to clang"<commit_after>// This file is part of the dune-stuff project:
//   https://users.dune-project.org/projects/dune-stuff
// Copyright holders: Rene Milk, Felix Schindler
// License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)

#include <boost/config.hpp>

#if BOOST_CLANG
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wunused-parameter"
# pragma GCC diagnostic ignored "-Wdeprecated-register"
# pragma GCC diagnostic ignored "-Wignored-qualifiers"
# pragma GCC diagnostic ignored "-Wextra"
# pragma GCC diagnostic ignored "-Wmissing-field-initializers"
# pragma GCC diagnostic ignored "-Wtype-limits"
# pragma GCC diagnostic ignored "-Wshadow"
# pragma GCC diagnostic ignored "-Wreorder"
# pragma GCC diagnostic ignored "-Wuninitialized"
# pragma GCC diagnostic ignored "-Wused-but-marked-unused"
# pragma GCC diagnostic ignored "-Wlogical-not-parentheses"
#elif BOOST_GCC
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wunused-parameter"
# pragma GCC diagnostic ignored "-Wignored-qualifiers"
# pragma GCC diagnostic ignored "-Wextra"
# pragma GCC diagnostic ignored "-Wmissing-field-initializers"
# pragma GCC diagnostic ignored "-Wtype-limits"
# pragma GCC diagnostic ignored "-Wshadow"
# pragma GCC diagnostic ignored "-Wreorder"
# pragma GCC diagnostic ignored "-Wuninitialized"
# pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#endif
<|endoftext|>


<commit_before>// This file is part of the dune-stuff project:
//   https://users.dune-project.org/projects/dune-stuff
// Copyright holders: Rene Milk, Felix Schindler
// License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
//
// Contributors: Kirsten Weber

#ifndef DUNE_STUFF_GRID_PROVIDER_INTERFACE_HH
#define DUNE_STUFF_GRID_PROVIDER_INTERFACE_HH

#include <memory>

#include <dune/common/fvector.hh>

#if HAVE_DUNE_GRID
# include <dune/stuff/common/disable_warnings.hh>
#   include <dune/grid/io/file/vtk/vtkwriter.hh>
# include <dune/stuff/common/reenable_warnings.hh>
#endif

#include <dune/stuff/common/ranges.hh>
#include <dune/stuff/common/exceptions.hh>
#include <dune/stuff/grid/layers.hh>
#include <dune/stuff/common/configtree.hh>
#include <dune/stuff/grid/boundaryinfo.hh>

namespace Dune {
namespace Stuff {
namespace Grid {

#if HAVE_DUNE_GRID

template< class GridImp >
class ConstProviderInterface
{
public:
  typedef GridImp GridType;
  static const unsigned int                         dimDomain = GridImp::dimension;
  typedef typename GridType::ctype                  DomainFieldType;
  typedef FieldVector< DomainFieldType, dimDomain>  DomainType;
  typedef typename GridType::template Codim< 0 >::Entity EntityType;

  template< ChooseLayer layer, ChoosePartView type >
  struct Layer
  {
    typedef typename Grid::Layer< GridType, layer, type >::Type Type;
  };

  template< ChoosePartView type >
  struct Level
  {
    typedef typename LevelPartView< GridType, type >::Type Type;
  };

  template< ChoosePartView type >
  struct Leaf
  {
    typedef typename LeafPartView< GridType, type >::Type Type;
  };

  template< ChooseLayer type >
  struct View
  {
    typedef typename LayerView< GridType, type >::Type Type;
  };

  template< ChooseLayer type >
  struct Part
  {
    typedef typename LayerView< GridType, type >::Type Type;
  };

  typedef typename Layer< ChooseLayer::level, ChoosePartView::view >::Type LevelGridViewType;
#if HAVE_DUNE_FEM
  typedef typename Layer< ChooseLayer::level, ChoosePartView::part >::Type LevelGridPartType;
#endif

  typedef typename Layer< ChooseLayer::leaf, ChoosePartView::view >::Type LeafGridViewType;
#if HAVE_DUNE_FEM
  typedef typename Layer< ChooseLayer::leaf, ChoosePartView::part >::Type LeafGridPartType;
#endif

  static const std::string static_id()
  {
    return "stuff.grid.provider";
  }

  virtual ~ConstProviderInterface(){}

  virtual std::shared_ptr< const GridType > grid() const = 0;

  template< ChooseLayer layer_type, ChoosePartView part_view_type >
  std::shared_ptr< const typename Layer< layer_type, part_view_type >::Type > layer(const int level = 0) const
  {
    GridType& non_const_grid = const_cast< GridType& >(*(grid()));
    return Grid::Layer< GridType, layer_type, part_view_type >::create(non_const_grid, level);
  }

  template< ChoosePartView type >
  std::shared_ptr< const typename Level< type >::Type > level(const int level) const
  {
    GridType& non_const_grid = const_cast< GridType& >(*(grid()));
    return LevelPartView< GridType, type >::create(non_const_grid, level);
  }

  std::shared_ptr< const LevelGridViewType > level_view(const int level) const
  {
    return this->template level< ChoosePartView::view >(level);
  }

#if HAVE_DUNE_FEM
  std::shared_ptr< const LevelGridPartType > level_part(const int level) const
  {
    return this->template level< ChoosePartView::part >(level);
  }
#endif // HAVE_DUNE_FEM

  template< ChoosePartView type >
  std::shared_ptr< const typename Leaf< type >::Type > leaf() const
  {
    GridType& non_const_grid = const_cast< GridType& >(*(grid()));
    return LeafPartView< GridType, type >::create(non_const_grid);
  }

  std::shared_ptr< const LeafGridViewType > leaf_view() const
  {
    return this->template leaf< ChoosePartView::view >();
  }

#if HAVE_DUNE_FEM
  std::shared_ptr< const LeafGridPartType > leaf_part() const
  {
    return this->template leaf< ChoosePartView::part >();
  }
#endif // HAVE_DUNE_FEM

  virtual void visualize(const std::string filename = static_id()) const
  {
    // vtk writer
    auto grid_view = leaf_view();
    Dune::VTKWriter< LeafGridViewType > vtkwriter(*grid_view);
    // codim 0 entity id
    std::vector< double > entityId = generateEntityVisualization(*grid_view);
    vtkwriter.addCellData(entityId, "entity_id");
    // boundary id
    std::vector< double > boundaryId = generateBoundaryIdVisualization(*grid_view);
    vtkwriter.addCellData(boundaryId, "boundary_id");
    // write
    vtkwriter.write(filename, VTK::appendedraw);
  } // ... visualize(...)

  virtual void visualize(const Common::ConfigTree& boundary_info_cfg,
                         const std::string filename = static_id()) const
  {
    // boundary info
    typedef Stuff::Grid::BoundaryInfoProvider< typename LeafGridViewType::Intersection > BoundaryInfoProvider;
    auto boundary_info_ptr = BoundaryInfoProvider::create(boundary_info_cfg.get< std::string >("type"),
                                                          boundary_info_cfg);
    // vtk writer
    auto grid_view = leaf_view();
    Dune::VTKWriter< LeafGridViewType > vtkwriter(*grid_view);
    // codim 0 entity id
    std::vector< double > entityId = generateEntityVisualization(*grid_view);
    vtkwriter.addCellData(entityId, "entityId");
    // boundary id
    std::vector< double > boundaryId = generateBoundaryIdVisualization(*grid_view);
    vtkwriter.addCellData(boundaryId, "boundaryId");
    // dirichlet values
    std::vector< double > dirichlet = generateBoundaryVisualization(*grid_view, *boundary_info_ptr, "dirichlet");
    vtkwriter.addCellData(dirichlet, "isDirichletBoundary");
    // neumann values
    std::vector< double > neumann = generateBoundaryVisualization(*grid_view, *boundary_info_ptr, "neumann");
    vtkwriter.addCellData(neumann, "isNeumannBoundary");
    // write
    vtkwriter.write(filename, VTK::appendedraw);
  } // ... visualize(...)

private:
  std::vector< double > generateBoundaryIdVisualization(const LeafGridViewType& gridView) const
  {
    std::vector< double > data(gridView.indexSet().size(0));
    // walk the grid
    for (typename LeafGridViewType::template Codim< 0 >::Iterator it = gridView.template begin< 0 >();
         it != gridView.template end< 0 >();
         ++it)
    {
      const auto& entity = *it;
      const auto& index = gridView.indexSet().index(entity);
      data[index] = 0.0;
      int numberOfBoundarySegments = 0;
      bool isOnBoundary = false;
      for (auto intersectionIt = gridView.ibegin(entity);
           intersectionIt != gridView.iend(entity);
           ++intersectionIt) {
        if (!intersectionIt->neighbor() && intersectionIt->boundary()){
          isOnBoundary = true;
          numberOfBoundarySegments += 1;
          data[index] += double(intersectionIt->boundaryId());
        }
      }
      if (isOnBoundary) {
        data[index] /= double(numberOfBoundarySegments);
      }
    } // walk the grid
    return data;
  } // std::vector< double > generateBoundaryIdVisualization(const LeafGridViewType& gridView) const

  template< class BoundaryInfoType >
  std::vector< double > generateBoundaryVisualization(const LeafGridViewType& gridView,
                                                      const BoundaryInfoType& boundaryInfo,
                                                      const std::string type) const
  {
    std::vector< double > data(gridView.indexSet().size(0));
    // walk the grid
    for (const auto& entity : DSC::viewRange(gridView))
    {
      const auto& index = gridView.indexSet().index(entity);
      data[index] = 0.0;
      for (auto intersectionIt = gridView.ibegin(entity);
           intersectionIt != gridView.iend(entity);
           ++intersectionIt) {
        if (type == "dirichlet") {
          if (boundaryInfo.dirichlet(*intersectionIt))
            data[index] = 1.0;
        } else if (type == "neumann") {
          if (boundaryInfo.neumann(*intersectionIt))
            data[index] = 1.0;
        } else
          DUNE_THROW_COLORFULLY(Exceptions::internal_error, "Unknown type '" << type << "'!");
      }
    } // walk the grid
    return data;
  } // std::vector< double > generateBoundaryVisualization(...) const

  std::vector< double > generateEntityVisualization(const LeafGridViewType& gridView) const
  {
    std::vector< double > data(gridView.indexSet().size(0));
    for (const auto& entity : DSC::viewRange(gridView))
    {
      const auto& index = gridView.indexSet().index(entity);
      data[index] = double(index);
    } // walk the grid
    return data;
  } // ... generateEntityVisualization(...)
}; // class ConstProviderInterface

template< class GridImp >
class ProviderInterface
  : public ConstProviderInterface< GridImp >
{
  typedef ConstProviderInterface< GridImp > BaseType;
public:
  using typename BaseType::GridType;
  using typename BaseType::LevelGridViewType;
  using typename BaseType::LevelGridPartType;
  using typename BaseType::LeafGridViewType;
  using typename BaseType::LeafGridPartType;

  static const std::string static_id()
  {
    return BaseType::static_id();
  }

  virtual ~ProviderInterface(){}

  using BaseType::grid;

  virtual std::shared_ptr< GridType > grid() = 0;

  using BaseType::layer;

  template< ChooseLayer layer_type, ChoosePartView part_view_type >
  std::shared_ptr< typename BaseType::template Layer< layer_type, part_view_type >::Type > layer(const int level = 0)
  {
    return Grid::Layer< GridType, layer_type, part_view_type >::create(*(grid()), level);
  }

  using BaseType::level;

  template< ChoosePartView type >
  std::shared_ptr< typename BaseType::template Level< type >::Type > level(const int level)
  {
    return LevelPartView< GridType, type >::create(*(grid()), level);
  }

  using BaseType::level_view;

  std::shared_ptr< LevelGridViewType > level_view(const int level)
  {
    return this->template level< ChoosePartView::view >(level);
  }

#if HAVE_DUNE_FEM
  using BaseType::level_part;

  std::shared_ptr< LevelGridPartType > level_part(const int level)
  {
    return this->template level< ChoosePartView::part >(level);
  }
#endif // HAVE_DUNE_FEM

  using BaseType::leaf;

  template< ChoosePartView type >
  std::shared_ptr< typename BaseType::template Leaf< type >::Type > leaf()
  {
    return LeafPartView< GridType, type >::create(*(grid()));
  }

  using BaseType::leaf_view;

  std::shared_ptr< LeafGridViewType > leaf_view()
  {
    return this->template leaf< ChoosePartView::view >();
  }

#if HAVE_DUNE_FEM
  using BaseType::leaf_part;

  std::shared_ptr< LeafGridPartType > leaf_part()
  {
    return this->template leaf< ChoosePartView::part >();
  }

#endif // HAVE_DUNE_FEM
}; // class ProviderInterface

#else // HAVE_DUNE_GRID

template< class GridImp >
class ConstProviderInterface
{
  static_assert(AlwaysFalse< GridImp >::value, "You are missing dune-grid!");
};

template< class GridImp >
class ProviderInterface
{
  static_assert(AlwaysFalse< GridImp >::value, "You are missing dune-grid!");
};

#endif // HAVE_DUNE_GRID

} // namespace Grid
} // namespace Stuff
} // namespace Dune

#endif // DUNE_STUFF_GRID_PROVIDER_INTERFACE_HH
<commit_msg>[grid.provider.interface] whitespace<commit_after>// This file is part of the dune-stuff project:
//   https://users.dune-project.org/projects/dune-stuff
// Copyright holders: Rene Milk, Felix Schindler
// License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
//
// Contributors: Kirsten Weber

#ifndef DUNE_STUFF_GRID_PROVIDER_INTERFACE_HH
#define DUNE_STUFF_GRID_PROVIDER_INTERFACE_HH

#include <memory>

#include <dune/common/fvector.hh>

#if HAVE_DUNE_GRID
# include <dune/stuff/common/disable_warnings.hh>
#   include <dune/grid/io/file/vtk/vtkwriter.hh>
# include <dune/stuff/common/reenable_warnings.hh>
#endif

#include <dune/stuff/common/ranges.hh>
#include <dune/stuff/common/exceptions.hh>
#include <dune/stuff/grid/layers.hh>
#include <dune/stuff/common/configtree.hh>
#include <dune/stuff/grid/boundaryinfo.hh>

namespace Dune {
namespace Stuff {
namespace Grid {

#if HAVE_DUNE_GRID

template< class GridImp >
class ConstProviderInterface
{
public:
  typedef GridImp GridType;
  static const unsigned int                         dimDomain = GridImp::dimension;
  typedef typename GridType::ctype                  DomainFieldType;
  typedef FieldVector< DomainFieldType, dimDomain>  DomainType;
  typedef typename GridType::template Codim< 0 >::Entity EntityType;

  template< ChooseLayer layer, ChoosePartView type >
  struct Layer
  {
    typedef typename Grid::Layer< GridType, layer, type >::Type Type;
  };

  template< ChoosePartView type >
  struct Level
  {
    typedef typename LevelPartView< GridType, type >::Type Type;
  };

  template< ChoosePartView type >
  struct Leaf
  {
    typedef typename LeafPartView< GridType, type >::Type Type;
  };

  template< ChooseLayer type >
  struct View
  {
    typedef typename LayerView< GridType, type >::Type Type;
  };

  template< ChooseLayer type >
  struct Part
  {
    typedef typename LayerView< GridType, type >::Type Type;
  };

  typedef typename Layer< ChooseLayer::level, ChoosePartView::view >::Type LevelGridViewType;
#if HAVE_DUNE_FEM
  typedef typename Layer< ChooseLayer::level, ChoosePartView::part >::Type LevelGridPartType;
#endif

  typedef typename Layer< ChooseLayer::leaf, ChoosePartView::view >::Type LeafGridViewType;
#if HAVE_DUNE_FEM
  typedef typename Layer< ChooseLayer::leaf, ChoosePartView::part >::Type LeafGridPartType;
#endif

  static const std::string static_id()
  {
    return "stuff.grid.provider";
  }

  virtual ~ConstProviderInterface(){}

  virtual std::shared_ptr< const GridType > grid() const = 0;

  template< ChooseLayer layer_type, ChoosePartView part_view_type >
  std::shared_ptr< const typename Layer< layer_type, part_view_type >::Type > layer(const int level = 0) const
  {
    GridType& non_const_grid = const_cast< GridType& >(*(grid()));
    return Grid::Layer< GridType, layer_type, part_view_type >::create(non_const_grid, level);
  }

  template< ChoosePartView type >
  std::shared_ptr< const typename Level< type >::Type > level(const int level) const
  {
    GridType& non_const_grid = const_cast< GridType& >(*(grid()));
    return LevelPartView< GridType, type >::create(non_const_grid, level);
  }

  std::shared_ptr< const LevelGridViewType > level_view(const int level) const
  {
    return this->template level< ChoosePartView::view >(level);
  }

#if HAVE_DUNE_FEM
  std::shared_ptr< const LevelGridPartType > level_part(const int level) const
  {
    return this->template level< ChoosePartView::part >(level);
  }
#endif // HAVE_DUNE_FEM

  template< ChoosePartView type >
  std::shared_ptr< const typename Leaf< type >::Type > leaf() const
  {
    GridType& non_const_grid = const_cast< GridType& >(*(grid()));
    return LeafPartView< GridType, type >::create(non_const_grid);
  }

  std::shared_ptr< const LeafGridViewType > leaf_view() const
  {
    return this->template leaf< ChoosePartView::view >();
  }

#if HAVE_DUNE_FEM
  std::shared_ptr< const LeafGridPartType > leaf_part() const
  {
    return this->template leaf< ChoosePartView::part >();
  }
#endif // HAVE_DUNE_FEM

  virtual void visualize(const std::string filename = static_id()) const
  {
    // vtk writer
    auto grid_view = leaf_view();
    Dune::VTKWriter< LeafGridViewType > vtkwriter(*grid_view);
    // codim 0 entity id
    std::vector< double > entityId = generateEntityVisualization(*grid_view);
    vtkwriter.addCellData(entityId, "entity_id");
    // boundary id
    std::vector< double > boundaryId = generateBoundaryIdVisualization(*grid_view);
    vtkwriter.addCellData(boundaryId, "boundary_id");
    // write
    vtkwriter.write(filename, VTK::appendedraw);
  } // ... visualize(...)

  virtual void visualize(const Common::ConfigTree& boundary_info_cfg, const std::string filename = static_id()) const
  {
    // boundary info
    typedef Stuff::Grid::BoundaryInfoProvider< typename LeafGridViewType::Intersection > BoundaryInfoProvider;
    auto boundary_info_ptr = BoundaryInfoProvider::create(boundary_info_cfg.get< std::string >("type"),
                                                          boundary_info_cfg);
    // vtk writer
    auto grid_view = leaf_view();
    Dune::VTKWriter< LeafGridViewType > vtkwriter(*grid_view);
    // codim 0 entity id
    std::vector< double > entityId = generateEntityVisualization(*grid_view);
    vtkwriter.addCellData(entityId, "entityId");
    // boundary id
    std::vector< double > boundaryId = generateBoundaryIdVisualization(*grid_view);
    vtkwriter.addCellData(boundaryId, "boundaryId");
    // dirichlet values
    std::vector< double > dirichlet = generateBoundaryVisualization(*grid_view, *boundary_info_ptr, "dirichlet");
    vtkwriter.addCellData(dirichlet, "isDirichletBoundary");
    // neumann values
    std::vector< double > neumann = generateBoundaryVisualization(*grid_view, *boundary_info_ptr, "neumann");
    vtkwriter.addCellData(neumann, "isNeumannBoundary");
    // write
    vtkwriter.write(filename, VTK::appendedraw);
  } // ... visualize(...)

private:
  std::vector< double > generateBoundaryIdVisualization(const LeafGridViewType& gridView) const
  {
    std::vector< double > data(gridView.indexSet().size(0));
    // walk the grid
    for (typename LeafGridViewType::template Codim< 0 >::Iterator it = gridView.template begin< 0 >();
         it != gridView.template end< 0 >();
         ++it)
    {
      const auto& entity = *it;
      const auto& index = gridView.indexSet().index(entity);
      data[index] = 0.0;
      int numberOfBoundarySegments = 0;
      bool isOnBoundary = false;
      for (auto intersectionIt = gridView.ibegin(entity);
           intersectionIt != gridView.iend(entity);
           ++intersectionIt) {
        if (!intersectionIt->neighbor() && intersectionIt->boundary()){
          isOnBoundary = true;
          numberOfBoundarySegments += 1;
          data[index] += double(intersectionIt->boundaryId());
        }
      }
      if (isOnBoundary) {
        data[index] /= double(numberOfBoundarySegments);
      }
    } // walk the grid
    return data;
  } // std::vector< double > generateBoundaryIdVisualization(const LeafGridViewType& gridView) const

  template< class BoundaryInfoType >
  std::vector< double > generateBoundaryVisualization(const LeafGridViewType& gridView,
                                                      const BoundaryInfoType& boundaryInfo,
                                                      const std::string type) const
  {
    std::vector< double > data(gridView.indexSet().size(0));
    // walk the grid
    for (const auto& entity : DSC::viewRange(gridView))
    {
      const auto& index = gridView.indexSet().index(entity);
      data[index] = 0.0;
      for (auto intersectionIt = gridView.ibegin(entity);
           intersectionIt != gridView.iend(entity);
           ++intersectionIt) {
        if (type == "dirichlet") {
          if (boundaryInfo.dirichlet(*intersectionIt))
            data[index] = 1.0;
        } else if (type == "neumann") {
          if (boundaryInfo.neumann(*intersectionIt))
            data[index] = 1.0;
        } else
          DUNE_THROW_COLORFULLY(Exceptions::internal_error, "Unknown type '" << type << "'!");
      }
    } // walk the grid
    return data;
  } // std::vector< double > generateBoundaryVisualization(...) const

  std::vector< double > generateEntityVisualization(const LeafGridViewType& gridView) const
  {
    std::vector< double > data(gridView.indexSet().size(0));
    for (const auto& entity : DSC::viewRange(gridView))
    {
      const auto& index = gridView.indexSet().index(entity);
      data[index] = double(index);
    } // walk the grid
    return data;
  } // ... generateEntityVisualization(...)
}; // class ConstProviderInterface

template< class GridImp >
class ProviderInterface
  : public ConstProviderInterface< GridImp >
{
  typedef ConstProviderInterface< GridImp > BaseType;
public:
  using typename BaseType::GridType;
  using typename BaseType::LevelGridViewType;
  using typename BaseType::LevelGridPartType;
  using typename BaseType::LeafGridViewType;
  using typename BaseType::LeafGridPartType;

  static const std::string static_id()
  {
    return BaseType::static_id();
  }

  virtual ~ProviderInterface(){}

  using BaseType::grid;

  virtual std::shared_ptr< GridType > grid() = 0;

  using BaseType::layer;

  template< ChooseLayer layer_type, ChoosePartView part_view_type >
  std::shared_ptr< typename BaseType::template Layer< layer_type, part_view_type >::Type > layer(const int level = 0)
  {
    return Grid::Layer< GridType, layer_type, part_view_type >::create(*(grid()), level);
  }

  using BaseType::level;

  template< ChoosePartView type >
  std::shared_ptr< typename BaseType::template Level< type >::Type > level(const int level)
  {
    return LevelPartView< GridType, type >::create(*(grid()), level);
  }

  using BaseType::level_view;

  std::shared_ptr< LevelGridViewType > level_view(const int level)
  {
    return this->template level< ChoosePartView::view >(level);
  }

#if HAVE_DUNE_FEM
  using BaseType::level_part;

  std::shared_ptr< LevelGridPartType > level_part(const int level)
  {
    return this->template level< ChoosePartView::part >(level);
  }
#endif // HAVE_DUNE_FEM

  using BaseType::leaf;

  template< ChoosePartView type >
  std::shared_ptr< typename BaseType::template Leaf< type >::Type > leaf()
  {
    return LeafPartView< GridType, type >::create(*(grid()));
  }

  using BaseType::leaf_view;

  std::shared_ptr< LeafGridViewType > leaf_view()
  {
    return this->template leaf< ChoosePartView::view >();
  }

#if HAVE_DUNE_FEM
  using BaseType::leaf_part;

  std::shared_ptr< LeafGridPartType > leaf_part()
  {
    return this->template leaf< ChoosePartView::part >();
  }

#endif // HAVE_DUNE_FEM
}; // class ProviderInterface

#else // HAVE_DUNE_GRID

template< class GridImp >
class ConstProviderInterface
{
  static_assert(AlwaysFalse< GridImp >::value, "You are missing dune-grid!");
};

template< class GridImp >
class ProviderInterface
{
  static_assert(AlwaysFalse< GridImp >::value, "You are missing dune-grid!");
};

#endif // HAVE_DUNE_GRID

} // namespace Grid
} // namespace Stuff
} // namespace Dune

#endif // DUNE_STUFF_GRID_PROVIDER_INTERFACE_HH
<|endoftext|>