<commit_before>#include <sal/char_array.hpp>
#include <sal/common.test.hpp>

namespace {

constexpr size_t size = 256;

struct char_array
  : public sal_test::fixture
{
  sal::char_array_t<256> chars;
  std::string exact, overflow;

  char_array ()
    : exact(chars.max_size(), '.')
    , overflow(exact + exact)
  {}
};

TEST_F(char_array, ctor)
{
  ASSERT_TRUE(chars.good());

  EXPECT_TRUE(bool(chars));
  EXPECT_FALSE(chars.bad());
  EXPECT_FALSE(chars.full());
  EXPECT_TRUE(chars.empty());

  EXPECT_EQ(0U, chars.size());
  EXPECT_EQ(size, chars.max_size());
  EXPECT_EQ(size, chars.available());

  EXPECT_STREQ("", chars.c_str());
}

TEST_F(char_array, ctor_assign)
{
  ASSERT_TRUE(bool(chars << case_name));
  auto a{chars};
  EXPECT_EQ(case_name, a.c_str());
}

TEST_F(char_array, ctor_assign_empty)
{
  auto a{chars};
  EXPECT_EQ("", a.to_string());
}

TEST_F(char_array, ctor_assign_bad)
{
  EXPECT_TRUE(bool(chars << exact));
  EXPECT_FALSE(bool(chars << case_name));
  EXPECT_TRUE(chars.bad());

  auto a{chars};
  EXPECT_TRUE(a.good());
  EXPECT_EQ(exact, a.c_str());
}

TEST_F(char_array, ctor_assign_smaller)
{
  ASSERT_TRUE(bool(chars << case_name));
  sal::char_array_t<size / 2> a{chars};
  EXPECT_EQ(case_name, a.c_str());
}

TEST_F(char_array, ctor_assign_smaller_empty)
{
  sal::char_array_t<size / 2> a{chars};
  EXPECT_EQ("", a.to_string());
}

TEST_F(char_array, ctor_assign_smaller_bad)
{
  EXPECT_TRUE(bool(chars << exact));
  EXPECT_FALSE(bool(chars << case_name));
  EXPECT_TRUE(chars.bad());

  sal::char_array_t<size / 2> a{chars};
  EXPECT_TRUE(a.good());
  std::string half_exact(exact, exact.size() / 2);
  EXPECT_EQ(half_exact, a.c_str());
}

TEST_F(char_array, ctor_assign_bigger)
{
  ASSERT_TRUE(bool(chars << case_name));
  sal::char_array_t<size * 2> a{chars};
  EXPECT_EQ(case_name, a.c_str());
}

TEST_F(char_array, ctor_assign_bigger_empty)
{
  sal::char_array_t<size * 2> a{chars};
  EXPECT_EQ("", a.to_string());
}

TEST_F(char_array, ctor_assign_bigger_bad)
{
  EXPECT_TRUE(bool(chars << exact));
  EXPECT_FALSE(bool(chars << case_name));
  EXPECT_TRUE(chars.bad());

  sal::char_array_t<size * 2> a{chars};
  EXPECT_TRUE(a.good());
  EXPECT_EQ(exact, a.c_str());
}

TEST_F(char_array, copy_assign)
{
  ASSERT_TRUE(bool(chars << case_name));
  decltype(chars) a;
  a = chars;
  EXPECT_EQ(case_name, a.c_str());
}

TEST_F(char_array, copy_assign_empty)
{
  decltype(chars) a;
  a = chars;
  EXPECT_EQ("", a.to_string());
}

TEST_F(char_array, copy_assign_bad)
{
  EXPECT_TRUE(bool(chars << exact));
  EXPECT_FALSE(bool(chars << case_name));
  EXPECT_TRUE(chars.bad());

  decltype(chars) a;
  a = chars;
  EXPECT_TRUE(a.good());
  EXPECT_EQ(exact, a.c_str());
}

TEST_F(char_array, copy_assign_smaller)
{
  ASSERT_TRUE(bool(chars << case_name));
  sal::char_array_t<size / 2> a;
  a = chars;
  EXPECT_EQ(case_name, a.c_str());
}

TEST_F(char_array, copy_assign_smaller_empty)
{
  sal::char_array_t<size / 2> a;
  a = chars;
  EXPECT_EQ("", a.to_string());
}

TEST_F(char_array, copy_assign_smaller_bad)
{
  EXPECT_TRUE(bool(chars << exact));
  EXPECT_FALSE(bool(chars << case_name));
  EXPECT_TRUE(chars.bad());

  sal::char_array_t<size / 2> a;
  a = chars;
  EXPECT_TRUE(a.good());
  std::string half_exact(exact, exact.size() / 2);
  EXPECT_EQ(half_exact, a.c_str());
}

TEST_F(char_array, copy_assign_bigger)
{
  ASSERT_TRUE(bool(chars << case_name));
  sal::char_array_t<size * 2> a;
  a = chars;
  EXPECT_EQ(case_name, a.c_str());
}

TEST_F(char_array, copy_assign_bigger_empty)
{
  sal::char_array_t<size * 2> a;
  a = chars;
  EXPECT_EQ("", a.to_string());
}

TEST_F(char_array, copy_assign_bigger_bad)
{
  EXPECT_TRUE(bool(chars << exact));
  EXPECT_FALSE(bool(chars << case_name));
  EXPECT_TRUE(chars.bad());

  sal::char_array_t<size * 2> a;
  a = chars;
  EXPECT_TRUE(a.good());
  EXPECT_EQ(exact, a.c_str());
}

TEST_F(char_array, index)
{
  ASSERT_TRUE(bool(chars << case_name));
  for (auto i = 0U;  i < case_name.size();  ++i)
  {
    EXPECT_EQ(case_name[i], chars[i]);
  }
}

TEST_F(char_array, front)
{
  ASSERT_TRUE(bool(chars << case_name));
  EXPECT_EQ(case_name.front(), chars.front());
}

TEST_F(char_array, back)
{
  ASSERT_TRUE(bool(chars << case_name));
  EXPECT_EQ(case_name.back(), chars.back());
}

TEST_F(char_array, iterator)
{
  ASSERT_TRUE(bool(chars << case_name));
  EXPECT_EQ(chars.data(), chars.begin());
  EXPECT_EQ(chars.data() + case_name.size(), chars.end());
}

TEST_F(char_array, iterator_empty)
{
  EXPECT_EQ(chars.data(), chars.begin());
  EXPECT_EQ(chars.data(), chars.end());
}

TEST_F(char_array, iterator_full)
{
  ASSERT_TRUE(bool(chars << exact));
  EXPECT_EQ(chars.data(), chars.begin());
  EXPECT_EQ(chars.data() + exact.size(), chars.end());
}

TEST_F(char_array, iterator_bad)
{
  EXPECT_FALSE(bool(chars << overflow));
  EXPECT_EQ(chars.data(), chars.begin());
  EXPECT_EQ(chars.data() + overflow.size(), chars.end());
}

TEST_F(char_array, remove_suffix)
{
  EXPECT_TRUE(bool(chars << case_name));
  chars.remove_suffix(case_name.size() / 2);
  std::string expected(case_name, 0, case_name.size() / 2);
  EXPECT_EQ(expected, chars.c_str());
}

TEST_F(char_array, remove_suffix_before_begin)
{
  EXPECT_TRUE(bool(chars << case_name));
  chars.remove_suffix(case_name.size() * 2);
  EXPECT_EQ(0U, chars.size());
  EXPECT_EQ(chars.begin(), chars.end());
}

TEST_F(char_array, remove_suffix_from_bad)
{
  EXPECT_FALSE(bool(chars << overflow));
  EXPECT_TRUE(chars.bad());

  chars.remove_suffix(overflow.size() / 3);
  EXPECT_TRUE(chars.bad());

  chars.remove_suffix(overflow.size() / 3);
  EXPECT_TRUE(chars.good());
}

TEST_F(char_array, mark_and_revert)
{
  ASSERT_TRUE(bool(chars << case_name));
  EXPECT_EQ(case_name, chars.c_str());

  auto mark = chars.mark();
  ASSERT_TRUE(bool(chars << case_name));
  EXPECT_EQ(case_name + case_name, chars.c_str());

  chars.revert(mark);
  EXPECT_EQ(case_name, chars.c_str());
}

TEST_F(char_array, mark_and_revert_from_bad)
{
  ASSERT_TRUE(bool(chars << case_name));
  EXPECT_EQ(case_name, chars.c_str());

  auto mark = chars.mark();
  ASSERT_FALSE(bool(chars << exact));
  EXPECT_TRUE(chars.bad());

  chars.revert(mark);
  ASSERT_TRUE(chars.good());
  EXPECT_EQ(case_name, chars.c_str());
}

TEST_F(char_array, reset)
{
  ASSERT_TRUE(bool(chars << case_name));
  EXPECT_EQ(case_name, chars.c_str());
  EXPECT_EQ(case_name.size(), chars.size());

  chars.reset();
  EXPECT_TRUE(chars.empty());
  EXPECT_STREQ("", chars.c_str());
}

TEST_F(char_array, reset_empty)
{
  chars.reset();
  EXPECT_TRUE(chars.empty());
  EXPECT_STREQ("", chars.c_str());
}

TEST_F(char_array, reset_full)
{
  ASSERT_TRUE(bool(chars << exact));
  EXPECT_EQ(exact, chars.c_str());
  EXPECT_EQ(exact.size(), chars.size());

  chars.reset();
  EXPECT_TRUE(chars.empty());
  EXPECT_STREQ("", chars.c_str());
}

TEST_F(char_array, reset_bad)
{
  EXPECT_FALSE(bool(chars << overflow));
  EXPECT_TRUE(chars.bad());

  chars.reset();
  ASSERT_TRUE(chars.good());
  ASSERT_FALSE(chars.bad());
  EXPECT_TRUE(chars.empty());
  EXPECT_STREQ("", chars.c_str());
}

TEST_F(char_array, insert)
{
  ASSERT_TRUE(bool(chars << case_name));
  EXPECT_TRUE(chars.good());
  EXPECT_EQ(case_name, chars.c_str());
}

TEST_F(char_array, insert_full)
{
  ASSERT_TRUE(bool(chars << exact));
  EXPECT_TRUE(chars.full());
  EXPECT_EQ(exact, chars.c_str());
}

TEST_F(char_array, insert_overflow)
{
  EXPECT_FALSE(bool(chars << overflow));
  EXPECT_TRUE(chars.bad());
}

TEST_F(char_array, insert_char_array)
{
  sal::char_array_t<2 * size> a;
  EXPECT_TRUE(bool(a << case_name));
  EXPECT_TRUE(bool(chars << a));
  EXPECT_EQ(case_name, chars.c_str());
}

TEST_F(char_array, insert_self)
{
  EXPECT_TRUE(bool(chars << case_name));
  EXPECT_TRUE(bool(chars << chars));
  EXPECT_EQ(case_name + case_name, chars.c_str());
}

struct user_defined_t
{
  static std::string name ()
  {
    return "user_defined_t";
  }
};

sal::memory_writer_t &operator<< (sal::memory_writer_t &writer,
  const user_defined_t &) noexcept
{
  return (writer << user_defined_t::name());
}

TEST_F(char_array, insert_user_defined_type)
{
  user_defined_t t;
  EXPECT_TRUE(bool(chars << t));
  EXPECT_EQ(user_defined_t::name(), chars.c_str());
}

TEST_F(char_array, print)
{
  ASSERT_TRUE(bool(chars.print(case_name)));
  EXPECT_TRUE(chars.good());
  EXPECT_EQ(case_name, chars.c_str());
}

TEST_F(char_array, print_full)
{
  ASSERT_TRUE(bool(chars.print(exact)));
  EXPECT_TRUE(chars.full());
  EXPECT_EQ(exact, chars.c_str());
}

TEST_F(char_array, print_overflow)
{
  EXPECT_FALSE(bool(chars.print(overflow)));
  EXPECT_TRUE(chars.bad());
}

TEST_F(char_array, print_char_array)
{
  sal::char_array_t<2 * size> a;
  EXPECT_TRUE(bool(a << case_name));
  EXPECT_TRUE(bool(chars.print(a)));
  EXPECT_EQ(case_name, chars.c_str());
}

TEST_F(char_array, print_self)
{
  EXPECT_TRUE(bool(chars << case_name));
  EXPECT_TRUE(bool(chars.print(chars)));
  EXPECT_EQ(case_name + case_name, chars.c_str());
}

TEST_F(char_array, print_user_defined_type)
{
  user_defined_t t;
  EXPECT_TRUE(bool(chars.print(t)));
  EXPECT_EQ(user_defined_t::name(), chars.c_str());
}

TEST_F(char_array, to_string)
{
  ASSERT_TRUE(bool(chars << case_name));
  EXPECT_TRUE(chars.good());
  EXPECT_EQ(case_name, chars.to_string());
}

TEST_F(char_array, to_string_empty)
{
  ASSERT_TRUE(chars.good());
  EXPECT_EQ("", chars.to_string());
}

TEST_F(char_array, to_string_full)
{
  ASSERT_TRUE(bool(chars << exact));
  EXPECT_TRUE(chars.good());
  EXPECT_TRUE(chars.full());
  EXPECT_EQ(exact, chars.to_string());
}

TEST_F(char_array, to_string_view)
{
  ASSERT_TRUE(bool(chars << case_name));
  EXPECT_TRUE(chars.good());
  EXPECT_EQ(case_name, chars.to_string_view());
}

TEST_F(char_array, to_string_view_empty)
{
  ASSERT_TRUE(chars.good());
  EXPECT_EQ("", chars.to_string_view());
}

TEST_F(char_array, to_string_view_full)
{
  ASSERT_TRUE(bool(chars << exact));
  EXPECT_TRUE(chars.good());
  EXPECT_TRUE(chars.full());
  EXPECT_EQ(exact, chars.to_string_view());
}

TEST_F(char_array, XXX)
{
  using namespace std::string_view_literals;
  auto x = "hello"sv;
  chars << x;
  std::cout << chars.c_str() << '\n';
}

} // namespace
<commit_msg>Remove mistakenly committed temporary unittest<commit_after>#include <sal/char_array.hpp>
#include <sal/common.test.hpp>

namespace {

constexpr size_t size = 256;

struct char_array
  : public sal_test::fixture
{
  sal::char_array_t<256> chars;
  std::string exact, overflow;

  char_array ()
    : exact(chars.max_size(), '.')
    , overflow(exact + exact)
  {}
};

TEST_F(char_array, ctor)
{
  ASSERT_TRUE(chars.good());

  EXPECT_TRUE(bool(chars));
  EXPECT_FALSE(chars.bad());
  EXPECT_FALSE(chars.full());
  EXPECT_TRUE(chars.empty());

  EXPECT_EQ(0U, chars.size());
  EXPECT_EQ(size, chars.max_size());
  EXPECT_EQ(size, chars.available());

  EXPECT_STREQ("", chars.c_str());
}

TEST_F(char_array, ctor_assign)
{
  ASSERT_TRUE(bool(chars << case_name));
  auto a{chars};
  EXPECT_EQ(case_name, a.c_str());
}

TEST_F(char_array, ctor_assign_empty)
{
  auto a{chars};
  EXPECT_EQ("", a.to_string());
}

TEST_F(char_array, ctor_assign_bad)
{
  EXPECT_TRUE(bool(chars << exact));
  EXPECT_FALSE(bool(chars << case_name));
  EXPECT_TRUE(chars.bad());

  auto a{chars};
  EXPECT_TRUE(a.good());
  EXPECT_EQ(exact, a.c_str());
}

TEST_F(char_array, ctor_assign_smaller)
{
  ASSERT_TRUE(bool(chars << case_name));
  sal::char_array_t<size / 2> a{chars};
  EXPECT_EQ(case_name, a.c_str());
}

TEST_F(char_array, ctor_assign_smaller_empty)
{
  sal::char_array_t<size / 2> a{chars};
  EXPECT_EQ("", a.to_string());
}

TEST_F(char_array, ctor_assign_smaller_bad)
{
  EXPECT_TRUE(bool(chars << exact));
  EXPECT_FALSE(bool(chars << case_name));
  EXPECT_TRUE(chars.bad());

  sal::char_array_t<size / 2> a{chars};
  EXPECT_TRUE(a.good());
  std::string half_exact(exact, exact.size() / 2);
  EXPECT_EQ(half_exact, a.c_str());
}

TEST_F(char_array, ctor_assign_bigger)
{
  ASSERT_TRUE(bool(chars << case_name));
  sal::char_array_t<size * 2> a{chars};
  EXPECT_EQ(case_name, a.c_str());
}

TEST_F(char_array, ctor_assign_bigger_empty)
{
  sal::char_array_t<size * 2> a{chars};
  EXPECT_EQ("", a.to_string());
}

TEST_F(char_array, ctor_assign_bigger_bad)
{
  EXPECT_TRUE(bool(chars << exact));
  EXPECT_FALSE(bool(chars << case_name));
  EXPECT_TRUE(chars.bad());

  sal::char_array_t<size * 2> a{chars};
  EXPECT_TRUE(a.good());
  EXPECT_EQ(exact, a.c_str());
}

TEST_F(char_array, copy_assign)
{
  ASSERT_TRUE(bool(chars << case_name));
  decltype(chars) a;
  a = chars;
  EXPECT_EQ(case_name, a.c_str());
}

TEST_F(char_array, copy_assign_empty)
{
  decltype(chars) a;
  a = chars;
  EXPECT_EQ("", a.to_string());
}

TEST_F(char_array, copy_assign_bad)
{
  EXPECT_TRUE(bool(chars << exact));
  EXPECT_FALSE(bool(chars << case_name));
  EXPECT_TRUE(chars.bad());

  decltype(chars) a;
  a = chars;
  EXPECT_TRUE(a.good());
  EXPECT_EQ(exact, a.c_str());
}

TEST_F(char_array, copy_assign_smaller)
{
  ASSERT_TRUE(bool(chars << case_name));
  sal::char_array_t<size / 2> a;
  a = chars;
  EXPECT_EQ(case_name, a.c_str());
}

TEST_F(char_array, copy_assign_smaller_empty)
{
  sal::char_array_t<size / 2> a;
  a = chars;
  EXPECT_EQ("", a.to_string());
}

TEST_F(char_array, copy_assign_smaller_bad)
{
  EXPECT_TRUE(bool(chars << exact));
  EXPECT_FALSE(bool(chars << case_name));
  EXPECT_TRUE(chars.bad());

  sal::char_array_t<size / 2> a;
  a = chars;
  EXPECT_TRUE(a.good());
  std::string half_exact(exact, exact.size() / 2);
  EXPECT_EQ(half_exact, a.c_str());
}

TEST_F(char_array, copy_assign_bigger)
{
  ASSERT_TRUE(bool(chars << case_name));
  sal::char_array_t<size * 2> a;
  a = chars;
  EXPECT_EQ(case_name, a.c_str());
}

TEST_F(char_array, copy_assign_bigger_empty)
{
  sal::char_array_t<size * 2> a;
  a = chars;
  EXPECT_EQ("", a.to_string());
}

TEST_F(char_array, copy_assign_bigger_bad)
{
  EXPECT_TRUE(bool(chars << exact));
  EXPECT_FALSE(bool(chars << case_name));
  EXPECT_TRUE(chars.bad());

  sal::char_array_t<size * 2> a;
  a = chars;
  EXPECT_TRUE(a.good());
  EXPECT_EQ(exact, a.c_str());
}

TEST_F(char_array, index)
{
  ASSERT_TRUE(bool(chars << case_name));
  for (auto i = 0U;  i < case_name.size();  ++i)
  {
    EXPECT_EQ(case_name[i], chars[i]);
  }
}

TEST_F(char_array, front)
{
  ASSERT_TRUE(bool(chars << case_name));
  EXPECT_EQ(case_name.front(), chars.front());
}

TEST_F(char_array, back)
{
  ASSERT_TRUE(bool(chars << case_name));
  EXPECT_EQ(case_name.back(), chars.back());
}

TEST_F(char_array, iterator)
{
  ASSERT_TRUE(bool(chars << case_name));
  EXPECT_EQ(chars.data(), chars.begin());
  EXPECT_EQ(chars.data() + case_name.size(), chars.end());
}

TEST_F(char_array, iterator_empty)
{
  EXPECT_EQ(chars.data(), chars.begin());
  EXPECT_EQ(chars.data(), chars.end());
}

TEST_F(char_array, iterator_full)
{
  ASSERT_TRUE(bool(chars << exact));
  EXPECT_EQ(chars.data(), chars.begin());
  EXPECT_EQ(chars.data() + exact.size(), chars.end());
}

TEST_F(char_array, iterator_bad)
{
  EXPECT_FALSE(bool(chars << overflow));
  EXPECT_EQ(chars.data(), chars.begin());
  EXPECT_EQ(chars.data() + overflow.size(), chars.end());
}

TEST_F(char_array, remove_suffix)
{
  EXPECT_TRUE(bool(chars << case_name));
  chars.remove_suffix(case_name.size() / 2);
  std::string expected(case_name, 0, case_name.size() / 2);
  EXPECT_EQ(expected, chars.c_str());
}

TEST_F(char_array, remove_suffix_before_begin)
{
  EXPECT_TRUE(bool(chars << case_name));
  chars.remove_suffix(case_name.size() * 2);
  EXPECT_EQ(0U, chars.size());
  EXPECT_EQ(chars.begin(), chars.end());
}

TEST_F(char_array, remove_suffix_from_bad)
{
  EXPECT_FALSE(bool(chars << overflow));
  EXPECT_TRUE(chars.bad());

  chars.remove_suffix(overflow.size() / 3);
  EXPECT_TRUE(chars.bad());

  chars.remove_suffix(overflow.size() / 3);
  EXPECT_TRUE(chars.good());
}

TEST_F(char_array, mark_and_revert)
{
  ASSERT_TRUE(bool(chars << case_name));
  EXPECT_EQ(case_name, chars.c_str());

  auto mark = chars.mark();
  ASSERT_TRUE(bool(chars << case_name));
  EXPECT_EQ(case_name + case_name, chars.c_str());

  chars.revert(mark);
  EXPECT_EQ(case_name, chars.c_str());
}

TEST_F(char_array, mark_and_revert_from_bad)
{
  ASSERT_TRUE(bool(chars << case_name));
  EXPECT_EQ(case_name, chars.c_str());

  auto mark = chars.mark();
  ASSERT_FALSE(bool(chars << exact));
  EXPECT_TRUE(chars.bad());

  chars.revert(mark);
  ASSERT_TRUE(chars.good());
  EXPECT_EQ(case_name, chars.c_str());
}

TEST_F(char_array, reset)
{
  ASSERT_TRUE(bool(chars << case_name));
  EXPECT_EQ(case_name, chars.c_str());
  EXPECT_EQ(case_name.size(), chars.size());

  chars.reset();
  EXPECT_TRUE(chars.empty());
  EXPECT_STREQ("", chars.c_str());
}

TEST_F(char_array, reset_empty)
{
  chars.reset();
  EXPECT_TRUE(chars.empty());
  EXPECT_STREQ("", chars.c_str());
}

TEST_F(char_array, reset_full)
{
  ASSERT_TRUE(bool(chars << exact));
  EXPECT_EQ(exact, chars.c_str());
  EXPECT_EQ(exact.size(), chars.size());

  chars.reset();
  EXPECT_TRUE(chars.empty());
  EXPECT_STREQ("", chars.c_str());
}

TEST_F(char_array, reset_bad)
{
  EXPECT_FALSE(bool(chars << overflow));
  EXPECT_TRUE(chars.bad());

  chars.reset();
  ASSERT_TRUE(chars.good());
  ASSERT_FALSE(chars.bad());
  EXPECT_TRUE(chars.empty());
  EXPECT_STREQ("", chars.c_str());
}

TEST_F(char_array, insert)
{
  ASSERT_TRUE(bool(chars << case_name));
  EXPECT_TRUE(chars.good());
  EXPECT_EQ(case_name, chars.c_str());
}

TEST_F(char_array, insert_full)
{
  ASSERT_TRUE(bool(chars << exact));
  EXPECT_TRUE(chars.full());
  EXPECT_EQ(exact, chars.c_str());
}

TEST_F(char_array, insert_overflow)
{
  EXPECT_FALSE(bool(chars << overflow));
  EXPECT_TRUE(chars.bad());
}

TEST_F(char_array, insert_char_array)
{
  sal::char_array_t<2 * size> a;
  EXPECT_TRUE(bool(a << case_name));
  EXPECT_TRUE(bool(chars << a));
  EXPECT_EQ(case_name, chars.c_str());
}

TEST_F(char_array, insert_self)
{
  EXPECT_TRUE(bool(chars << case_name));
  EXPECT_TRUE(bool(chars << chars));
  EXPECT_EQ(case_name + case_name, chars.c_str());
}

struct user_defined_t
{
  static std::string name ()
  {
    return "user_defined_t";
  }
};

sal::memory_writer_t &operator<< (sal::memory_writer_t &writer,
  const user_defined_t &) noexcept
{
  return (writer << user_defined_t::name());
}

TEST_F(char_array, insert_user_defined_type)
{
  user_defined_t t;
  EXPECT_TRUE(bool(chars << t));
  EXPECT_EQ(user_defined_t::name(), chars.c_str());
}

TEST_F(char_array, print)
{
  ASSERT_TRUE(bool(chars.print(case_name)));
  EXPECT_TRUE(chars.good());
  EXPECT_EQ(case_name, chars.c_str());
}

TEST_F(char_array, print_full)
{
  ASSERT_TRUE(bool(chars.print(exact)));
  EXPECT_TRUE(chars.full());
  EXPECT_EQ(exact, chars.c_str());
}

TEST_F(char_array, print_overflow)
{
  EXPECT_FALSE(bool(chars.print(overflow)));
  EXPECT_TRUE(chars.bad());
}

TEST_F(char_array, print_char_array)
{
  sal::char_array_t<2 * size> a;
  EXPECT_TRUE(bool(a << case_name));
  EXPECT_TRUE(bool(chars.print(a)));
  EXPECT_EQ(case_name, chars.c_str());
}

TEST_F(char_array, print_self)
{
  EXPECT_TRUE(bool(chars << case_name));
  EXPECT_TRUE(bool(chars.print(chars)));
  EXPECT_EQ(case_name + case_name, chars.c_str());
}

TEST_F(char_array, print_user_defined_type)
{
  user_defined_t t;
  EXPECT_TRUE(bool(chars.print(t)));
  EXPECT_EQ(user_defined_t::name(), chars.c_str());
}

TEST_F(char_array, to_string)
{
  ASSERT_TRUE(bool(chars << case_name));
  EXPECT_TRUE(chars.good());
  EXPECT_EQ(case_name, chars.to_string());
}

TEST_F(char_array, to_string_empty)
{
  ASSERT_TRUE(chars.good());
  EXPECT_EQ("", chars.to_string());
}

TEST_F(char_array, to_string_full)
{
  ASSERT_TRUE(bool(chars << exact));
  EXPECT_TRUE(chars.good());
  EXPECT_TRUE(chars.full());
  EXPECT_EQ(exact, chars.to_string());
}

TEST_F(char_array, to_string_view)
{
  ASSERT_TRUE(bool(chars << case_name));
  EXPECT_TRUE(chars.good());
  EXPECT_EQ(case_name, chars.to_string_view());
}

TEST_F(char_array, to_string_view_empty)
{
  ASSERT_TRUE(chars.good());
  EXPECT_EQ("", chars.to_string_view());
}

TEST_F(char_array, to_string_view_full)
{
  ASSERT_TRUE(bool(chars << exact));
  EXPECT_TRUE(chars.good());
  EXPECT_TRUE(chars.full());
  EXPECT_EQ(exact, chars.to_string_view());
}

} // namespace
<|endoftext|>


<commit_before>#include <cmath>
#include <limits>

#include "numgrid.h"
#include "AtomGrid.h"
#include "becke_partitioning.h"
#include "bragg.h"
#include "error_handling.h"
#include "grid_radial.h"
#include "lebedev/sphere_lebedev_rule.h"
#include "parameters.h"

#define AS_TYPE(Type, Obj) reinterpret_cast<Type *>(Obj)
#define AS_CTYPE(Type, Obj) reinterpret_cast<const Type *>(Obj)

int lebedev_table[33] = {6,    14,   26,   38,   50,   74,   86,   110,
                         146,  170,  194,  230,  266,  302,  350,  434,
                         590,  770,  974,  1202, 1454, 1730, 2030, 2354,
                         2702, 3074, 3470, 3890, 4334, 4802, 5294, 5810};

int get_closest_num_angular(int n)
{
    int m;

    for (int i = 0; i < MAX_ANGULAR_ORDER; i++)
    {
        m = lebedev_table[i];
        if (m >= n)
            return m;
    }

    NUMGRID_ERROR("Input n too high in get_closest_num_angular");
}

int get_angular_order(int n)
{
    for (int i = 0; i < MAX_ANGULAR_ORDER; i++)
    {
        if (lebedev_table[i] == n)
            return i;
    }

    NUMGRID_ERROR("No match found in get_angular_offset");
}

context_t *numgrid_new_atom_grid(const double radial_precision,
                                 const int min_num_angular_points,
                                 const int max_num_angular_points,
                                 const int proton_charge,
                                 const double alpha_max,
                                 const int max_l_quantum_number,
                                 const double alpha_min[])
{
    return AS_TYPE(context_t,
                   new AtomGrid(radial_precision,
                                min_num_angular_points,
                                max_num_angular_points,
                                proton_charge,
                                alpha_max,
                                max_l_quantum_number,
                                alpha_min));
}
AtomGrid::AtomGrid(const double radial_precision,
                   const int min_num_angular_points,
                   const int max_num_angular_points,
                   const int proton_charge,
                   const double alpha_max,
                   const int max_l_quantum_number,
                   const double alpha_min[])
{
    int min_num_angular_points_closest =
        get_closest_num_angular(min_num_angular_points);
    int max_num_angular_points_closest =
        get_closest_num_angular(max_num_angular_points);

    double *angular_x = new double[MAX_ANGULAR_ORDER * MAX_ANGULAR_GRID];
    double *angular_y = new double[MAX_ANGULAR_ORDER * MAX_ANGULAR_GRID];
    double *angular_z = new double[MAX_ANGULAR_ORDER * MAX_ANGULAR_GRID];
    double *angular_w = new double[MAX_ANGULAR_ORDER * MAX_ANGULAR_GRID];

    for (int i = get_angular_order(min_num_angular_points_closest);
         i <= get_angular_order(max_num_angular_points_closest);
         i++)
    {
        int angular_off = i * MAX_ANGULAR_GRID;
        ld_by_order(lebedev_table[i],
                    &angular_x[angular_off],
                    &angular_y[angular_off],
                    &angular_z[angular_off],
                    &angular_w[angular_off]);
    }

    // obtain radial parameters
    double r_inner = get_r_inner(radial_precision,
                                 alpha_max * 2.0); // factor 2.0 to match DIRAC
    double h = std::numeric_limits<float>::max();
    double r_outer = 0.0;
    for (int l = 0; l <= max_l_quantum_number; l++)
    {
        if (alpha_min[l] > 0.0)
        {
            r_outer =
                std::max(r_outer,
                         get_r_outer(radial_precision,
                                     alpha_min[l],
                                     l,
                                     4.0 * get_bragg_angstrom(proton_charge)));
            NUMGRID_ASSERT(r_outer > r_inner);
            h = std::min(h,
                         get_h(radial_precision, l, 0.1 * (r_outer - r_inner)));
        }
    }
    NUMGRID_ASSERT(r_outer > h);

    num_grid_points = 0;
    num_radial_grid_points = 0;

    double rb = get_bragg_angstrom(proton_charge) /
                (5.0 * 0.529177249); // factors match DIRAC code
    double c = r_inner / (exp(h) - 1.0);
    int num_radial = int(log(1.0 + (r_outer / c)) / h);
    for (int irad = 0; irad < num_radial; irad++)
    {
        double radial_r = c * (exp((irad + 1) * h) - 1.0);
        double radial_w = (radial_r + c) * radial_r * radial_r * h;

        radial_atom_grid_r_au.push_back(radial_r);
        radial_atom_grid_w.push_back(radial_w);
        num_radial_grid_points++;

        int num_angular = max_num_angular_points_closest;
        if (radial_r < rb)
        {
            num_angular = static_cast<int>(max_num_angular_points_closest *
                                           (radial_r / rb));
            num_angular = get_closest_num_angular(num_angular);
            if (num_angular < min_num_angular_points_closest)
                num_angular = min_num_angular_points_closest;
        }

        int angular_off = get_angular_order(num_angular) * MAX_ANGULAR_GRID;

        for (int iang = 0; iang < num_angular; iang++)
        {
            atom_grid_x_au.push_back(angular_x[angular_off + iang] * radial_r);
            atom_grid_y_au.push_back(angular_y[angular_off + iang] * radial_r);
            atom_grid_z_au.push_back(angular_z[angular_off + iang] * radial_r);

            atom_grid_w.push_back(4.0 * M_PI * angular_w[angular_off + iang] *
                                  radial_w);

            num_grid_points++;
        }
    }

    delete[] angular_x;
    delete[] angular_y;
    delete[] angular_z;
    delete[] angular_w;
}

void numgrid_free_atom_grid(context_t *context)
{
    if (!context)
        return;
    delete AS_TYPE(AtomGrid, context);
}
AtomGrid::~AtomGrid()
{
    atom_grid_x_au.clear();
    atom_grid_y_au.clear();
    atom_grid_z_au.clear();
    atom_grid_w.clear();

    radial_atom_grid_r_au.clear();
    radial_atom_grid_w.clear();
}

int numgrid_get_num_grid_points(const context_t *context)
{
    return AS_CTYPE(AtomGrid, context)->get_num_grid_points();
}
int AtomGrid::get_num_grid_points() const { return num_grid_points; }

int numgrid_get_num_radial_grid_points(const context_t *context)
{
    return AS_CTYPE(AtomGrid, context)->get_num_radial_grid_points();
}
int AtomGrid::get_num_radial_grid_points() const
{
    return num_radial_grid_points;
}

void numgrid_get_grid(const context_t *context,
                      const int num_centers,
                      const int center_index,
                      const double x_coordinates_au[],
                      const double y_coordinates_au[],
                      const double z_coordinates_au[],
                      const int proton_charges[],
                      double grid_x_au[],
                      double grid_y_au[],
                      double grid_z_au[],
                      double grid_w[])
{
    return AS_CTYPE(AtomGrid, context)
        ->get_grid(num_centers,
                   center_index,
                   x_coordinates_au,
                   y_coordinates_au,
                   z_coordinates_au,
                   proton_charges,
                   grid_x_au,
                   grid_y_au,
                   grid_z_au,
                   grid_w);
}
void AtomGrid::get_grid(const int num_centers,
                        const int center_index,
                        const double x_coordinates_au[],
                        const double y_coordinates_au[],
                        const double z_coordinates_au[],
                        const int proton_charges[],
                        double grid_x_au[],
                        double grid_y_au[],
                        double grid_z_au[],
                        double grid_w[]) const
{
    for (int ipoint = 0; ipoint < num_grid_points; ipoint++)
    {
        grid_x_au[ipoint] =
            atom_grid_x_au[ipoint] + x_coordinates_au[center_index];
        grid_y_au[ipoint] =
            atom_grid_y_au[ipoint] + y_coordinates_au[center_index];
        grid_z_au[ipoint] =
            atom_grid_z_au[ipoint] + z_coordinates_au[center_index];

        double becke_w = 1.0;

        // if there are no other centers
        // no point in partitioning the space
        if (num_centers > 1)
        {
            becke_w = get_becke_w(num_centers,
                                  proton_charges,
                                  x_coordinates_au,
                                  y_coordinates_au,
                                  z_coordinates_au,
                                  center_index,
                                  grid_x_au[ipoint],
                                  grid_y_au[ipoint],
                                  grid_z_au[ipoint]);
        }

        grid_w[ipoint] = atom_grid_w[ipoint] * becke_w;
    }
}

void numgrid_get_radial_grid(const context_t *context,
                             double grid_r_au[],
                             double grid_w[])
{
    return AS_CTYPE(AtomGrid, context)
        ->get_radial_grid(grid_r_au, grid_w);
}
void AtomGrid::get_radial_grid(double grid_r_au[], double grid_w[]) const
{
    for (int ipoint = 0; ipoint < num_radial_grid_points; ipoint++)
    {
        grid_r_au[ipoint] = radial_atom_grid_r_au[ipoint];
        grid_w[ipoint] = radial_atom_grid_w[ipoint];
    }
}

// TODO this implementation should move to separate file
void numgrid_get_angular_grid(const int num_angular_grid_points,
                              double grid_x_au[],
                              double grid_y_au[],
                              double grid_z_au[],
                              double grid_w[])
{
    int i = get_angular_order(num_angular_grid_points);
    ld_by_order(lebedev_table[i], grid_x_au, grid_y_au, grid_z_au, grid_w);
}
<commit_msg>more idiomatic for loop<commit_after>#include <cmath>
#include <limits>

#include "numgrid.h"
#include "AtomGrid.h"
#include "becke_partitioning.h"
#include "bragg.h"
#include "error_handling.h"
#include "grid_radial.h"
#include "lebedev/sphere_lebedev_rule.h"
#include "parameters.h"

#define AS_TYPE(Type, Obj) reinterpret_cast<Type *>(Obj)
#define AS_CTYPE(Type, Obj) reinterpret_cast<const Type *>(Obj)

int lebedev_table[33] = {6,    14,   26,   38,   50,   74,   86,   110,
                         146,  170,  194,  230,  266,  302,  350,  434,
                         590,  770,  974,  1202, 1454, 1730, 2030, 2354,
                         2702, 3074, 3470, 3890, 4334, 4802, 5294, 5810};

int get_closest_num_angular(int n)
{
    int m;

    for (int i = 0; i < MAX_ANGULAR_ORDER; i++)
    {
        m = lebedev_table[i];
        if (m >= n)
            return m;
    }

    NUMGRID_ERROR("Input n too high in get_closest_num_angular");
}

int get_angular_order(int n)
{
    for (int i = 0; i < MAX_ANGULAR_ORDER; i++)
    {
        if (lebedev_table[i] == n)
            return i;
    }

    NUMGRID_ERROR("No match found in get_angular_offset");
}

context_t *numgrid_new_atom_grid(const double radial_precision,
                                 const int min_num_angular_points,
                                 const int max_num_angular_points,
                                 const int proton_charge,
                                 const double alpha_max,
                                 const int max_l_quantum_number,
                                 const double alpha_min[])
{
    return AS_TYPE(context_t,
                   new AtomGrid(radial_precision,
                                min_num_angular_points,
                                max_num_angular_points,
                                proton_charge,
                                alpha_max,
                                max_l_quantum_number,
                                alpha_min));
}
AtomGrid::AtomGrid(const double radial_precision,
                   const int min_num_angular_points,
                   const int max_num_angular_points,
                   const int proton_charge,
                   const double alpha_max,
                   const int max_l_quantum_number,
                   const double alpha_min[])
{
    int min_num_angular_points_closest =
        get_closest_num_angular(min_num_angular_points);
    int max_num_angular_points_closest =
        get_closest_num_angular(max_num_angular_points);

    double *angular_x = new double[MAX_ANGULAR_ORDER * MAX_ANGULAR_GRID];
    double *angular_y = new double[MAX_ANGULAR_ORDER * MAX_ANGULAR_GRID];
    double *angular_z = new double[MAX_ANGULAR_ORDER * MAX_ANGULAR_GRID];
    double *angular_w = new double[MAX_ANGULAR_ORDER * MAX_ANGULAR_GRID];

    for (int i = get_angular_order(min_num_angular_points_closest);
         i < get_angular_order(max_num_angular_points_closest) + 1;
         ++i)
    {
        int angular_off = i * MAX_ANGULAR_GRID;
        ld_by_order(lebedev_table[i],
                    &angular_x[angular_off],
                    &angular_y[angular_off],
                    &angular_z[angular_off],
                    &angular_w[angular_off]);
    }

    // obtain radial parameters
    double r_inner = get_r_inner(radial_precision,
                                 alpha_max * 2.0); // factor 2.0 to match DIRAC
    double h = std::numeric_limits<float>::max();
    double r_outer = 0.0;
    for (int l = 0; l <= max_l_quantum_number; l++)
    {
        if (alpha_min[l] > 0.0)
        {
            r_outer =
                std::max(r_outer,
                         get_r_outer(radial_precision,
                                     alpha_min[l],
                                     l,
                                     4.0 * get_bragg_angstrom(proton_charge)));
            NUMGRID_ASSERT(r_outer > r_inner);
            h = std::min(h,
                         get_h(radial_precision, l, 0.1 * (r_outer - r_inner)));
        }
    }
    NUMGRID_ASSERT(r_outer > h);

    num_grid_points = 0;
    num_radial_grid_points = 0;

    double rb = get_bragg_angstrom(proton_charge) /
                (5.0 * 0.529177249); // factors match DIRAC code
    double c = r_inner / (exp(h) - 1.0);
    int num_radial = int(log(1.0 + (r_outer / c)) / h);
    for (int irad = 0; irad < num_radial; irad++)
    {
        double radial_r = c * (exp((irad + 1) * h) - 1.0);
        double radial_w = (radial_r + c) * radial_r * radial_r * h;

        radial_atom_grid_r_au.push_back(radial_r);
        radial_atom_grid_w.push_back(radial_w);
        num_radial_grid_points++;

        int num_angular = max_num_angular_points_closest;
        if (radial_r < rb)
        {
            num_angular = static_cast<int>(max_num_angular_points_closest *
                                           (radial_r / rb));
            num_angular = get_closest_num_angular(num_angular);
            if (num_angular < min_num_angular_points_closest)
                num_angular = min_num_angular_points_closest;
        }

        int angular_off = get_angular_order(num_angular) * MAX_ANGULAR_GRID;

        for (int iang = 0; iang < num_angular; iang++)
        {
            atom_grid_x_au.push_back(angular_x[angular_off + iang] * radial_r);
            atom_grid_y_au.push_back(angular_y[angular_off + iang] * radial_r);
            atom_grid_z_au.push_back(angular_z[angular_off + iang] * radial_r);

            atom_grid_w.push_back(4.0 * M_PI * angular_w[angular_off + iang] *
                                  radial_w);

            num_grid_points++;
        }
    }

    delete[] angular_x;
    delete[] angular_y;
    delete[] angular_z;
    delete[] angular_w;
}

void numgrid_free_atom_grid(context_t *context)
{
    if (!context)
        return;
    delete AS_TYPE(AtomGrid, context);
}
AtomGrid::~AtomGrid()
{
    atom_grid_x_au.clear();
    atom_grid_y_au.clear();
    atom_grid_z_au.clear();
    atom_grid_w.clear();

    radial_atom_grid_r_au.clear();
    radial_atom_grid_w.clear();
}

int numgrid_get_num_grid_points(const context_t *context)
{
    return AS_CTYPE(AtomGrid, context)->get_num_grid_points();
}
int AtomGrid::get_num_grid_points() const { return num_grid_points; }

int numgrid_get_num_radial_grid_points(const context_t *context)
{
    return AS_CTYPE(AtomGrid, context)->get_num_radial_grid_points();
}
int AtomGrid::get_num_radial_grid_points() const
{
    return num_radial_grid_points;
}

void numgrid_get_grid(const context_t *context,
                      const int num_centers,
                      const int center_index,
                      const double x_coordinates_au[],
                      const double y_coordinates_au[],
                      const double z_coordinates_au[],
                      const int proton_charges[],
                      double grid_x_au[],
                      double grid_y_au[],
                      double grid_z_au[],
                      double grid_w[])
{
    return AS_CTYPE(AtomGrid, context)
        ->get_grid(num_centers,
                   center_index,
                   x_coordinates_au,
                   y_coordinates_au,
                   z_coordinates_au,
                   proton_charges,
                   grid_x_au,
                   grid_y_au,
                   grid_z_au,
                   grid_w);
}
void AtomGrid::get_grid(const int num_centers,
                        const int center_index,
                        const double x_coordinates_au[],
                        const double y_coordinates_au[],
                        const double z_coordinates_au[],
                        const int proton_charges[],
                        double grid_x_au[],
                        double grid_y_au[],
                        double grid_z_au[],
                        double grid_w[]) const
{
    for (int ipoint = 0; ipoint < num_grid_points; ipoint++)
    {
        grid_x_au[ipoint] =
            atom_grid_x_au[ipoint] + x_coordinates_au[center_index];
        grid_y_au[ipoint] =
            atom_grid_y_au[ipoint] + y_coordinates_au[center_index];
        grid_z_au[ipoint] =
            atom_grid_z_au[ipoint] + z_coordinates_au[center_index];

        double becke_w = 1.0;

        // if there are no other centers
        // no point in partitioning the space
        if (num_centers > 1)
        {
            becke_w = get_becke_w(num_centers,
                                  proton_charges,
                                  x_coordinates_au,
                                  y_coordinates_au,
                                  z_coordinates_au,
                                  center_index,
                                  grid_x_au[ipoint],
                                  grid_y_au[ipoint],
                                  grid_z_au[ipoint]);
        }

        grid_w[ipoint] = atom_grid_w[ipoint] * becke_w;
    }
}

void numgrid_get_radial_grid(const context_t *context,
                             double grid_r_au[],
                             double grid_w[])
{
    return AS_CTYPE(AtomGrid, context)
        ->get_radial_grid(grid_r_au, grid_w);
}
void AtomGrid::get_radial_grid(double grid_r_au[], double grid_w[]) const
{
    for (int ipoint = 0; ipoint < num_radial_grid_points; ipoint++)
    {
        grid_r_au[ipoint] = radial_atom_grid_r_au[ipoint];
        grid_w[ipoint] = radial_atom_grid_w[ipoint];
    }
}

// TODO this implementation should move to separate file
void numgrid_get_angular_grid(const int num_angular_grid_points,
                              double grid_x_au[],
                              double grid_y_au[],
                              double grid_z_au[],
                              double grid_w[])
{
    int i = get_angular_order(num_angular_grid_points);
    ld_by_order(lebedev_table[i], grid_x_au, grid_y_au, grid_z_au, grid_w);
}
<|endoftext|>


<commit_before>// $Id$
// Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007

/**************************************************************************
 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for          *
 * full copyright notice.                                                 *
 **************************************************************************/
#ifndef __CINT__

#include <TEveManager.h>
#include <TEveQuadSet.h>
#include <TGeoNode.h>
#include <TGeoBBox.h>
#include <TGeoManager.h>
#include <TStyle.h>
#include <TEveTrans.h>
#include <TClonesArray.h>

#include <EveBase/AliEveEventManager.h>

#include <AliRunLoader.h>
#include <AliCluster.h>
#include <EMCAL/AliEMCALGeometry.h>
#include <EMCAL/AliEMCALDigit.h>

#include <iostream>
#endif

void emcal_digits()
{
  AliRunLoader* rl =  AliEveEventManager::AssertRunLoader();

  rl->LoadDigits("EMCAL");
  TTree* dt = rl->GetTreeD("EMCAL", kFALSE);
  if (!dt) return;

  AliEveEventManager::AssertGeometry();

  TGeoNode* node = gGeoManager->GetTopVolume()->FindNode("XEN1_1");

  TGeoBBox* bbbox = (TGeoBBox*) node->GetDaughter(0) ->GetVolume()->GetShape();
  TGeoBBox* sbbox = (TGeoBBox*) node->GetDaughter(10)->GetVolume()->GetShape();

  TEveElementList* l = new TEveElementList("EMCAL");
  l->SetTitle("Tooltip");
  gEve->AddElement(l);

  TEveFrameBox* frame_big = new TEveFrameBox();
  frame_big->SetFrameColorRGBA(200,200,0,50);
  frame_big->SetAABoxCenterHalfSize(0, 0, 0, bbbox->GetDX(), bbbox->GetDY(), bbbox->GetDZ());

  TEveFrameBox* frame_sml = new TEveFrameBox();
  frame_sml->SetFrameColorRGBA(200,200,0,50);
  frame_sml->SetAABoxCenterHalfSize(0, 0, 0, sbbox->GetDX(), sbbox->GetDY(), sbbox->GetDZ());

  gStyle->SetPalette(1, 0);
  TEveRGBAPalette* pal = new TEveRGBAPalette(0, 512);
  pal->SetLimits(0, 1024);

  TEveQuadSet* smodules[12];

  AliEMCALGeometry * geom  = AliEMCALGeometry::GetInstance();
  if (!geom) geom = AliEMCALGeometry::GetInstance("","");

  for (Int_t sm=0; sm<12; ++sm)
  {
    TEveQuadSet* q = new TEveQuadSet(Form("SM %d", sm+1));
    q->SetOwnIds(kTRUE);
    q->Reset(TEveQuadSet::kQT_RectangleYZFixedDimX, kFALSE, 32);
    q->SetDefWidth (geom->GetPhiTileSize());
    q->SetDefHeight(geom->GetEtaTileSize());

    q->RefMainTrans().SetFrom(*node->GetDaughter(sm)->GetMatrix());

    q->SetFrame(sm < 10 ? frame_big : frame_sml);
    q->SetPalette(pal);

    gEve->AddElement(q, l);
    smodules[sm] = q;
  }

  TClonesArray *digits = 0;
  dt->SetBranchAddress("EMCAL", &digits);
  dt->GetEntry(0);
  Int_t nEnt = digits->GetEntriesFast();
  AliEMCALDigit * dig;

  Float_t amp   = -1 ;
  Float_t time  = -1 ;
  Int_t id      = -1 ;
  Int_t iSupMod =  0 ;
  Int_t iTower  =  0 ;
  Int_t iIphi   =  0 ;
  Int_t iIeta   =  0 ;
  Int_t iphi    =  0 ;
  Int_t ieta    =  0 ;
  Double_t x, y, z;

  for (Int_t idig = 0; idig < nEnt; ++idig)
  {
    dig = static_cast<AliEMCALDigit *>(digits->At(idig));

    if(dig != 0) {
      id   = dig->GetId() ; //cell (digit) label
      amp  = dig->GetAmp(); //amplitude in cell (digit)
      time = dig->GetTime();//time of creation of digit after collision

      std::cout<<"Cell ID "<<id<<" Amp "<<amp<<std::endl;//" time "<<time<<endl;

      //Geometry methods
      geom->GetCellIndex(id,iSupMod,iTower,iIphi,iIeta);
      //Gives SuperModule and Tower numbers
      geom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,
					iIphi, iIeta,iphi,ieta);
      //Gives label of cell in eta-phi position per each supermodule

      std::cout<< "SModule "<<iSupMod<<"; Tower "<<iTower
	  <<"; Eta "<<iIeta<<"; Phi "<<iIphi
	  <<"; Cell Eta "<<ieta<<"; Cell Phi "<<iphi<<std::endl;

      geom->RelPosCellInSModule(id, x, y, z);
      std::cout << x <<" "<< y <<" "<< z <<std::endl;

      TEveQuadSet* q = smodules[iSupMod];
      q->AddQuad(y, z);
      q->QuadValue(TMath::Nint(amp));
      q->QuadId(new AliEMCALDigit(*dig));
    } else {
      std::cout<<"Digit pointer 0x0"<<std::endl;
    }
  }

  rl->UnloadDigits("EMCAL");

  for (Int_t sm = 0; sm < 12; ++sm)
  {
    smodules[iSupMod]->RefitPlex();
  }

  gEve->Redraw3D();
}
<commit_msg>Add example of how to assign lines to a module.<commit_after>// $Id$
// Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007

/**************************************************************************
 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for          *
 * full copyright notice.                                                 *
 **************************************************************************/
#ifndef __CINT__

#include <TEveManager.h>
#include <TEveQuadSet.h>
#include <TGeoNode.h>
#include <TGeoBBox.h>
#include <TGeoManager.h>
#include <TStyle.h>
#include <TEveTrans.h>
#include <TClonesArray.h>

#include <EveBase/AliEveEventManager.h>

#include <AliRunLoader.h>
#include <AliCluster.h>
#include <EMCAL/AliEMCALGeometry.h>
#include <EMCAL/AliEMCALDigit.h>

#include <iostream>
#endif

void emcal_digits()
{
  AliRunLoader* rl =  AliEveEventManager::AssertRunLoader();

  rl->LoadDigits("EMCAL");
  TTree* dt = rl->GetTreeD("EMCAL", kFALSE);
  if (!dt) return;

  AliEveEventManager::AssertGeometry();

  TGeoNode* node = gGeoManager->GetTopVolume()->FindNode("XEN1_1");

  TGeoBBox* bbbox = (TGeoBBox*) node->GetDaughter(0) ->GetVolume()->GetShape();
  TGeoBBox* sbbox = (TGeoBBox*) node->GetDaughter(10)->GetVolume()->GetShape();

  TEveElementList* l = new TEveElementList("EMCAL");
  l->SetTitle("Tooltip");
  gEve->AddElement(l);

  TEveFrameBox* frame_big = new TEveFrameBox();
  frame_big->SetFrameColorRGBA(200,200,0,50);
  frame_big->SetAABoxCenterHalfSize(0, 0, 0, bbbox->GetDX(), bbbox->GetDY(), bbbox->GetDZ());

  TEveFrameBox* frame_sml = new TEveFrameBox();
  frame_sml->SetFrameColorRGBA(200,200,0,50);
  frame_sml->SetAABoxCenterHalfSize(0, 0, 0, sbbox->GetDX(), sbbox->GetDY(), sbbox->GetDZ());

  gStyle->SetPalette(1, 0);
  TEveRGBAPalette* pal = new TEveRGBAPalette(0, 512);
  pal->SetLimits(0, 1024);

  TEveQuadSet* smodules[12];

  AliEMCALGeometry * geom  = AliEMCALGeometry::GetInstance();
  if (!geom) geom = AliEMCALGeometry::GetInstance("","");

  for (Int_t sm=0; sm<12; ++sm)
  {
    TEveQuadSet* q = new TEveQuadSet(Form("SM %d", sm+1));
    q->SetOwnIds(kTRUE);
    q->Reset(TEveQuadSet::kQT_RectangleYZFixedDimX, kFALSE, 32);
    q->SetDefWidth (geom->GetPhiTileSize());
    q->SetDefHeight(geom->GetEtaTileSize());

    q->RefMainTrans().SetFrom(*node->GetDaughter(sm)->GetMatrix());

    q->SetFrame(sm < 10 ? frame_big : frame_sml);
    q->SetPalette(pal);

    gEve->AddElement(q, l);
    smodules[sm] = q;

    // Add line
    /*
    TEveLine *ll = new TEveLine("Test");
    ll->SetMainColor(kRed);
    ll->SetLineWidth(2);

    ll->SetNextPoint(0, -20, -20);
    ll->SetNextPoint(0,  20, -20);
    ll->SetNextPoint(0,  20,  20);
    ll->SetNextPoint(0, -20,  20);
    ll->SetNextPoint(0, -20, -20);
    ll->RefMainTrans() = q->RefMainTrans();

    q->AddElement(ll);
    */
  }

  TClonesArray *digits = 0;
  dt->SetBranchAddress("EMCAL", &digits);
  dt->GetEntry(0);
  Int_t nEnt = digits->GetEntriesFast();
  AliEMCALDigit * dig;

  Float_t amp   = -1 ;
  Float_t time  = -1 ;
  Int_t id      = -1 ;
  Int_t iSupMod =  0 ;
  Int_t iTower  =  0 ;
  Int_t iIphi   =  0 ;
  Int_t iIeta   =  0 ;
  Int_t iphi    =  0 ;
  Int_t ieta    =  0 ;
  Double_t x, y, z;

  for (Int_t idig = 0; idig < nEnt; ++idig)
  {
    dig = static_cast<AliEMCALDigit *>(digits->At(idig));

    if(dig != 0) {
      id   = dig->GetId() ; //cell (digit) label
      amp  = dig->GetAmp(); //amplitude in cell (digit)
      time = dig->GetTime();//time of creation of digit after collision

      std::cout<<"Cell ID "<<id<<" Amp "<<amp<<std::endl;//" time "<<time<<endl;

      //Geometry methods
      geom->GetCellIndex(id,iSupMod,iTower,iIphi,iIeta);
      //Gives SuperModule and Tower numbers
      geom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,
					iIphi, iIeta,iphi,ieta);
      //Gives label of cell in eta-phi position per each supermodule

      std::cout<< "SModule "<<iSupMod<<"; Tower "<<iTower
	  <<"; Eta "<<iIeta<<"; Phi "<<iIphi
	  <<"; Cell Eta "<<ieta<<"; Cell Phi "<<iphi<<std::endl;

      geom->RelPosCellInSModule(id, x, y, z);
      std::cout << x <<" "<< y <<" "<< z <<std::endl;

      TEveQuadSet* q = smodules[iSupMod];
      q->AddQuad(y, z);
      q->QuadValue(TMath::Nint(amp));
      q->QuadId(new AliEMCALDigit(*dig));
    } else {
      std::cout<<"Digit pointer 0x0"<<std::endl;
    }
  }

  rl->UnloadDigits("EMCAL");

  for (Int_t sm = 0; sm < 12; ++sm)
  {
    smodules[iSupMod]->RefitPlex();
  }

  gEve->Redraw3D();
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: VertSplitView.cxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-17 07:01:04 $
 *
 *  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
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_dbaccess.hxx"
#ifndef DBAUI_VERTSPLITVIEW_HXX
#include "VertSplitView.hxx"
#endif

#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif

#define SPLITTER_WIDTH  80

using namespace ::dbaui;

//==================================================================
// class OSplitterView
//==================================================================
DBG_NAME(OSplitterView)
OSplitterView::OSplitterView(Window* _pParent,sal_Bool _bVertical) : Window(_pParent,WB_DIALOGCONTROL) // ,WB_BORDER
    ,m_pSplitter( NULL )
    ,m_pLeft(NULL)
    ,m_pRight(NULL)
    ,m_bVertical(_bVertical)
{
    DBG_CTOR(OSplitterView,NULL);
    ImplInitSettings( sal_True, sal_True, sal_True );
}
// -----------------------------------------------------------------------------
OSplitterView::~OSplitterView()
{
    DBG_DTOR(OSplitterView,NULL);
    m_pRight = m_pLeft = NULL;
}
//------------------------------------------------------------------------------
IMPL_LINK( OSplitterView, SplitHdl, Splitter*, /*pSplit*/ )
{
    OSL_ENSURE(m_pSplitter, "Splitter is NULL!");
    if ( m_bVertical )
    {
        long nPosY = m_pSplitter->GetPosPixel().Y();
        m_pSplitter->SetPosPixel( Point( m_pSplitter->GetSplitPosPixel(), nPosY ) );
    }
    else
        m_pSplitter->SetPosPixel( Point( m_pSplitter->GetPosPixel().X(),m_pSplitter->GetSplitPosPixel() ) );

    Resize();
    return 0L;
}
// -----------------------------------------------------------------------------
void OSplitterView::ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground )
{
    const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();

    if ( bFont )
    {
        Font aFont = rStyleSettings.GetAppFont();
        if ( IsControlFont() )
            aFont.Merge( GetControlFont() );
        SetPointFont( aFont );
//      Set/*Zoomed*/PointFont( aFont );
    }

    if ( bFont || bForeground )
    {
        Color aTextColor = rStyleSettings.GetButtonTextColor();
        if ( IsControlForeground() )
            aTextColor = GetControlForeground();
        SetTextColor( aTextColor );
    }

    if ( bBackground )
    {
        if( IsControlBackground() )
            SetBackground( GetControlBackground() );
        else
            SetBackground( rStyleSettings.GetFaceColor() );
    }
}
// -----------------------------------------------------------------------
void OSplitterView::DataChanged( const DataChangedEvent& rDCEvt )
{
    Window::DataChanged( rDCEvt );

    if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
         (rDCEvt.GetFlags() & SETTINGS_STYLE) )
    {
        ImplInitSettings( sal_True, sal_True, sal_True );
        Invalidate();
    }
}
// -----------------------------------------------------------------------------
void OSplitterView::GetFocus()
{
    Window::GetFocus();

    // forward the focus to the current cell of the editor control
    if ( m_pLeft )
        m_pLeft->GrabFocus();
    else if ( m_pRight )
        m_pRight->GrabFocus();
}

// -------------------------------------------------------------------------
void OSplitterView::Resize()
{
    Window::Resize();
    OSL_ENSURE( m_pRight, "No init called!");

    Point   aSplitPos;
    Size    aSplitSize;
    Point   aPlaygroundPos( 0,0 );
    Size    aPlaygroundSize( GetOutputSizePixel() );

    if ( m_pLeft && m_pLeft->IsVisible() && m_pSplitter )
    {
        aSplitPos   = m_pSplitter->GetPosPixel();
        aSplitSize  = m_pSplitter->GetOutputSizePixel();
        if ( m_bVertical )
        {
            // calculate the splitter pos and size
            aSplitPos.Y() = aPlaygroundPos.Y();
            aSplitSize.Height() = aPlaygroundSize.Height();

            if( ( aSplitPos.X() + aSplitSize.Width() ) > ( aPlaygroundSize.Width() ))
                aSplitPos.X() = aPlaygroundSize.Width() - aSplitSize.Width();

            if( aSplitPos.X() <= aPlaygroundPos.X() )
                aSplitPos.X() = aPlaygroundPos.X() + sal_Int32(aPlaygroundSize.Width() * 0.3);

            // the tree pos and size
            Point   aTreeViewPos( aPlaygroundPos );
            Size    aTreeViewSize( aSplitPos.X(), aPlaygroundSize.Height() );

            // set the size of treelistbox
            m_pLeft->SetPosSizePixel( aTreeViewPos, aTreeViewSize );

            //set the size of the splitter
            m_pSplitter->SetPosSizePixel( aSplitPos, Size( aSplitSize.Width(), aPlaygroundSize.Height() ) );
            m_pSplitter->SetDragRectPixel( Rectangle(aPlaygroundPos,aPlaygroundSize) );
        }
        else
        {
            aSplitPos.X() = aPlaygroundPos.X();
            aSplitSize.Width() = aPlaygroundSize.Width();

            if( ( aSplitPos.Y() + aSplitSize.Height() ) > ( aPlaygroundSize.Height() ))
                aSplitPos.Y() = aPlaygroundSize.Height() - aSplitSize.Height();

            if( aSplitPos.Y() <= aPlaygroundPos.Y() )
                aSplitPos.Y() = aPlaygroundPos.Y() + sal_Int32(aPlaygroundSize.Height() * 0.3);

            // the tree pos and size
            Point   aTreeViewPos( aPlaygroundPos );
            Size    aTreeViewSize( aPlaygroundSize.Width() ,aSplitPos.Y());

            // set the size of treelistbox
            m_pLeft->SetPosSizePixel( aTreeViewPos, aTreeViewSize );

            //set the size of the splitter
            m_pSplitter->SetPosSizePixel( aSplitPos, Size( aPlaygroundSize.Width(), aSplitSize.Height() ) );
            m_pSplitter->SetDragRectPixel( Rectangle(aPlaygroundPos,aPlaygroundSize) );
        }
    }

    if ( m_pRight )
    {
        if ( m_bVertical )
            m_pRight->SetPosSizePixel( aSplitPos.X() + aSplitSize.Width(), aPlaygroundPos.Y(),
                                   aPlaygroundSize.Width() - aSplitSize.Width() - aSplitPos.X(), aPlaygroundSize.Height());
        else
            m_pRight->SetPosSizePixel( aSplitPos.X(), aPlaygroundPos.Y() + aSplitPos.Y() + aSplitSize.Height(),
                                   aPlaygroundSize.Width() , aPlaygroundSize.Height() - aSplitSize.Height() - aSplitPos.Y());
    }

}
// -----------------------------------------------------------------------------
void OSplitterView::set(Window* _pRight,Window* _pLeft)
{
    m_pLeft = _pLeft;
    m_pRight = _pRight;
}
// -----------------------------------------------------------------------------
void OSplitterView::setSplitter(Splitter* _pSplitter)
{
    m_pSplitter = _pSplitter;
    if ( m_pSplitter )
    {
        m_pSplitter->SetSplitPosPixel( LogicToPixel( Size( SPLITTER_WIDTH, 0 ), MAP_APPFONT ).Width() );
        m_pSplitter->SetSplitHdl( LINK(this, OSplitterView, SplitHdl) );
        m_pSplitter->Show();
        LINK( this, OSplitterView, SplitHdl ).Call(m_pSplitter);
    }
}
<commit_msg>INTEGRATION: CWS changefileheader (1.6.258); FILE MERGED 2008/03/31 13:27:10 rt 1.6.258.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: VertSplitView.cxx,v $
 * $Revision: 1.7 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org 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 version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_dbaccess.hxx"
#ifndef DBAUI_VERTSPLITVIEW_HXX
#include "VertSplitView.hxx"
#endif

#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif

#define SPLITTER_WIDTH  80

using namespace ::dbaui;

//==================================================================
// class OSplitterView
//==================================================================
DBG_NAME(OSplitterView)
OSplitterView::OSplitterView(Window* _pParent,sal_Bool _bVertical) : Window(_pParent,WB_DIALOGCONTROL) // ,WB_BORDER
    ,m_pSplitter( NULL )
    ,m_pLeft(NULL)
    ,m_pRight(NULL)
    ,m_bVertical(_bVertical)
{
    DBG_CTOR(OSplitterView,NULL);
    ImplInitSettings( sal_True, sal_True, sal_True );
}
// -----------------------------------------------------------------------------
OSplitterView::~OSplitterView()
{
    DBG_DTOR(OSplitterView,NULL);
    m_pRight = m_pLeft = NULL;
}
//------------------------------------------------------------------------------
IMPL_LINK( OSplitterView, SplitHdl, Splitter*, /*pSplit*/ )
{
    OSL_ENSURE(m_pSplitter, "Splitter is NULL!");
    if ( m_bVertical )
    {
        long nPosY = m_pSplitter->GetPosPixel().Y();
        m_pSplitter->SetPosPixel( Point( m_pSplitter->GetSplitPosPixel(), nPosY ) );
    }
    else
        m_pSplitter->SetPosPixel( Point( m_pSplitter->GetPosPixel().X(),m_pSplitter->GetSplitPosPixel() ) );

    Resize();
    return 0L;
}
// -----------------------------------------------------------------------------
void OSplitterView::ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground )
{
    const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();

    if ( bFont )
    {
        Font aFont = rStyleSettings.GetAppFont();
        if ( IsControlFont() )
            aFont.Merge( GetControlFont() );
        SetPointFont( aFont );
//      Set/*Zoomed*/PointFont( aFont );
    }

    if ( bFont || bForeground )
    {
        Color aTextColor = rStyleSettings.GetButtonTextColor();
        if ( IsControlForeground() )
            aTextColor = GetControlForeground();
        SetTextColor( aTextColor );
    }

    if ( bBackground )
    {
        if( IsControlBackground() )
            SetBackground( GetControlBackground() );
        else
            SetBackground( rStyleSettings.GetFaceColor() );
    }
}
// -----------------------------------------------------------------------
void OSplitterView::DataChanged( const DataChangedEvent& rDCEvt )
{
    Window::DataChanged( rDCEvt );

    if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
         (rDCEvt.GetFlags() & SETTINGS_STYLE) )
    {
        ImplInitSettings( sal_True, sal_True, sal_True );
        Invalidate();
    }
}
// -----------------------------------------------------------------------------
void OSplitterView::GetFocus()
{
    Window::GetFocus();

    // forward the focus to the current cell of the editor control
    if ( m_pLeft )
        m_pLeft->GrabFocus();
    else if ( m_pRight )
        m_pRight->GrabFocus();
}

// -------------------------------------------------------------------------
void OSplitterView::Resize()
{
    Window::Resize();
    OSL_ENSURE( m_pRight, "No init called!");

    Point   aSplitPos;
    Size    aSplitSize;
    Point   aPlaygroundPos( 0,0 );
    Size    aPlaygroundSize( GetOutputSizePixel() );

    if ( m_pLeft && m_pLeft->IsVisible() && m_pSplitter )
    {
        aSplitPos   = m_pSplitter->GetPosPixel();
        aSplitSize  = m_pSplitter->GetOutputSizePixel();
        if ( m_bVertical )
        {
            // calculate the splitter pos and size
            aSplitPos.Y() = aPlaygroundPos.Y();
            aSplitSize.Height() = aPlaygroundSize.Height();

            if( ( aSplitPos.X() + aSplitSize.Width() ) > ( aPlaygroundSize.Width() ))
                aSplitPos.X() = aPlaygroundSize.Width() - aSplitSize.Width();

            if( aSplitPos.X() <= aPlaygroundPos.X() )
                aSplitPos.X() = aPlaygroundPos.X() + sal_Int32(aPlaygroundSize.Width() * 0.3);

            // the tree pos and size
            Point   aTreeViewPos( aPlaygroundPos );
            Size    aTreeViewSize( aSplitPos.X(), aPlaygroundSize.Height() );

            // set the size of treelistbox
            m_pLeft->SetPosSizePixel( aTreeViewPos, aTreeViewSize );

            //set the size of the splitter
            m_pSplitter->SetPosSizePixel( aSplitPos, Size( aSplitSize.Width(), aPlaygroundSize.Height() ) );
            m_pSplitter->SetDragRectPixel( Rectangle(aPlaygroundPos,aPlaygroundSize) );
        }
        else
        {
            aSplitPos.X() = aPlaygroundPos.X();
            aSplitSize.Width() = aPlaygroundSize.Width();

            if( ( aSplitPos.Y() + aSplitSize.Height() ) > ( aPlaygroundSize.Height() ))
                aSplitPos.Y() = aPlaygroundSize.Height() - aSplitSize.Height();

            if( aSplitPos.Y() <= aPlaygroundPos.Y() )
                aSplitPos.Y() = aPlaygroundPos.Y() + sal_Int32(aPlaygroundSize.Height() * 0.3);

            // the tree pos and size
            Point   aTreeViewPos( aPlaygroundPos );
            Size    aTreeViewSize( aPlaygroundSize.Width() ,aSplitPos.Y());

            // set the size of treelistbox
            m_pLeft->SetPosSizePixel( aTreeViewPos, aTreeViewSize );

            //set the size of the splitter
            m_pSplitter->SetPosSizePixel( aSplitPos, Size( aPlaygroundSize.Width(), aSplitSize.Height() ) );
            m_pSplitter->SetDragRectPixel( Rectangle(aPlaygroundPos,aPlaygroundSize) );
        }
    }

    if ( m_pRight )
    {
        if ( m_bVertical )
            m_pRight->SetPosSizePixel( aSplitPos.X() + aSplitSize.Width(), aPlaygroundPos.Y(),
                                   aPlaygroundSize.Width() - aSplitSize.Width() - aSplitPos.X(), aPlaygroundSize.Height());
        else
            m_pRight->SetPosSizePixel( aSplitPos.X(), aPlaygroundPos.Y() + aSplitPos.Y() + aSplitSize.Height(),
                                   aPlaygroundSize.Width() , aPlaygroundSize.Height() - aSplitSize.Height() - aSplitPos.Y());
    }

}
// -----------------------------------------------------------------------------
void OSplitterView::set(Window* _pRight,Window* _pLeft)
{
    m_pLeft = _pLeft;
    m_pRight = _pRight;
}
// -----------------------------------------------------------------------------
void OSplitterView::setSplitter(Splitter* _pSplitter)
{
    m_pSplitter = _pSplitter;
    if ( m_pSplitter )
    {
        m_pSplitter->SetSplitPosPixel( LogicToPixel( Size( SPLITTER_WIDTH, 0 ), MAP_APPFONT ).Width() );
        m_pSplitter->SetSplitHdl( LINK(this, OSplitterView, SplitHdl) );
        m_pSplitter->Show();
        LINK( this, OSplitterView, SplitHdl ).Call(m_pSplitter);
    }
}
<|endoftext|>


<commit_before>// RUN: %clang_cc1 -emit-llvm %s -o - -cxx-abi microsoft -triple=i386-pc-win32 | FileCheck %s

struct ClassWithoutDtor {
  char x;
};

void check_array_no_cookies() {
// CHECK: define void @"\01?check_array_no_cookies@@YAXXZ"() nounwind

// CHECK: call noalias i8* @"\01??_U@YAPAXI@Z"(i32 42)
  ClassWithoutDtor *array = new ClassWithoutDtor[42];

// CHECK: call void @"\01??_V@YAXPAX@Z"(
  delete [] array;

}

struct ClassWithDtor {
  char x;
  ~ClassWithDtor() {}
};

void check_array_cookies_simple() {
// CHECK: define {{.*}} @"\01?check_array_cookies_simple@@YAXXZ"()

  ClassWithDtor *array = new ClassWithDtor[42];
// CHECK: [[ALLOCATED:%.*]] = call noalias i8* @"\01??_U@YAPAXI@Z"(i32 46)
// 46 = 42 + size of cookie (4)
// CHECK: [[COOKIE:%.*]] = bitcast i8* [[ALLOCATED]] to i32*
// CHECK: store i32 42, i32* [[COOKIE]]
// CHECK: [[ARRAY:%.*]] = getelementptr inbounds i8* [[ALLOCATED]], i{{[0-9]+}} 4
// CHECK: bitcast i8* [[ARRAY]] to %struct.ClassWithDtor*

  delete [] array;
// CHECK: [[ARRAY_AS_CHAR:%.*]] = bitcast %struct.ClassWithDtor* %3 to i8*
// CHECK: getelementptr inbounds i8* [[ARRAY_AS_CHAR]], i{{[0-9]+}} -4
}

struct __attribute__((aligned(8))) ClassWithAlignment {
  // FIXME: replace __attribute__((aligned(8))) with __declspec(align(8)) once
  // http://llvm.org/bugs/show_bug.cgi?id=12631 is fixed.
  int *x, *y;
  ~ClassWithAlignment() {}
};

void check_array_cookies_aligned() {
// CHECK: define {{.*}} @"\01?check_array_cookies_aligned@@YAXXZ"()
  ClassWithAlignment *array = new ClassWithAlignment[42];
// CHECK: [[ALLOCATED:%.*]] = call noalias i8* @"\01??_U@YAPAXI@Z"(i32 344)
//   344 = 42*8 + size of cookie (8, due to aligment)
// CHECK: [[COOKIE:%.*]] = bitcast i8* [[ALLOCATED]] to i32*
// CHECK: store i32 42, i32* [[COOKIE]]
// CHECK: [[ARRAY:%.*]] = getelementptr inbounds i8* [[ALLOCATED]], i{{[0-9]+}} 8
// CHECK: bitcast i8* [[ARRAY]] to %struct.ClassWithAlignment*

  delete [] array;
// CHECK: [[ARRAY_AS_CHAR:%.*]] = bitcast %struct.ClassWithAlignment* %3 to i8*
// CHECK: getelementptr inbounds i8* [[ARRAY_AS_CHAR]], i{{[0-9]+}} -8
}
<commit_msg>Remove some not-very-stable assumptions from this testcase.<commit_after>// RUN: %clang_cc1 -emit-llvm %s -o - -cxx-abi microsoft -triple=i386-pc-win32 | FileCheck %s

struct ClassWithoutDtor {
  char x;
};

void check_array_no_cookies() {
// CHECK: define void @"\01?check_array_no_cookies@@YAXXZ"() nounwind

// CHECK: call noalias i8* @"\01??_U@YAPAXI@Z"(i32 42)
  ClassWithoutDtor *array = new ClassWithoutDtor[42];

// CHECK: call void @"\01??_V@YAXPAX@Z"(
  delete [] array;

}

struct ClassWithDtor {
  char x;
  ~ClassWithDtor() {}
};

void check_array_cookies_simple() {
// CHECK: define {{.*}} @"\01?check_array_cookies_simple@@YAXXZ"()

  ClassWithDtor *array = new ClassWithDtor[42];
// CHECK: [[ALLOCATED:%.*]] = call noalias i8* @"\01??_U@YAPAXI@Z"(i32 46)
// 46 = 42 + size of cookie (4)
// CHECK: [[COOKIE:%.*]] = bitcast i8* [[ALLOCATED]] to i32*
// CHECK: store i32 42, i32* [[COOKIE]]
// CHECK: [[ARRAY:%.*]] = getelementptr inbounds i8* [[ALLOCATED]], i64 4
// CHECK: bitcast i8* [[ARRAY]] to [[CLASS:%.*]]*

  delete [] array;
// CHECK: [[ARRAY_AS_CHAR:%.*]] = bitcast [[CLASS]]* {{%.*}} to i8*
// CHECK: getelementptr inbounds i8* [[ARRAY_AS_CHAR]], i64 -4
}

struct __attribute__((aligned(8))) ClassWithAlignment {
  // FIXME: replace __attribute__((aligned(8))) with __declspec(align(8)) once
  // http://llvm.org/bugs/show_bug.cgi?id=12631 is fixed.
  int *x, *y;
  ~ClassWithAlignment() {}
};

void check_array_cookies_aligned() {
// CHECK: define {{.*}} @"\01?check_array_cookies_aligned@@YAXXZ"()
  ClassWithAlignment *array = new ClassWithAlignment[42];
// CHECK: [[ALLOCATED:%.*]] = call noalias i8* @"\01??_U@YAPAXI@Z"(i32 344)
//   344 = 42*8 + size of cookie (8, due to alignment)
// CHECK: [[COOKIE:%.*]] = bitcast i8* [[ALLOCATED]] to i32*
// CHECK: store i32 42, i32* [[COOKIE]]
// CHECK: [[ARRAY:%.*]] = getelementptr inbounds i8* [[ALLOCATED]], i64 8
// CHECK: bitcast i8* [[ARRAY]] to [[CLASS:%.*]]*

  delete [] array;
// CHECK: [[ARRAY_AS_CHAR:%.*]] = bitcast [[CLASS]]* %3 to i8*
// CHECK: getelementptr inbounds i8* [[ARRAY_AS_CHAR]], i64 -8
}
<|endoftext|>


<commit_before><commit_msg>Re-enable track manager debug draw<commit_after><|endoftext|>


<commit_before>
#include "dw-lr-helper.h"

void exit_input_error(int line_num)
{
  fprintf(stderr,"Wrong input format at line %d\n", line_num);
  exit(1);
}

/**
 * I can make this 10x faster with SIMD. But lets do a slower version first.
 **/
void get_corpus_stats(std::string filename, size_t * n_elements, size_t * n_examples){

  FILE *fp = fopen(filename.c_str(),"r");
  size_t elements, examples;
  char *endptr;
  char *idx, *val, *label;
  ssize_t read;

  if(fp == NULL){
    fprintf(stderr,"can't open input file %s\n",filename.c_str());
    exit(1);
  }

  elements = 0;
  examples = 0;

  size_t max_line_len = 1024;
  char * line = new char[max_line_len];

  while ((read = getline(&line, &max_line_len, fp)) != -1) {

    char *p = strtok(line," \t"); // label

    while(1)
    {
      p = strtok(NULL," \t");
      if(p == NULL || *p == '\n') // check '\n' as ' ' may be after the last feature
        break;
      ++elements;
    }
    ++elements;
    ++examples;
  }

  delete[] line;
  fclose(fp);

  *n_elements = elements;
  *n_examples = examples;

}

/**
 * I can make this 10x faster with SIMD. But lets do a slower version first.
 **/
size_t create_dw_corpus(std::string filename, const size_t n_elements, const size_t n_examples,
  double * & p_examples, long * & p_cols, long * & p_rows){

  p_examples = new double[n_elements];
  p_cols = new long[n_elements];
  p_rows = new long[n_examples];

  FILE *fp = fopen(filename.c_str(),"r");
  ssize_t read;
  size_t max_line_len = 1024;
  char * line = new char[max_line_len];
  char *endptr;
  char *idx, *val, *label;

  double * y = new double[n_examples];

  int input_idx;
  double input_label;
  double input_value;

  if(fp == NULL){
    fprintf(stderr,"can't open input file %s\n",filename.c_str());
    exit(1);
  }

  size_t maxidx = 0;
  int inst_max_index, j=0;
  size_t ct = 0;
  for(int i=0;i<n_examples;i++){
    inst_max_index = -1; // strtol gives 0 if wrong format, and precomputed kernel has <index> start from 0

    read = getline(&line, &max_line_len, fp);

    label = strtok(line," \t\n");
    if(label == NULL) // empty line
      exit_input_error(i+1);

    input_label = strtod(label,&endptr);
    if(endptr == label || *endptr != '\0')
      exit_input_error(i+1);

    p_rows[i] = ct;

    while(1){
      idx = strtok(NULL,":");
      val = strtok(NULL," \t");

      if(val == NULL)
        break;

      errno = 0;
      input_idx = (int) strtol(idx,&endptr,10);
      if(endptr == idx || errno != 0 || *endptr != '\0')
        exit_input_error(i+1);

      errno = 0;
      input_value = strtod(val,&endptr);
      if(endptr == val || errno != 0 || (*endptr != '\0' && !isspace(*endptr)))
        exit_input_error(i+1);

      ++j;

      p_examples[ct] = input_value;
      p_cols[ct] = input_idx;
      ct ++;

      //std::cout << input_idx << std::endl;
      if(input_idx > maxidx){
        maxidx = input_idx;
      }
    }
    p_examples[ct] = (input_label+1)/2; // normalize +1/-1 to 1/0
    p_cols[ct] = -1;
    ct ++;

  }
  maxidx ++;

  return maxidx;
}
<commit_msg>more comments<commit_after>
#include "dw-lr-helper.h"

void exit_input_error(int line_num)
{
  fprintf(stderr,"Wrong input format at line %d\n", line_num);
  exit(1);
}

/**
 * This code is largely borrowed from LIBLINEAR.
 * TODO: This can be made faster with SIMD.
 **/
void get_corpus_stats(std::string filename, size_t * n_elements, size_t * n_examples){

  FILE *fp = fopen(filename.c_str(),"r");
  size_t elements, examples;
  char *endptr;
  char *idx, *val, *label;
  ssize_t read;

  if(fp == NULL){
    fprintf(stderr,"can't open input file %s\n",filename.c_str());
    exit(1);
  }

  elements = 0;
  examples = 0;

  size_t max_line_len = 1024;
  char * line = new char[max_line_len];

  while ((read = getline(&line, &max_line_len, fp)) != -1) {

    char *p = strtok(line," \t"); // label

    while(1)
    {
      p = strtok(NULL," \t");
      if(p == NULL || *p == '\n') // check '\n' as ' ' may be after the last feature
        break;
      ++elements;
    }
    ++elements;
    ++examples;
  }

  delete[] line;
  fclose(fp);

  *n_elements = elements;
  *n_examples = examples;

}

/**
 * This code is largely borrowed from LIBLINEAR.
 * TODO: This can be made faster with SIMD.
 **/
size_t create_dw_corpus(std::string filename, const size_t n_elements, const size_t n_examples,
  double * & p_examples, long * & p_cols, long * & p_rows){

  p_examples = new double[n_elements];
  p_cols = new long[n_elements];
  p_rows = new long[n_examples];

  FILE *fp = fopen(filename.c_str(),"r");
  ssize_t read;
  size_t max_line_len = 1024;
  char * line = new char[max_line_len];
  char *endptr;
  char *idx, *val, *label;

  double * y = new double[n_examples];

  int input_idx;
  double input_label;
  double input_value;

  if(fp == NULL){
    fprintf(stderr,"can't open input file %s\n",filename.c_str());
    exit(1);
  }

  size_t maxidx = 0;
  int inst_max_index, j=0;
  size_t ct = 0;
  for(int i=0;i<n_examples;i++){
    inst_max_index = -1; // strtol gives 0 if wrong format, and precomputed kernel has <index> start from 0

    read = getline(&line, &max_line_len, fp);

    label = strtok(line," \t\n");
    if(label == NULL) // empty line
      exit_input_error(i+1);

    input_label = strtod(label,&endptr);
    if(endptr == label || *endptr != '\0')
      exit_input_error(i+1);

    p_rows[i] = ct;

    while(1){
      idx = strtok(NULL,":");
      val = strtok(NULL," \t");

      if(val == NULL)
        break;

      errno = 0;
      input_idx = (int) strtol(idx,&endptr,10);
      if(endptr == idx || errno != 0 || *endptr != '\0')
        exit_input_error(i+1);

      errno = 0;
      input_value = strtod(val,&endptr);
      if(endptr == val || errno != 0 || (*endptr != '\0' && !isspace(*endptr)))
        exit_input_error(i+1);

      ++j;

      p_examples[ct] = input_value;
      p_cols[ct] = input_idx;
      ct ++;

      //std::cout << input_idx << std::endl;
      if(input_idx > maxidx){
        maxidx = input_idx;
      }
    }
    p_examples[ct] = (input_label+1)/2; // normalize +1/-1 to 1/0
    p_cols[ct] = -1;
    ct ++;

  }
  maxidx ++;

  return maxidx;
}
<|endoftext|>


<commit_before><commit_msg>fix the "array overflow" problem in JSFilter<commit_after><|endoftext|>