<commit_before>///
/// @file   primesieve.hpp
/// @brief  primesieve C++ API. primesieve is a library for fast prime
///         number generation. In case an error occurs the functions
///         declared in this header will throw a
///         primesieve::primesieve_error exception (derived form
///         std::runtime_error).
///
/// Copyright (C) 2015 Kim Walisch, <kim.walisch@gmail.com>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
///

#ifndef PRIMESIEVE_HPP
#define PRIMESIEVE_HPP

#define PRIMESIEVE_VERSION "5.5.0"
#define PRIMESIEVE_VERSION_MAJOR 5
#define PRIMESIEVE_VERSION_MINOR 5
#define PRIMESIEVE_VERSION_PATCH 0

#include "primesieve/PrimeSieve.hpp"
#include "primesieve/ParallelPrimeSieve.hpp"
#include "primesieve/Callback.hpp"
#include "primesieve/cancel_callback.hpp"
#include "primesieve/iterator.hpp"
#include "primesieve/PushBackPrimes.hpp"
#include "primesieve/primesieve_error.hpp"

#include <stdint.h>
#include <vector>
#include <string>

/// All of primesieve's C++ functions and classes are declared
/// inside this namespace.
///
namespace primesieve
{
  enum {
    /// Use all CPU cores for prime sieving.
    MAX_THREADS = -1
  };

  /// Store the primes <= stop in the primes vector.
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  template <typename T>
  inline void generate_primes(uint64_t stop, std::vector<T>* primes)
  {
    if (primes)
    {
      PushBackPrimes<T> pb(*primes);
      pb.pushBackPrimes(0, stop);
    }
  }

  /// Store the primes within the interval [start, stop]
  /// in the primes vector.
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  template <typename T>
  inline void generate_primes(uint64_t start, uint64_t stop, std::vector<T>* primes)
  {
    if (primes)
    {
      PushBackPrimes<T> pb(*primes);
      pb.pushBackPrimes(start, stop);
    }
  }

  /// Store the first n primes in the primes vector.
  template <typename T>
  inline void generate_n_primes(uint64_t n, std::vector<T>* primes)
  {
    if (primes)
    {
      PushBack_N_Primes<T> pb(*primes);
      pb.pushBack_N_Primes(n, 0);
    }
  }

  /// Store the first n primes >= start in the primes vector.
  /// @pre start <= 2^64 - 2^32 * 10.
  ///
  template <typename T>
  inline void generate_n_primes(uint64_t n, uint64_t start, std::vector<T>* primes)
  {
    if (primes)
    {
      PushBack_N_Primes<T> pb(*primes);
      pb.pushBack_N_Primes(n, start);
    }
  }

  /// Find the nth prime.
  /// @param n  if n = 0 finds the 1st prime >= start,

  ///           if n > 0 finds the nth prime > start,

  ///           if n < 0 finds the nth prime < start (backwards).
  /// @pre   start <= 2^64 - 2^32 * 11.
  ///
  uint64_t nth_prime(int64_t n, uint64_t start = 0);

  /// Find the nth prime in parallel.
  /// By default all CPU cores are used, use
  /// primesieve::set_num_threads(int) to change the number of
  /// threads.
  /// @param n  if n = 0 finds the 1st prime >= start,

  ///           if n > 0 finds the nth prime > start,

  ///           if n < 0 finds the nth prime < start (backwards).
  /// @pre   start <= 2^64 - 2^32 * 11.
  ///
  uint64_t parallel_nth_prime(int64_t n, uint64_t start = 0);

  /// Count the primes within the interval [start, stop].
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  uint64_t count_primes(uint64_t start, uint64_t stop);

  /// Count the twin primes within the interval [start, stop].
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  uint64_t count_twins(uint64_t start, uint64_t stop);

  /// Count the prime triplets within the interval [start, stop].
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  uint64_t count_triplets(uint64_t start, uint64_t stop);

  /// Count the prime quadruplets within the interval [start, stop].
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  uint64_t count_quadruplets(uint64_t start, uint64_t stop);

  /// Count the prime quintuplets within the interval [start, stop].
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  uint64_t count_quintuplets(uint64_t start, uint64_t stop);

  /// Count the prime sextuplets within the interval [start, stop].
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  uint64_t count_sextuplets(uint64_t start, uint64_t stop);

  /// Count the primes within the interval [start, stop] in
  /// parallel. By default all CPU cores are used, use
  /// primesieve::set_num_threads(int) to change the number of
  /// threads.
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  uint64_t parallel_count_primes(uint64_t start, uint64_t stop);

  /// Count the twin primes within the interval [start, stop] in
  /// parallel. By default all CPU cores are used, use
  /// primesieve::set_num_threads(int) to change the number of
  /// threads.
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  uint64_t parallel_count_twins(uint64_t start, uint64_t stop);

  /// Count the prime triplets within the interval [start, stop] in
  /// parallel. By default all CPU cores are used, use
  /// primesieve::set_num_threads(int) to change the number of
  /// threads.
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  uint64_t parallel_count_triplets(uint64_t start, uint64_t stop);

  /// Count the prime quadruplets within the interval [start, stop] in
  /// parallel. By default all CPU cores are used, use
  /// primesieve::set_num_threads(int) to change the number of
  /// threads.
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  uint64_t parallel_count_quadruplets(uint64_t start, uint64_t stop);

  /// Count the prime quintuplets within the interval [start, stop] in
  /// parallel. By default all CPU cores are used, use
  /// primesieve::set_num_threads(int) to change the number of
  /// threads.
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  uint64_t parallel_count_quintuplets(uint64_t start, uint64_t stop);

  /// Count the prime sextuplets within the interval [start, stop] in
  /// parallel. By default all CPU cores are used, use
  /// primesieve::set_num_threads(int) to change the number of
  /// threads.
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  uint64_t parallel_count_sextuplets(uint64_t start, uint64_t stop);

  /// Print the primes within the interval [start, stop]
  /// to the standard output.
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  void print_primes(uint64_t start, uint64_t stop);

  /// Print the twin primes within the interval [start, stop]
  /// to the standard output.
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  void print_twins(uint64_t start, uint64_t stop);

  /// Print the prime triplets within the interval [start, stop]
  /// to the standard output.
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  void print_triplets(uint64_t start, uint64_t stop);

  /// Print the prime quadruplets within the interval [start, stop]
  /// to the standard output.
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  void print_quadruplets(uint64_t start, uint64_t stop);

  /// Print the prime quintuplets within the interval [start, stop]
  /// to the standard output.
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  void print_quintuplets(uint64_t start, uint64_t stop);

  /// Print the prime sextuplets within the interval [start, stop]
  /// to the standard output.
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  void print_sextuplets(uint64_t start, uint64_t stop);

  /// Call back the primes within the interval [start, stop].
  /// @param callback  A callback function.
  /// @pre   stop <= 2^64 - 2^32 * 10.
  ///
  void callback_primes(uint64_t start, uint64_t stop, void (*callback)(uint64_t prime));

  /// Call back the primes within the interval [start, stop].
  /// @param callback  An object derived from primesieve::Callback<uint64_t>.
  /// @pre   stop <= 2^64 - 2^32 * 10.
  ///
  void callback_primes(uint64_t start, uint64_t stop, primesieve::Callback<uint64_t>* callback);

  /// Call back the primes within the interval [start, stop].
  /// This function is synchronized, only one thread at a time calls
  /// back primes. By default all CPU cores are used, use
  /// primesieve::set_num_threads(int) to change the number of
  /// threads.
  /// @warning         Primes are not called back in arithmetic order.
  /// @param callback  A callback function.
  /// @pre   stop      <= 2^64 - 2^32 * 10.
  ///
  void parallel_callback_primes(uint64_t start, uint64_t stop, void (*callback)(uint64_t prime));

  /// Call back the primes within the interval [start, stop].
  /// This function is synchronized, only one thread at a time calls
  /// back primes. By default all CPU cores are used, use
  /// primesieve::set_num_threads(int) to change the number of
  /// threads.
  /// @warning         Primes are not called back in arithmetic order.
  /// @param callback  An object derived from primesieve::Callback<uint64_t>.
  /// @pre   stop      <= 2^64 - 2^32 * 10.
  ///
  void parallel_callback_primes(uint64_t start, uint64_t stop, primesieve::Callback<uint64_t>* callback);

  /// Call back the primes within the interval [start, stop].
  /// This function is not synchronized, multiple threads call back
  /// primes in parallel. By default all CPU cores are used, use
  /// primesieve::set_num_threads(int) to change the number of
  /// threads.
  /// @warning         Primes are not called back in arithmetic order.
  /// @param callback  A callback function.
  /// @pre   stop      <= 2^64 - 2^32 * 10.
  ///
  void parallel_callback_primes(uint64_t start, uint64_t stop, void (*callback)(uint64_t prime, int thread_id));

  /// Call back the primes within the interval [start, stop].
  /// This function is not synchronized, multiple threads call back
  /// primes in parallel. By default all CPU cores are used, use
  /// primesieve::set_num_threads(int) to change the number of
  /// threads.
  /// @warning         Primes are not called back in arithmetic order.
  /// @param callback  An object derived from primesieve::Callback<uint64_t, int>.
  /// @pre   stop      <= 2^64 - 2^32 * 10.
  ///
  void parallel_callback_primes(uint64_t start, uint64_t stop, primesieve::Callback<uint64_t, int>* callback);

  /// Get the current set sieve size in kilobytes.
  int get_sieve_size();

  /// Get the current set number of threads.
  /// @note By default MAX_THREADS (-1) is returned.
  ///
  int get_num_threads();

  /// Returns the largest valid stop number for primesieve.
  /// @return (2^64-1) - (2^32-1) * 10.
  ///
  uint64_t get_max_stop();

  /// Set the sieve size in kilobytes.
  /// The best sieving performance is achieved with a sieve size of
  /// your CPU's L1 data cache size (per core). For sieving >= 10^17 a
  /// sieve size of your CPU's L2 cache size sometimes performs
  /// better.
  /// @param sieve_size Sieve size in kilobytes.
  /// @pre   sieve_size >= 1 && sieve_size <= 2048.
  ///
  void set_sieve_size(int sieve_size);

  /// Set the number of threads for use in subsequent
  /// primesieve::parallel_* function calls. Note that this only
  /// changes the number of threads for the current process.
  /// @param num_threads  Number of threads for sieving
  ///                     or MAX_THREADS to use all CPU cores.
  ///
  void set_num_threads(int num_threads);

  /// Run extensive correctness tests.
  /// The tests last about one minute on a quad core CPU from
  /// 2013 and use up to 1 gigabyte of memory.
  /// @return true if success else false.
  ///
  bool primesieve_test();

  /// Get the primesieve version number, in the form “i.j.k”.
  std::string primesieve_version();
}

#endif
<commit_msg>Remove COPYING comment<commit_after>///
/// @file   primesieve.hpp
/// @brief  primesieve C++ API. primesieve is a library for fast prime
///         number generation, in case an error occurs a
///         primesieve::primesieve_error exception (derived form
///         std::runtime_error) will be thrown.
///
/// Copyright (C) 2015 Kim Walisch, <kim.walisch@gmail.com>
///
/// This file is distributed under the BSD License.
///

#ifndef PRIMESIEVE_HPP
#define PRIMESIEVE_HPP

#define PRIMESIEVE_VERSION "5.5.0"
#define PRIMESIEVE_VERSION_MAJOR 5
#define PRIMESIEVE_VERSION_MINOR 5
#define PRIMESIEVE_VERSION_PATCH 0

#include "primesieve/PrimeSieve.hpp"
#include "primesieve/ParallelPrimeSieve.hpp"
#include "primesieve/Callback.hpp"
#include "primesieve/cancel_callback.hpp"
#include "primesieve/iterator.hpp"
#include "primesieve/PushBackPrimes.hpp"
#include "primesieve/primesieve_error.hpp"

#include <stdint.h>
#include <vector>
#include <string>

/// All of primesieve's C++ functions and classes are declared
/// inside this namespace.
///
namespace primesieve
{
  enum {
    /// Use all CPU cores for prime sieving.
    MAX_THREADS = -1
  };

  /// Store the primes <= stop in the primes vector.
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  template <typename T>
  inline void generate_primes(uint64_t stop, std::vector<T>* primes)
  {
    if (primes)
    {
      PushBackPrimes<T> pb(*primes);
      pb.pushBackPrimes(0, stop);
    }
  }

  /// Store the primes within the interval [start, stop]
  /// in the primes vector.
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  template <typename T>
  inline void generate_primes(uint64_t start, uint64_t stop, std::vector<T>* primes)
  {
    if (primes)
    {
      PushBackPrimes<T> pb(*primes);
      pb.pushBackPrimes(start, stop);
    }
  }

  /// Store the first n primes in the primes vector.
  template <typename T>
  inline void generate_n_primes(uint64_t n, std::vector<T>* primes)
  {
    if (primes)
    {
      PushBack_N_Primes<T> pb(*primes);
      pb.pushBack_N_Primes(n, 0);
    }
  }

  /// Store the first n primes >= start in the primes vector.
  /// @pre start <= 2^64 - 2^32 * 10.
  ///
  template <typename T>
  inline void generate_n_primes(uint64_t n, uint64_t start, std::vector<T>* primes)
  {
    if (primes)
    {
      PushBack_N_Primes<T> pb(*primes);
      pb.pushBack_N_Primes(n, start);
    }
  }

  /// Find the nth prime.
  /// @param n  if n = 0 finds the 1st prime >= start,

  ///           if n > 0 finds the nth prime > start,

  ///           if n < 0 finds the nth prime < start (backwards).
  /// @pre   start <= 2^64 - 2^32 * 11.
  ///
  uint64_t nth_prime(int64_t n, uint64_t start = 0);

  /// Find the nth prime in parallel.
  /// By default all CPU cores are used, use
  /// primesieve::set_num_threads(int) to change the number of
  /// threads.
  /// @param n  if n = 0 finds the 1st prime >= start,

  ///           if n > 0 finds the nth prime > start,

  ///           if n < 0 finds the nth prime < start (backwards).
  /// @pre   start <= 2^64 - 2^32 * 11.
  ///
  uint64_t parallel_nth_prime(int64_t n, uint64_t start = 0);

  /// Count the primes within the interval [start, stop].
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  uint64_t count_primes(uint64_t start, uint64_t stop);

  /// Count the twin primes within the interval [start, stop].
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  uint64_t count_twins(uint64_t start, uint64_t stop);

  /// Count the prime triplets within the interval [start, stop].
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  uint64_t count_triplets(uint64_t start, uint64_t stop);

  /// Count the prime quadruplets within the interval [start, stop].
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  uint64_t count_quadruplets(uint64_t start, uint64_t stop);

  /// Count the prime quintuplets within the interval [start, stop].
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  uint64_t count_quintuplets(uint64_t start, uint64_t stop);

  /// Count the prime sextuplets within the interval [start, stop].
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  uint64_t count_sextuplets(uint64_t start, uint64_t stop);

  /// Count the primes within the interval [start, stop] in
  /// parallel. By default all CPU cores are used, use
  /// primesieve::set_num_threads(int) to change the number of
  /// threads.
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  uint64_t parallel_count_primes(uint64_t start, uint64_t stop);

  /// Count the twin primes within the interval [start, stop] in
  /// parallel. By default all CPU cores are used, use
  /// primesieve::set_num_threads(int) to change the number of
  /// threads.
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  uint64_t parallel_count_twins(uint64_t start, uint64_t stop);

  /// Count the prime triplets within the interval [start, stop] in
  /// parallel. By default all CPU cores are used, use
  /// primesieve::set_num_threads(int) to change the number of
  /// threads.
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  uint64_t parallel_count_triplets(uint64_t start, uint64_t stop);

  /// Count the prime quadruplets within the interval [start, stop] in
  /// parallel. By default all CPU cores are used, use
  /// primesieve::set_num_threads(int) to change the number of
  /// threads.
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  uint64_t parallel_count_quadruplets(uint64_t start, uint64_t stop);

  /// Count the prime quintuplets within the interval [start, stop] in
  /// parallel. By default all CPU cores are used, use
  /// primesieve::set_num_threads(int) to change the number of
  /// threads.
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  uint64_t parallel_count_quintuplets(uint64_t start, uint64_t stop);

  /// Count the prime sextuplets within the interval [start, stop] in
  /// parallel. By default all CPU cores are used, use
  /// primesieve::set_num_threads(int) to change the number of
  /// threads.
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  uint64_t parallel_count_sextuplets(uint64_t start, uint64_t stop);

  /// Print the primes within the interval [start, stop]
  /// to the standard output.
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  void print_primes(uint64_t start, uint64_t stop);

  /// Print the twin primes within the interval [start, stop]
  /// to the standard output.
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  void print_twins(uint64_t start, uint64_t stop);

  /// Print the prime triplets within the interval [start, stop]
  /// to the standard output.
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  void print_triplets(uint64_t start, uint64_t stop);

  /// Print the prime quadruplets within the interval [start, stop]
  /// to the standard output.
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  void print_quadruplets(uint64_t start, uint64_t stop);

  /// Print the prime quintuplets within the interval [start, stop]
  /// to the standard output.
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  void print_quintuplets(uint64_t start, uint64_t stop);

  /// Print the prime sextuplets within the interval [start, stop]
  /// to the standard output.
  /// @pre stop <= 2^64 - 2^32 * 10.
  ///
  void print_sextuplets(uint64_t start, uint64_t stop);

  /// Call back the primes within the interval [start, stop].
  /// @param callback  A callback function.
  /// @pre   stop <= 2^64 - 2^32 * 10.
  ///
  void callback_primes(uint64_t start, uint64_t stop, void (*callback)(uint64_t prime));

  /// Call back the primes within the interval [start, stop].
  /// @param callback  An object derived from primesieve::Callback<uint64_t>.
  /// @pre   stop <= 2^64 - 2^32 * 10.
  ///
  void callback_primes(uint64_t start, uint64_t stop, primesieve::Callback<uint64_t>* callback);

  /// Call back the primes within the interval [start, stop].
  /// This function is synchronized, only one thread at a time calls
  /// back primes. By default all CPU cores are used, use
  /// primesieve::set_num_threads(int) to change the number of
  /// threads.
  /// @warning         Primes are not called back in arithmetic order.
  /// @param callback  A callback function.
  /// @pre   stop      <= 2^64 - 2^32 * 10.
  ///
  void parallel_callback_primes(uint64_t start, uint64_t stop, void (*callback)(uint64_t prime));

  /// Call back the primes within the interval [start, stop].
  /// This function is synchronized, only one thread at a time calls
  /// back primes. By default all CPU cores are used, use
  /// primesieve::set_num_threads(int) to change the number of
  /// threads.
  /// @warning         Primes are not called back in arithmetic order.
  /// @param callback  An object derived from primesieve::Callback<uint64_t>.
  /// @pre   stop      <= 2^64 - 2^32 * 10.
  ///
  void parallel_callback_primes(uint64_t start, uint64_t stop, primesieve::Callback<uint64_t>* callback);

  /// Call back the primes within the interval [start, stop].
  /// This function is not synchronized, multiple threads call back
  /// primes in parallel. By default all CPU cores are used, use
  /// primesieve::set_num_threads(int) to change the number of
  /// threads.
  /// @warning         Primes are not called back in arithmetic order.
  /// @param callback  A callback function.
  /// @pre   stop      <= 2^64 - 2^32 * 10.
  ///
  void parallel_callback_primes(uint64_t start, uint64_t stop, void (*callback)(uint64_t prime, int thread_id));

  /// Call back the primes within the interval [start, stop].
  /// This function is not synchronized, multiple threads call back
  /// primes in parallel. By default all CPU cores are used, use
  /// primesieve::set_num_threads(int) to change the number of
  /// threads.
  /// @warning         Primes are not called back in arithmetic order.
  /// @param callback  An object derived from primesieve::Callback<uint64_t, int>.
  /// @pre   stop      <= 2^64 - 2^32 * 10.
  ///
  void parallel_callback_primes(uint64_t start, uint64_t stop, primesieve::Callback<uint64_t, int>* callback);

  /// Get the current set sieve size in kilobytes.
  int get_sieve_size();

  /// Get the current set number of threads.
  /// @note By default MAX_THREADS (-1) is returned.
  ///
  int get_num_threads();

  /// Returns the largest valid stop number for primesieve.
  /// @return (2^64-1) - (2^32-1) * 10.
  ///
  uint64_t get_max_stop();

  /// Set the sieve size in kilobytes.
  /// The best sieving performance is achieved with a sieve size of
  /// your CPU's L1 data cache size (per core). For sieving >= 10^17 a
  /// sieve size of your CPU's L2 cache size sometimes performs
  /// better.
  /// @param sieve_size Sieve size in kilobytes.
  /// @pre   sieve_size >= 1 && sieve_size <= 2048.
  ///
  void set_sieve_size(int sieve_size);

  /// Set the number of threads for use in subsequent
  /// primesieve::parallel_* function calls. Note that this only
  /// changes the number of threads for the current process.
  /// @param num_threads  Number of threads for sieving
  ///                     or MAX_THREADS to use all CPU cores.
  ///
  void set_num_threads(int num_threads);

  /// Run extensive correctness tests.
  /// The tests last about one minute on a quad core CPU from
  /// 2013 and use up to 1 gigabyte of memory.
  /// @return true if success else false.
  ///
  bool primesieve_test();

  /// Get the primesieve version number, in the form “i.j.k”.
  std::string primesieve_version();
}

#endif
<|endoftext|>


<commit_before>// 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.

#ifndef __STOUT_OS_CONSTANTS_HPP__
#define __STOUT_OS_CONSTANTS_HPP__

#include <string>

namespace os {

constexpr char WINDOWS_PATH_SEPARATOR = '\\';
constexpr char POSIX_PATH_SEPARATOR = '/';

#ifndef __WINDOWS__
constexpr char PATH_SEPARATOR = POSIX_PATH_SEPARATOR;
#else
constexpr char PATH_SEPARATOR = WINDOWS_PATH_SEPARATOR;
#endif // __WINDOWS__

#ifndef __WINDOWS__
constexpr char DEV_NULL[] = "/dev/null";
#else
constexpr char DEV_NULL[] = "NUL";
#endif // __WINDOWS__

} // namespace os {

#endif // __STOUT_OS_CONSTANTS_HPP__
<commit_msg>Windows: Added `os::LONGPATH_PREFIX` constant.<commit_after>// 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.

#ifndef __STOUT_OS_CONSTANTS_HPP__
#define __STOUT_OS_CONSTANTS_HPP__

#include <string>

namespace os {

constexpr char WINDOWS_PATH_SEPARATOR = '\\';
constexpr char POSIX_PATH_SEPARATOR = '/';

#ifndef __WINDOWS__
constexpr char PATH_SEPARATOR = POSIX_PATH_SEPARATOR;
#else
constexpr char PATH_SEPARATOR = WINDOWS_PATH_SEPARATOR;
#endif // __WINDOWS__

#ifndef __WINDOWS__
constexpr char DEV_NULL[] = "/dev/null";
#else
constexpr char DEV_NULL[] = "NUL";
#endif // __WINDOWS__

#ifdef __WINDOWS__
// This prefix is prepended to absolute paths on Windows to indicate the path
// may be greater than 255 characters.
//
// NOTE: We do not use a R"raw string" here because syntax highlighters do not
// handle mismatched backslashes well.
constexpr char LONGPATH_PREFIX[] = "\\\\?\\";
#endif // __WINDOWS__

} // namespace os {

#endif // __STOUT_OS_CONSTANTS_HPP__
<|endoftext|>


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

#include "sync/util/immutable.h"

#include <algorithm>
#include <cstddef>
#include <deque>
#include <list>
#include <set>
#include <string>
#include <vector>

#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace browser_sync {

// Helper class that keeps track of the token passed in at
// construction and how many times that token is copied.
class TokenCore : public base::RefCounted<TokenCore> {
 public:
  explicit TokenCore(const char* token) : token_(token), copy_count_(0) {}

  const char* GetToken() const { return token_; }

  void RecordCopy() { ++copy_count_; }

  int GetCopyCount() const { return copy_count_; }

 private:
  friend class base::RefCounted<TokenCore>;

  ~TokenCore() {}

  const char* const token_;
  int copy_count_;
};

enum SwapBehavior {
  USE_DEFAULT_SWAP,
  USE_FAST_SWAP_VIA_ADL,
  USE_FAST_SWAP_VIA_SPECIALIZATION
};

const char kEmptyToken[] = "<empty token>";

// Base class for various token classes, differing in swap behavior.
template <SwapBehavior>
class TokenBase {
 public:
  TokenBase() : core_(new TokenCore(kEmptyToken)) {}

  explicit TokenBase(const char* token) : core_(new TokenCore(token)) {}

  TokenBase(const TokenBase& other) : core_(other.core_) {
    core_->RecordCopy();
  }

  TokenBase& operator=(const TokenBase& other) {
    core_ = other.core_;
    core_->RecordCopy();
    return *this;
  }

  const char* GetToken() const {
    return core_->GetToken();
  }

  int GetCopyCount() const {
    return core_->GetCopyCount();
  }

  // For associative containers.
  bool operator<(const TokenBase& other) const {
    return std::string(GetToken()) < std::string(other.GetToken());
  }

  // STL-style swap.
  void swap(TokenBase& other) {
    using std::swap;
    swap(other.core_, core_);
  }

  // Google-style swap.
  void Swap(TokenBase* other) {
    using std::swap;
    swap(other->core_, core_);
  }

 private:
  scoped_refptr<TokenCore> core_;
};

typedef TokenBase<USE_DEFAULT_SWAP> Token;
typedef TokenBase<USE_FAST_SWAP_VIA_ADL> ADLToken;
typedef TokenBase<USE_FAST_SWAP_VIA_SPECIALIZATION> SpecializationToken;

void swap(ADLToken& t1, ADLToken& t2) {
  t1.Swap(&t2);
}

}  // namespace browser_sync

// Allowed by the standard (17.4.3.1/1).
namespace std {

template <>
void swap(browser_sync::SpecializationToken& t1,
          browser_sync::SpecializationToken& t2) {
  t1.Swap(&t2);
}

}  // namespace

namespace browser_sync {
namespace {

class ImmutableTest : public ::testing::Test {};

TEST_F(ImmutableTest, Int) {
  int x = 5;
  Immutable<int> ix(&x);
  EXPECT_EQ(5, ix.Get());
  EXPECT_EQ(0, x);
}

TEST_F(ImmutableTest, IntCopy) {
  int x = 5;
  Immutable<int> ix = Immutable<int>(&x);
  EXPECT_EQ(5, ix.Get());
  EXPECT_EQ(0, x);
}

TEST_F(ImmutableTest, IntAssign) {
  int x = 5;
  Immutable<int> ix;
  EXPECT_EQ(0, ix.Get());
  ix = Immutable<int>(&x);
  EXPECT_EQ(5, ix.Get());
  EXPECT_EQ(0, x);
}

TEST_F(ImmutableTest, IntMakeImmutable) {
  int x = 5;
  Immutable<int> ix = MakeImmutable(&x);
  EXPECT_EQ(5, ix.Get());
  EXPECT_EQ(0, x);
}

template <typename T, typename ImmutableT>
void RunTokenTest(const char* token, bool expect_copies) {
  SCOPED_TRACE(token);
  T t(token);
  EXPECT_EQ(token, t.GetToken());
  EXPECT_EQ(0, t.GetCopyCount());

  ImmutableT immutable_t(&t);
  EXPECT_EQ(token, immutable_t.Get().GetToken());
  EXPECT_EQ(kEmptyToken, t.GetToken());
  EXPECT_EQ(expect_copies, immutable_t.Get().GetCopyCount() > 0);
  EXPECT_EQ(expect_copies, t.GetCopyCount() > 0);
}

TEST_F(ImmutableTest, Token) {
  RunTokenTest<Token, Immutable<Token> >("Token", true /* expect_copies */);
}

TEST_F(ImmutableTest, TokenSwapMemFnByRef) {
  RunTokenTest<Token, Immutable<Token, HasSwapMemFnByRef<Token> > >(
      "TokenSwapMemFnByRef", false /* expect_copies */);
}

TEST_F(ImmutableTest, TokenSwapMemFnByPtr) {
  RunTokenTest<Token, Immutable<Token, HasSwapMemFnByPtr<Token> > >(
      "TokenSwapMemFnByPtr", false /* expect_copies */);
}

TEST_F(ImmutableTest, ADLToken) {
  RunTokenTest<ADLToken, Immutable<ADLToken> >(
      "ADLToken", false /* expect_copies */);
}

TEST_F(ImmutableTest, SpecializationToken) {
  RunTokenTest<SpecializationToken, Immutable<SpecializationToken> >(
      "SpecializationToken", false /* expect_copies */);
}

template <typename C, typename ImmutableC>
void RunTokenContainerTest(const char* token) {
  SCOPED_TRACE(token);
  const Token tokens[] = { Token(), Token(token) };
  const size_t token_count = arraysize(tokens);
  C c(tokens, tokens + token_count);
  const int copy_count = c.begin()->GetCopyCount();
  EXPECT_GT(copy_count, 0);
  for (typename C::const_iterator it = c.begin(); it != c.end(); ++it) {
    EXPECT_EQ(copy_count, it->GetCopyCount());
  }

  // Make sure that making the container immutable doesn't incur any
  // copies of the tokens.
  ImmutableC immutable_c(&c);
  EXPECT_TRUE(c.empty());
  ASSERT_EQ(token_count, immutable_c.Get().size());
  int i = 0;
  for (typename C::const_iterator it = c.begin(); it != c.end(); ++it) {
    EXPECT_EQ(tokens[i].GetToken(), it->GetToken());
    EXPECT_EQ(copy_count, it->GetCopyCount());
    ++i;
  }
}

TEST_F(ImmutableTest, Vector) {
  RunTokenContainerTest<std::vector<Token>, Immutable<std::vector<Token> > >(
      "Vector");
}

TEST_F(ImmutableTest, VectorSwapMemFnByRef) {
  RunTokenContainerTest<
    std::vector<Token>,
    Immutable<std::vector<Token>, HasSwapMemFnByRef<std::vector<Token> > > >(
        "VectorSwapMemFnByRef");
}

TEST_F(ImmutableTest, Deque) {
  RunTokenContainerTest<std::deque<Token>, Immutable<std::deque<Token> > >(
      "Deque");
}

TEST_F(ImmutableTest, List) {
  RunTokenContainerTest<std::list<Token>, Immutable<std::list<Token> > >(
      "List");
}

TEST_F(ImmutableTest, Set) {
  RunTokenContainerTest<std::set<Token>, Immutable<std::set<Token> > >(
      "Set");
}

}  // namespace
}  // namespace browser_sync
<commit_msg>Disable failing test ImmutableTest.Deque on Windows<commit_after>// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "sync/util/immutable.h"

#include <algorithm>
#include <cstddef>
#include <deque>
#include <list>
#include <set>
#include <string>
#include <vector>

#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace browser_sync {

// Helper class that keeps track of the token passed in at
// construction and how many times that token is copied.
class TokenCore : public base::RefCounted<TokenCore> {
 public:
  explicit TokenCore(const char* token) : token_(token), copy_count_(0) {}

  const char* GetToken() const { return token_; }

  void RecordCopy() { ++copy_count_; }

  int GetCopyCount() const { return copy_count_; }

 private:
  friend class base::RefCounted<TokenCore>;

  ~TokenCore() {}

  const char* const token_;
  int copy_count_;
};

enum SwapBehavior {
  USE_DEFAULT_SWAP,
  USE_FAST_SWAP_VIA_ADL,
  USE_FAST_SWAP_VIA_SPECIALIZATION
};

const char kEmptyToken[] = "<empty token>";

// Base class for various token classes, differing in swap behavior.
template <SwapBehavior>
class TokenBase {
 public:
  TokenBase() : core_(new TokenCore(kEmptyToken)) {}

  explicit TokenBase(const char* token) : core_(new TokenCore(token)) {}

  TokenBase(const TokenBase& other) : core_(other.core_) {
    core_->RecordCopy();
  }

  TokenBase& operator=(const TokenBase& other) {
    core_ = other.core_;
    core_->RecordCopy();
    return *this;
  }

  const char* GetToken() const {
    return core_->GetToken();
  }

  int GetCopyCount() const {
    return core_->GetCopyCount();
  }

  // For associative containers.
  bool operator<(const TokenBase& other) const {
    return std::string(GetToken()) < std::string(other.GetToken());
  }

  // STL-style swap.
  void swap(TokenBase& other) {
    using std::swap;
    swap(other.core_, core_);
  }

  // Google-style swap.
  void Swap(TokenBase* other) {
    using std::swap;
    swap(other->core_, core_);
  }

 private:
  scoped_refptr<TokenCore> core_;
};

typedef TokenBase<USE_DEFAULT_SWAP> Token;
typedef TokenBase<USE_FAST_SWAP_VIA_ADL> ADLToken;
typedef TokenBase<USE_FAST_SWAP_VIA_SPECIALIZATION> SpecializationToken;

void swap(ADLToken& t1, ADLToken& t2) {
  t1.Swap(&t2);
}

}  // namespace browser_sync

// Allowed by the standard (17.4.3.1/1).
namespace std {

template <>
void swap(browser_sync::SpecializationToken& t1,
          browser_sync::SpecializationToken& t2) {
  t1.Swap(&t2);
}

}  // namespace

namespace browser_sync {
namespace {

class ImmutableTest : public ::testing::Test {};

TEST_F(ImmutableTest, Int) {
  int x = 5;
  Immutable<int> ix(&x);
  EXPECT_EQ(5, ix.Get());
  EXPECT_EQ(0, x);
}

TEST_F(ImmutableTest, IntCopy) {
  int x = 5;
  Immutable<int> ix = Immutable<int>(&x);
  EXPECT_EQ(5, ix.Get());
  EXPECT_EQ(0, x);
}

TEST_F(ImmutableTest, IntAssign) {
  int x = 5;
  Immutable<int> ix;
  EXPECT_EQ(0, ix.Get());
  ix = Immutable<int>(&x);
  EXPECT_EQ(5, ix.Get());
  EXPECT_EQ(0, x);
}

TEST_F(ImmutableTest, IntMakeImmutable) {
  int x = 5;
  Immutable<int> ix = MakeImmutable(&x);
  EXPECT_EQ(5, ix.Get());
  EXPECT_EQ(0, x);
}

template <typename T, typename ImmutableT>
void RunTokenTest(const char* token, bool expect_copies) {
  SCOPED_TRACE(token);
  T t(token);
  EXPECT_EQ(token, t.GetToken());
  EXPECT_EQ(0, t.GetCopyCount());

  ImmutableT immutable_t(&t);
  EXPECT_EQ(token, immutable_t.Get().GetToken());
  EXPECT_EQ(kEmptyToken, t.GetToken());
  EXPECT_EQ(expect_copies, immutable_t.Get().GetCopyCount() > 0);
  EXPECT_EQ(expect_copies, t.GetCopyCount() > 0);
}

TEST_F(ImmutableTest, Token) {
  RunTokenTest<Token, Immutable<Token> >("Token", true /* expect_copies */);
}

TEST_F(ImmutableTest, TokenSwapMemFnByRef) {
  RunTokenTest<Token, Immutable<Token, HasSwapMemFnByRef<Token> > >(
      "TokenSwapMemFnByRef", false /* expect_copies */);
}

TEST_F(ImmutableTest, TokenSwapMemFnByPtr) {
  RunTokenTest<Token, Immutable<Token, HasSwapMemFnByPtr<Token> > >(
      "TokenSwapMemFnByPtr", false /* expect_copies */);
}

TEST_F(ImmutableTest, ADLToken) {
  RunTokenTest<ADLToken, Immutable<ADLToken> >(
      "ADLToken", false /* expect_copies */);
}

TEST_F(ImmutableTest, SpecializationToken) {
  RunTokenTest<SpecializationToken, Immutable<SpecializationToken> >(
      "SpecializationToken", false /* expect_copies */);
}

template <typename C, typename ImmutableC>
void RunTokenContainerTest(const char* token) {
  SCOPED_TRACE(token);
  const Token tokens[] = { Token(), Token(token) };
  const size_t token_count = arraysize(tokens);
  C c(tokens, tokens + token_count);
  const int copy_count = c.begin()->GetCopyCount();
  EXPECT_GT(copy_count, 0);
  for (typename C::const_iterator it = c.begin(); it != c.end(); ++it) {
    EXPECT_EQ(copy_count, it->GetCopyCount());
  }

  // Make sure that making the container immutable doesn't incur any
  // copies of the tokens.
  ImmutableC immutable_c(&c);
  EXPECT_TRUE(c.empty());
  ASSERT_EQ(token_count, immutable_c.Get().size());
  int i = 0;
  for (typename C::const_iterator it = c.begin(); it != c.end(); ++it) {
    EXPECT_EQ(tokens[i].GetToken(), it->GetToken());
    EXPECT_EQ(copy_count, it->GetCopyCount());
    ++i;
  }
}

TEST_F(ImmutableTest, Vector) {
  RunTokenContainerTest<std::vector<Token>, Immutable<std::vector<Token> > >(
      "Vector");
}

TEST_F(ImmutableTest, VectorSwapMemFnByRef) {
  RunTokenContainerTest<
    std::vector<Token>,
    Immutable<std::vector<Token>, HasSwapMemFnByRef<std::vector<Token> > > >(
        "VectorSwapMemFnByRef");
}

// http://crbug.com/129128
#if defined(OS_WIN)
#define MAYBE_Deque DISABLED_Deque
#else
#define MAYBE_Deque Deque
#endif
TEST_F(ImmutableTest, MAYBE_Deque) {
  RunTokenContainerTest<std::deque<Token>, Immutable<std::deque<Token> > >(
      "Deque");
}

TEST_F(ImmutableTest, List) {
  RunTokenContainerTest<std::list<Token>, Immutable<std::list<Token> > >(
      "List");
}

TEST_F(ImmutableTest, Set) {
  RunTokenContainerTest<std::set<Token>, Immutable<std::set<Token> > >(
      "Set");
}

}  // namespace
}  // namespace browser_sync
<|endoftext|>


<commit_before>// Copyright (c) 2009 Chris Pickel <sfiera@gmail.com>
//
// This file is part of libsfz, a free software project.  You can redistribute it and/or modify it
// under the terms of the MIT License.

#ifndef SFZ_FORMAT_HPP_
#define SFZ_FORMAT_HPP_

#include "sfz/PrintItem.hpp"
#include "sfz/PrintTarget.hpp"

namespace sfz {

template <size_t size> class Format;

inline Format<16> format(
        const char* format_string,
        const PrintItem& item0 = PrintItem(), const PrintItem& item1 = PrintItem(),
        const PrintItem& item2 = PrintItem(), const PrintItem& item3 = PrintItem(),
        const PrintItem& item4 = PrintItem(), const PrintItem& item5 = PrintItem(),
        const PrintItem& item6 = PrintItem(), const PrintItem& item7 = PrintItem(),
        const PrintItem& item8 = PrintItem(), const PrintItem& item9 = PrintItem(),
        const PrintItem& item10 = PrintItem(), const PrintItem& item11 = PrintItem(),
        const PrintItem& item12 = PrintItem(), const PrintItem& item13 = PrintItem(),
        const PrintItem& item14 = PrintItem(), const PrintItem& item15 = PrintItem());

template <size_t size>
struct Format {
    const char* format_string;
    const PrintItem* items[size];
};

void print_format_to(
        PrintTarget out, const char* format_string, const PrintItem* const* items, size_t size);

template <size_t size>
inline void print_to(PrintTarget out, const Format<size>& format) {
    print_format_to(out, format.format_string, format.items, size);
}

Format<16> format(
        const char* format_string,
        const PrintItem& item0, const PrintItem& item1,
        const PrintItem& item2, const PrintItem& item3,
        const PrintItem& item4, const PrintItem& item5,
        const PrintItem& item6, const PrintItem& item7,
        const PrintItem& item8, const PrintItem& item9,
        const PrintItem& item10, const PrintItem& item11,
        const PrintItem& item12, const PrintItem& item13,
        const PrintItem& item14, const PrintItem& item15) {
    Format<16> result = {
        format_string,
        {
            &item0, &item1, &item2, &item3, &item4, &item5, &item6, &item7,
            &item8, &item9, &item10, &item11, &item12, &item13, &item14, &item15,
        },
    };
    return result;
}

}  // namespace sfz

#endif  // SFZ_FORMAT_HPP_
<commit_msg>Use compound literals in Format.hpp.<commit_after>// Copyright (c) 2009 Chris Pickel <sfiera@gmail.com>
//
// This file is part of libsfz, a free software project.  You can redistribute it and/or modify it
// under the terms of the MIT License.

#ifndef SFZ_FORMAT_HPP_
#define SFZ_FORMAT_HPP_

#include "sfz/PrintItem.hpp"
#include "sfz/PrintTarget.hpp"

namespace sfz {

template <size_t size> class Format;

Format<16> format(
        const char* format_string,
        const PrintItem& item0 = PrintItem(), const PrintItem& item1 = PrintItem(),
        const PrintItem& item2 = PrintItem(), const PrintItem& item3 = PrintItem(),
        const PrintItem& item4 = PrintItem(), const PrintItem& item5 = PrintItem(),
        const PrintItem& item6 = PrintItem(), const PrintItem& item7 = PrintItem(),
        const PrintItem& item8 = PrintItem(), const PrintItem& item9 = PrintItem(),
        const PrintItem& item10 = PrintItem(), const PrintItem& item11 = PrintItem(),
        const PrintItem& item12 = PrintItem(), const PrintItem& item13 = PrintItem(),
        const PrintItem& item14 = PrintItem(), const PrintItem& item15 = PrintItem());

template <size_t size>
struct Format {
    const char* format_string;
    const PrintItem* items[size];
};

void print_format_to(
        PrintTarget out, const char* format_string, const PrintItem* const* items, size_t size);

template <size_t size>
inline void print_to(PrintTarget out, const Format<size>& format) {
    print_format_to(out, format.format_string, format.items, size);
}

inline Format<16> format(
        const char* format_string,
        const PrintItem& item0, const PrintItem& item1,
        const PrintItem& item2, const PrintItem& item3,
        const PrintItem& item4, const PrintItem& item5,
        const PrintItem& item6, const PrintItem& item7,
        const PrintItem& item8, const PrintItem& item9,
        const PrintItem& item10, const PrintItem& item11,
        const PrintItem& item12, const PrintItem& item13,
        const PrintItem& item14, const PrintItem& item15) {
    return (Format<16>){
        format_string,
        {
            &item0, &item1, &item2, &item3, &item4, &item5, &item6, &item7,
            &item8, &item9, &item10, &item11, &item12, &item13, &item14, &item15,
        },
    };
}

}  // namespace sfz

#endif  // SFZ_FORMAT_HPP_
<|endoftext|>


<commit_before>//===-- Mangler.cpp - Self-contained c/asm llvm name mangler --------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Unified name mangler for CWriter and assembly backends.
//
//===----------------------------------------------------------------------===//

#include "llvm/Support/Mangler.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Module.h"
#include "llvm/ADT/StringExtras.h"
using namespace llvm;

static char HexDigit(int V) {
  return V < 10 ? V+'0' : V+'A'-10;
}

static std::string MangleLetter(unsigned char C) {
  char Result[] = { '_', HexDigit(C >> 4), HexDigit(C & 15), '_', 0 };
  return Result;
}

/// makeNameProper - We don't want identifier names non-C-identifier characters
/// in them, so mangle them as appropriate.
///
std::string Mangler::makeNameProper(const std::string &X, const char *Prefix) {
  std::string Result;
  if (X.empty()) return X;  // Empty names are uniqued by the caller.

  if (!UseQuotes) {
    // If X does not start with (char)1, add the prefix.
    std::string::const_iterator I = X.begin();
    if (*I != 1)
      Result = Prefix;
    else
      ++I;  // Skip over the marker.

    // Mangle the first letter specially, don't allow numbers.
    if (*I >= '0' && *I <= '9')
      Result += MangleLetter(*I++);

    for (std::string::const_iterator E = X.end(); I != E; ++I) {
      if (!isCharAcceptable(*I))
        Result += MangleLetter(*I);
      else
        Result += *I;
    }
  } else {
    bool NeedsQuotes = false;

    // If X does not start with (char)1, add the prefix.
    std::string::const_iterator I = X.begin();
    if (*I != 1)
      Result = Prefix;
    else
      ++I;  // Skip over the marker.

    // If the first character is a number, we need quotes.
    if (*I >= '0' && *I <= '9')
      NeedsQuotes = true;

    // Do an initial scan of the string, checking to see if we need quotes or
    // to escape a '"' or not.
    if (!NeedsQuotes)
      for (std::string::const_iterator E = X.end(); I != E; ++I)
        if (!isCharAcceptable(*I)) {
          NeedsQuotes = true;
          break;
        }

    // In the common case, we don't need quotes.  Handle this quickly.
    if (!NeedsQuotes)
      return Result + X;

    // Otherwise, construct the string the expensive way.
    I = X.begin();
    if (*I == 1) ++I;   // Skip the marker if present.
    for (std::string::const_iterator E = X.end(); I != E; ++I) {
      if (*I == '"')
        Result += "_QQ_";
      else
        Result += *I;
    }
    Result = '"' + Result + '"';
  }
  return Result;
}

/// getTypeID - Return a unique ID for the specified LLVM type.
///
unsigned Mangler::getTypeID(const Type *Ty) {
  unsigned &E = TypeMap[Ty];
  if (E == 0) E = ++TypeCounter;
  return E;
}

std::string Mangler::getValueName(const Value *V) {
  if (const GlobalValue *GV = dyn_cast<GlobalValue>(V))
    return getValueName(GV);

  std::string &Name = Memo[V];
  if (!Name.empty())
    return Name;       // Return the already-computed name for V.

  // Always mangle local names.
  Name = "ltmp_" + utostr(Count++) + "_" + utostr(getTypeID(V->getType()));
  return Name;
}

std::string Mangler::getValueName(const GlobalValue *GV) {
  // Check to see whether we've already named V.
  std::string &Name = Memo[GV];
  if (!Name.empty())
    return Name;       // Return the already-computed name for V.

  // Name mangling occurs as follows:
  // - If V is an intrinsic function, do not change name at all
  // - Otherwise, mangling occurs if global collides with existing name.
  if (isa<Function>(GV) && cast<Function>(GV)->getIntrinsicID()) {
    Name = GV->getName(); // Is an intrinsic function
  } else if (!MangledGlobals.count(GV)) {
    Name = makeNameProper(GV->getName(), Prefix);
  } else {
    unsigned TypeUniqueID = getTypeID(GV->getType());
    Name = "l" + utostr(TypeUniqueID) + "_" + makeNameProper(GV->getName());
  }

  return Name;
}

void Mangler::InsertName(GlobalValue *GV,
                         std::map<std::string, GlobalValue*> &Names) {
  if (!GV->hasName()) {   // We must mangle unnamed globals.
    MangledGlobals.insert(GV);
    return;
  }

  // Figure out if this is already used.
  GlobalValue *&ExistingValue = Names[GV->getName()];
  if (!ExistingValue) {
    ExistingValue = GV;
  } else {
    // If GV is external but the existing one is static, mangle the existing one
    if (GV->hasExternalLinkage() && !ExistingValue->hasExternalLinkage()) {
      MangledGlobals.insert(ExistingValue);
      ExistingValue = GV;
    } else {
      // Otherwise, mangle GV
      MangledGlobals.insert(GV);
    }
  }
}

Mangler::Mangler(Module &M, const char *prefix)
  : Prefix(prefix), UseQuotes(false), Count(0), TypeCounter(0) {
  std::fill(AcceptableChars,
          AcceptableChars+sizeof(AcceptableChars)/sizeof(AcceptableChars[0]),
            0);

  // Letters and numbers are acceptable.
  for (unsigned char X = 'a'; X <= 'z'; ++X)
    markCharAcceptable(X);
  for (unsigned char X = 'A'; X <= 'Z'; ++X)
    markCharAcceptable(X);
  for (unsigned char X = '0'; X <= '9'; ++X)
    markCharAcceptable(X);

  // These chars are acceptable.
  markCharAcceptable('_');
  markCharAcceptable('$');
  markCharAcceptable('.');

  // Calculate which global values have names that will collide when we throw
  // away type information.
  std::map<std::string, GlobalValue*> Names;
  for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
    InsertName(I, Names);
  for (Module::global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I)
    InsertName(I, Names);
}
<commit_msg>Fix the optimized code handling of user asm strings<commit_after>//===-- Mangler.cpp - Self-contained c/asm llvm name mangler --------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Unified name mangler for CWriter and assembly backends.
//
//===----------------------------------------------------------------------===//

#include "llvm/Support/Mangler.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Module.h"
#include "llvm/ADT/StringExtras.h"
using namespace llvm;

static char HexDigit(int V) {
  return V < 10 ? V+'0' : V+'A'-10;
}

static std::string MangleLetter(unsigned char C) {
  char Result[] = { '_', HexDigit(C >> 4), HexDigit(C & 15), '_', 0 };
  return Result;
}

/// makeNameProper - We don't want identifier names non-C-identifier characters
/// in them, so mangle them as appropriate.
///
std::string Mangler::makeNameProper(const std::string &X, const char *Prefix) {
  std::string Result;
  if (X.empty()) return X;  // Empty names are uniqued by the caller.

  if (!UseQuotes) {
    // If X does not start with (char)1, add the prefix.
    std::string::const_iterator I = X.begin();
    if (*I != 1)
      Result = Prefix;
    else
      ++I;  // Skip over the marker.

    // Mangle the first letter specially, don't allow numbers.
    if (*I >= '0' && *I <= '9')
      Result += MangleLetter(*I++);

    for (std::string::const_iterator E = X.end(); I != E; ++I) {
      if (!isCharAcceptable(*I))
        Result += MangleLetter(*I);
      else
        Result += *I;
    }
  } else {
    bool NeedsQuotes = false;

    std::string::const_iterator I = X.begin();
    if (*I == 1)
      ++I;  // Skip over the marker.

    // If the first character is a number, we need quotes.
    if (*I >= '0' && *I <= '9')
      NeedsQuotes = true;

    // Do an initial scan of the string, checking to see if we need quotes or
    // to escape a '"' or not.
    if (!NeedsQuotes)
      for (std::string::const_iterator E = X.end(); I != E; ++I)
        if (!isCharAcceptable(*I)) {
          NeedsQuotes = true;
          break;
        }

    // In the common case, we don't need quotes.  Handle this quickly.
    if (!NeedsQuotes) {
      if (*X.begin() != 1)
        return Prefix+X;
      else
        return X.substr(1);
    }

    // Otherwise, construct the string the expensive way.
    I = X.begin();

    // If X does not start with (char)1, add the prefix.
    if (*I != 1)
      Result = Prefix;
    else
      ++I;   // Skip the marker if present.

    for (std::string::const_iterator E = X.end(); I != E; ++I) {
      if (*I == '"')
        Result += "_QQ_";
      else
        Result += *I;
    }
    Result = '"' + Result + '"';
  }
  return Result;
}

/// getTypeID - Return a unique ID for the specified LLVM type.
///
unsigned Mangler::getTypeID(const Type *Ty) {
  unsigned &E = TypeMap[Ty];
  if (E == 0) E = ++TypeCounter;
  return E;
}

std::string Mangler::getValueName(const Value *V) {
  if (const GlobalValue *GV = dyn_cast<GlobalValue>(V))
    return getValueName(GV);

  std::string &Name = Memo[V];
  if (!Name.empty())
    return Name;       // Return the already-computed name for V.

  // Always mangle local names.
  Name = "ltmp_" + utostr(Count++) + "_" + utostr(getTypeID(V->getType()));
  return Name;
}

std::string Mangler::getValueName(const GlobalValue *GV) {
  // Check to see whether we've already named V.
  std::string &Name = Memo[GV];
  if (!Name.empty())
    return Name;       // Return the already-computed name for V.

  // Name mangling occurs as follows:
  // - If V is an intrinsic function, do not change name at all
  // - Otherwise, mangling occurs if global collides with existing name.
  if (isa<Function>(GV) && cast<Function>(GV)->getIntrinsicID()) {
    Name = GV->getName(); // Is an intrinsic function
  } else if (!MangledGlobals.count(GV)) {
    Name = makeNameProper(GV->getName(), Prefix);
  } else {
    unsigned TypeUniqueID = getTypeID(GV->getType());
    Name = "l" + utostr(TypeUniqueID) + "_" + makeNameProper(GV->getName());
  }

  return Name;
}

void Mangler::InsertName(GlobalValue *GV,
                         std::map<std::string, GlobalValue*> &Names) {
  if (!GV->hasName()) {   // We must mangle unnamed globals.
    MangledGlobals.insert(GV);
    return;
  }

  // Figure out if this is already used.
  GlobalValue *&ExistingValue = Names[GV->getName()];
  if (!ExistingValue) {
    ExistingValue = GV;
  } else {
    // If GV is external but the existing one is static, mangle the existing one
    if (GV->hasExternalLinkage() && !ExistingValue->hasExternalLinkage()) {
      MangledGlobals.insert(ExistingValue);
      ExistingValue = GV;
    } else {
      // Otherwise, mangle GV
      MangledGlobals.insert(GV);
    }
  }
}

Mangler::Mangler(Module &M, const char *prefix)
  : Prefix(prefix), UseQuotes(false), Count(0), TypeCounter(0) {
  std::fill(AcceptableChars,
          AcceptableChars+sizeof(AcceptableChars)/sizeof(AcceptableChars[0]),
            0);

  // Letters and numbers are acceptable.
  for (unsigned char X = 'a'; X <= 'z'; ++X)
    markCharAcceptable(X);
  for (unsigned char X = 'A'; X <= 'Z'; ++X)
    markCharAcceptable(X);
  for (unsigned char X = '0'; X <= '9'; ++X)
    markCharAcceptable(X);

  // These chars are acceptable.
  markCharAcceptable('_');
  markCharAcceptable('$');
  markCharAcceptable('.');

  // Calculate which global values have names that will collide when we throw
  // away type information.
  std::map<std::string, GlobalValue*> Names;
  for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
    InsertName(I, Names);
  for (Module::global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I)
    InsertName(I, Names);
}
<|endoftext|>


<commit_before>

<commit_msg>Removing unnecesary file<commit_after><|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_VCL_METRIC_HXX
#define INCLUDED_VCL_METRIC_HXX

#include <vcl/dllapi.h>
#include <vcl/font.hxx>
#include <vcl/outdev.hxx>

class ImplFontMetric;
class ImplFontCharMap;

typedef sal_uInt32 sal_UCS4;

namespace vcl {

// avoid problems where poppler's FontInfo is picked up
class VCL_DLLPUBLIC FontInfo : public Font
{
    friend class OutputDevice;

protected:

public:
                        FontInfo();
                        FontInfo( const FontInfo& );
                        ~FontInfo();

    FontType            GetType() const;

    FontInfo&           operator=( const FontInfo& );
    bool                operator==( const FontInfo& ) const;
    bool                operator!=( const FontInfo& rInfo ) const
                            { return !operator==( rInfo ); }
    ImplFontMetric*     mpImplMetric;    // Implementation
};

}

class VCL_DLLPUBLIC FontMetric : public vcl::FontInfo
{
public:
                        FontMetric() {}
                        FontMetric( const FontMetric& );
                        ~FontMetric() {}

    long                GetAscent() const;
    long                GetDescent() const;
    long                GetIntLeading() const;
    long                GetExtLeading() const;
    long                GetLineHeight() const;
    long                GetSlant() const;

    FontMetric&         operator=( const FontMetric& rMetric );
    bool                operator==( const FontMetric& rMetric ) const;
    bool                operator!=( const FontMetric& rMetric ) const
                            { return !operator==( rMetric ); }
};

template< typename charT, typename traits >
inline std::basic_ostream<charT, traits> & operator <<(
    std::basic_ostream<charT, traits> & stream, const FontMetric& rMetric )
{
    stream << "{"
           << "name=" << "\"" << rMetric.GetName() << "\""
           << ",size=(" << rMetric.GetSize().Width() << "," << rMetric.GetSize().Height() << ")"
           << ",ascent=" << rMetric.GetAscent()
           << ",descent=" << rMetric.GetDescent()
           << ",intLeading=" << rMetric.GetIntLeading()
           << ",extLeading=" << rMetric.GetExtLeading()
           << ",lineHeight=" << rMetric.GetLineHeight()
           << ",slant=" << rMetric.GetSlant()
           << "}";
    return stream;
}

class VCL_DLLPUBLIC FontCharMap
{
private:
    const ImplFontCharMap* mpImpl;

public:
                        FontCharMap();
                        ~FontCharMap();

    bool                IsDefaultMap( void ) const;
    bool                HasChar( sal_UCS4 ) const;
    int                 CountCharsInRange( sal_UCS4 cMin, sal_UCS4 cMax ) const;
    int                 GetCharCount( void ) const;

    sal_UCS4            GetFirstChar() const;

    sal_UCS4            GetNextChar( sal_UCS4 ) const;
    sal_UCS4            GetPrevChar( sal_UCS4 ) const;

    int                 GetIndexFromChar( sal_UCS4 ) const;
    sal_UCS4            GetCharFromIndex( int ) const;

private:
    friend class OutputDevice;
    void                Reset( const ImplFontCharMap* pNewMap = NULL );

    // prevent assignment and copy construction
                        FontCharMap( const FontCharMap& );
    void                operator=( const FontCharMap& );
};

class VCL_DLLPUBLIC TextRectInfo
{
    friend class OutputDevice;

private:
    long            mnMaxWidth;
    sal_uInt16          mnLineCount;
    bool            mbEllipsis;

public:
                    TextRectInfo();

    sal_uInt16          GetLineCount() const { return mnLineCount; }
    long            GetMaxLineWidth() const { return mnMaxWidth; }
    bool            IsEllipses() const { return mbEllipsis; }

    bool            operator ==( const TextRectInfo& rInfo ) const
                        { return ((mnMaxWidth   == rInfo.mnMaxWidth)    &&
                                  (mnLineCount  == rInfo.mnLineCount)   &&
                                  (mbEllipsis   == rInfo.mbEllipsis)); }
    bool            operator !=( const TextRectInfo& rInfo ) const
                        { return !(TextRectInfo::operator==( rInfo )); }
};

inline TextRectInfo::TextRectInfo()
{
    mnMaxWidth      = 0;
    mnLineCount     = 0;
    mbEllipsis      = false;
}

#endif // INCLUDED_VCL_METRIC_HXX

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<commit_msg>make that variable protected again<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_VCL_METRIC_HXX
#define INCLUDED_VCL_METRIC_HXX

#include <vcl/dllapi.h>
#include <vcl/font.hxx>
#include <vcl/outdev.hxx>

class ImplFontMetric;
class ImplFontCharMap;

typedef sal_uInt32 sal_UCS4;

namespace vcl {

// avoid problems where poppler's FontInfo is picked up
class VCL_DLLPUBLIC FontInfo : public Font
{
    friend class ::OutputDevice;

protected:
    ImplFontMetric*     mpImplMetric;    // Implementation

public:
                        FontInfo();
                        FontInfo( const FontInfo& );
                        ~FontInfo();

    FontType            GetType() const;

    FontInfo&           operator=( const FontInfo& );
    bool                operator==( const FontInfo& ) const;
    bool                operator!=( const FontInfo& rInfo ) const
                            { return !operator==( rInfo ); }
};

}

class VCL_DLLPUBLIC FontMetric : public vcl::FontInfo
{
public:
                        FontMetric() {}
                        FontMetric( const FontMetric& );
                        ~FontMetric() {}

    long                GetAscent() const;
    long                GetDescent() const;
    long                GetIntLeading() const;
    long                GetExtLeading() const;
    long                GetLineHeight() const;
    long                GetSlant() const;

    FontMetric&         operator=( const FontMetric& rMetric );
    bool                operator==( const FontMetric& rMetric ) const;
    bool                operator!=( const FontMetric& rMetric ) const
                            { return !operator==( rMetric ); }
};

template< typename charT, typename traits >
inline std::basic_ostream<charT, traits> & operator <<(
    std::basic_ostream<charT, traits> & stream, const FontMetric& rMetric )
{
    stream << "{"
           << "name=" << "\"" << rMetric.GetName() << "\""
           << ",size=(" << rMetric.GetSize().Width() << "," << rMetric.GetSize().Height() << ")"
           << ",ascent=" << rMetric.GetAscent()
           << ",descent=" << rMetric.GetDescent()
           << ",intLeading=" << rMetric.GetIntLeading()
           << ",extLeading=" << rMetric.GetExtLeading()
           << ",lineHeight=" << rMetric.GetLineHeight()
           << ",slant=" << rMetric.GetSlant()
           << "}";
    return stream;
}

class VCL_DLLPUBLIC FontCharMap
{
private:
    const ImplFontCharMap* mpImpl;

public:
                        FontCharMap();
                        ~FontCharMap();

    bool                IsDefaultMap( void ) const;
    bool                HasChar( sal_UCS4 ) const;
    int                 CountCharsInRange( sal_UCS4 cMin, sal_UCS4 cMax ) const;
    int                 GetCharCount( void ) const;

    sal_UCS4            GetFirstChar() const;

    sal_UCS4            GetNextChar( sal_UCS4 ) const;
    sal_UCS4            GetPrevChar( sal_UCS4 ) const;

    int                 GetIndexFromChar( sal_UCS4 ) const;
    sal_UCS4            GetCharFromIndex( int ) const;

private:
    friend class OutputDevice;
    void                Reset( const ImplFontCharMap* pNewMap = NULL );

    // prevent assignment and copy construction
                        FontCharMap( const FontCharMap& );
    void                operator=( const FontCharMap& );
};

class VCL_DLLPUBLIC TextRectInfo
{
    friend class OutputDevice;

private:
    long            mnMaxWidth;
    sal_uInt16          mnLineCount;
    bool            mbEllipsis;

public:
                    TextRectInfo();

    sal_uInt16          GetLineCount() const { return mnLineCount; }
    long            GetMaxLineWidth() const { return mnMaxWidth; }
    bool            IsEllipses() const { return mbEllipsis; }

    bool            operator ==( const TextRectInfo& rInfo ) const
                        { return ((mnMaxWidth   == rInfo.mnMaxWidth)    &&
                                  (mnLineCount  == rInfo.mnLineCount)   &&
                                  (mbEllipsis   == rInfo.mbEllipsis)); }
    bool            operator !=( const TextRectInfo& rInfo ) const
                        { return !(TextRectInfo::operator==( rInfo )); }
};

inline TextRectInfo::TextRectInfo()
{
    mnMaxWidth      = 0;
    mnLineCount     = 0;
    mbEllipsis      = false;
}

#endif // INCLUDED_VCL_METRIC_HXX

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


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

  Program:   Visualization Toolkit
  Module:    vtkRenderer.hh
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

Copyright (c) 1993-1995 Ken Martin, Will Schroeder, Bill Lorensen.

This software is copyrighted by Ken Martin, Will Schroeder and Bill Lorensen.
The following terms apply to all files associated with the software unless
explicitly disclaimed in individual files. This copyright specifically does
not apply to the related textbook "The Visualization Toolkit" ISBN
013199837-4 published by Prentice Hall which is covered by its own copyright.

The authors hereby grant permission to use, copy, and distribute this
software and its documentation for any purpose, provided that existing
copyright notices are retained in all copies and that this notice is included
verbatim in any distributions. Additionally, the authors grant permission to
modify this software and its documentation for any purpose, provided that
such modifications are not distributed without the explicit consent of the
authors and that existing copyright notices are retained in all copies. Some
of the algorithms implemented by this software are patented, observe all
applicable patent law.

IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  THIS SOFTWARE IS PROVIDED ON AN
"AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

=========================================================================*/
// .NAME vtkRenderer - abstract specification for renderers
// .SECTION Description
// vtkRenderer provides an abstract specification for renderers. A renderer
// is an object that controls the rendering process for objects. Rendering
// is the process of converting geometry, a specification for lights, and
// a camera view into an image. vtkRenderer also performs coordinate
// transformation between world coordinates, view coordinates (the computer
// graphics rendering coordinate system), and display coordinates (the
// actual screen coordinates on the display device). Certain advanced
// rendering features such as two-sided lighting can also be controlled.

// .SECTION See Also
// vtkRenderWindow vtkActor vtkCamera vtkLight

#ifndef __vtkRenderer_hh
#define __vtkRenderer_hh

#include "vtkMatrix4x4.hh"
#include "vtkLightCollection.hh"
#include "vtkCamera.hh"
#include "vtkActor.hh"

class vtkRenderWindow;
class vtkVolumeRenderer;

class vtkRenderer : public vtkObject
{
public:
  vtkRenderer();
  ~vtkRenderer();
  char *GetClassName() {return "vtkRenderer";};
  void PrintSelf(ostream& os, vtkIndent indent);

  void AddLights(vtkLight *);
  void AddActors(vtkActor *);
  void RemoveLights(vtkLight *);
  void RemoveActors(vtkActor *);
  vtkLightCollection *GetLights();
  vtkActorCollection *GetActors();
  void SetActiveCamera(vtkCamera *);
  vtkCamera *GetActiveCamera();
  void SetVolumeRenderer(vtkVolumeRenderer *);
  vtkVolumeRenderer *GetVolumeRenderer();

  // Description:
  // Set/Get the background color of the rendering screen using an rgb color
  // specification.
  vtkSetVector3Macro(Background,float);
  vtkGetVectorMacro(Background,float,3);

  // Description:
  // Set the aspect ratio of the rendered image. This is computed
  // automatically and should not be set by the user.
  vtkSetVector2Macro(Aspect,float);
  vtkGetVectorMacro(Aspect,float,2);

  // Description:
  // Set the intensity of ambient lighting.
  vtkSetVector3Macro(Ambient,float);
  vtkGetVectorMacro(Ambient,float,3);

  // Description:
  // Set/Get the amount of time this renderer is allowed to spend
  // rendering its scene. Zero indicates an infinite amount of time.
  // This is used by vtkLODActor's.
  vtkSetMacro(AllocatedRenderTime,float);
  vtkGetMacro(AllocatedRenderTime,float);

  // Description:
  // Create an image. Subclasses of vtkRenderer must implement this method.
  virtual void Render() = 0;

  // Description:
  // Ask all actors to build and draw themselves.
  virtual int UpdateActors(void) = 0;

  // Description:
  // Ask the active camera to do whatever it needs to do prior to rendering.
  // This method returns one if there was an active camera and it
  // was on. It returns zero otherwise.
  virtual int UpdateCameras(void) = 0;

  // Description:
  // Ask all lights to load themselves into rendering pipeline.
  // This method will return the actual number of lights that were on.
  virtual int UpdateLights(void) = 0;

  void DoCameras();
  void DoLights();
  void DoActors();
  void ResetCamera();
  void ResetCamera(float bounds[6]);

  void SetRenderWindow(vtkRenderWindow *);
  vtkRenderWindow *GetRenderWindow() {return RenderWindow;};

  // Description:
  // Set/get a point location in display (or screen) coordinates.
  // The lower left corner of the window is the origin and y increases
  // as you go up the screen.
  vtkSetVector3Macro(DisplayPoint,float);
  vtkGetVectorMacro(DisplayPoint,float,3);

  // Description:
  // Specify a point location in view coordinates. The origin is in the
  // middle of the viewport and it extends from -1 to 1 in all three
  // dimensions.
  vtkSetVector3Macro(ViewPoint,float);
  vtkGetVectorMacro(ViewPoint,float,3);

  // Description:
  // Specify a point location in world coordinates. This method takes
  // homogeneous coordinates.
  vtkSetVector4Macro(WorldPoint,float);
  vtkGetVectorMacro(WorldPoint,float,4);

  // Description:
  // Specify the viewport for the renderer to draw in the rendering window.
  // Coordinates are expressed as (xmin,ymin,xmax,ymax), where each
  // coordinate is 0 <= coordinate <= 1.0.
  vtkSetVector4Macro(Viewport,float);
  vtkGetVectorMacro(Viewport,float,4);

  // Description:
  // Turn on/off two-sided lighting of surfaces. If two-sided lighting is
  // off, then only the side of the surface facing the light(s) will be lit,
  // and the other side dark. If two-sided lighting on, both sides of the
  // surface will be lit.
  vtkGetMacro(TwoSidedLighting,int);
  vtkSetMacro(TwoSidedLighting,int);
  vtkBooleanMacro(TwoSidedLighting,int);

  virtual float *GetCenter();

  virtual void DisplayToView(); // these get modified in subclasses
  virtual void ViewToDisplay(); // to handle stereo rendering
  virtual int  IsInViewport(int x,int y);
  void WorldToView();
  void ViewToWorld();
  void DisplayToWorld();
  void WorldToDisplay();

  void SetStartRenderMethod(void (*f)(void *), void *arg);
  void SetEndRenderMethod(void (*f)(void *), void *arg);
  void SetStartRenderMethodArgDelete(void (*f)(void *));
  void SetEndRenderMethodArgDelete(void (*f)(void *));

protected:
  vtkVolumeRenderer *VolumeRenderer;
  vtkCamera *ActiveCamera;
  vtkLight  *CreatedLight;
  vtkLightCollection Lights;
  vtkActorCollection Actors;
  float Ambient[3];
  float Background[3];
  vtkRenderWindow *RenderWindow;
  float DisplayPoint[3];
  float ViewPoint[3];
  float WorldPoint[4];
  float Viewport[4];
  float Aspect[2];
  float Center[2];
  int   SelfCreatedCamera;
  int   SelfCreatedLight;
  float AllocatedRenderTime;
  int   TwoSidedLighting;

  void (*StartRenderMethod)(void *);
  void (*StartRenderMethodArgDelete)(void *);
  void *StartRenderMethodArg;
  void (*EndRenderMethod)(void *);
  void (*EndRenderMethodArgDelete)(void *);
  void *EndRenderMethodArg;
};

// Description:
// Get the list of lights for this renderer.
inline vtkLightCollection *vtkRenderer::GetLights() {return &(this->Lights);};

// Description:
// Get the list of actors for this renderer.
inline vtkActorCollection *vtkRenderer::GetActors() {return &(this->Actors);};

// Description:
// Convert display (or screen) coordinates to world coordinates.
inline void vtkRenderer::DisplayToWorld() {DisplayToView(); ViewToWorld();};

// Description:
// Convert world point coordinates to display (or screen) coordinates.
inline void vtkRenderer::WorldToDisplay() {WorldToView(); ViewToDisplay();};

#endif
<commit_msg>Added a vtkNewVolumeRenderer<commit_after>/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkRenderer.hh
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

Copyright (c) 1993-1995 Ken Martin, Will Schroeder, Bill Lorensen.

This software is copyrighted by Ken Martin, Will Schroeder and Bill Lorensen.
The following terms apply to all files associated with the software unless
explicitly disclaimed in individual files. This copyright specifically does
not apply to the related textbook "The Visualization Toolkit" ISBN
013199837-4 published by Prentice Hall which is covered by its own copyright.

The authors hereby grant permission to use, copy, and distribute this
software and its documentation for any purpose, provided that existing
copyright notices are retained in all copies and that this notice is included
verbatim in any distributions. Additionally, the authors grant permission to
modify this software and its documentation for any purpose, provided that
such modifications are not distributed without the explicit consent of the
authors and that existing copyright notices are retained in all copies. Some
of the algorithms implemented by this software are patented, observe all
applicable patent law.

IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  THIS SOFTWARE IS PROVIDED ON AN
"AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

=========================================================================*/
// .NAME vtkRenderer - abstract specification for renderers
// .SECTION Description
// vtkRenderer provides an abstract specification for renderers. A renderer
// is an object that controls the rendering process for objects. Rendering
// is the process of converting geometry, a specification for lights, and
// a camera view into an image. vtkRenderer also performs coordinate
// transformation between world coordinates, view coordinates (the computer
// graphics rendering coordinate system), and display coordinates (the
// actual screen coordinates on the display device). Certain advanced
// rendering features such as two-sided lighting can also be controlled.

// .SECTION See Also
// vtkRenderWindow vtkActor vtkCamera vtkLight

#ifndef __vtkRenderer_hh
#define __vtkRenderer_hh

#include "vtkMatrix4x4.hh"
#include "vtkLightCollection.hh"
#include "vtkCamera.hh"
#include "vtkActor.hh"

class vtkRenderWindow;
class vtkVolumeRenderer;
class vtkNewVolumeRenderer;

class vtkRenderer : public vtkObject
{
public:
  vtkRenderer();
  ~vtkRenderer();
  char *GetClassName() {return "vtkRenderer";};
  void PrintSelf(ostream& os, vtkIndent indent);

  void AddLights(vtkLight *);
  void AddActors(vtkActor *);
  void RemoveLights(vtkLight *);
  void RemoveActors(vtkActor *);
  vtkLightCollection *GetLights();
  vtkActorCollection *GetActors();
  void SetActiveCamera(vtkCamera *);
  vtkCamera *GetActiveCamera();
  void SetVolumeRenderer(vtkVolumeRenderer *);
  vtkVolumeRenderer *GetVolumeRenderer();

  void SetNewVolumeRenderer(vtkNewVolumeRenderer *);
  vtkNewVolumeRenderer *GetNewVolumeRenderer();

  // Description:
  // Set/Get the background color of the rendering screen using an rgb color
  // specification.
  vtkSetVector3Macro(Background,float);
  vtkGetVectorMacro(Background,float,3);

  // Description:
  // Set the aspect ratio of the rendered image. This is computed
  // automatically and should not be set by the user.
  vtkSetVector2Macro(Aspect,float);
  vtkGetVectorMacro(Aspect,float,2);

  // Description:
  // Set the intensity of ambient lighting.
  vtkSetVector3Macro(Ambient,float);
  vtkGetVectorMacro(Ambient,float,3);

  // Description:
  // Set/Get the amount of time this renderer is allowed to spend
  // rendering its scene. Zero indicates an infinite amount of time.
  // This is used by vtkLODActor's.
  vtkSetMacro(AllocatedRenderTime,float);
  vtkGetMacro(AllocatedRenderTime,float);

  // Description:
  // Create an image. Subclasses of vtkRenderer must implement this method.
  virtual void Render() = 0;

  // Description:
  // Ask all actors to build and draw themselves.
  virtual int UpdateActors(void) = 0;

  // Description:
  // Ask the active camera to do whatever it needs to do prior to rendering.
  // This method returns one if there was an active camera and it
  // was on. It returns zero otherwise.
  virtual int UpdateCameras(void) = 0;

  // Description:
  // Ask all lights to load themselves into rendering pipeline.
  // This method will return the actual number of lights that were on.
  virtual int UpdateLights(void) = 0;

  void DoCameras();
  void DoLights();
  void DoActors();
  void ResetCamera();
  void ResetCamera(float bounds[6]);

  void SetRenderWindow(vtkRenderWindow *);
  vtkRenderWindow *GetRenderWindow() {return RenderWindow;};

  // Description:
  // Set/get a point location in display (or screen) coordinates.
  // The lower left corner of the window is the origin and y increases
  // as you go up the screen.
  vtkSetVector3Macro(DisplayPoint,float);
  vtkGetVectorMacro(DisplayPoint,float,3);

  // Description:
  // Specify a point location in view coordinates. The origin is in the
  // middle of the viewport and it extends from -1 to 1 in all three
  // dimensions.
  vtkSetVector3Macro(ViewPoint,float);
  vtkGetVectorMacro(ViewPoint,float,3);

  // Description:
  // Specify a point location in world coordinates. This method takes
  // homogeneous coordinates.
  vtkSetVector4Macro(WorldPoint,float);
  vtkGetVectorMacro(WorldPoint,float,4);

  // Description:
  // Specify the viewport for the renderer to draw in the rendering window.
  // Coordinates are expressed as (xmin,ymin,xmax,ymax), where each
  // coordinate is 0 <= coordinate <= 1.0.
  vtkSetVector4Macro(Viewport,float);
  vtkGetVectorMacro(Viewport,float,4);

  // Description:
  // Turn on/off two-sided lighting of surfaces. If two-sided lighting is
  // off, then only the side of the surface facing the light(s) will be lit,
  // and the other side dark. If two-sided lighting on, both sides of the
  // surface will be lit.
  vtkGetMacro(TwoSidedLighting,int);
  vtkSetMacro(TwoSidedLighting,int);
  vtkBooleanMacro(TwoSidedLighting,int);

  virtual float *GetCenter();

  virtual void DisplayToView(); // these get modified in subclasses
  virtual void ViewToDisplay(); // to handle stereo rendering
  virtual int  IsInViewport(int x,int y);
  void WorldToView();
  void ViewToWorld();
  void DisplayToWorld();
  void WorldToDisplay();

  void SetStartRenderMethod(void (*f)(void *), void *arg);
  void SetEndRenderMethod(void (*f)(void *), void *arg);
  void SetStartRenderMethodArgDelete(void (*f)(void *));
  void SetEndRenderMethodArgDelete(void (*f)(void *));

protected:
  vtkVolumeRenderer *VolumeRenderer;
  vtkNewVolumeRenderer *NewVolumeRenderer;
  vtkCamera *ActiveCamera;
  vtkLight  *CreatedLight;
  vtkLightCollection Lights;
  vtkActorCollection Actors;
  float Ambient[3];
  float Background[3];
  vtkRenderWindow *RenderWindow;
  float DisplayPoint[3];
  float ViewPoint[3];
  float WorldPoint[4];
  float Viewport[4];
  float Aspect[2];
  float Center[2];
  int   SelfCreatedCamera;
  int   SelfCreatedLight;
  float AllocatedRenderTime;
  int   TwoSidedLighting;

  void (*StartRenderMethod)(void *);
  void (*StartRenderMethodArgDelete)(void *);
  void *StartRenderMethodArg;
  void (*EndRenderMethod)(void *);
  void (*EndRenderMethodArgDelete)(void *);
  void *EndRenderMethodArg;
};

// Description:
// Get the list of lights for this renderer.
inline vtkLightCollection *vtkRenderer::GetLights() {return &(this->Lights);};

// Description:
// Get the list of actors for this renderer.
inline vtkActorCollection *vtkRenderer::GetActors() {return &(this->Actors);};

// Description:
// Convert display (or screen) coordinates to world coordinates.
inline void vtkRenderer::DisplayToWorld() {DisplayToView(); ViewToWorld();};

// Description:
// Convert world point coordinates to display (or screen) coordinates.
inline void vtkRenderer::WorldToDisplay() {WorldToView(); ViewToDisplay();};

#endif
<|endoftext|>