<commit_before>//****************************************************************************//
// mesh.cpp                                                                   //
// Copyright (C) 2001, 2002 Bruno 'Beosil' Heidelberger                       //
//****************************************************************************//
// This library is free software; you can redistribute it and/or modify it    //
// under the terms of the GNU Lesser General Public License as published by   //
// the Free Software Foundation; either version 2.1 of the License, or (at    //
// your option) any later version.                                            //
//****************************************************************************//

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "cal3d/mesh.h"
#include "cal3d/error.h"
#include "cal3d/coremesh.h"
#include "cal3d/coresubmesh.h"
#include "cal3d/submesh.h"

CalMesh::CalMesh(const CalCoreMeshPtr& pCoreMesh)
    : coreMesh(pCoreMesh) {
    assert(pCoreMesh);

    // clone the mesh structure of the core mesh
    CalCoreMesh::CalCoreSubmeshVector& vectorCoreSubmesh = pCoreMesh->submeshes;

    SubmeshVector& m_vectorSubmesh = const_cast<SubmeshVector&>(submeshes); // Oh for a 'readonly' keyword like C#

    size_t submeshCount = vectorCoreSubmesh.size();
    m_vectorSubmesh.reserve(submeshCount);
    for (size_t submeshId = 0; submeshId < submeshCount; ++submeshId) {
        m_vectorSubmesh.push_back(CalSubmeshPtr(new CalSubmesh(vectorCoreSubmesh[submeshId])));
    }
}
<commit_msg>remove some const_cast wonkiness<commit_after>//****************************************************************************//
// mesh.cpp                                                                   //
// Copyright (C) 2001, 2002 Bruno 'Beosil' Heidelberger                       //
//****************************************************************************//
// This library is free software; you can redistribute it and/or modify it    //
// under the terms of the GNU Lesser General Public License as published by   //
// the Free Software Foundation; either version 2.1 of the License, or (at    //
// your option) any later version.                                            //
//****************************************************************************//

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "cal3d/mesh.h"
#include "cal3d/error.h"
#include "cal3d/coremesh.h"
#include "cal3d/coresubmesh.h"
#include "cal3d/submesh.h"

CalMesh::SubmeshVector fromCoreSubmeshes(const CalCoreMesh::CalCoreSubmeshVector& coreSubmeshes) {
    CalMesh::SubmeshVector rv;
    rv.reserve(coreSubmeshes.size());
    for (size_t i = 0; i < coreSubmeshes.size(); ++i) {
        rv.push_back(CalSubmeshPtr(new CalSubmesh(coreSubmeshes[i])));
    }
    return rv;
}

CalMesh::CalMesh(const CalCoreMeshPtr& pCoreMesh)
    : coreMesh(pCoreMesh)
    , submeshes(fromCoreSubmeshes(pCoreMesh->submeshes))
{}
<|endoftext|>


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

/*
 * Modified by Cloudius Systems
 * Copyright 2015 Cloudius Systems
 */

#pragma once

#include "core/shared_ptr.hh"
#include "database.hh"
#include <memory>

namespace dht {

class DecoratedKey;
class Token;

class i_partitioner {
    /**
     * Transform key to object representation of the on-disk format.
     *
     * @param key the raw, client-facing key
     * @return decorated version of key
     */
    virtual shared_ptr<DecoratedKey> decorate_key(bytes key) = 0;

    /**
     * Calculate a Token representing the approximate "middle" of the given
     * range.
     *
     * @return The approximate midpoint between left and right.
     */
    virtual shared_ptr<Token> midpoint(Token& left, Token& right) = 0;

    /**
     * @return A Token smaller than all others in the range that is being partitioned.
     * Not legal to assign to a node or key.  (But legal to use in range scans.)
     */
    virtual shared_ptr<Token> get_minimum_token() = 0;

    /**
     * @return a Token that can be used to route a given key
     * (This is NOT a method to create a Token from its string representation;
     * for that, use TokenFactory.fromString.)
     */
    virtual shared_ptr<Token> get_token(bytes key) = 0;

    /**
     * @return a randomly generated token
     */
    virtual shared_ptr<Token> get_random_token() = 0;

    // FIXME: Token.TokenFactory
    //virtual Token.TokenFactory getTokenFactory() = 0;

    /**
     * @return True if the implementing class preserves key order in the Tokens
     * it generates.
     */
    virtual bool preserves_order() = 0;

    /**
     * Calculate the deltas between tokens in the ring in order to compare
     *  relative sizes.
     *
     * @param sortedTokens a sorted List of Tokens
     * @return the mapping from 'token' to 'percentage of the ring owned by that token'.
     */
    virtual std::map<shared_ptr<Token>, float> describe_ownership(std::vector<shared_ptr<Token>> sorted_tokens) = 0;

    virtual data_type get_token_validator() = 0;
};

} // dht
<commit_msg>dht: rename DecoratedKey and Token to fit with naming conventions<commit_after>/*
 * 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
 *
 * 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.
 */

/*
 * Modified by Cloudius Systems
 * Copyright 2015 Cloudius Systems
 */

#pragma once

#include "core/shared_ptr.hh"
#include "types.hh"
#include <memory>

namespace dht {

class decorated_key;
class token;

class i_partitioner {
    /**
     * Transform key to object representation of the on-disk format.
     *
     * @param key the raw, client-facing key
     * @return decorated version of key
     */
    virtual shared_ptr<decorated_key> decorate_key(bytes key) = 0;

    /**
     * Calculate a token representing the approximate "middle" of the given
     * range.
     *
     * @return The approximate midpoint between left and right.
     */
    virtual shared_ptr<token> midpoint(token& left, token& right) = 0;

    /**
     * @return A token smaller than all others in the range that is being partitioned.
     * Not legal to assign to a node or key.  (But legal to use in range scans.)
     */
    virtual shared_ptr<token> get_minimum_token() = 0;

    /**
     * @return a token that can be used to route a given key
     * (This is NOT a method to create a token from its string representation;
     * for that, use tokenFactory.fromString.)
     */
    virtual shared_ptr<token> get_token(bytes key) = 0;

    /**
     * @return a randomly generated token
     */
    virtual shared_ptr<token> get_random_token() = 0;

    // FIXME: token.tokenFactory
    //virtual token.tokenFactory gettokenFactory() = 0;

    /**
     * @return True if the implementing class preserves key order in the tokens
     * it generates.
     */
    virtual bool preserves_order() = 0;

    /**
     * Calculate the deltas between tokens in the ring in order to compare
     *  relative sizes.
     *
     * @param sortedtokens a sorted List of tokens
     * @return the mapping from 'token' to 'percentage of the ring owned by that token'.
     */
    virtual std::map<shared_ptr<token>, float> describe_ownership(std::vector<shared_ptr<token>> sorted_tokens) = 0;

    virtual data_type get_token_validator() = 0;
};

} // dht
<|endoftext|>


<commit_before>// Copyright (c) 2011 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 "views/examples/native_theme_button_example.h"

#include "base/logging.h"
#include "base/stringprintf.h"
#include "base/utf_string_conversions.h"
#include "ui/base/animation/throb_animation.h"
#include "ui/base/models/combobox_model.h"
#include "ui/gfx/canvas.h"
#include "views/controls/label.h"
#include "views/layout/grid_layout.h"
#include "views/native_theme_painter.h"

namespace {

class ExampleComboboxModel : public ui::ComboboxModel {
 public:
  ExampleComboboxModel(const wchar_t** strings, int count)
      : strings_(strings), count_(count) {
  }

  ~ExampleComboboxModel() {
  }

  void set_data(const wchar_t** strings, int count) {
    strings_ = strings;
    count_ = count;
  }

  // Overridden from ui::ComboboxModel:
  virtual int GetItemCount() OVERRIDE {
    return count_;
  }
  virtual string16 GetItemAt(int index) OVERRIDE {
    return WideToUTF16Hack(strings_[index]);
  }

 private:
  const wchar_t** strings_;
  int count_;

  DISALLOW_COPY_AND_ASSIGN(ExampleComboboxModel);
};

const wchar_t* kParts[] = {
    L"PushButton",
    L"RadioButton",
    L"Checkbox",
};

const wchar_t* kStates[] = {
    L"Disabled",
    L"Normal",
    L"Hot",
    L"Pressed",
    L"<Dynamic>",
};

}  // anonymous namespace

namespace examples {

ExampleNativeThemeButton::ExampleNativeThemeButton(
    views::ButtonListener* listener,
    views::Combobox* cb_part,
    views::Combobox* cb_state)
    : CustomButton(listener),
      cb_part_(cb_part),
      cb_state_(cb_state),
      count_(0),
      is_checked_(false),
      is_indeterminate_(false) {
  cb_part_->set_listener(this);
  cb_state_->set_listener(this);

  painter_.reset(new views::NativeThemePainter(this));
  set_background(views::Background::CreateBackgroundPainter(
      false, painter_.get()));
}

ExampleNativeThemeButton::~ExampleNativeThemeButton() {
}

std::string ExampleNativeThemeButton::MessWithState() {
  const char* message = NULL;
  switch(GetThemePart()) {
  case gfx::NativeTheme::kPushButton:
    message = "Pressed! count:%d";
    break;
  case gfx::NativeTheme::kRadio:
    is_checked_ = !is_checked_;
    message = is_checked_ ? "Checked! count:%d" : "Unchecked! count:%d";
    break;
  case gfx::NativeTheme::kCheckbox:
    if (is_indeterminate_) {
      is_checked_ = false;
      is_indeterminate_ = false;
    } else if (!is_checked_) {
      is_checked_ = true;
    } else {
      is_checked_ = false;
      is_indeterminate_ = true;
    }

    message = is_checked_ ? "Checked! count:%d" :
      is_indeterminate_ ? "Indeterminate! count:%d" : "Unchecked! count:%d";
    break;
  default:
    DCHECK(false);
  }

  return base::StringPrintf(message, ++count_);
}

void ExampleNativeThemeButton::ItemChanged(views::Combobox* combo_box,
                                           int prev_index,
                                           int new_index) {
  SchedulePaint();
}

gfx::NativeTheme::Part ExampleNativeThemeButton::GetThemePart() const {
  int selected = cb_part_->selected_item();
  switch(selected) {
    case 0:
      return gfx::NativeTheme::kPushButton;
    case 1:
      return gfx::NativeTheme::kRadio;
    case 2:
      return gfx::NativeTheme::kCheckbox;
    default:
      DCHECK(false);
  }
  return gfx::NativeTheme::kPushButton;
}

gfx::Rect ExampleNativeThemeButton::GetThemePaintRect() const {
  gfx::NativeTheme::ExtraParams extra;
  gfx::NativeTheme::State state = GetThemeState(&extra);
  gfx::Size size(gfx::NativeTheme::instance()->GetPartSize(GetThemePart(),
                                                           state,
                                                           extra));
  gfx::Rect rect(size);
  rect.set_x(GetMirroredXForRect(rect));
  return rect;
}

gfx::NativeTheme::State ExampleNativeThemeButton::GetThemeState(
    gfx::NativeTheme::ExtraParams* params) const {
  GetExtraParams(params);

  int selected = cb_state_->selected_item();
  if (selected > 3) {
    switch(state()) {
      case BS_DISABLED:
        return gfx::NativeTheme::kDisabled;
      case BS_NORMAL:
        return gfx::NativeTheme::kNormal;
      case BS_HOT:
        return gfx::NativeTheme::kHovered;
      case BS_PUSHED:
        return gfx::NativeTheme::kPressed;
      default:
        DCHECK(false);
    }
  }

  switch(selected) {
    case 0:
      return gfx::NativeTheme::kDisabled;
    case 1:
      return gfx::NativeTheme::kNormal;
    case 2:
      return gfx::NativeTheme::kHovered;
    case 3:
      return gfx::NativeTheme::kPressed;
    default:
      DCHECK(false);
  }
  return gfx::NativeTheme::kNormal;
}

void ExampleNativeThemeButton::GetExtraParams(
    gfx::NativeTheme::ExtraParams* params) const {

  params->button.checked = is_checked_;
  params->button.indeterminate = is_indeterminate_;
  params->button.is_default = false;
  params->button.has_border = false;
  params->button.classic_state = 0;
  params->button.background_color = SkColorSetARGB(0, 0, 0, 0);
}

const ui::Animation* ExampleNativeThemeButton::GetThemeAnimation() const {
  int selected = cb_state_->selected_item();
  return selected <= 3 ? NULL : hover_animation_.get();
}

gfx::NativeTheme::State ExampleNativeThemeButton::GetBackgroundThemeState(
    gfx::NativeTheme::ExtraParams* params) const {
  GetExtraParams(params);
  return gfx::NativeTheme::kNormal;
}

gfx::NativeTheme::State ExampleNativeThemeButton::GetForegroundThemeState(
    gfx::NativeTheme::ExtraParams* params) const {
  GetExtraParams(params);
  return gfx::NativeTheme::kHovered;
}

gfx::Size ExampleNativeThemeButton::GetPreferredSize() {
  return painter_.get() == NULL ? gfx::Size() : painter_->GetPreferredSize();
}

void ExampleNativeThemeButton::OnPaintBackground(gfx::Canvas* canvas) {
  // Fill the background with a known colour so that we know where the bounds
  // of the View are.
  canvas->FillRectInt(SkColorSetRGB(255, 128, 128), 0, 0, width(), height());
  CustomButton::OnPaintBackground(canvas);
}

////////////////////////////////////////////////////////////////////////////////

NativeThemeButtonExample::NativeThemeButtonExample(ExamplesMain* main)
    : ExampleBase(main) {
}

NativeThemeButtonExample::~NativeThemeButtonExample() {
}

std::wstring NativeThemeButtonExample::GetExampleTitle() {
  return L"Native Theme Button";
}

void NativeThemeButtonExample::CreateExampleView(views::View* container) {
  views::GridLayout* layout = new views::GridLayout(container);
  container->SetLayoutManager(layout);

  layout->AddPaddingRow(0, 8);

  views::ColumnSet* column_set = layout->AddColumnSet(0);
  column_set->AddPaddingColumn(0, 8);
  column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL,
                        0.1f, views::GridLayout::USE_PREF, 0, 0);
  column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
                        0.9f, views::GridLayout::USE_PREF, 0, 0);
  column_set->AddPaddingColumn(0, 8);

  layout->StartRow(0, 0);
  layout->AddView(new views::Label(L"Part:"));
  views::Combobox* cb_part = new views::Combobox(
      new ExampleComboboxModel(kParts, arraysize(kParts)));
  cb_part->SetSelectedItem(0);
  layout->AddView(cb_part);

  layout->StartRow(0, 0);
  layout->AddView(new views::Label(L"State:"));
  views::Combobox* cb_state = new views::Combobox(
      new ExampleComboboxModel(kStates, arraysize(kStates)));
  cb_state->SetSelectedItem(0);
  layout->AddView(cb_state);

  layout->AddPaddingRow(0, 32);

  button_ = new ExampleNativeThemeButton(this, cb_part, cb_state);

  column_set = layout->AddColumnSet(1);
  column_set->AddPaddingColumn(0, 16);
  column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
                        1, views::GridLayout::USE_PREF, 0, 0);
  column_set->AddPaddingColumn(0, 16);
  layout->StartRow(1, 1);
  layout->AddView(button_);

  layout->AddPaddingRow(0, 8);
}

void NativeThemeButtonExample::ButtonPressed(views::Button* sender,
                                             const views::Event& event) {
  PrintStatus(button_->MessWithState().c_str());
}

}  // namespace examples
<commit_msg>views/examples: Switch usages of wchar_t in ExampleComboboxModel to char type.<commit_after>// Copyright (c) 2011 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 "views/examples/native_theme_button_example.h"

#include "base/logging.h"
#include "base/stringprintf.h"
#include "base/utf_string_conversions.h"
#include "ui/base/animation/throb_animation.h"
#include "ui/base/models/combobox_model.h"
#include "ui/gfx/canvas.h"
#include "views/controls/label.h"
#include "views/layout/grid_layout.h"
#include "views/native_theme_painter.h"

namespace {

class ExampleComboboxModel : public ui::ComboboxModel {
 public:
  ExampleComboboxModel(const char** strings, int count)
      : strings_(strings), count_(count) {
  }

  virtual ~ExampleComboboxModel() {}

  // Overridden from ui::ComboboxModel:
  virtual int GetItemCount() OVERRIDE {
    return count_;
  }
  virtual string16 GetItemAt(int index) OVERRIDE {
    return ASCIIToUTF16(strings_[index]);
  }

 private:
  const char** strings_;
  int count_;

  DISALLOW_COPY_AND_ASSIGN(ExampleComboboxModel);
};

const char* kParts[] = {
    "PushButton",
    "RadioButton",
    "Checkbox",
};

const char* kStates[] = {
    "Disabled",
    "Normal",
    "Hot",
    "Pressed",
    "<Dynamic>",
};

}  // namespace

namespace examples {

ExampleNativeThemeButton::ExampleNativeThemeButton(
    views::ButtonListener* listener,
    views::Combobox* cb_part,
    views::Combobox* cb_state)
    : CustomButton(listener),
      cb_part_(cb_part),
      cb_state_(cb_state),
      count_(0),
      is_checked_(false),
      is_indeterminate_(false) {
  cb_part_->set_listener(this);
  cb_state_->set_listener(this);

  painter_.reset(new views::NativeThemePainter(this));
  set_background(views::Background::CreateBackgroundPainter(
      false, painter_.get()));
}

ExampleNativeThemeButton::~ExampleNativeThemeButton() {
}

std::string ExampleNativeThemeButton::MessWithState() {
  const char* message = NULL;
  switch(GetThemePart()) {
  case gfx::NativeTheme::kPushButton:
    message = "Pressed! count:%d";
    break;
  case gfx::NativeTheme::kRadio:
    is_checked_ = !is_checked_;
    message = is_checked_ ? "Checked! count:%d" : "Unchecked! count:%d";
    break;
  case gfx::NativeTheme::kCheckbox:
    if (is_indeterminate_) {
      is_checked_ = false;
      is_indeterminate_ = false;
    } else if (!is_checked_) {
      is_checked_ = true;
    } else {
      is_checked_ = false;
      is_indeterminate_ = true;
    }

    message = is_checked_ ? "Checked! count:%d" :
      is_indeterminate_ ? "Indeterminate! count:%d" : "Unchecked! count:%d";
    break;
  default:
    DCHECK(false);
  }

  return base::StringPrintf(message, ++count_);
}

void ExampleNativeThemeButton::ItemChanged(views::Combobox* combo_box,
                                           int prev_index,
                                           int new_index) {
  SchedulePaint();
}

gfx::NativeTheme::Part ExampleNativeThemeButton::GetThemePart() const {
  int selected = cb_part_->selected_item();
  switch(selected) {
    case 0:
      return gfx::NativeTheme::kPushButton;
    case 1:
      return gfx::NativeTheme::kRadio;
    case 2:
      return gfx::NativeTheme::kCheckbox;
    default:
      DCHECK(false);
  }
  return gfx::NativeTheme::kPushButton;
}

gfx::Rect ExampleNativeThemeButton::GetThemePaintRect() const {
  gfx::NativeTheme::ExtraParams extra;
  gfx::NativeTheme::State state = GetThemeState(&extra);
  gfx::Size size(gfx::NativeTheme::instance()->GetPartSize(GetThemePart(),
                                                           state,
                                                           extra));
  gfx::Rect rect(size);
  rect.set_x(GetMirroredXForRect(rect));
  return rect;
}

gfx::NativeTheme::State ExampleNativeThemeButton::GetThemeState(
    gfx::NativeTheme::ExtraParams* params) const {
  GetExtraParams(params);

  int selected = cb_state_->selected_item();
  if (selected > 3) {
    switch(state()) {
      case BS_DISABLED:
        return gfx::NativeTheme::kDisabled;
      case BS_NORMAL:
        return gfx::NativeTheme::kNormal;
      case BS_HOT:
        return gfx::NativeTheme::kHovered;
      case BS_PUSHED:
        return gfx::NativeTheme::kPressed;
      default:
        DCHECK(false);
    }
  }

  switch(selected) {
    case 0:
      return gfx::NativeTheme::kDisabled;
    case 1:
      return gfx::NativeTheme::kNormal;
    case 2:
      return gfx::NativeTheme::kHovered;
    case 3:
      return gfx::NativeTheme::kPressed;
    default:
      DCHECK(false);
  }
  return gfx::NativeTheme::kNormal;
}

void ExampleNativeThemeButton::GetExtraParams(
    gfx::NativeTheme::ExtraParams* params) const {

  params->button.checked = is_checked_;
  params->button.indeterminate = is_indeterminate_;
  params->button.is_default = false;
  params->button.has_border = false;
  params->button.classic_state = 0;
  params->button.background_color = SkColorSetARGB(0, 0, 0, 0);
}

const ui::Animation* ExampleNativeThemeButton::GetThemeAnimation() const {
  int selected = cb_state_->selected_item();
  return selected <= 3 ? NULL : hover_animation_.get();
}

gfx::NativeTheme::State ExampleNativeThemeButton::GetBackgroundThemeState(
    gfx::NativeTheme::ExtraParams* params) const {
  GetExtraParams(params);
  return gfx::NativeTheme::kNormal;
}

gfx::NativeTheme::State ExampleNativeThemeButton::GetForegroundThemeState(
    gfx::NativeTheme::ExtraParams* params) const {
  GetExtraParams(params);
  return gfx::NativeTheme::kHovered;
}

gfx::Size ExampleNativeThemeButton::GetPreferredSize() {
  return painter_.get() == NULL ? gfx::Size() : painter_->GetPreferredSize();
}

void ExampleNativeThemeButton::OnPaintBackground(gfx::Canvas* canvas) {
  // Fill the background with a known colour so that we know where the bounds
  // of the View are.
  canvas->FillRectInt(SkColorSetRGB(255, 128, 128), 0, 0, width(), height());
  CustomButton::OnPaintBackground(canvas);
}

////////////////////////////////////////////////////////////////////////////////

NativeThemeButtonExample::NativeThemeButtonExample(ExamplesMain* main)
    : ExampleBase(main) {
}

NativeThemeButtonExample::~NativeThemeButtonExample() {
}

std::wstring NativeThemeButtonExample::GetExampleTitle() {
  return L"Native Theme Button";
}

void NativeThemeButtonExample::CreateExampleView(views::View* container) {
  views::GridLayout* layout = new views::GridLayout(container);
  container->SetLayoutManager(layout);

  layout->AddPaddingRow(0, 8);

  views::ColumnSet* column_set = layout->AddColumnSet(0);
  column_set->AddPaddingColumn(0, 8);
  column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL,
                        0.1f, views::GridLayout::USE_PREF, 0, 0);
  column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
                        0.9f, views::GridLayout::USE_PREF, 0, 0);
  column_set->AddPaddingColumn(0, 8);

  layout->StartRow(0, 0);
  layout->AddView(new views::Label(L"Part:"));
  views::Combobox* cb_part = new views::Combobox(
      new ExampleComboboxModel(kParts, arraysize(kParts)));
  cb_part->SetSelectedItem(0);
  layout->AddView(cb_part);

  layout->StartRow(0, 0);
  layout->AddView(new views::Label(L"State:"));
  views::Combobox* cb_state = new views::Combobox(
      new ExampleComboboxModel(kStates, arraysize(kStates)));
  cb_state->SetSelectedItem(0);
  layout->AddView(cb_state);

  layout->AddPaddingRow(0, 32);

  button_ = new ExampleNativeThemeButton(this, cb_part, cb_state);

  column_set = layout->AddColumnSet(1);
  column_set->AddPaddingColumn(0, 16);
  column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
                        1, views::GridLayout::USE_PREF, 0, 0);
  column_set->AddPaddingColumn(0, 16);
  layout->StartRow(1, 1);
  layout->AddView(button_);

  layout->AddPaddingRow(0, 8);
}

void NativeThemeButtonExample::ButtonPressed(views::Button* sender,
                                             const views::Event& event) {
  PrintStatus(button_->MessWithState().c_str());
}

}  // namespace examples
<|endoftext|>


<commit_before>/**
 * 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
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <algorithm>
#include <sstream>
#include <map>

#include <process/dispatch.hpp>
#include <process/id.hpp>

#include <stout/foreach.hpp>
#include <stout/os.hpp>
#include <stout/path.hpp>

#include "common/type_utils.hpp"
#include "common/units.hpp"

#include "launcher/launcher.hpp"

#include "slave/flags.hpp"
#include "slave/lxc_isolation_module.hpp"

using namespace mesos;
using namespace mesos::internal;
using namespace mesos::internal::slave;

using namespace process;

using launcher::ExecutorLauncher;

using process::wait; // Necessary on some OS's to disambiguate.

using std::map;
using std::max;
using std::string;
using std::vector;

namespace {

const int32_t CPU_SHARES_PER_CPU = 1024;
const int32_t MIN_CPU_SHARES = 10;
const int64_t MIN_MEMORY_MB = 128 * Megabyte;

} // namespace {

LxcIsolationModule::LxcIsolationModule()
  : ProcessBase(ID::generate("lxc-isolation-module")),
    initialized(false)
{
  // Spawn the reaper, note that it might send us a message before we
  // actually get spawned ourselves, but that's okay, the message will
  // just get dropped.
  reaper = new Reaper();
  spawn(reaper);
  dispatch(reaper, &Reaper::addProcessExitedListener, this);
}

LxcIsolationModule::~LxcIsolationModule()
{
  CHECK(reaper != NULL);
  terminate(reaper);
  wait(reaper);
  delete reaper;
}

void LxcIsolationModule::initialize(
    const Flags& _flags,
    bool _local,
    const PID<Slave>& _slave)
{
  flags = _flags;
  local = _local;
  slave = _slave;

  // Check if Linux Container tools are available.
  if (system("lxc-version > /dev/null") != 0) {
    LOG(FATAL) << "Could not run lxc-version; make sure Linux Container "
                << "tools are installed";
  }

  // Check that we are root (it might also be possible to create Linux
  // containers without being root, but we can support that later).
  if (getuid() != 0) {
    LOG(FATAL) << "LXC isolation module requires slave to run as root";
  }

  initialized = true;
}

void LxcIsolationModule::launchExecutor(
    const FrameworkID& frameworkId,
    const FrameworkInfo& frameworkInfo,
    const ExecutorInfo& executorInfo,
    const string& directory,
    const Resources& resources)
{
  CHECK(initialized) << "Cannot launch executors before initialization!";

  const ExecutorID& executorId = executorInfo.executor_id();

  LOG(INFO) << "Launching " << executorId
            << " (" << executorInfo.command().value() << ")"
            << " in " << directory
            << " with resources " << resources
            << "' for framework " << frameworkId;

  // Create a name for the container.
  std::ostringstream out;
  out << "mesos_executor_" << executorId << "_framework_" << frameworkId;

  const string& container = out.str();

  ContainerInfo* info = new ContainerInfo();

  info->frameworkId = frameworkId;
  info->executorId = executorId;
  info->container = container;
  info->pid = -1;

  infos[frameworkId][executorId] = info;

  // Run lxc-execute mesos-launcher using a fork-exec (since lxc-execute
  // does not return until the container is finished). Note that lxc-execute
  // automatically creates the container and will delete it when finished.
  pid_t pid;
  if ((pid = fork()) == -1) {
    PLOG(FATAL) << "Failed to fork to launch new executor";
  }

  if (pid) {
    // In parent process.
    LOG(INFO) << "Forked executor at = " << pid;

    // Record the pid.
    info->pid = pid;

    // Tell the slave this executor has started.
    dispatch(slave, &Slave::executorStarted,
             frameworkId, executorId, pid);
  } else {
    // Close unnecessary file descriptors. Note that we are assuming
    // stdin, stdout, and stderr can ONLY be found at the POSIX
    // specified file numbers (0, 1, 2).
    foreach (const string& entry, os::listdir("/proc/self/fd")) {
      if (entry != "." && entry != "..") {
        try {
          int fd = boost::lexical_cast<int>(entry);
          if (fd != STDIN_FILENO &&
            fd != STDOUT_FILENO &&
            fd != STDERR_FILENO) {
            close(fd);
          }
        } catch (boost::bad_lexical_cast&) {
          LOG(FATAL) << "Failed to close file descriptors";
        }
      }
    }

    ExecutorLauncher* launcher =
      new ExecutorLauncher(frameworkId,
			   executorId,
			   executorInfo.command(),
			   frameworkInfo.user(),
                           directory,
			   slave,
			   flags.frameworks_home,
			   flags.hadoop_home,
			   !local,
			   flags.switch_user,
			   container);

    launcher->setupEnvironmentForLauncherMain();

    // Construct the initial control group options that specify the
    // initial resources limits for this executor.
    const vector<string>& options = getControlGroupOptions(resources);

    const char** args = (const char**) new char*[3 + options.size() + 2];

    int i = 0;

    args[i++] = "lxc-execute";
    args[i++] = "-n";
    args[i++] = container.c_str();

    for (int j = 0; j < options.size(); j++) {
      args[i++] = options[j].c_str();
    }

    // Determine path for mesos-launcher from Mesos home directory.
    string path = path::join(flags.launcher_dir, "mesos-launcher");
    args[i++] = path.c_str();
    args[i++] = NULL;

    // Run lxc-execute.
    execvp(args[0], (char* const*) args);

    // If we get here, the execvp call failed.
    LOG(FATAL) << "Could not exec lxc-execute";
  }
}

void LxcIsolationModule::killExecutor(
    const FrameworkID& frameworkId,
    const ExecutorID& executorId)
{
  CHECK(initialized) << "Cannot kill executors before initialization!";
  if (!infos.contains(frameworkId) ||
      !infos[frameworkId].contains(executorId)) {
    LOG(ERROR) << "ERROR! Asked to kill an unknown executor!";
    return;
  }

  ContainerInfo* info = infos[frameworkId][executorId];

  CHECK(info->container != "");

  LOG(INFO) << "Stopping container " << info->container;

  Try<int> status =
    os::shell(NULL, "lxc-stop -n %s", info->container.c_str());

  if (status.isError()) {
    LOG(ERROR) << "Failed to stop container " << info->container
               << ": " << status.error();
  } else if (status.get() != 0) {
    LOG(ERROR) << "Failed to stop container " << info->container
               << ", lxc-stop returned: " << status.get();
  }

  if (infos[frameworkId].size() == 1) {
    infos.erase(frameworkId);
  } else {
    infos[frameworkId].erase(executorId);
  }

  delete info;

  // NOTE: Both frameworkId and executorId are no longer valid because
  // they have just been deleted above!
}

void LxcIsolationModule::resourcesChanged(
    const FrameworkID& frameworkId,
    const ExecutorID& executorId,
    const Resources& resources)
{
  CHECK(initialized) << "Cannot change resources before initialization!";
  if (!infos.contains(frameworkId) ||
      !infos[frameworkId].contains(executorId)) {
    LOG(ERROR) << "ERROR! Asked to update resources for an unknown executor!";
    return;
  }

  ContainerInfo* info = infos[frameworkId][executorId];

  CHECK(info->container != "");

  const string& container = info->container;

  // For now, just try setting the CPUs and memory right away, and kill the
  // framework if this fails (needs to be fixed).
  // A smarter thing to do might be to only update them periodically in a
  // separate thread, and to give frameworks some time to scale down their
  // memory usage.
  string property;
  uint64_t value;

  double cpu = resources.get("cpu", Value::Scalar()).value();
  int32_t cpu_shares = max(CPU_SHARES_PER_CPU * (int32_t) cpu, MIN_CPU_SHARES);

  property = "cpu.shares";
  value = cpu_shares;

  if (!setControlGroupValue(container, property, value)) {
    // TODO(benh): Kill the executor, but do it in such a way that the
    // slave finds out about it exiting.
    return;
  }

  double mem = resources.get("mem", Value::Scalar()).value();
  int64_t limit_in_bytes = max((int64_t) mem, MIN_MEMORY_MB) * 1024LL * 1024LL;

  property = "memory.limit_in_bytes";
  value = limit_in_bytes;

  if (!setControlGroupValue(container, property, value)) {
    // TODO(benh): Kill the executor, but do it in such a way that the
    // slave finds out about it exiting.
    return;
  }
}

void LxcIsolationModule::processExited(pid_t pid, int status)
{
  foreachkey (const FrameworkID& frameworkId, infos) {
    foreachvalue (ContainerInfo* info, infos[frameworkId]) {
      if (info->pid == pid) {
        LOG(INFO) << "Telling slave of lost executor "
		  << info->executorId
                  << " of framework " << info->frameworkId;

        dispatch(slave, &Slave::executorExited,
                 info->frameworkId, info->executorId, status);

        // Try and cleanup after the executor.
        killExecutor(info->frameworkId, info->executorId);
        return;
      }
    }
  }
}

bool LxcIsolationModule::setControlGroupValue(
    const string& container,
    const string& property,
    int64_t value)
{
  LOG(INFO) << "Setting " << property
            << " for container " << container
            << " to " << value;

  Try<int> status =
    os::shell(NULL, "lxc-cgroup -n %s %s %lld",
                     container.c_str(), property.c_str(), value);

  if (status.isError()) {
    LOG(ERROR) << "Failed to set " << property
               << " for container " << container
               << ": " << status.error();
    return false;
  } else if (status.get() != 0) {
    LOG(ERROR) << "Failed to set " << property
               << " for container " << container
               << ": lxc-cgroup returned " << status.get();
    return false;
  }

  return true;
}

vector<string> LxcIsolationModule::getControlGroupOptions(
    const Resources& resources)
{
  vector<string> options;

  std::ostringstream out;

  double cpu = resources.get("cpu", Value::Scalar()).value();
  int32_t cpu_shares = max(CPU_SHARES_PER_CPU * (int32_t) cpu, MIN_CPU_SHARES);

  options.push_back("-s");
  out << "lxc.cgroup.cpu.shares=" << cpu_shares;
  options.push_back(out.str());

  out.str("");

  double mem = resources.get("mem", Value::Scalar()).value();
  int64_t limit_in_bytes = max((int64_t) mem, MIN_MEMORY_MB) * 1024LL * 1024LL;

  options.push_back("-s");
  out << "lxc.cgroup.memory.limit_in_bytes=" << limit_in_bytes;
  options.push_back(out.str());

  return options;
}
<commit_msg>Fixed a bug in LXC isolation module (contributed by Jie Yu, https://reviews.apache.org/r/6321).<commit_after>/**
 * 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
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <algorithm>
#include <sstream>
#include <map>

#include <process/dispatch.hpp>
#include <process/id.hpp>

#include <stout/foreach.hpp>
#include <stout/os.hpp>
#include <stout/path.hpp>

#include "common/type_utils.hpp"
#include "common/units.hpp"

#include "launcher/launcher.hpp"

#include "slave/flags.hpp"
#include "slave/lxc_isolation_module.hpp"

using namespace mesos;
using namespace mesos::internal;
using namespace mesos::internal::slave;

using namespace process;

using launcher::ExecutorLauncher;

using process::wait; // Necessary on some OS's to disambiguate.

using std::map;
using std::max;
using std::string;
using std::vector;

namespace {

const int32_t CPU_SHARES_PER_CPU = 1024;
const int32_t MIN_CPU_SHARES = 10;
const int64_t MIN_MEMORY_MB = 128 * Megabyte;

} // namespace {

LxcIsolationModule::LxcIsolationModule()
  : ProcessBase(ID::generate("lxc-isolation-module")),
    initialized(false)
{
  // Spawn the reaper, note that it might send us a message before we
  // actually get spawned ourselves, but that's okay, the message will
  // just get dropped.
  reaper = new Reaper();
  spawn(reaper);
  dispatch(reaper, &Reaper::addProcessExitedListener, this);
}

LxcIsolationModule::~LxcIsolationModule()
{
  CHECK(reaper != NULL);
  terminate(reaper);
  wait(reaper);
  delete reaper;
}

void LxcIsolationModule::initialize(
    const Flags& _flags,
    bool _local,
    const PID<Slave>& _slave)
{
  flags = _flags;
  local = _local;
  slave = _slave;

  // Check if Linux Container tools are available.
  if (system("lxc-version > /dev/null") != 0) {
    LOG(FATAL) << "Could not run lxc-version; make sure Linux Container "
                << "tools are installed";
  }

  // Check that we are root (it might also be possible to create Linux
  // containers without being root, but we can support that later).
  if (getuid() != 0) {
    LOG(FATAL) << "LXC isolation module requires slave to run as root";
  }

  initialized = true;
}

void LxcIsolationModule::launchExecutor(
    const FrameworkID& frameworkId,
    const FrameworkInfo& frameworkInfo,
    const ExecutorInfo& executorInfo,
    const string& directory,
    const Resources& resources)
{
  CHECK(initialized) << "Cannot launch executors before initialization!";

  const ExecutorID& executorId = executorInfo.executor_id();

  LOG(INFO) << "Launching " << executorId
            << " (" << executorInfo.command().value() << ")"
            << " in " << directory
            << " with resources " << resources
            << "' for framework " << frameworkId;

  // Create a name for the container.
  std::ostringstream out;
  out << "mesos_executor_" << executorId << "_framework_" << frameworkId;

  const string& container = out.str();

  ContainerInfo* info = new ContainerInfo();

  info->frameworkId = frameworkId;
  info->executorId = executorId;
  info->container = container;
  info->pid = -1;

  infos[frameworkId][executorId] = info;

  // Run lxc-execute mesos-launcher using a fork-exec (since lxc-execute
  // does not return until the container is finished). Note that lxc-execute
  // automatically creates the container and will delete it when finished.
  pid_t pid;
  if ((pid = fork()) == -1) {
    PLOG(FATAL) << "Failed to fork to launch new executor";
  }

  if (pid) {
    // In parent process.
    LOG(INFO) << "Forked executor at = " << pid;

    // Record the pid.
    info->pid = pid;

    // Tell the slave this executor has started.
    dispatch(slave, &Slave::executorStarted,
             frameworkId, executorId, pid);
  } else {
    // Close unnecessary file descriptors. Note that we are assuming
    // stdin, stdout, and stderr can ONLY be found at the POSIX
    // specified file numbers (0, 1, 2).
    foreach (const string& entry, os::listdir("/proc/self/fd")) {
      if (entry != "." && entry != "..") {
        try {
          int fd = boost::lexical_cast<int>(entry);
          if (fd != STDIN_FILENO &&
            fd != STDOUT_FILENO &&
            fd != STDERR_FILENO) {
            close(fd);
          }
        } catch (boost::bad_lexical_cast&) {
          LOG(FATAL) << "Failed to close file descriptors";
        }
      }
    }

    ExecutorLauncher* launcher =
      new ExecutorLauncher(frameworkId,
			   executorId,
			   executorInfo.command(),
			   frameworkInfo.user(),
                           directory,
			   slave,
			   flags.frameworks_home,
			   flags.hadoop_home,
			   !local,
			   flags.switch_user,
			   container);

    launcher->setupEnvironmentForLauncherMain();

    // Construct the initial control group options that specify the
    // initial resources limits for this executor.
    const vector<string>& options = getControlGroupOptions(resources);

    const char** args = (const char**) new char*[3 + options.size() + 2];

    int i = 0;

    args[i++] = "lxc-execute";
    args[i++] = "-n";
    args[i++] = container.c_str();

    for (int j = 0; j < options.size(); j++) {
      args[i++] = options[j].c_str();
    }

    // Determine path for mesos-launcher from Mesos home directory.
    string path = path::join(flags.launcher_dir, "mesos-launcher");
    args[i++] = path.c_str();
    args[i++] = NULL;

    // Run lxc-execute.
    execvp(args[0], (char* const*) args);

    // If we get here, the execvp call failed.
    LOG(FATAL) << "Could not exec lxc-execute";
  }
}

void LxcIsolationModule::killExecutor(
    const FrameworkID& frameworkId,
    const ExecutorID& executorId)
{
  CHECK(initialized) << "Cannot kill executors before initialization!";
  if (!infos.contains(frameworkId) ||
      !infos[frameworkId].contains(executorId)) {
    LOG(ERROR) << "ERROR! Asked to kill an unknown executor!";
    return;
  }

  ContainerInfo* info = infos[frameworkId][executorId];

  CHECK(info->container != "");

  LOG(INFO) << "Stopping container " << info->container;

  Try<int> status =
    os::shell(NULL, "lxc-stop -n %s", info->container.c_str());

  if (status.isError()) {
    LOG(ERROR) << "Failed to stop container " << info->container
               << ": " << status.error();
  } else if (status.get() != 0) {
    LOG(ERROR) << "Failed to stop container " << info->container
               << ", lxc-stop returned: " << status.get();
  }

  if (infos[frameworkId].size() == 1) {
    infos.erase(frameworkId);
  } else {
    infos[frameworkId].erase(executorId);
  }

  delete info;

  // NOTE: Both frameworkId and executorId are no longer valid because
  // they have just been deleted above!
}

void LxcIsolationModule::resourcesChanged(
    const FrameworkID& frameworkId,
    const ExecutorID& executorId,
    const Resources& resources)
{
  CHECK(initialized) << "Cannot change resources before initialization!";
  if (!infos.contains(frameworkId) ||
      !infos[frameworkId].contains(executorId)) {
    LOG(ERROR) << "ERROR! Asked to update resources for an unknown executor!";
    return;
  }

  ContainerInfo* info = infos[frameworkId][executorId];

  CHECK(info->container != "");

  const string& container = info->container;

  // For now, just try setting the CPUs and memory right away, and kill the
  // framework if this fails (needs to be fixed).
  // A smarter thing to do might be to only update them periodically in a
  // separate thread, and to give frameworks some time to scale down their
  // memory usage.
  string property;
  uint64_t value;

  double cpu = resources.get("cpus", Value::Scalar()).value();
  int32_t cpu_shares = max(CPU_SHARES_PER_CPU * (int32_t) cpu, MIN_CPU_SHARES);

  property = "cpu.shares";
  value = cpu_shares;

  if (!setControlGroupValue(container, property, value)) {
    // TODO(benh): Kill the executor, but do it in such a way that the
    // slave finds out about it exiting.
    return;
  }

  double mem = resources.get("mem", Value::Scalar()).value();
  int64_t limit_in_bytes = max((int64_t) mem, MIN_MEMORY_MB) * 1024LL * 1024LL;

  property = "memory.limit_in_bytes";
  value = limit_in_bytes;

  if (!setControlGroupValue(container, property, value)) {
    // TODO(benh): Kill the executor, but do it in such a way that the
    // slave finds out about it exiting.
    return;
  }
}

void LxcIsolationModule::processExited(pid_t pid, int status)
{
  foreachkey (const FrameworkID& frameworkId, infos) {
    foreachvalue (ContainerInfo* info, infos[frameworkId]) {
      if (info->pid == pid) {
        LOG(INFO) << "Telling slave of lost executor "
		  << info->executorId
                  << " of framework " << info->frameworkId;

        dispatch(slave, &Slave::executorExited,
                 info->frameworkId, info->executorId, status);

        // Try and cleanup after the executor.
        killExecutor(info->frameworkId, info->executorId);
        return;
      }
    }
  }
}

bool LxcIsolationModule::setControlGroupValue(
    const string& container,
    const string& property,
    int64_t value)
{
  LOG(INFO) << "Setting " << property
            << " for container " << container
            << " to " << value;

  Try<int> status =
    os::shell(NULL, "lxc-cgroup -n %s %s %lld",
                     container.c_str(), property.c_str(), value);

  if (status.isError()) {
    LOG(ERROR) << "Failed to set " << property
               << " for container " << container
               << ": " << status.error();
    return false;
  } else if (status.get() != 0) {
    LOG(ERROR) << "Failed to set " << property
               << " for container " << container
               << ": lxc-cgroup returned " << status.get();
    return false;
  }

  return true;
}

vector<string> LxcIsolationModule::getControlGroupOptions(
    const Resources& resources)
{
  vector<string> options;

  std::ostringstream out;

  double cpu = resources.get("cpu", Value::Scalar()).value();
  int32_t cpu_shares = max(CPU_SHARES_PER_CPU * (int32_t) cpu, MIN_CPU_SHARES);

  options.push_back("-s");
  out << "lxc.cgroup.cpu.shares=" << cpu_shares;
  options.push_back(out.str());

  out.str("");

  double mem = resources.get("mem", Value::Scalar()).value();
  int64_t limit_in_bytes = max((int64_t) mem, MIN_MEMORY_MB) * 1024LL * 1024LL;

  options.push_back("-s");
  out << "lxc.cgroup.memory.limit_in_bytes=" << limit_in_bytes;
  options.push_back(out.str());

  return options;
}
<|endoftext|>


<commit_before>// @(#)root/gl:$Name:  $:$Id: TGLEditor.cxx,v 1.16 2004/09/08 09:54:47 brun Exp $
// Author:  Timur Pocheptsov  13/09/2004

#include <TVirtualGL.h>
#include <TVirtualX.h>
#include <TGCanvas.h>
#include <TGLayout.h>
#include <TGButton.h>
#include <TGSlider.h>
#include <TGLabel.h>

#include "TGLEditor.h"

ClassImp(TGLEditor)

class TGLMatView : public TGCompositeFrame {
private:
   TGLEditor *fOwner;
public:
   TGLMatView(const TGWindow *parent, Window_t wid, TGLEditor *owner);
   Bool_t HandleConfigureNotify(Event_t *event);
   Bool_t HandleExpose(Event_t *event);

private:
   TGLMatView(const TGLMatView &);
   TGLMatView & operator = (const TGLMatView &);
};

TGLMatView::TGLMatView(const TGWindow *parent, Window_t wid, TGLEditor *owner)
               :TGCompositeFrame(gClient, wid, parent), fOwner(owner)
{
}

Bool_t TGLMatView::HandleConfigureNotify(Event_t *event)
{
   return fOwner->HandleContainerNotify(event);
}

Bool_t TGLMatView::HandleExpose(Event_t *event)
{
   return fOwner->HandleContainerExpose(event);
}

enum EGLEditorIdent{
   kHSr,
   kHSg,
   kHSb,
   kHSa,
   kTBa
};

TGLEditor::TGLEditor(const TGWindow *parent, Int_t r, Int_t g, Int_t b, Int_t a)
               :TGCompositeFrame(parent, 100, 100, kVerticalFrame | kRaisedFrame),
                fRedSlider(0), fGreenSlider(0), fBlueSlider(0), fAlphaSlider(0),
                fApplyButton(0), fLayout(0), fLabelLayout(0),
                fIsActive(kFALSE), fRGBA(), fInfo()
{
   fRGBA[0] = r;
   fRGBA[1] = g;
   fRGBA[2] = b;
   fRGBA[3] = a;
   //////////////////////////////////////
   fViewCanvas = new TGCanvas(this, 120, 120, kSunkenFrame | kDoubleBorder);
   Window_t wid = fViewCanvas->GetViewPort()->GetId();
   fGLWin = gVirtualGL->CreateGLWindow(wid);
   fMatView = new TGLMatView(fViewCanvas->GetViewPort(), fGLWin, this);
   fCtx = gVirtualGL->CreateContext(fGLWin);
   fViewCanvas->SetContainer(fMatView);
   fViewLayout = new TGLayoutHints(kLHintsTop | kLHintsCenterX, 2, 2, 2, 2);
   AddFrame(fViewCanvas, fViewLayout);

   //sliders creation
   fRedSlider = new TGHSlider(this, 100, kSlider1 | kScaleBoth, kHSr);
   fRedSlider->Connect("PositionChanged(Int_t)", "TGLEditor", this, "DoSlider(Int_t)");
   fRedSlider->SetRange(0, 100);
   fRedSlider->SetPosition(fRGBA[0]);

   fGreenSlider = new TGHSlider(this, 100, kSlider1 | kScaleBoth, kHSg);
   fGreenSlider->Connect("PositionChanged(Int_t)", "TGLEditor", this, "DoSlider(Int_t)");
   fGreenSlider->SetRange(0, 100);
   fGreenSlider->SetPosition(fRGBA[1]);

   fBlueSlider = new TGHSlider(this, 100, kSlider1 | kScaleBoth, kHSb);
   fBlueSlider->Connect("PositionChanged(Int_t)", "TGLEditor", this, "DoSlider(Int_t)");
   fBlueSlider->SetRange(0, 100);
   fBlueSlider->SetPosition(fRGBA[2]);

   fAlphaSlider = new TGHSlider(this, 100, kSlider1 | kScaleBoth, kHSa);
   fAlphaSlider->Connect("PositionChanged(Int_t)", "TGLEditor", this, "DoSlider(Int_t)");
   fAlphaSlider->SetRange(0, 100);
   fAlphaSlider->SetPosition(fRGBA[3]);

   fInfo[0] = new TGLabel(this, "Red :");
   fInfo[1] = new TGLabel(this, "Green :");
   fInfo[2] = new TGLabel(this, "Blue :");
   fInfo[3] = new TGLabel(this, "Alpha :");
   fLabelLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 2, 2, 5);

   fLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 5, 2, 5, 10);
   AddFrame(fInfo[0], fLabelLayout);
   AddFrame(fRedSlider, fLayout);
   AddFrame(fInfo[1], fLabelLayout);
   AddFrame(fGreenSlider, fLayout);
   AddFrame(fInfo[2], fLabelLayout);
   AddFrame(fBlueSlider, fLayout);
   AddFrame(fInfo[3], fLabelLayout);
   AddFrame(fAlphaSlider, fLayout);

   //apply button creation
   fApplyButton = new TGTextButton(this, "Apply changes", kTBa);
   AddFrame(fApplyButton, fLayout);
   fApplyButton->SetState(kButtonDisabled);

   MakeCurrent();
   gVirtualGL->NewPRGL();
   gVirtualGL->FrustumGL(-0.5, 0.5, -0.5, 0.5, 1., 10.);
   gVirtualGL->LightModel(kLIGHT_MODEL_TWO_SIDE, kFALSE);
   gVirtualGL->EnableGL(kLIGHTING);
   gVirtualGL->EnableGL(kLIGHT0);
   gVirtualGL->EnableGL(kDEPTH_TEST);
   gVirtualGL->EnableGL(kCULL_FACE);
   gVirtualGL->CullFaceGL(kBACK);
   DrawSphere();
}

TGLEditor::~TGLEditor()
{
   gVirtualGL->DeleteContext(fCtx);
   delete fRedSlider;
   delete fGreenSlider;
   delete fBlueSlider;
   delete fAlphaSlider;
   delete fLayout;
   delete fLabelLayout;
   delete fViewCanvas;
   delete fViewLayout;
   delete fMatView;
}

void TGLEditor::SetRGBA(Color_t r, Color_t g, Color_t b, Color_t a)
{
   fIsActive = kTRUE;
   fRGBA[0] = r;
   fRGBA[1] = g;
   fRGBA[2] = b;
   fRGBA[3] = a;
   fRedSlider->SetPosition(fRGBA[0]);
   fGreenSlider->SetPosition(fRGBA[1]);
   fBlueSlider->SetPosition(fRGBA[2]);
   fAlphaSlider->SetPosition(fRGBA[3]);
   DrawSphere();
}

void TGLEditor::GetRGBA(Color_t &r, Color_t &g, Color_t &b, Color_t &a)const
{
   r = fRGBA[0];
   g = fRGBA[1];
   b = fRGBA[2];
   a = fRGBA[3];
}

void TGLEditor::DoSlider(Int_t val)
{
   TGSlider *frm = (TGSlider *)gTQSender;

   if(fApplyButton->GetState() == kButtonDisabled && fIsActive)
      fApplyButton->SetState(kButtonUp);

   if (frm) {
      switch (frm->WidgetId()) {
      case kHSr:
         fRGBA[0] = val;
         break;
      case kHSg:
         fRGBA[1] = val;
         break;
      case kHSb:
         fRGBA[2] = val;
         break;
      default:
         fRGBA[3] = val;
         break;
      }
      DrawSphere();
   }
}

Bool_t TGLEditor::HandleContainerNotify(Event_t *event)
{
   gVirtualX->ResizeWindow(fGLWin, event->fWidth, event->fHeight);
   DrawSphere();
   return kTRUE;
}

Bool_t TGLEditor::HandleContainerExpose(Event_t *event)
{
   DrawSphere();
   return kTRUE;
}

void TGLEditor::DrawSphere()const
{
   MakeCurrent();
   gVirtualGL->ClearGL(0);
   gVirtualGL->ViewportGL(0, 0, fMatView->GetWidth(), fMatView->GetHeight());
   gVirtualGL->NewMVGL();
   gVirtualGL->PushGLMatrix();
   gVirtualGL->TranslateGL(0., 0., -3.);
   gVirtualGL->DrawSphere((Color_t *)fRGBA);
   gVirtualGL->PopGLMatrix();
   Float_t ligPos[] = {0.f, 0.f, 0.f, 1.f};
   gVirtualGL->GLLight(kLIGHT0, kPOSITION, ligPos);
   SwapBuffers();
}

void TGLEditor::MakeCurrent()const
{
   gVirtualGL->MakeCurrent(fGLWin, fCtx);
}

void TGLEditor::SwapBuffers()const
{
   gVirtualGL->SwapBuffers(fGLWin);
}
<commit_msg>Remove a compiler warning about unused argument<commit_after>// @(#)root/gl:$Name:  $:$Id: TGLEditor.cxx,v 1.1 2004/09/13 09:56:33 brun Exp $
// Author:  Timur Pocheptsov  13/09/2004

#include <TVirtualGL.h>
#include <TVirtualX.h>
#include <TGCanvas.h>
#include <TGLayout.h>
#include <TGButton.h>
#include <TGSlider.h>
#include <TGLabel.h>

#include "TGLEditor.h"

ClassImp(TGLEditor)

class TGLMatView : public TGCompositeFrame {
private:
   TGLEditor *fOwner;
public:
   TGLMatView(const TGWindow *parent, Window_t wid, TGLEditor *owner);
   Bool_t HandleConfigureNotify(Event_t *event);
   Bool_t HandleExpose(Event_t *event);

private:
   TGLMatView(const TGLMatView &);
   TGLMatView & operator = (const TGLMatView &);
};

TGLMatView::TGLMatView(const TGWindow *parent, Window_t wid, TGLEditor *owner)
               :TGCompositeFrame(gClient, wid, parent), fOwner(owner)
{
}

Bool_t TGLMatView::HandleConfigureNotify(Event_t *event)
{
   return fOwner->HandleContainerNotify(event);
}

Bool_t TGLMatView::HandleExpose(Event_t *event)
{
   return fOwner->HandleContainerExpose(event);
}

enum EGLEditorIdent{
   kHSr,
   kHSg,
   kHSb,
   kHSa,
   kTBa
};

TGLEditor::TGLEditor(const TGWindow *parent, Int_t r, Int_t g, Int_t b, Int_t a)
               :TGCompositeFrame(parent, 100, 100, kVerticalFrame | kRaisedFrame),
                fRedSlider(0), fGreenSlider(0), fBlueSlider(0), fAlphaSlider(0),
                fApplyButton(0), fLayout(0), fLabelLayout(0),
                fIsActive(kFALSE), fRGBA(), fInfo()
{
   fRGBA[0] = r;
   fRGBA[1] = g;
   fRGBA[2] = b;
   fRGBA[3] = a;
   //////////////////////////////////////
   fViewCanvas = new TGCanvas(this, 120, 120, kSunkenFrame | kDoubleBorder);
   Window_t wid = fViewCanvas->GetViewPort()->GetId();
   fGLWin = gVirtualGL->CreateGLWindow(wid);
   fMatView = new TGLMatView(fViewCanvas->GetViewPort(), fGLWin, this);
   fCtx = gVirtualGL->CreateContext(fGLWin);
   fViewCanvas->SetContainer(fMatView);
   fViewLayout = new TGLayoutHints(kLHintsTop | kLHintsCenterX, 2, 2, 2, 2);
   AddFrame(fViewCanvas, fViewLayout);

   //sliders creation
   fRedSlider = new TGHSlider(this, 100, kSlider1 | kScaleBoth, kHSr);
   fRedSlider->Connect("PositionChanged(Int_t)", "TGLEditor", this, "DoSlider(Int_t)");
   fRedSlider->SetRange(0, 100);
   fRedSlider->SetPosition(fRGBA[0]);

   fGreenSlider = new TGHSlider(this, 100, kSlider1 | kScaleBoth, kHSg);
   fGreenSlider->Connect("PositionChanged(Int_t)", "TGLEditor", this, "DoSlider(Int_t)");
   fGreenSlider->SetRange(0, 100);
   fGreenSlider->SetPosition(fRGBA[1]);

   fBlueSlider = new TGHSlider(this, 100, kSlider1 | kScaleBoth, kHSb);
   fBlueSlider->Connect("PositionChanged(Int_t)", "TGLEditor", this, "DoSlider(Int_t)");
   fBlueSlider->SetRange(0, 100);
   fBlueSlider->SetPosition(fRGBA[2]);

   fAlphaSlider = new TGHSlider(this, 100, kSlider1 | kScaleBoth, kHSa);
   fAlphaSlider->Connect("PositionChanged(Int_t)", "TGLEditor", this, "DoSlider(Int_t)");
   fAlphaSlider->SetRange(0, 100);
   fAlphaSlider->SetPosition(fRGBA[3]);

   fInfo[0] = new TGLabel(this, "Red :");
   fInfo[1] = new TGLabel(this, "Green :");
   fInfo[2] = new TGLabel(this, "Blue :");
   fInfo[3] = new TGLabel(this, "Alpha :");
   fLabelLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 2, 2, 5);

   fLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 5, 2, 5, 10);
   AddFrame(fInfo[0], fLabelLayout);
   AddFrame(fRedSlider, fLayout);
   AddFrame(fInfo[1], fLabelLayout);
   AddFrame(fGreenSlider, fLayout);
   AddFrame(fInfo[2], fLabelLayout);
   AddFrame(fBlueSlider, fLayout);
   AddFrame(fInfo[3], fLabelLayout);
   AddFrame(fAlphaSlider, fLayout);

   //apply button creation
   fApplyButton = new TGTextButton(this, "Apply changes", kTBa);
   AddFrame(fApplyButton, fLayout);
   fApplyButton->SetState(kButtonDisabled);

   MakeCurrent();
   gVirtualGL->NewPRGL();
   gVirtualGL->FrustumGL(-0.5, 0.5, -0.5, 0.5, 1., 10.);
   gVirtualGL->LightModel(kLIGHT_MODEL_TWO_SIDE, kFALSE);
   gVirtualGL->EnableGL(kLIGHTING);
   gVirtualGL->EnableGL(kLIGHT0);
   gVirtualGL->EnableGL(kDEPTH_TEST);
   gVirtualGL->EnableGL(kCULL_FACE);
   gVirtualGL->CullFaceGL(kBACK);
   DrawSphere();
}

TGLEditor::~TGLEditor()
{
   gVirtualGL->DeleteContext(fCtx);
   delete fRedSlider;
   delete fGreenSlider;
   delete fBlueSlider;
   delete fAlphaSlider;
   delete fLayout;
   delete fLabelLayout;
   delete fViewCanvas;
   delete fViewLayout;
   delete fMatView;
}

void TGLEditor::SetRGBA(Color_t r, Color_t g, Color_t b, Color_t a)
{
   fIsActive = kTRUE;
   fRGBA[0] = r;
   fRGBA[1] = g;
   fRGBA[2] = b;
   fRGBA[3] = a;
   fRedSlider->SetPosition(fRGBA[0]);
   fGreenSlider->SetPosition(fRGBA[1]);
   fBlueSlider->SetPosition(fRGBA[2]);
   fAlphaSlider->SetPosition(fRGBA[3]);
   DrawSphere();
}

void TGLEditor::GetRGBA(Color_t &r, Color_t &g, Color_t &b, Color_t &a)const
{
   r = fRGBA[0];
   g = fRGBA[1];
   b = fRGBA[2];
   a = fRGBA[3];
}

void TGLEditor::DoSlider(Int_t val)
{
   TGSlider *frm = (TGSlider *)gTQSender;

   if(fApplyButton->GetState() == kButtonDisabled && fIsActive)
      fApplyButton->SetState(kButtonUp);

   if (frm) {
      switch (frm->WidgetId()) {
      case kHSr:
         fRGBA[0] = val;
         break;
      case kHSg:
         fRGBA[1] = val;
         break;
      case kHSb:
         fRGBA[2] = val;
         break;
      default:
         fRGBA[3] = val;
         break;
      }
      DrawSphere();
   }
}

Bool_t TGLEditor::HandleContainerNotify(Event_t *event)
{
   gVirtualX->ResizeWindow(fGLWin, event->fWidth, event->fHeight);
   DrawSphere();
   return kTRUE;
}

Bool_t TGLEditor::HandleContainerExpose(Event_t * /*event*/)
{
   DrawSphere();
   return kTRUE;
}

void TGLEditor::DrawSphere()const
{
   MakeCurrent();
   gVirtualGL->ClearGL(0);
   gVirtualGL->ViewportGL(0, 0, fMatView->GetWidth(), fMatView->GetHeight());
   gVirtualGL->NewMVGL();
   gVirtualGL->PushGLMatrix();
   gVirtualGL->TranslateGL(0., 0., -3.);
   gVirtualGL->DrawSphere((Color_t *)fRGBA);
   gVirtualGL->PopGLMatrix();
   Float_t ligPos[] = {0.f, 0.f, 0.f, 1.f};
   gVirtualGL->GLLight(kLIGHT0, kPOSITION, ligPos);
   SwapBuffers();
}

void TGLEditor::MakeCurrent()const
{
   gVirtualGL->MakeCurrent(fGLWin, fCtx);
}

void TGLEditor::SwapBuffers()const
{
   gVirtualGL->SwapBuffers(fGLWin);
}
<|endoftext|>


<commit_before>///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref core
/// @file glm/core/_detail.hpp
/// @date 2008-07-24 / 2011-06-14
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////

#ifndef glm_core_detail
#define glm_core_detail

#include "setup.hpp"
#include <cassert>

namespace glm{
namespace detail
{
	class thalf;

#if(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) // C99 detected, 64 bit types available
	typedef int64_t								sint64;
	typedef uint64_t							uint64;
#elif(GLM_COMPILER & GLM_COMPILER_VC)
	typedef signed __int64						sint64;
	typedef unsigned __int64					uint64;
#elif(GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_LLVM_GCC | GLM_COMPILER_CLANG))
	__extension__ typedef signed long long		sint64;
	__extension__ typedef unsigned long long	uint64;
#elif(GLM_COMPILER & GLM_COMPILER_BC)
	typedef Int64								sint64;
	typedef Uint64								uint64;
#else//unknown compiler
	typedef signed long	long					sint64;
	typedef unsigned long long					uint64;
#endif//GLM_COMPILER

	template<bool C>
	struct If
	{
		template<typename F, typename T>
		static GLM_FUNC_QUALIFIER T apply(F functor, const T& val)
		{
			return functor(val);
		}
	};

	template<>
	struct If<false>
	{
		template<typename F, typename T>
		static GLM_FUNC_QUALIFIER T apply(F, const T& val)
		{
			return val;
		}
	};

	//template <typename T>
	//struct traits
	//{
	//	static const bool is_signed = false;
	//	static const bool is_float = false;
	//	static const bool is_vector = false;
	//	static const bool is_matrix = false;
	//	static const bool is_genType = false;
	//	static const bool is_genIType = false;
	//	static const bool is_genUType = false;
	//};

	//template <>
	//struct traits<half>
	//{
	//	static const bool is_float = true;
	//	static const bool is_genType = true;
	//};

	//template <>
	//struct traits<float>
	//{
	//	static const bool is_float = true;
	//	static const bool is_genType = true;
	//};

	//template <>
	//struct traits<double>
	//{
	//	static const bool is_float = true;
	//	static const bool is_genType = true;
	//};

	//template <typename genType>
	//struct desc
	//{
	//	typedef genType							type;
	//	typedef genType *						pointer;
	//	typedef genType const*					const_pointer;
	//	typedef genType const *const			const_pointer_const;
	//	typedef genType *const					pointer_const;
	//	typedef genType &						reference;
	//	typedef genType const&					const_reference;
	//	typedef genType const&					param_type;

	//	typedef typename genType::value_type	value_type;
	//	typedef typename genType::size_type		size_type;
	//	static const typename size_type			value_size;
	//};

	//template <typename genType>
	//const typename desc<genType>::size_type desc<genType>::value_size = genType::value_size();

	union uif32
	{
		GLM_FUNC_QUALIFIER uif32() :
			i(0)
		{}

		GLM_FUNC_QUALIFIER uif32(float f) :
			f(f)
		{}

		GLM_FUNC_QUALIFIER uif32(unsigned int i) :
			i(i)
		{}

		float f;
		unsigned int i;
	};

	union uif64
	{
		GLM_FUNC_QUALIFIER uif64() :
			i(0)
		{}

		GLM_FUNC_QUALIFIER uif64(double f) :
			f(f)
		{}

		GLM_FUNC_QUALIFIER uif64(uint64 i) :
			i(i)
		{}

		double f;
		uint64 i;
	};

	typedef uif32 uif;

	//////////////////
	// int

	template <typename T>
	struct is_int
	{
		enum is_int_enum
		{
			_YES = 0,
			_NO = 1
		};
	};

#define GLM_DETAIL_IS_INT(T)	\
	template <>					\
	struct is_int<T>			\
	{							\
		enum is_int_enum		\
		{						\
			_YES = 1,			\
			_NO = 0				\
		};						\
	}

	//////////////////
	// uint

	template <typename T>
	struct is_uint
	{
		enum is_uint_enum
		{
			_YES = 0,
			_NO = 1
		};
	};

#define GLM_DETAIL_IS_UINT(T)	\
	template <>					\
	struct is_uint<T>			\
	{							\
		enum is_uint_enum		\
		{						\
			_YES = 1,			\
			_NO = 0				\
		};						\
	}

	//GLM_DETAIL_IS_UINT(unsigned long long)

	//////////////////
	// float

	template <typename T>
	struct is_float
	{
		enum is_float_enum
		{
			_YES = 0,
			_NO = 1
		};
	};

#define GLM_DETAIL_IS_FLOAT(T)	\
	template <>					\
	struct is_float<T>			\
	{							\
		enum is_float_enum		\
		{						\
			_YES = 1,			\
			_NO = 0				\
		};						\
	}

	//////////////////
	// bool

	template <typename T>
	struct is_bool
	{
		enum is_bool_enum
		{
			_YES = 0,
			_NO = 1
		};
	};

	template <>
	struct is_bool<bool>
	{
		enum is_bool_enum
		{
			_YES = 1,
			_NO = 0
		};
	};

	//////////////////
	// vector

	template <typename T>
	struct is_vector
	{
		enum is_vector_enum
		{
			_YES = 0,
			_NO = 1
		};
	};

#	define GLM_DETAIL_IS_VECTOR(TYPE) \
		template <typename T> \
		struct is_vector<TYPE<T> > \
		{ \
			enum is_vector_enum \
			{ \
				_YES = 1, \
				_NO = 0 \
			}; \
		}

	//////////////////
	// matrix

	template <typename T>
	struct is_matrix
	{
		enum is_matrix_enum
		{
			_YES = 0,
			_NO = 1
		};
	};

#define GLM_DETAIL_IS_MATRIX(T)	\
	template <>					\
	struct is_matrix			\
	{							\
		enum is_matrix_enum		\
		{						\
			_YES = 1,			\
			_NO = 0				\
		};						\
	}

	//////////////////
	// type

	template <typename T>
	struct type
	{
		enum type_enum
		{
			is_float = is_float<T>::_YES,
			is_int = is_int<T>::_YES,
			is_uint = is_uint<T>::_YES,
			is_bool = is_bool<T>::_YES
		};
	};

	//////////////////
	// type

	typedef signed char							int8;
	typedef signed short						int16;
	typedef signed int							int32;
	typedef detail::sint64						int64;

	typedef unsigned char						uint8;
	typedef unsigned short						uint16;
	typedef unsigned int						uint32;
	typedef detail::uint64						uint64;

	typedef detail::thalf						float16;
	typedef float								float32;
	typedef double								float64;

}//namespace detail
}//namespace glm

#if((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC2005))
#	define GLM_DEPRECATED __declspec(deprecated)
#	define GLM_ALIGN(x) __declspec(align(x))
#	define GLM_ALIGNED_STRUCT(x) __declspec(align(x)) struct
#	define GLM_RESTRICT __declspec(restrict)
#	define GLM_RESTRICT_VAR __restrict
#elif((GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_LLVM_GCC)) && (GLM_COMPILER >= GLM_COMPILER_GCC31))
#	define GLM_DEPRECATED __attribute__((__deprecated__))
#	define GLM_ALIGN(x) __attribute__((aligned(x)))
#	define GLM_ALIGNED_STRUCT(x) struct __attribute__((aligned(x)))
#	if(GLM_COMPILER >= GLM_COMPILER_GCC33)
#		define GLM_RESTRICT __restrict__
#		define GLM_RESTRICT_VAR __restrict__
#	else
#		define GLM_RESTRICT
#		define GLM_RESTRICT_VAR
#	endif
#	define GLM_RESTRICT __restrict__
#	define GLM_RESTRICT_VAR __restrict__
#else
#	define GLM_DEPRECATED
#	define GLM_ALIGN
#	define GLM_ALIGNED_STRUCT(x)
#	define GLM_RESTRICT
#	define GLM_RESTRICT_VAR
#endif//GLM_COMPILER

#endif//glm_core_detail
<commit_msg>Fixed cppcheck type<commit_after>///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref core
/// @file glm/core/_detail.hpp
/// @date 2008-07-24 / 2011-06-14
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////

#ifndef glm_core_detail
#define glm_core_detail

#include "setup.hpp"
#include <cassert>

namespace glm{
namespace detail
{
	class thalf;

#if(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) // C99 detected, 64 bit types available
	typedef int64_t								sint64;
	typedef uint64_t							uint64;
#elif(GLM_COMPILER & GLM_COMPILER_VC)
	typedef signed __int64						sint64;
	typedef unsigned __int64					uint64;
#elif(GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_LLVM_GCC | GLM_COMPILER_CLANG))
	__extension__ typedef signed long long		sint64;
	__extension__ typedef unsigned long long	uint64;
#elif(GLM_COMPILER & GLM_COMPILER_BC)
	typedef Int64								sint64;
	typedef Uint64								uint64;
#else//unknown compiler
	typedef signed long	long					sint64;
	typedef unsigned long long					uint64;
#endif//GLM_COMPILER

	template<bool C>
	struct If
	{
		template<typename F, typename T>
		static GLM_FUNC_QUALIFIER T apply(F functor, const T& val)
		{
			return functor(val);
		}
	};

	template<>
	struct If<false>
	{
		template<typename F, typename T>
		static GLM_FUNC_QUALIFIER T apply(F, const T& val)
		{
			return val;
		}
	};

	//template <typename T>
	//struct traits
	//{
	//	static const bool is_signed = false;
	//	static const bool is_float = false;
	//	static const bool is_vector = false;
	//	static const bool is_matrix = false;
	//	static const bool is_genType = false;
	//	static const bool is_genIType = false;
	//	static const bool is_genUType = false;
	//};

	//template <>
	//struct traits<half>
	//{
	//	static const bool is_float = true;
	//	static const bool is_genType = true;
	//};

	//template <>
	//struct traits<float>
	//{
	//	static const bool is_float = true;
	//	static const bool is_genType = true;
	//};

	//template <>
	//struct traits<double>
	//{
	//	static const bool is_float = true;
	//	static const bool is_genType = true;
	//};

	//template <typename genType>
	//struct desc
	//{
	//	typedef genType							type;
	//	typedef genType *						pointer;
	//	typedef genType const*					const_pointer;
	//	typedef genType const *const			const_pointer_const;
	//	typedef genType *const					pointer_const;
	//	typedef genType &						reference;
	//	typedef genType const&					const_reference;
	//	typedef genType const&					param_type;

	//	typedef typename genType::value_type	value_type;
	//	typedef typename genType::size_type		size_type;
	//	static const typename size_type			value_size;
	//};

	//template <typename genType>
	//const typename desc<genType>::size_type desc<genType>::value_size = genType::value_size();

	union uif32
	{
		GLM_FUNC_QUALIFIER uif32() :
			i(0)
		{}

		GLM_FUNC_QUALIFIER uif32(float f) :
			f(f)
		{}

		GLM_FUNC_QUALIFIER uif32(unsigned int i) :
			i(i)
		{}

		float f;
		unsigned int i;
	};

	union uif64
	{
		GLM_FUNC_QUALIFIER uif64() :
			i(0)
		{}

		GLM_FUNC_QUALIFIER uif64(double f) :
			f(f)
		{}

		GLM_FUNC_QUALIFIER uif64(uint64 i) :
			i(i)
		{}

		double f;
		uint64 i;
	};

	typedef uif32 uif;

	//////////////////
	// int

	template <typename T>
	struct is_int
	{
		enum is_int_enum
		{
			_YES = 0,
			_NO = 1
		};
	};

#define GLM_DETAIL_IS_INT(T)	\
	template <>					\
	struct is_int<T>			\
	{							\
		enum is_int_enum		\
		{						\
			_YES = 1,			\
			_NO = 0				\
		};						\
	}

	//////////////////
	// uint

	template <typename T>
	struct is_uint
	{
		enum is_uint_enum
		{
			_YES = 0,
			_NO = 1
		};
	};

#define GLM_DETAIL_IS_UINT(T)	\
	template <>					\
	struct is_uint<T>			\
	{							\
		enum is_uint_enum		\
		{						\
			_YES = 1,			\
			_NO = 0				\
		};						\
	}

	//GLM_DETAIL_IS_UINT(unsigned long long)

	//////////////////
	// float

	template <typename T>
	struct is_float
	{
		enum is_float_enum
		{
			_YES = 0,
			_NO = 1
		};
	};

#define GLM_DETAIL_IS_FLOAT(T)	\
	template <>					\
	struct is_float<T>			\
	{							\
		enum is_float_enum		\
		{						\
			_YES = 1,			\
			_NO = 0				\
		};						\
	}

	//////////////////
	// bool

	template <typename T>
	struct is_bool
	{
		enum is_bool_enum
		{
			_YES = 0,
			_NO = 1
		};
	};

	template <>
	struct is_bool<bool>
	{
		enum is_bool_enum
		{
			_YES = 1,
			_NO = 0
		};
	};

	//////////////////
	// vector

	template <typename T>
	struct is_vector
	{
		enum is_vector_enum
		{
			_YES = 0,
			_NO = 1
		};
	};

#	define GLM_DETAIL_IS_VECTOR(TYPE) \
		template <typename T> \
		struct is_vector<TYPE<T> > \
		{ \
			enum is_vector_enum \
			{ \
				_YES = 1, \
				_NO = 0 \
			}; \
		}

	//////////////////
	// matrix

	template <typename T>
	struct is_matrix
	{
		enum is_matrix_enum
		{
			_YES = 0,
			_NO = 1
		};
	};

#define GLM_DETAIL_IS_MATRIX(T)	\
	template <>					\
	struct is_matrix			\
	{							\
		enum is_matrix_enum		\
		{						\
			_YES = 1,			\
			_NO = 0				\
		};						\
	}

	//////////////////
	// type

	template <typename T>
	struct type
	{
		enum type_enum
		{
			is_float = is_float<T>::_YES,
			is_int = is_int<T>::_YES,
			is_uint = is_uint<T>::_YES,
			is_bool = is_bool<T>::_YES
		};
	};
}//namespace detail

	//////////////////
	// type

	typedef signed char							int8;
	typedef signed short						int16;
	typedef signed int							int32;
	typedef detail::sint64						int64;

	typedef unsigned char						uint8;
	typedef unsigned short						uint16;
	typedef unsigned int						uint32;
	typedef detail::uint64						uint64;

	typedef detail::thalf						float16;
	typedef float								float32;
	typedef double								float64;

}//namespace glm

#if((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC2005))
#	define GLM_DEPRECATED __declspec(deprecated)
#	define GLM_ALIGN(x) __declspec(align(x))
#	define GLM_ALIGNED_STRUCT(x) __declspec(align(x)) struct
#	define GLM_RESTRICT __declspec(restrict)
#	define GLM_RESTRICT_VAR __restrict
#elif((GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_LLVM_GCC)) && (GLM_COMPILER >= GLM_COMPILER_GCC31))
#	define GLM_DEPRECATED __attribute__((__deprecated__))
#	define GLM_ALIGN(x) __attribute__((aligned(x)))
#	define GLM_ALIGNED_STRUCT(x) struct __attribute__((aligned(x)))
#	if(GLM_COMPILER >= GLM_COMPILER_GCC33)
#		define GLM_RESTRICT __restrict__
#		define GLM_RESTRICT_VAR __restrict__
#	else
#		define GLM_RESTRICT
#		define GLM_RESTRICT_VAR
#	endif
#	define GLM_RESTRICT __restrict__
#	define GLM_RESTRICT_VAR __restrict__
#else
#	define GLM_DEPRECATED
#	define GLM_ALIGN
#	define GLM_ALIGNED_STRUCT(x)
#	define GLM_RESTRICT
#	define GLM_RESTRICT_VAR
#endif//GLM_COMPILER

#endif//glm_core_detail
<|endoftext|>