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

#include <iostream>
#include <string>
#include <vector>
#include <exception>
#include <fstream>
#include <iomanip>
#include <limits>
#include <ctime>

#include <ArgumentList.hpp>
#include <Observation.hpp>
#include <utils.hpp>
#include <Bins.hpp>

typedef float dataType;
std::string typeName("float");

int main(int argc, char *argv[]) {
  bool print = false;
	AstroData::Observation observation;

	try {
    isa::utils::ArgumentList args(argc, argv);
    print = args.getSwitch("-print");
    observation.setPadding(1);
    observation.setNrSeconds(args.getSwitchArgument< unsigned int >("-seconds"));
    observation.setNrSamplesPerSecond(args.getSwitchArgument< unsigned int >("-samples"));
    observation.setDMRange(args.getSwitchArgument< unsigned int >("-dms"), 0.0, 0.0);
    observation.setPeriodRange(args.getSwitchArgument< unsigned int >("-periods"), args.getSwitchArgument< unsigned int >("-first_period"), args.getSwitchArgument< unsigned int >("-period_step"));
    observation.setNrBins(args.getSwitchArgument< unsigned int >("-bins"));
	} catch  ( isa::utils::SwitchNotFound &err ) {
    std::cerr << err.what() << std::endl;
    return 1;
  }catch ( std::exception &err ) {
    std::cerr << "Usage: " << argv[0] << " [-print] -seconds ... -samples ... -dms ... -periods ... -bins ... -first_period ... -period_step ..." << std::endl;
		return 1;
	}

  std::vector< unsigned int > * samplesPerBin = PulsarSearch::getSamplesPerBin(observation);

  // Allocate memory
  std::vector< std::vector< unsigned int > > sequentialMap(observation.getNrSeconds());
  std::vector< std::vector< unsigned int > > parallelMap(observation.getNrSeconds());
  for ( unsigned int second = 0; second < observation.getNrSeconds(); second++ ) {
    sequentialMap[second] = std::vector< unsigned int >(observation.getNrDMs() * observation.getNrPeriods() * observation.getNrSamplesPerSecond());
    parallelMap[second] = std::vector< unsigned int >(observation.getNrDMs() * observation.getNrPeriods() * observation.getNrSamplesPerSecond());
  }
  std::vector< unsigned int > parallelCounter(observation.getNrDMs() * observation.getNrPeriods() * observation.getNrBins());

  std::fill(parallelCounter.begin(), parallelCounter.end(), 0);

  // Sequential
  for ( unsigned int dm = 0; dm < observation.getNrDMs(); dm++ ) {
    for ( unsigned int period = 0; period < observation.getNrPeriods(); period++ ) {
      const unsigned int periodValue = observation.getFirstPeriod() + (period * observation.getPeriodStep());

      for ( unsigned int second = 0; second < observation.getNrSeconds(); second++ ) {
        for ( unsigned int sample = 0; sample < observation.getNrSamplesPerSecond(); sample++ ) {
          const unsigned int globalSample = (second * observation.getNrSamplesPerSecond()) + sample;
          const float phase = (globalSample / static_cast< float >(periodValue)) - (globalSample / periodValue);
          const unsigned int bin = static_cast< unsigned int >(phase * static_cast< float >(observation.getNrBins()));

          sequentialMap[second][(dm * observation.getNrPeriods() * observation.getNrSamplesPerSecond()) + (period * observation.getNrSamplesPerSecond()) + sample] = bin;
        }
      }
    }
  }

  // Parallel
  for ( unsigned int second = 0; second < observation.getNrSeconds(); second++ ) {
    for ( unsigned int period = 0; period < observation.getNrPeriods(); period++ ) {
      const unsigned int periodValue = observation.getFirstPeriod() + (period * observation.getPeriodStep());

      for ( unsigned int bin = 0; bin < observation.getNrBins(); bin++ ) {
        for ( unsigned int dm = 0; dm < observation.getNrDMs(); dm++ ) {
          unsigned int sample = samplesPerBin->at((period * observation.getNrBins() * isa::utils::pad(2, observation.getPadding())) + (bin * isa::utils::pad(2, observation.getPadding())) + 1) + ((parallelCounter[(dm * observation.getNrPeriods() * observation.getNrBins()) + (period * observation.getNrBins()) + bin] / samplesPerBin->at((period * observation.getNrBins() * isa::utils::pad(2, observation.getPadding())) + (bin * isa::utils::pad(2, observation.getPadding())))) * periodValue) + (parallelCounter[(dm * observation.getNrPeriods() * observation.getNrBins()) + (period * observation.getNrBins()) + bin] % samplesPerBin->at((period * observation.getNrBins() * isa::utils::pad(2, observation.getPadding())) + (bin * isa::utils::pad(2, observation.getPadding()))));

          if ( (sample / observation.getNrSamplesPerSecond()) == second ) {
            sample %= observation.getNrSamplesPerSecond();
          }
          while ( sample < observation.getNrSamplesPerSecond() ) {
            parallelMap[second][(dm * observation.getNrPeriods() * observation.getNrSamplesPerSecond()) + (period * observation.getNrSamplesPerSecond()) + sample] = bin;
            parallelCounter[(dm * observation.getNrPeriods() * observation.getNrBins()) + (period * observation.getNrBins()) + bin] += 1;
            if ( parallelCounter[(dm * observation.getNrPeriods() * observation.getNrBins()) + (period * observation.getNrBins()) + bin] % samplesPerBin->at((period * observation.getNrBins() * isa::utils::pad(2, observation.getPadding())) + (bin * isa::utils::pad(2, observation.getPadding()))) == 0 ) {
              sample += periodValue - (samplesPerBin->at((period * observation.getNrBins() * isa::utils::pad(2, observation.getPadding())) + (bin * isa::utils::pad(2, observation.getPadding()))) - 1);
            } else {
              sample++;
            }
          }
        }
      }
    }
  }

  for ( unsigned int dm = 0; dm < observation.getNrDMs(); dm++ ) {
    for ( unsigned int period = 0; period < observation.getNrPeriods(); period++ ) {
      for ( unsigned int second = 0; second < observation.getNrSeconds(); second++ ) {
        for ( unsigned int sample = 0; sample < observation.getNrSamplesPerSecond(); sample++ ) {
          if ( sequentialMap[second][(dm * observation.getNrPeriods() * observation.getNrSamplesPerSecond()) + (period * observation.getNrSamplesPerSecond()) + sample] != parallelMap[second][(dm * observation.getNrPeriods() * observation.getNrSamplesPerSecond()) + (period * observation.getNrSamplesPerSecond()) + sample] ) {
            std::cout << "DM: " << dm << ", ";
            std::cout << "Period: " << period << ", ";
            std::cout << "Second: " << second << ", ";
            std::cout << "Sample: " << sample << ", ";
            std::cout << "Bin (seq): " << sequentialMap[second][(dm * observation.getNrPeriods() * observation.getNrSamplesPerSecond()) + (period * observation.getNrSamplesPerSecond()) + sample] << ", ";
            std::cout << "Bin (par): " << parallelMap[second][(dm * observation.getNrPeriods() * observation.getNrSamplesPerSecond()) + (period * observation.getNrSamplesPerSecond()) + sample] << std::endl;
          } else if ( print ) {
            std::cout << "DM: " << dm << ", ";
            std::cout << "Period: " << period << ", ";
            std::cout << "Second: " << second << ", ";
            std::cout << "Sample: " << sample << ", ";
            std::cout << "Bin (seq): " << sequentialMap[second][(dm * observation.getNrPeriods() * observation.getNrSamplesPerSecond()) + (period * observation.getNrSamplesPerSecond()) + sample] << ", ";
            std::cout << "Bin (par): " << parallelMap[second][(dm * observation.getNrPeriods() * observation.getNrSamplesPerSecond()) + (period * observation.getNrSamplesPerSecond()) + sample] << std::endl;
          }
        }
      }
    }
  }

	return 0;
}

<commit_msg>Using two separate counters, like in OpenCL code. A bug may lie there.<commit_after>// Copyright 2014 Alessio Sclocco <a.sclocco@vu.nl>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <iostream>
#include <string>
#include <vector>
#include <exception>
#include <fstream>
#include <iomanip>
#include <limits>
#include <ctime>

#include <ArgumentList.hpp>
#include <Observation.hpp>
#include <utils.hpp>
#include <Bins.hpp>

typedef float dataType;
std::string typeName("float");

int main(int argc, char *argv[]) {
  bool print = false;
	AstroData::Observation observation;

	try {
    isa::utils::ArgumentList args(argc, argv);
    print = args.getSwitch("-print");
    observation.setPadding(1);
    observation.setNrSeconds(args.getSwitchArgument< unsigned int >("-seconds"));
    observation.setNrSamplesPerSecond(args.getSwitchArgument< unsigned int >("-samples"));
    observation.setDMRange(args.getSwitchArgument< unsigned int >("-dms"), 0.0, 0.0);
    observation.setPeriodRange(args.getSwitchArgument< unsigned int >("-periods"), args.getSwitchArgument< unsigned int >("-first_period"), args.getSwitchArgument< unsigned int >("-period_step"));
    observation.setNrBins(args.getSwitchArgument< unsigned int >("-bins"));
	} catch  ( isa::utils::SwitchNotFound &err ) {
    std::cerr << err.what() << std::endl;
    return 1;
  }catch ( std::exception &err ) {
    std::cerr << "Usage: " << argv[0] << " [-print] -seconds ... -samples ... -dms ... -periods ... -bins ... -first_period ... -period_step ..." << std::endl;
		return 1;
	}

  std::vector< unsigned int > * samplesPerBin = PulsarSearch::getSamplesPerBin(observation);

  // Allocate memory
  std::vector< std::vector< unsigned int > > sequentialMap(observation.getNrSeconds());
  std::vector< std::vector< unsigned int > > parallelMap(observation.getNrSeconds());
  for ( unsigned int second = 0; second < observation.getNrSeconds(); second++ ) {
    sequentialMap[second] = std::vector< unsigned int >(observation.getNrDMs() * observation.getNrPeriods() * observation.getNrSamplesPerSecond());
    parallelMap[second] = std::vector< unsigned int >(observation.getNrDMs() * observation.getNrPeriods() * observation.getNrSamplesPerSecond());
  }
  std::vector< unsigned int > parallelCounter0(observation.getNrPeriods() * observation.getNrBins());
  std::vector< unsigned int > parallelCounter1(observation.getNrPeriods() * observation.getNrBins());

  std::fill(parallelCounter0.begin(), parallelCounter0.end(), 0);
  std::fill(parallelCounter1.begin(), parallelCounter1.end(), 0);

  // Sequential
  for ( unsigned int dm = 0; dm < observation.getNrDMs(); dm++ ) {
    for ( unsigned int period = 0; period < observation.getNrPeriods(); period++ ) {
      const unsigned int periodValue = observation.getFirstPeriod() + (period * observation.getPeriodStep());

      for ( unsigned int second = 0; second < observation.getNrSeconds(); second++ ) {
        for ( unsigned int sample = 0; sample < observation.getNrSamplesPerSecond(); sample++ ) {
          const unsigned int globalSample = (second * observation.getNrSamplesPerSecond()) + sample;
          const float phase = (globalSample / static_cast< float >(periodValue)) - (globalSample / periodValue);
          const unsigned int bin = static_cast< unsigned int >(phase * static_cast< float >(observation.getNrBins()));

          sequentialMap[second][(dm * observation.getNrPeriods() * observation.getNrSamplesPerSecond()) + (period * observation.getNrSamplesPerSecond()) + sample] = bin;
        }
      }
    }
  }

  // Parallel
  for ( unsigned int second = 0; second < observation.getNrSeconds(); second++ ) {
    for ( unsigned int period = 0; period < observation.getNrPeriods(); period++ ) {
      const unsigned int periodValue = observation.getFirstPeriod() + (period * observation.getPeriodStep());

      for ( unsigned int bin = 0; bin < observation.getNrBins(); bin++ ) {
        for ( unsigned int dm = 0; dm < observation.getNrDMs(); dm++ ) {
          unsigned int sample = 0;

          if ( second % 2 == 0 ) {
            sample = samplesPerBin->at((period * observation.getNrBins() * isa::utils::pad(2, observation.getPadding())) + (bin * isa::utils::pad(2, observation.getPadding())) + 1) + ((parallelCounter0[(dm * observation.getNrPeriods() * observation.getNrBins()) + (period * observation.getNrBins()) + bin] / samplesPerBin->at((period * observation.getNrBins() * isa::utils::pad(2, observation.getPadding())) + (bin * isa::utils::pad(2, observation.getPadding())))) * periodValue) + (parallelCounter0[(dm * observation.getNrPeriods() * observation.getNrBins()) + (period * observation.getNrBins()) + bin] % samplesPerBin->at((period * observation.getNrBins() * isa::utils::pad(2, observation.getPadding())) + (bin * isa::utils::pad(2, observation.getPadding()))));
          } else {
            sample = samplesPerBin->at((period * observation.getNrBins() * isa::utils::pad(2, observation.getPadding())) + (bin * isa::utils::pad(2, observation.getPadding())) + 1) + ((parallelCounter1[(dm * observation.getNrPeriods() * observation.getNrBins()) + (period * observation.getNrBins()) + bin] / samplesPerBin->at((period * observation.getNrBins() * isa::utils::pad(2, observation.getPadding())) + (bin * isa::utils::pad(2, observation.getPadding())))) * periodValue) + (parallelCounter1[(dm * observation.getNrPeriods() * observation.getNrBins()) + (period * observation.getNrBins()) + bin] % samplesPerBin->at((period * observation.getNrBins() * isa::utils::pad(2, observation.getPadding())) + (bin * isa::utils::pad(2, observation.getPadding()))));
          }

          if ( (sample / observation.getNrSamplesPerSecond()) == second ) {
            sample %= observation.getNrSamplesPerSecond();
          }
          while ( sample < observation.getNrSamplesPerSecond() ) {
            parallelMap[second][(dm * observation.getNrPeriods() * observation.getNrSamplesPerSecond()) + (period * observation.getNrSamplesPerSecond()) + sample] = bin;
            if ( second % 2 == 0 ) {
              parallelCounter1[(dm * observation.getNrPeriods() * observation.getNrBins()) + (period * observation.getNrBins()) + bin] += 1;
              if ( parallelCounter1[(dm * observation.getNrPeriods() * observation.getNrBins()) + (period * observation.getNrBins()) + bin] % samplesPerBin->at((period * observation.getNrBins() * isa::utils::pad(2, observation.getPadding())) + (bin * isa::utils::pad(2, observation.getPadding()))) == 0 ) {
                sample += periodValue - (samplesPerBin->at((period * observation.getNrBins() * isa::utils::pad(2, observation.getPadding())) + (bin * isa::utils::pad(2, observation.getPadding()))) - 1);
              } else {
                sample++;
              }
            } else {
              parallelCounter0[(dm * observation.getNrPeriods() * observation.getNrBins()) + (period * observation.getNrBins()) + bin] += 1;
              if ( parallelCounter0[(dm * observation.getNrPeriods() * observation.getNrBins()) + (period * observation.getNrBins()) + bin] % samplesPerBin->at((period * observation.getNrBins() * isa::utils::pad(2, observation.getPadding())) + (bin * isa::utils::pad(2, observation.getPadding()))) == 0 ) {
                sample += periodValue - (samplesPerBin->at((period * observation.getNrBins() * isa::utils::pad(2, observation.getPadding())) + (bin * isa::utils::pad(2, observation.getPadding()))) - 1);
              } else {
                sample++;
              }
            }
          }
        }
      }
    }
  }

  for ( unsigned int dm = 0; dm < observation.getNrDMs(); dm++ ) {
    for ( unsigned int period = 0; period < observation.getNrPeriods(); period++ ) {
      for ( unsigned int second = 0; second < observation.getNrSeconds(); second++ ) {
        for ( unsigned int sample = 0; sample < observation.getNrSamplesPerSecond(); sample++ ) {
          if ( sequentialMap[second][(dm * observation.getNrPeriods() * observation.getNrSamplesPerSecond()) + (period * observation.getNrSamplesPerSecond()) + sample] != parallelMap[second][(dm * observation.getNrPeriods() * observation.getNrSamplesPerSecond()) + (period * observation.getNrSamplesPerSecond()) + sample] ) {
            std::cout << "DM: " << dm << ", ";
            std::cout << "Period: " << period << ", ";
            std::cout << "Second: " << second << ", ";
            std::cout << "Sample: " << sample << ", ";
            std::cout << "Bin (seq): " << sequentialMap[second][(dm * observation.getNrPeriods() * observation.getNrSamplesPerSecond()) + (period * observation.getNrSamplesPerSecond()) + sample] << ", ";
            std::cout << "Bin (par): " << parallelMap[second][(dm * observation.getNrPeriods() * observation.getNrSamplesPerSecond()) + (period * observation.getNrSamplesPerSecond()) + sample] << std::endl;
          } else if ( print ) {
            std::cout << "DM: " << dm << ", ";
            std::cout << "Period: " << period << ", ";
            std::cout << "Second: " << second << ", ";
            std::cout << "Sample: " << sample << ", ";
            std::cout << "Bin (seq): " << sequentialMap[second][(dm * observation.getNrPeriods() * observation.getNrSamplesPerSecond()) + (period * observation.getNrSamplesPerSecond()) + sample] << ", ";
            std::cout << "Bin (par): " << parallelMap[second][(dm * observation.getNrPeriods() * observation.getNrSamplesPerSecond()) + (period * observation.getNrSamplesPerSecond()) + sample] << std::endl;
          }
        }
      }
    }
  }

	return 0;
}

<|endoftext|>


<commit_before>/***********************************************************************
 *    filename:   NamedElement.cpp
 *    created:    30/10/2011
 *    author:     Martin Preisler
 *************************************************************************/
/***************************************************************************
 *   Copyright (C) 2004 - 2011 Paul D Turner & The CEGUI Development Team
 *
 *   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 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.
 ***************************************************************************/

#include "CEGUI/NamedElement.h"

#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE(NamedElement)

BOOST_AUTO_TEST_CASE(Children)
{
    CEGUI::NamedElement* root = new CEGUI::NamedElement("root");
    BOOST_CHECK_EQUAL(root->getName(), "root");
    BOOST_CHECK_EQUAL(root->getProperty("Name"), "root");
    CEGUI::NamedElement* child1 = new CEGUI::NamedElement("child");
    CEGUI::NamedElement* child2 = new CEGUI::NamedElement("child");
    root->addChild(child1);
    BOOST_CHECK_THROW(root->addChild(child2), CEGUI::AlreadyExistsException);
    root->removeChild(child1);
    BOOST_CHECK_THROW(root->removeChild("child"), CEGUI::UnknownObjectException);
    root->addChild(child2);
    BOOST_CHECK_THROW(root->addChild(child1), CEGUI::AlreadyExistsException);

    delete child2;
    delete child1;
    delete root;
}

BOOST_AUTO_TEST_CASE(NamePath)
{
    CEGUI::NamedElement* root = new CEGUI::NamedElement("root");
    CEGUI::NamedElement* child = new CEGUI::NamedElement("child");
    CEGUI::NamedElement* inner_child = new CEGUI::NamedElement("inner_child");
    root->addChild(child);
    child->addChild(inner_child);

    BOOST_CHECK_EQUAL(child->getNamePath(), "root/child");
    BOOST_CHECK_EQUAL(child->getProperty("NamePath"), "root/child");
    BOOST_CHECK_EQUAL(inner_child->getNamePath(), "root/child/inner_child");

    BOOST_CHECK_EQUAL(root->getChildElement("child"), child);
    BOOST_CHECK_EQUAL(root->getChildElement("child/inner_child"), inner_child);
    BOOST_CHECK_EQUAL(child->getChildElement("inner_child"), inner_child);
    BOOST_CHECK_THROW(child->getChildElement("nonexistant"), CEGUI::UnknownObjectException);

    delete inner_child;
    delete child;
    delete root;
}

BOOST_AUTO_TEST_SUITE_END()
<commit_msg>Test string removeChild in NamedElement tests<commit_after>/***********************************************************************
 *    filename:   NamedElement.cpp
 *    created:    30/10/2011
 *    author:     Martin Preisler
 *************************************************************************/
/***************************************************************************
 *   Copyright (C) 2004 - 2011 Paul D Turner & The CEGUI Development Team
 *
 *   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 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.
 ***************************************************************************/

#include "CEGUI/NamedElement.h"

#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE(NamedElement)

BOOST_AUTO_TEST_CASE(Children)
{
    CEGUI::NamedElement* root = new CEGUI::NamedElement("root");
    BOOST_CHECK_EQUAL(root->getName(), "root");
    BOOST_CHECK_EQUAL(root->getProperty("Name"), "root");
    CEGUI::NamedElement* child1 = new CEGUI::NamedElement("child");
    CEGUI::NamedElement* child2 = new CEGUI::NamedElement("child");
    root->addChild(child1);
    BOOST_CHECK_THROW(root->addChild(child2), CEGUI::AlreadyExistsException);
    root->removeChild("child");
    BOOST_CHECK_THROW(root->removeChild("child"), CEGUI::UnknownObjectException);
    root->addChild(child2);
    BOOST_CHECK_THROW(root->addChild(child1), CEGUI::AlreadyExistsException);

    delete child2;
    delete child1;
    delete root;
}

BOOST_AUTO_TEST_CASE(NamePath)
{
    CEGUI::NamedElement* root = new CEGUI::NamedElement("root");
    CEGUI::NamedElement* child = new CEGUI::NamedElement("child");
    CEGUI::NamedElement* inner_child = new CEGUI::NamedElement("inner_child");
    root->addChild(child);
    child->addChild(inner_child);

    BOOST_CHECK_EQUAL(child->getNamePath(), "root/child");
    BOOST_CHECK_EQUAL(child->getProperty("NamePath"), "root/child");
    BOOST_CHECK_EQUAL(inner_child->getNamePath(), "root/child/inner_child");

    BOOST_CHECK_EQUAL(root->getChildElement("child"), child);
    BOOST_CHECK_EQUAL(root->getChildElement("child/inner_child"), inner_child);
    BOOST_CHECK_EQUAL(child->getChildElement("inner_child"), inner_child);
    BOOST_CHECK_THROW(child->getChildElement("nonexistant"), CEGUI::UnknownObjectException);

    delete inner_child;
    delete child;
    delete root;
}

BOOST_AUTO_TEST_SUITE_END()
<|endoftext|>


<commit_before>/*
 * Copyright 2014 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkPaint.h"
#include "SkPoint.h"
#include "SkTextBlob.h"

#include "Test.h"

class TextBlobTester {
public:
    // This unit test feeds an SkTextBlobBuilder various runs then checks to see if
    // the result contains the provided data and merges runs when appropriate.
    static void TestBuilder(skiatest::Reporter* reporter) {
        SkTextBlobBuilder builder;

        // empty run set
        RunBuilderTest(reporter, builder, nullptr, 0, nullptr, 0);

        RunDef set1[] = {
            { 128, SkTextBlob::kDefault_Positioning, 100, 100 },
        };
        RunBuilderTest(reporter, builder, set1, SK_ARRAY_COUNT(set1), set1, SK_ARRAY_COUNT(set1));

        RunDef set2[] = {
            { 128, SkTextBlob::kHorizontal_Positioning, 100, 100 },
        };
        RunBuilderTest(reporter, builder, set2, SK_ARRAY_COUNT(set2), set2, SK_ARRAY_COUNT(set2));

        RunDef set3[] = {
            { 128, SkTextBlob::kFull_Positioning, 100, 100 },
        };
        RunBuilderTest(reporter, builder, set3, SK_ARRAY_COUNT(set3), set3, SK_ARRAY_COUNT(set3));

        RunDef set4[] = {
            { 128, SkTextBlob::kDefault_Positioning, 100, 150 },
            { 128, SkTextBlob::kDefault_Positioning, 100, 150 },
            { 128, SkTextBlob::kDefault_Positioning, 100, 150 },
        };
        RunBuilderTest(reporter, builder, set4, SK_ARRAY_COUNT(set4), set4, SK_ARRAY_COUNT(set4));

        RunDef set5[] = {
            { 128, SkTextBlob::kHorizontal_Positioning, 100, 150 },
            { 128, SkTextBlob::kHorizontal_Positioning, 200, 150 },
            { 128, SkTextBlob::kHorizontal_Positioning, 300, 250 },
        };
        RunDef mergedSet5[] = {
            { 256, SkTextBlob::kHorizontal_Positioning, 0, 150 },
            { 128, SkTextBlob::kHorizontal_Positioning, 0, 250 },
        };
        RunBuilderTest(reporter, builder, set5, SK_ARRAY_COUNT(set5), mergedSet5,
                       SK_ARRAY_COUNT(mergedSet5));

        RunDef set6[] = {
            { 128, SkTextBlob::kFull_Positioning, 100, 100 },
            { 128, SkTextBlob::kFull_Positioning, 200, 200 },
            { 128, SkTextBlob::kFull_Positioning, 300, 300 },
        };
        RunDef mergedSet6[] = {
            { 384, SkTextBlob::kFull_Positioning, 0, 0 },
        };
        RunBuilderTest(reporter, builder, set6, SK_ARRAY_COUNT(set6), mergedSet6,
                       SK_ARRAY_COUNT(mergedSet6));

        RunDef set7[] = {
            { 128, SkTextBlob::kDefault_Positioning, 100, 150 },
            { 128, SkTextBlob::kDefault_Positioning, 100, 150 },
            { 128, SkTextBlob::kHorizontal_Positioning, 100, 150 },
            { 128, SkTextBlob::kHorizontal_Positioning, 200, 150 },
            { 128, SkTextBlob::kFull_Positioning, 400, 350 },
            { 128, SkTextBlob::kFull_Positioning, 400, 350 },
            { 128, SkTextBlob::kDefault_Positioning, 100, 450 },
            { 128, SkTextBlob::kDefault_Positioning, 100, 450 },
            { 128, SkTextBlob::kHorizontal_Positioning, 100, 550 },
            { 128, SkTextBlob::kHorizontal_Positioning, 200, 650 },
            { 128, SkTextBlob::kFull_Positioning, 400, 750 },
            { 128, SkTextBlob::kFull_Positioning, 400, 850 },
        };
        RunDef mergedSet7[] = {
            { 128, SkTextBlob::kDefault_Positioning, 100, 150 },
            { 128, SkTextBlob::kDefault_Positioning, 100, 150 },
            { 256, SkTextBlob::kHorizontal_Positioning, 0, 150 },
            { 256, SkTextBlob::kFull_Positioning, 0, 0 },
            { 128, SkTextBlob::kDefault_Positioning, 100, 450 },
            { 128, SkTextBlob::kDefault_Positioning, 100, 450 },
            { 128, SkTextBlob::kHorizontal_Positioning, 0, 550 },
            { 128, SkTextBlob::kHorizontal_Positioning, 0, 650 },
            { 256, SkTextBlob::kFull_Positioning, 0, 0 },
        };
        RunBuilderTest(reporter, builder, set7, SK_ARRAY_COUNT(set7), mergedSet7,
                       SK_ARRAY_COUNT(mergedSet7));
    }

    // This unit test verifies blob bounds computation.
    static void TestBounds(skiatest::Reporter* reporter) {
        SkTextBlobBuilder builder;
        SkPaint font;
        font.setTextEncoding(SkPaint::kGlyphID_TextEncoding);

        // Explicit bounds.
        {
            SkAutoTUnref<const SkTextBlob> blob(builder.build());
            REPORTER_ASSERT(reporter, blob->bounds().isEmpty());
        }

        {
            SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20);
            builder.allocRun(font, 16, 0, 0, &r1);
            SkAutoTUnref<const SkTextBlob> blob(builder.build());
            REPORTER_ASSERT(reporter, blob->bounds() == r1);
        }

        {
            SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20);
            builder.allocRunPosH(font, 16, 0, &r1);
            SkAutoTUnref<const SkTextBlob> blob(builder.build());
            REPORTER_ASSERT(reporter, blob->bounds() == r1);
        }

        {
            SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20);
            builder.allocRunPos(font, 16, &r1);
            SkAutoTUnref<const SkTextBlob> blob(builder.build());
            REPORTER_ASSERT(reporter, blob->bounds() == r1);
        }

        {
            SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20);
            SkRect r2 = SkRect::MakeXYWH(15, 20, 50, 50);
            SkRect r3 = SkRect::MakeXYWH(0, 5, 10, 5);

            builder.allocRun(font, 16, 0, 0, &r1);
            builder.allocRunPosH(font, 16, 0, &r2);
            builder.allocRunPos(font, 16, &r3);

            SkAutoTUnref<const SkTextBlob> blob(builder.build());
            REPORTER_ASSERT(reporter, blob->bounds() == SkRect::MakeXYWH(0, 5, 65, 65));
        }

        {
            // Verify empty blob bounds after building some non-empty blobs.
            SkAutoTUnref<const SkTextBlob> blob(builder.build());
            REPORTER_ASSERT(reporter, blob->bounds().isEmpty());
        }

        // Implicit bounds

        {
            // Exercise the empty bounds path, and ensure that RunRecord-aligned pos buffers
            // don't trigger asserts (http://crbug.com/542643).
            SkPaint p;
            p.setTextSize(0);
            p.setTextEncoding(SkPaint::kGlyphID_TextEncoding);

            const char* txt = "BOOO";
            const size_t len = strlen(txt);
            const SkTextBlobBuilder::RunBuffer& buffer = builder.allocRunPos(p, (int)len);
            p.textToGlyphs(txt, len, buffer.glyphs);
            memset(buffer.pos, 0, sizeof(SkScalar) * len * 2);
            SkAutoTUnref<const SkTextBlob> blob(builder.build());
            REPORTER_ASSERT(reporter, blob->bounds().isEmpty());
        }
    }

private:
    struct RunDef {
        unsigned                     count;
        SkTextBlob::GlyphPositioning pos;
        SkScalar                     x, y;
    };

    static void RunBuilderTest(skiatest::Reporter* reporter, SkTextBlobBuilder& builder,
                               const RunDef in[], unsigned inCount,
                               const RunDef out[], unsigned outCount) {
        SkPaint font;
        font.setTextEncoding(SkPaint::kGlyphID_TextEncoding);

        unsigned glyphCount = 0;
        unsigned posCount = 0;

        for (unsigned i = 0; i < inCount; ++i) {
            AddRun(font, in[i].count, in[i].pos, SkPoint::Make(in[i].x, in[i].y), builder);
            glyphCount += in[i].count;
            posCount += in[i].count * in[i].pos;
        }

        SkAutoTUnref<const SkTextBlob> blob(builder.build());

        SkTextBlob::RunIterator it(blob);
        for (unsigned i = 0; i < outCount; ++i) {
            REPORTER_ASSERT(reporter, !it.done());
            REPORTER_ASSERT(reporter, out[i].pos == it.positioning());
            REPORTER_ASSERT(reporter, out[i].count == it.glyphCount());
            if (SkTextBlob::kDefault_Positioning == out[i].pos) {
                REPORTER_ASSERT(reporter, out[i].x == it.offset().x());
                REPORTER_ASSERT(reporter, out[i].y == it.offset().y());
            } else if (SkTextBlob::kHorizontal_Positioning == out[i].pos) {
                REPORTER_ASSERT(reporter, out[i].y == it.offset().y());
            }

            for (unsigned k = 0; k < it.glyphCount(); ++k) {
                REPORTER_ASSERT(reporter, k % 128 == it.glyphs()[k]);
                if (SkTextBlob::kHorizontal_Positioning == it.positioning()) {
                    REPORTER_ASSERT(reporter, SkIntToScalar(k % 128) == it.pos()[k]);
                } else if (SkTextBlob::kFull_Positioning == it.positioning()) {
                    REPORTER_ASSERT(reporter, SkIntToScalar(k % 128) == it.pos()[k * 2]);
                    REPORTER_ASSERT(reporter, -SkIntToScalar(k % 128) == it.pos()[k * 2 + 1]);
                }
            }

            it.next();
        }

        REPORTER_ASSERT(reporter, it.done());
    }

    static void AddRun(const SkPaint& font, int count, SkTextBlob::GlyphPositioning pos,
                       const SkPoint& offset, SkTextBlobBuilder& builder,
                       const SkRect* bounds = nullptr) {
        switch (pos) {
        case SkTextBlob::kDefault_Positioning: {
            const SkTextBlobBuilder::RunBuffer& rb = builder.allocRun(font, count, offset.x(),
                                                                      offset.y(), bounds);
            for (int i = 0; i < count; ++i) {
                rb.glyphs[i] = i;
            }
        } break;
        case SkTextBlob::kHorizontal_Positioning: {
            const SkTextBlobBuilder::RunBuffer& rb = builder.allocRunPosH(font, count, offset.y(),
                                                                          bounds);
            for (int i = 0; i < count; ++i) {
                rb.glyphs[i] = i;
                rb.pos[i] = SkIntToScalar(i);
            }
        } break;
        case SkTextBlob::kFull_Positioning: {
            const SkTextBlobBuilder::RunBuffer& rb = builder.allocRunPos(font, count, bounds);
            for (int i = 0; i < count; ++i) {
                rb.glyphs[i] = i;
                rb.pos[i * 2] = SkIntToScalar(i);
                rb.pos[i * 2 + 1] = -SkIntToScalar(i);
            }
        } break;
        default:
            SkFAIL("unhandled positioning value");
        }
    }
};

DEF_TEST(TextBlob_builder, reporter) {
    TextBlobTester::TestBuilder(reporter);
    TextBlobTester::TestBounds(reporter);
}
<commit_msg>Fix TextBlobTest valgrind error<commit_after>/*
 * Copyright 2014 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkPaint.h"
#include "SkPoint.h"
#include "SkTextBlob.h"

#include "Test.h"

class TextBlobTester {
public:
    // This unit test feeds an SkTextBlobBuilder various runs then checks to see if
    // the result contains the provided data and merges runs when appropriate.
    static void TestBuilder(skiatest::Reporter* reporter) {
        SkTextBlobBuilder builder;

        // empty run set
        RunBuilderTest(reporter, builder, nullptr, 0, nullptr, 0);

        RunDef set1[] = {
            { 128, SkTextBlob::kDefault_Positioning, 100, 100 },
        };
        RunBuilderTest(reporter, builder, set1, SK_ARRAY_COUNT(set1), set1, SK_ARRAY_COUNT(set1));

        RunDef set2[] = {
            { 128, SkTextBlob::kHorizontal_Positioning, 100, 100 },
        };
        RunBuilderTest(reporter, builder, set2, SK_ARRAY_COUNT(set2), set2, SK_ARRAY_COUNT(set2));

        RunDef set3[] = {
            { 128, SkTextBlob::kFull_Positioning, 100, 100 },
        };
        RunBuilderTest(reporter, builder, set3, SK_ARRAY_COUNT(set3), set3, SK_ARRAY_COUNT(set3));

        RunDef set4[] = {
            { 128, SkTextBlob::kDefault_Positioning, 100, 150 },
            { 128, SkTextBlob::kDefault_Positioning, 100, 150 },
            { 128, SkTextBlob::kDefault_Positioning, 100, 150 },
        };
        RunBuilderTest(reporter, builder, set4, SK_ARRAY_COUNT(set4), set4, SK_ARRAY_COUNT(set4));

        RunDef set5[] = {
            { 128, SkTextBlob::kHorizontal_Positioning, 100, 150 },
            { 128, SkTextBlob::kHorizontal_Positioning, 200, 150 },
            { 128, SkTextBlob::kHorizontal_Positioning, 300, 250 },
        };
        RunDef mergedSet5[] = {
            { 256, SkTextBlob::kHorizontal_Positioning, 0, 150 },
            { 128, SkTextBlob::kHorizontal_Positioning, 0, 250 },
        };
        RunBuilderTest(reporter, builder, set5, SK_ARRAY_COUNT(set5), mergedSet5,
                       SK_ARRAY_COUNT(mergedSet5));

        RunDef set6[] = {
            { 128, SkTextBlob::kFull_Positioning, 100, 100 },
            { 128, SkTextBlob::kFull_Positioning, 200, 200 },
            { 128, SkTextBlob::kFull_Positioning, 300, 300 },
        };
        RunDef mergedSet6[] = {
            { 384, SkTextBlob::kFull_Positioning, 0, 0 },
        };
        RunBuilderTest(reporter, builder, set6, SK_ARRAY_COUNT(set6), mergedSet6,
                       SK_ARRAY_COUNT(mergedSet6));

        RunDef set7[] = {
            { 128, SkTextBlob::kDefault_Positioning, 100, 150 },
            { 128, SkTextBlob::kDefault_Positioning, 100, 150 },
            { 128, SkTextBlob::kHorizontal_Positioning, 100, 150 },
            { 128, SkTextBlob::kHorizontal_Positioning, 200, 150 },
            { 128, SkTextBlob::kFull_Positioning, 400, 350 },
            { 128, SkTextBlob::kFull_Positioning, 400, 350 },
            { 128, SkTextBlob::kDefault_Positioning, 100, 450 },
            { 128, SkTextBlob::kDefault_Positioning, 100, 450 },
            { 128, SkTextBlob::kHorizontal_Positioning, 100, 550 },
            { 128, SkTextBlob::kHorizontal_Positioning, 200, 650 },
            { 128, SkTextBlob::kFull_Positioning, 400, 750 },
            { 128, SkTextBlob::kFull_Positioning, 400, 850 },
        };
        RunDef mergedSet7[] = {
            { 128, SkTextBlob::kDefault_Positioning, 100, 150 },
            { 128, SkTextBlob::kDefault_Positioning, 100, 150 },
            { 256, SkTextBlob::kHorizontal_Positioning, 0, 150 },
            { 256, SkTextBlob::kFull_Positioning, 0, 0 },
            { 128, SkTextBlob::kDefault_Positioning, 100, 450 },
            { 128, SkTextBlob::kDefault_Positioning, 100, 450 },
            { 128, SkTextBlob::kHorizontal_Positioning, 0, 550 },
            { 128, SkTextBlob::kHorizontal_Positioning, 0, 650 },
            { 256, SkTextBlob::kFull_Positioning, 0, 0 },
        };
        RunBuilderTest(reporter, builder, set7, SK_ARRAY_COUNT(set7), mergedSet7,
                       SK_ARRAY_COUNT(mergedSet7));
    }

    // This unit test verifies blob bounds computation.
    static void TestBounds(skiatest::Reporter* reporter) {
        SkTextBlobBuilder builder;
        SkPaint font;
        font.setTextEncoding(SkPaint::kGlyphID_TextEncoding);

        // Explicit bounds.
        {
            SkAutoTUnref<const SkTextBlob> blob(builder.build());
            REPORTER_ASSERT(reporter, blob->bounds().isEmpty());
        }

        {
            SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20);
            builder.allocRun(font, 16, 0, 0, &r1);
            SkAutoTUnref<const SkTextBlob> blob(builder.build());
            REPORTER_ASSERT(reporter, blob->bounds() == r1);
        }

        {
            SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20);
            builder.allocRunPosH(font, 16, 0, &r1);
            SkAutoTUnref<const SkTextBlob> blob(builder.build());
            REPORTER_ASSERT(reporter, blob->bounds() == r1);
        }

        {
            SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20);
            builder.allocRunPos(font, 16, &r1);
            SkAutoTUnref<const SkTextBlob> blob(builder.build());
            REPORTER_ASSERT(reporter, blob->bounds() == r1);
        }

        {
            SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20);
            SkRect r2 = SkRect::MakeXYWH(15, 20, 50, 50);
            SkRect r3 = SkRect::MakeXYWH(0, 5, 10, 5);

            builder.allocRun(font, 16, 0, 0, &r1);
            builder.allocRunPosH(font, 16, 0, &r2);
            builder.allocRunPos(font, 16, &r3);

            SkAutoTUnref<const SkTextBlob> blob(builder.build());
            REPORTER_ASSERT(reporter, blob->bounds() == SkRect::MakeXYWH(0, 5, 65, 65));
        }

        {
            // Verify empty blob bounds after building some non-empty blobs.
            SkAutoTUnref<const SkTextBlob> blob(builder.build());
            REPORTER_ASSERT(reporter, blob->bounds().isEmpty());
        }

        // Implicit bounds

        {
            // Exercise the empty bounds path, and ensure that RunRecord-aligned pos buffers
            // don't trigger asserts (http://crbug.com/542643).
            SkPaint p;
            p.setTextSize(0);
            p.setTextEncoding(SkPaint::kUTF8_TextEncoding);

            const char* txt = "BOOO";
            const size_t txtLen = strlen(txt);
            const int glyphCount = p.textToGlyphs(txt, txtLen, nullptr);

            p.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
            const SkTextBlobBuilder::RunBuffer& buffer = builder.allocRunPos(p, glyphCount);

            p.setTextEncoding(SkPaint::kUTF8_TextEncoding);
            p.textToGlyphs(txt, txtLen, buffer.glyphs);

            memset(buffer.pos, 0, sizeof(SkScalar) * glyphCount * 2);
            SkAutoTUnref<const SkTextBlob> blob(builder.build());
            REPORTER_ASSERT(reporter, blob->bounds().isEmpty());
        }
    }

private:
    struct RunDef {
        unsigned                     count;
        SkTextBlob::GlyphPositioning pos;
        SkScalar                     x, y;
    };

    static void RunBuilderTest(skiatest::Reporter* reporter, SkTextBlobBuilder& builder,
                               const RunDef in[], unsigned inCount,
                               const RunDef out[], unsigned outCount) {
        SkPaint font;
        font.setTextEncoding(SkPaint::kGlyphID_TextEncoding);

        unsigned glyphCount = 0;
        unsigned posCount = 0;

        for (unsigned i = 0; i < inCount; ++i) {
            AddRun(font, in[i].count, in[i].pos, SkPoint::Make(in[i].x, in[i].y), builder);
            glyphCount += in[i].count;
            posCount += in[i].count * in[i].pos;
        }

        SkAutoTUnref<const SkTextBlob> blob(builder.build());

        SkTextBlob::RunIterator it(blob);
        for (unsigned i = 0; i < outCount; ++i) {
            REPORTER_ASSERT(reporter, !it.done());
            REPORTER_ASSERT(reporter, out[i].pos == it.positioning());
            REPORTER_ASSERT(reporter, out[i].count == it.glyphCount());
            if (SkTextBlob::kDefault_Positioning == out[i].pos) {
                REPORTER_ASSERT(reporter, out[i].x == it.offset().x());
                REPORTER_ASSERT(reporter, out[i].y == it.offset().y());
            } else if (SkTextBlob::kHorizontal_Positioning == out[i].pos) {
                REPORTER_ASSERT(reporter, out[i].y == it.offset().y());
            }

            for (unsigned k = 0; k < it.glyphCount(); ++k) {
                REPORTER_ASSERT(reporter, k % 128 == it.glyphs()[k]);
                if (SkTextBlob::kHorizontal_Positioning == it.positioning()) {
                    REPORTER_ASSERT(reporter, SkIntToScalar(k % 128) == it.pos()[k]);
                } else if (SkTextBlob::kFull_Positioning == it.positioning()) {
                    REPORTER_ASSERT(reporter, SkIntToScalar(k % 128) == it.pos()[k * 2]);
                    REPORTER_ASSERT(reporter, -SkIntToScalar(k % 128) == it.pos()[k * 2 + 1]);
                }
            }

            it.next();
        }

        REPORTER_ASSERT(reporter, it.done());
    }

    static void AddRun(const SkPaint& font, int count, SkTextBlob::GlyphPositioning pos,
                       const SkPoint& offset, SkTextBlobBuilder& builder,
                       const SkRect* bounds = nullptr) {
        switch (pos) {
        case SkTextBlob::kDefault_Positioning: {
            const SkTextBlobBuilder::RunBuffer& rb = builder.allocRun(font, count, offset.x(),
                                                                      offset.y(), bounds);
            for (int i = 0; i < count; ++i) {
                rb.glyphs[i] = i;
            }
        } break;
        case SkTextBlob::kHorizontal_Positioning: {
            const SkTextBlobBuilder::RunBuffer& rb = builder.allocRunPosH(font, count, offset.y(),
                                                                          bounds);
            for (int i = 0; i < count; ++i) {
                rb.glyphs[i] = i;
                rb.pos[i] = SkIntToScalar(i);
            }
        } break;
        case SkTextBlob::kFull_Positioning: {
            const SkTextBlobBuilder::RunBuffer& rb = builder.allocRunPos(font, count, bounds);
            for (int i = 0; i < count; ++i) {
                rb.glyphs[i] = i;
                rb.pos[i * 2] = SkIntToScalar(i);
                rb.pos[i * 2 + 1] = -SkIntToScalar(i);
            }
        } break;
        default:
            SkFAIL("unhandled positioning value");
        }
    }
};

DEF_TEST(TextBlob_builder, reporter) {
    TextBlobTester::TestBuilder(reporter);
    TextBlobTester::TestBounds(reporter);
}
<|endoftext|>


<commit_before>#pragma once

#include <ctime>
#include <initializer_list>

#include "blackhole/attribute/name.hpp"
#include "blackhole/attribute/scope.hpp"
#include "blackhole/attribute/set.hpp"
#include "blackhole/attribute/view.hpp"
#include "blackhole/attribute/traits.hpp"
#include "blackhole/attribute/value.hpp"
#include "blackhole/utils/timeval.hpp"
#include "blackhole/utils/types.hpp"
#include "blackhole/utils/underlying.hpp"
#include "blackhole/utils/noexcept.hpp"

namespace blackhole {

namespace attribute {

// Simple typedef for attributes initializer list. Useful when specifying local attributes.
typedef std::initializer_list<std::pair<std::string, attribute::value_t>> list;

// Dynamic attribute factory function.
template<typename T>
inline attribute::pair_t make(const std::string& name, const T& value, attribute::scope_t scope = attribute::DEFAULT_SCOPE) {
    return std::make_pair(name, attribute_t(value, scope));
}

template<typename T>
inline attribute::pair_t make(const std::string& name, T&& value, attribute::scope_t scope = attribute::DEFAULT_SCOPE) {
    return std::make_pair(name, attribute_t(std::move(value), scope));
}

// Attribute packing/unpacking/extracting.
template<typename T, class = void>
struct traits {
    static inline T pack(const T& value) {
        return value;
    }

    static inline T extract(const attribute::set_view_t& attributes, const std::string& name) {
        return boost::get<T>(attributes.at(name).value);
    }
};

template<typename T>
struct traits<T, typename std::enable_if<std::is_enum<T>::value>::type> {
    typedef typename aux::underlying_type<T>::type underlying_type;

    static inline underlying_type pack(const T& value) {
        return static_cast<underlying_type>(value);
    }

    static inline T extract(const attribute::set_view_t& attributes, const std::string& name) {
        return static_cast<T>(boost::get<underlying_type>(attributes.at(name).value));
    }
};

} // namespace attribute

} // namespace blackhole
<commit_msg>[Code Style] Using typedefs, offsets, margins and other stuff.<commit_after>#pragma once

#include <ctime>
#include <initializer_list>
#include <utility>

#include "blackhole/attribute/name.hpp"
#include "blackhole/attribute/scope.hpp"
#include "blackhole/attribute/set.hpp"
#include "blackhole/attribute/view.hpp"
#include "blackhole/attribute/traits.hpp"
#include "blackhole/attribute/value.hpp"
#include "blackhole/utils/timeval.hpp"
#include "blackhole/utils/types.hpp"
#include "blackhole/utils/underlying.hpp"
#include "blackhole/utils/noexcept.hpp"

namespace blackhole {

namespace attribute {

/*!
 * Simple typedef for attributes initializer list.
 * Useful when specifying local attributes.
 */
typedef std::initializer_list<std::pair<name_t, value_t>> list;

// Dynamic attribute factory function.
template<typename T>
inline
pair_t
make(const name_t& name, const T& value, scope_t scope = DEFAULT_SCOPE) {
    return std::make_pair(name, attribute_t(value, scope));
}

template<typename T>
inline
pair_t
make(const name_t& name, T&& value, scope_t scope = DEFAULT_SCOPE) {
    return std::make_pair(name, attribute_t(std::move(value), scope));
}

// Attribute packing/unpacking/extracting.
template<typename T, class = void>
struct traits {
    static inline T pack(const T& value) {
        return value;
    }

    static inline T extract(const set_view_t& attributes, const name_t& name) {
        return boost::get<T>(attributes.at(name).value);
    }
};

template<typename T>
struct traits<T, typename std::enable_if<std::is_enum<T>::value>::type> {
    typedef typename aux::underlying_type<T>::type underlying_type;

    static inline underlying_type pack(const T& value) {
        return static_cast<underlying_type>(value);
    }

    static inline T extract(const set_view_t& attributes, const name_t& name) {
        return static_cast<T>(boost::get<underlying_type>(attributes.at(name).value));
    }
};

} // namespace attribute

} // namespace blackhole
<|endoftext|>


<commit_before>#pragma once

#include <cstdint>
#include <initializer_list>
#include <unordered_map>

#include <boost/variant.hpp>

namespace blackhole {

namespace log {

typedef boost::variant<
    std::time_t,
    std::uint8_t,
    std::int32_t,
    std::uint64_t,
    std::int64_t,
    std::double_t,
    std::string
> attribute_value_t;

typedef std::pair<
    std::string,
    attribute_value_t
> attribute_pair_t;

typedef std::unordered_map<
    attribute_pair_t::first_type,
    attribute_pair_t::second_type
> attributes_t;

} // namespace log

inline log::attributes_t merge(const std::initializer_list<log::attributes_t>& args) {
    log::attributes_t summary;
    for (auto it = args.begin(); it != args.end(); ++it) {
        summary.insert(it->begin(), it->end());
    }

    return summary;
}

namespace attr {

template<typename T>
inline log::attribute_pair_t make(const std::string& name, const T& value) {
    return std::make_pair(name, value);
}

} // namespace attr

} // namespace blackhole
<commit_msg>More comments.<commit_after>#pragma once

#include <cstdint>
#include <initializer_list>
#include <unordered_map>

#include <boost/variant.hpp>

namespace blackhole {

namespace log {

typedef boost::variant<
    std::time_t,
    std::uint8_t,
    std::int32_t,
    std::uint64_t,
    std::int64_t,
    std::double_t,
    std::string
> attribute_value_t;

typedef std::pair<
    std::string,
    attribute_value_t
> attribute_pair_t;

typedef std::unordered_map<
    attribute_pair_t::first_type,
    attribute_pair_t::second_type
> attributes_t;

} // namespace log

inline log::attributes_t merge(const std::initializer_list<log::attributes_t>& args) {
    log::attributes_t summary;
    for (auto it = args.begin(); it != args.end(); ++it) {
        summary.insert(it->begin(), it->end());
    }

    return summary;
}

namespace attr {

// Dynamic attribute factory function.
template<typename T>
inline log::attribute_pair_t make(const std::string& name, const T& value) {
    return std::make_pair(name, value);
}

} // namespace attr

} // namespace blackhole
<|endoftext|>


<commit_before>/*
 * Copyright (C) 2014 furan
 * Copyright (C) 2016 deipi.com LLC and contributors.
 *
 * 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.
 */

#include "Lexer.h"

#define AND "AND"
#define OR "OR"
#define NOT "NOT"
#define XOR "XOR"

#define DOUBLEQUOTE '"'
#define SINGLEQUOTE '\''
#define LEFT_SQUARE_BRACKET '['
#define RIGHT_SQUARE_BRACKET ']'

Lexer::Lexer(ContentReader contentReader)
{
	this->contentReader = contentReader;
	currentSymbol = this->contentReader.NextSymbol();

	InitDictionary();
}

Lexer::Lexer(char * input)
{
	ContentReader cr(input);
	contentReader = cr;
	currentSymbol = this->contentReader.NextSymbol();

	InitDictionary();

}

void
Lexer::InitDictionary()
{
	singleSymbolDictionary["("] = TokenType::LeftParenthesis;
	singleSymbolDictionary[")"] = TokenType::RightParenthesis;
	singleSymbolDictionary["&"] = TokenType::And;
	singleSymbolDictionary["|"] = TokenType::Or;
	singleSymbolDictionary["~"] = TokenType::Not;
}

Token
Lexer::NextToken()
{
	string lexeme = "";
	LexerState currentState = LexerState::INIT;
	Token token;
	char quote;

	auto upState = currentState;

	string symbol;
	string lcSymbol;

	while (true) {
		symbol.clear();
		symbol += currentSymbol.symbol;
		switch (currentState) {
			case LexerState::INIT:
				if (currentSymbol.symbol == LEFT_SQUARE_BRACKET)
				{
					lexeme += currentSymbol.symbol;
					currentState = LexerState::INIT_SQUARE_BRACKET;
					currentSymbol = contentReader.NextSymbol();
				}
				else if (currentSymbol.symbol == SINGLEQUOTE)
				{
					lexeme += currentSymbol.symbol;
					currentState = LexerState::TOKEN_QUOTE;
					quote = SINGLEQUOTE;
					currentSymbol = contentReader.NextSymbol();
				}
				else if (currentSymbol.symbol == DOUBLEQUOTE)
				{
					lexeme += currentSymbol.symbol;
					currentState = LexerState::TOKEN_QUOTE;
					quote = DOUBLEQUOTE;
					currentSymbol = contentReader.NextSymbol();
				}
				else if(isalnum(currentSymbol.symbol) || currentSymbol.symbol == '_')
				{
					lexeme += currentSymbol.symbol;
					currentState = LexerState::TOKEN;
					currentSymbol = contentReader.NextSymbol();
				}
				else if (currentSymbol.symbol == '\0')
				{
					currentState = LexerState::EOFILE;
				}
				else if (isspace(currentSymbol.symbol))
				{
					currentState = LexerState::INIT;
					currentSymbol = contentReader.NextSymbol();
				}
				else if(singleSymbolDictionary.find(symbol) != singleSymbolDictionary.end())
				{
					lexeme += currentSymbol.symbol;
					currentState = LexerState::SYMBOL_OP;
					currentSymbol = contentReader.NextSymbol();
				}
				else
				{
					string msj = "Symbol " + symbol + " not expected";
					throw LexicalException(msj.c_str());
				}
				break;
			case LexerState::TOKEN:
				if (currentSymbol.symbol == DOUBLEQUOTE)
				{
					lexeme += currentSymbol.symbol;
					currentState = LexerState::TOKEN_QUOTE;
					quote = DOUBLEQUOTE;
					currentSymbol = contentReader.NextSymbol();
				}
				else if (currentSymbol.symbol == SINGLEQUOTE)
				{
					lexeme += currentSymbol.symbol;
					currentState = LexerState::TOKEN_QUOTE;
					quote = SINGLEQUOTE;
					currentSymbol = contentReader.NextSymbol();
				}
				else if (!IsSymbolOp(currentSymbol.symbol) && currentSymbol.symbol != ' ' && currentSymbol.symbol != '\0')
				{
					lexeme += currentSymbol.symbol;
					currentState =  LexerState::TOKEN;
					currentSymbol = contentReader.NextSymbol();
				} else
				{
					token.lexeme = lexeme;
					token.type = TokenType::Id;
					IsStringOperator(token);
					return token;
				}
				break;
			case LexerState::TOKEN_QUOTE:
				if (currentSymbol.symbol == quote)
				{
					lexeme += currentSymbol.symbol;
					upState == LexerState::INIT_SQUARE_BRACKET ? currentState = LexerState::END_SQUARE_BRACKET : currentState = LexerState::TOKEN;
					currentSymbol = contentReader.NextSymbol();
				}
				else if (currentSymbol.symbol == '\\')
				{
					lexeme += currentSymbol.symbol;
					currentState =  LexerState::ESCAPE;
					currentSymbol = contentReader.NextSymbol();
				}
				else if (currentSymbol.symbol != '\0')
				{
					lexeme += currentSymbol.symbol;
					currentSymbol = contentReader.NextSymbol();
				}
				else
				{
					string msj = "Symbol double quote expected";
					throw LexicalException(msj.c_str());
				}
				break;
			case LexerState::ESCAPE:
				if (currentSymbol.symbol != '\0')
				{
					lexeme += currentSymbol.symbol;
					currentState = LexerState::TOKEN_QUOTE;
					currentSymbol = contentReader.NextSymbol();
				}
				else
				{
					string msj = "Symbol EOF not expected";
					throw LexicalException(msj.c_str());
				}
				break;
			case LexerState::INIT_SQUARE_BRACKET:
				if (currentSymbol.symbol == DOUBLEQUOTE)
				{
					lexeme += currentSymbol.symbol;
					currentState = LexerState::TOKEN_QUOTE;
					upState = LexerState::INIT_SQUARE_BRACKET;
					quote = DOUBLEQUOTE;
					currentSymbol = contentReader.NextSymbol();
					continue;
				}
				else if (currentSymbol.symbol == SINGLEQUOTE)
				{
					lexeme += currentSymbol.symbol;
					currentState = LexerState::TOKEN_QUOTE;
					upState = LexerState::INIT_SQUARE_BRACKET;
					quote = SINGLEQUOTE;
					currentSymbol = contentReader.NextSymbol();
					continue;
				}
				else if (currentSymbol.symbol != RIGHT_SQUARE_BRACKET && currentSymbol.symbol != '\0')
				{
					lexeme += currentSymbol.symbol;
					currentSymbol = contentReader.NextSymbol();
					continue;
				}
			case LexerState::END_SQUARE_BRACKET:
				if (currentSymbol.symbol == RIGHT_SQUARE_BRACKET)
				{
					lexeme += currentSymbol.symbol;
					currentState = LexerState::TOKEN;
					currentSymbol = contentReader.NextSymbol();
				}
				else if (currentSymbol.symbol == ',')
				{
					lexeme += currentSymbol.symbol;
					currentState = LexerState::INIT_SQUARE_BRACKET;
					currentSymbol = contentReader.NextSymbol();
				}
				else
				{
					string msj = "Symbol ] expected";
					throw LexicalException(msj.c_str());
				}
				break;
			case LexerState::SYMBOL_OP:
				token.lexeme = lexeme;
				token.type = singleSymbolDictionary.at(lexeme);
				return token;
			case LexerState::EOFILE:
				token.type = TokenType::EndOfFile;
				return token;
			default:
				break;
		}
	}

	return token;
}

void
Lexer::IsStringOperator(Token& token)
{
	if (!token.lexeme.empty()) {
		switch (token.lexeme.at(0)) {
			 case 'A':
				if (strcmp(token.lexeme.data(), AND) == 0) {
					token.type = TokenType::And;
				}
				break;
			 case 'O':
				if (strcmp(token.lexeme.data(), OR) == 0) {
					token.type = TokenType::Or;
				}
				break;
			 case 'N':
				if (strcmp(token.lexeme.data(), NOT) == 0) {
					token.type = TokenType::Not;
				}
				break;
			 case 'X':
				if (strcmp(token.lexeme.data(), XOR) == 0) {
					token.type = TokenType::Xor;
				}
				break;
			 default:
				return;
		}
	}
}

bool
Lexer::IsSymbolOp(char c)
{
	try {
		singleSymbolDictionary.at(std::string(1, c));
		return true;
	} catch (std::out_of_range) {
		return false;
	}
}<commit_msg>Improve lexical parser<commit_after>/*
 * Copyright (C) 2014 furan
 * Copyright (C) 2016 deipi.com LLC and contributors.
 *
 * 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.
 */

#include "Lexer.h"

#define AND "AND"
#define OR "OR"
#define NOT "NOT"
#define XOR "XOR"

#define DOUBLEQUOTE '"'
#define SINGLEQUOTE '\''
#define LEFT_SQUARE_BRACKET '['
#define RIGHT_SQUARE_BRACKET ']'

Lexer::Lexer(ContentReader contentReader)
{
	this->contentReader = contentReader;
	currentSymbol = this->contentReader.NextSymbol();

	InitDictionary();
}

Lexer::Lexer(char * input)
{
	ContentReader cr(input);
	contentReader = cr;
	currentSymbol = this->contentReader.NextSymbol();

	InitDictionary();

}

void
Lexer::InitDictionary()
{
	singleSymbolDictionary["("] = TokenType::LeftParenthesis;
	singleSymbolDictionary[")"] = TokenType::RightParenthesis;
	singleSymbolDictionary["&"] = TokenType::And;
	singleSymbolDictionary["|"] = TokenType::Or;
	singleSymbolDictionary["~"] = TokenType::Not;
}

Token
Lexer::NextToken()
{
	string lexeme = "";
	LexerState currentState = LexerState::INIT;
	Token token;
	char quote;

	auto upState = currentState;

	string symbol;
	string lcSymbol;

	while (true) {
		symbol.clear();
		symbol += currentSymbol.symbol;
		switch (currentState) {
			case LexerState::INIT:
				switch(currentSymbol.symbol) {
					case LEFT_SQUARE_BRACKET:
						lexeme += currentSymbol.symbol;
						currentState = LexerState::INIT_SQUARE_BRACKET;
						currentSymbol = contentReader.NextSymbol();
						break;

					case SINGLEQUOTE:
						lexeme += currentSymbol.symbol;
						currentState = LexerState::TOKEN_QUOTE;
						quote = SINGLEQUOTE;
						currentSymbol = contentReader.NextSymbol();
						break;

					case DOUBLEQUOTE:
						lexeme += currentSymbol.symbol;
						currentState = LexerState::TOKEN_QUOTE;
						quote = DOUBLEQUOTE;
						currentSymbol = contentReader.NextSymbol();
						break;

					case '\0':
						currentState = LexerState::EOFILE;
						break;

					default:
						if(isalnum(currentSymbol.symbol) || currentSymbol.symbol == '_') {
							lexeme += currentSymbol.symbol;
							currentState = LexerState::TOKEN;
							currentSymbol = contentReader.NextSymbol();
						} else if (isspace(currentSymbol.symbol)) {
							currentState = LexerState::INIT;
							currentSymbol = contentReader.NextSymbol();
						} else if(singleSymbolDictionary.find(symbol) != singleSymbolDictionary.end()) {
							lexeme += currentSymbol.symbol;
							currentState = LexerState::SYMBOL_OP;
							currentSymbol = contentReader.NextSymbol();
						} else {
							string msj = "Symbol " + symbol + " not expected";
							throw LexicalException(msj.c_str());
						}
				}
				break;

			case LexerState::TOKEN:
				switch(currentSymbol.symbol) {
					case DOUBLEQUOTE:
						lexeme += currentSymbol.symbol;
						currentState = LexerState::TOKEN_QUOTE;
						quote = DOUBLEQUOTE;
						currentSymbol = contentReader.NextSymbol();
						break;

					case SINGLEQUOTE:
						lexeme += currentSymbol.symbol;
						currentState = LexerState::TOKEN_QUOTE;
						quote = SINGLEQUOTE;
						currentSymbol = contentReader.NextSymbol();
						break;

					default:
						if (!IsSymbolOp(currentSymbol.symbol) && currentSymbol.symbol != ' ' && currentSymbol.symbol != '\0') {
							lexeme += currentSymbol.symbol;
							currentState =  LexerState::TOKEN;
							currentSymbol = contentReader.NextSymbol();
						}  else {
							token.lexeme = lexeme;
							token.type = TokenType::Id;
							IsStringOperator(token);
							return token;
						}
				}
				break;

			case LexerState::TOKEN_QUOTE:
				switch (currentSymbol.symbol) {
					case '\\':
						lexeme += currentSymbol.symbol;
						currentState =  LexerState::ESCAPE;
						currentSymbol = contentReader.NextSymbol();
						break;

					case '\0': {
						string msj = "Symbol double quote expected";
						throw LexicalException(msj.c_str());
					}

					default:
						if (currentSymbol.symbol == quote) {
							lexeme += currentSymbol.symbol;
							upState == LexerState::INIT_SQUARE_BRACKET ? currentState = LexerState::END_SQUARE_BRACKET : currentState = LexerState::TOKEN;
							currentSymbol = contentReader.NextSymbol();
						} else {
							lexeme += currentSymbol.symbol;
							currentSymbol = contentReader.NextSymbol();
						}
				}
				break;

			case LexerState::ESCAPE:
				switch(currentSymbol.symbol) {
					case '\0': {
						string msj = "Symbol EOF not expected";
						throw LexicalException(msj.c_str());
					}

					default:
						lexeme += currentSymbol.symbol;
						currentState = LexerState::TOKEN_QUOTE;
						currentSymbol = contentReader.NextSymbol();
						break;

				}
				break;

			case LexerState::INIT_SQUARE_BRACKET:
				switch (currentSymbol.symbol) {
					case DOUBLEQUOTE:
						lexeme += currentSymbol.symbol;
						currentState = LexerState::TOKEN_QUOTE;
						upState = LexerState::INIT_SQUARE_BRACKET;
						quote = DOUBLEQUOTE;
						currentSymbol = contentReader.NextSymbol();
						continue;

					case SINGLEQUOTE:
						lexeme += currentSymbol.symbol;
						currentState = LexerState::TOKEN_QUOTE;
						upState = LexerState::INIT_SQUARE_BRACKET;
						quote = SINGLEQUOTE;
						currentSymbol = contentReader.NextSymbol();
						continue;

					default:
						if (currentSymbol.symbol != RIGHT_SQUARE_BRACKET && currentSymbol.symbol != '\0') {
							lexeme += currentSymbol.symbol;
							currentSymbol = contentReader.NextSymbol();
							continue;
						}
				}

			case LexerState::END_SQUARE_BRACKET:
				switch (currentSymbol.symbol) {
					case RIGHT_SQUARE_BRACKET:
						lexeme += currentSymbol.symbol;
						currentState = LexerState::TOKEN;
						currentSymbol = contentReader.NextSymbol();
						break;

					case ',':
						lexeme += currentSymbol.symbol;
						currentState = LexerState::INIT_SQUARE_BRACKET;
						currentSymbol = contentReader.NextSymbol();
						break;

					default:
						string msj = "Symbol ] expected";
						throw LexicalException(msj.c_str());

				}
				break;

			case LexerState::SYMBOL_OP:
				token.lexeme = lexeme;
				token.type = singleSymbolDictionary.at(lexeme);
				return token;
			case LexerState::EOFILE:
				token.type = TokenType::EndOfFile;
				return token;
			default:
				break;
		}
	}

	return token;
}

void
Lexer::IsStringOperator(Token& token)
{
	if (!token.lexeme.empty()) {
		switch (token.lexeme.at(0)) {
			 case 'A':
				if (strcmp(token.lexeme.data(), AND) == 0) {
					token.type = TokenType::And;
				}
				break;
			 case 'O':
				if (strcmp(token.lexeme.data(), OR) == 0) {
					token.type = TokenType::Or;
				}
				break;
			 case 'N':
				if (strcmp(token.lexeme.data(), NOT) == 0) {
					token.type = TokenType::Not;
				}
				break;
			 case 'X':
				if (strcmp(token.lexeme.data(), XOR) == 0) {
					token.type = TokenType::Xor;
				}
				break;
			 default:
				return;
		}
	}
}

bool
Lexer::IsSymbolOp(char c)
{
	try {
		singleSymbolDictionary.at(std::string(1, c));
		return true;
	} catch (std::out_of_range) {
		return false;
	}
}<|endoftext|>


<commit_before>/**
 * Clever programming language
 * Copyright (c) Clever Team
 *
 * This file is distributed under the MIT license. See LICENSE for details.
 */

#include <string>
#include <sstream>
#include "types/str.h"

namespace clever {

CLEVER_TYPE_OPERATOR(StrType::add)
{
	if (EXPECTED(rhs->getType() == this)) {
		// TODO(Felipe): Do not require CString everywhere (because it stores the
		// data in an string table)
		result->setStr(CSTRING(*lhs->getStr() + *rhs->getStr()));
	}
}

CLEVER_TYPE_OPERATOR(StrType::sub)
{
}

CLEVER_TYPE_OPERATOR(StrType::mul)
{
	if (rhs->getType() == CLEVER_INT_TYPE) {
		std::ostringstream os;

		for (long i = 0, j = rhs->getInt(); i < j; ++i) {
			os << *lhs->getStr();
		}

		result->setStr(CSTRING(os.str()));
	}
}

CLEVER_TYPE_OPERATOR(StrType::div)
{
}

CLEVER_TYPE_OPERATOR(StrType::mod)
{
}

// String.subString(string str, [int start, [int count]])
// String.subString(int start, [int count])
// Returns a substring of the argument or string object referenced using bounds provided
CLEVER_METHOD(StrType::subString)
{
	const CString *of = NULL;
	int bounds[2];

	bounds[0]=-1;
	bounds[1]=-1;

	if (CLEVER_THIS()) {
		of = (const CString*) CLEVER_THIS()->getStr();
		switch(CLEVER_ARG_COUNT()) {
			case 2:
				bounds[0]=CLEVER_ARG_INT(0);
				bounds[1]=CLEVER_ARG_INT(1);
			break;
			case 1:
				bounds[0]=CLEVER_ARG_INT(0);
			break;
			default: std::cerr << "String.subString expected at least one argument";
		}
	} else if (CLEVER_ARG_COUNT()) {
		of = (const CString*) CLEVER_ARG_CSTR(0);
		switch(CLEVER_ARG_COUNT()) {
			case 3:
				bounds[0]=CLEVER_ARG_INT(1);
				bounds[1]=CLEVER_ARG_INT(2);
			break;
			case 2: bounds[0]=CLEVER_ARG_INT(1); break;

			default: std::cerr << "String.subString expected at least two arguments";
		}
	}

	if (of && bounds[0]>-1) {
		if (bounds[1]>-1) {
			result->setStr(CSTRING(of->substr(bounds[0], bounds[1])));
		} else result->setStr(CSTRING(of->substr(bounds[0])));
	}
}

// String.findString(string haystack, string needle, [int position, [int count]])
// String.findString(string needle, [int position, [int count]])
// Finds a string in a string returning the position
CLEVER_METHOD(StrType::find)
{
	const char *needle;
	const CString *haystack;
	int bounds[2];

	bounds[0]=-1;
	bounds[1]=-1;

	if (CLEVER_THIS()) {
		haystack = (const CString*) CLEVER_THIS()->getStr();
		switch (CLEVER_ARG_COUNT()) {
			case 1:
				needle = CLEVER_ARG_PSTR(0);
			break;
			case 2:
				needle = CLEVER_ARG_PSTR(0);
				bounds[0] = CLEVER_ARG_INT(1);
			break;
			case 3:
				needle = CLEVER_ARG_PSTR(0);
				bounds[0] = CLEVER_ARG_INT(1);
				bounds[1] = CLEVER_ARG_INT(2);
			break;
			default: std::cerr << "String.find expected a maximum of 2 arguments";
		}
	} else if(CLEVER_ARG_COUNT()) {
		haystack = (const CString*) CLEVER_ARG_CSTR(0);
		switch (CLEVER_ARG_COUNT()) {
			case 4:
				needle = CLEVER_ARG_PSTR(1);
				bounds[0] = CLEVER_ARG_INT(2);
				bounds[1] = CLEVER_ARG_INT(3);
			break;
			case 3:
				needle = CLEVER_ARG_PSTR(1);
				bounds[0] = CLEVER_ARG_INT(2);
			break;
			case 2:
				needle = CLEVER_ARG_PSTR(1);
			break;
			default: std::cerr << "String.find expected at least two arguments";
		}
	}

	if (needle && haystack) {
		if (bounds[0]>-1) {
			if (bounds[1]>-1) {
				result->setInt(haystack->find((const char*)needle, bounds[0], bounds[1]));
			} else result->setInt(haystack->find((const char*)needle, bounds[0]));
		} else result->setInt(haystack->find((const char*)needle));
	}
}

CLEVER_METHOD(StrType::findFirst)
{
	const char *needle;
	const CString *haystack;
	int bounds[2];

	bounds[0]=-1;
	bounds[1]=-1;

	if (CLEVER_THIS()) {
		haystack = (const CString*) CLEVER_THIS()->getStr();
		switch (CLEVER_ARG_COUNT()) {
			case 1:
				needle = CLEVER_ARG_PSTR(0);
			break;
			case 2:
				needle = CLEVER_ARG_PSTR(0);
				bounds[0] = CLEVER_ARG_INT(1);
			break;
			case 3:
				needle = CLEVER_ARG_PSTR(0);
				bounds[0] = CLEVER_ARG_INT(1);
				bounds[1] = CLEVER_ARG_INT(2);
			break;
			default: std::cerr << "String.findFirst expected a maximum of 2 arguments";
		}
	} else if(CLEVER_ARG_COUNT()) {
		haystack = (const CString*) CLEVER_ARG_CSTR(0);
		switch (CLEVER_ARG_COUNT()) {
			case 4:
				needle = CLEVER_ARG_PSTR(1);
				bounds[0] = CLEVER_ARG_INT(2);
				bounds[1] = CLEVER_ARG_INT(3);
			break;
			case 3:
				needle = CLEVER_ARG_PSTR(1);
				bounds[0] = CLEVER_ARG_INT(2);
			break;
			case 2:
				needle = CLEVER_ARG_PSTR(1);
			break;
			default: std::cerr << "String.findFirst expected at least two arguments";
		}
	}

	if (needle && haystack) {
		if (bounds[0]>-1) {
			if (bounds[1]>-1) {
				result->setInt(haystack->find_first_of((const char*)needle, bounds[0], bounds[1]));
			} else result->setInt(haystack->find_first_of((const char*)needle, bounds[0]));
		} else result->setInt(haystack->find_first_of((const char*)needle));
	}
}

CLEVER_METHOD(StrType::findLast)
{
	const char *needle;
	const CString *haystack;
	int bounds[2];

	bounds[0]=-1;
	bounds[1]=-1;

	if (CLEVER_THIS()) {
		haystack = (const CString*) CLEVER_THIS()->getStr();
		switch (CLEVER_ARG_COUNT()) {
			case 1:
				needle = CLEVER_ARG_PSTR(0);
			break;
			case 2:
				needle = CLEVER_ARG_PSTR(0);
				bounds[0] = CLEVER_ARG_INT(1);
			break;
			case 3:
				needle = CLEVER_ARG_PSTR(0);
				bounds[0] = CLEVER_ARG_INT(1);
				bounds[1] = CLEVER_ARG_INT(2);
			break;
			default: std::cerr << "String.findLast expected a maximum of 2 arguments";
		}
	} else if(CLEVER_ARG_COUNT()) {
		haystack = (const CString*) CLEVER_ARG_CSTR(0);
		switch (CLEVER_ARG_COUNT()) {
			case 4:
				needle = CLEVER_ARG_PSTR(1);
				bounds[0] = CLEVER_ARG_INT(2);
				bounds[1] = CLEVER_ARG_INT(3);
			break;
			case 3:
				needle = CLEVER_ARG_PSTR(1);
				bounds[0] = CLEVER_ARG_INT(2);
			break;
			case 2:
				needle = CLEVER_ARG_PSTR(1);
			break;
			default: std::cerr << "String.findLast expected at least two arguments";
		}
	}

	if (needle && haystack) {
		if (bounds[0]>-1) {
			if (bounds[1]>-1) {
				result->setInt(haystack->find_last_of((const char*)needle, bounds[0], bounds[1]));
			} else result->setInt(haystack->find_last_of((const char*)needle, bounds[0]));
		} else result->setInt(haystack->find_last_of((const char*)needle));
	}
}

CLEVER_METHOD(StrType::getLength)
{
	if (CLEVER_THIS()) {
		result->setInt(((const CString*) CLEVER_THIS()->getStr())->length());
	} else {
		if(CLEVER_ARG_COUNT()) {
			result->setInt(((const CString*) CLEVER_ARG_CSTR(0))->length());
		} else std::cerr << "String.getLength expected a string argument";
	}
}

CLEVER_TYPE_INIT(StrType::init)
{
	addMethod(CSTRING("subString"),  	(MethodPtr) &StrType::subString);
	addMethod(CSTRING("find"), 			(MethodPtr) &StrType::find);
	addMethod(CSTRING("findFirst"), 	(MethodPtr) &StrType::findFirst);
	addMethod(CSTRING("findLast"), 		(MethodPtr) &StrType::findLast);
	addMethod(CSTRING("getLength"),		(MethodPtr) &StrType::getLength);
}

} // clever
<commit_msg>comments<commit_after>/**
 * Clever programming language
 * Copyright (c) Clever Team
 *
 * This file is distributed under the MIT license. See LICENSE for details.
 */

#include <string>
#include <sstream>
#include "types/str.h"

namespace clever {

CLEVER_TYPE_OPERATOR(StrType::add)
{
	if (EXPECTED(rhs->getType() == this)) {
		// TODO(Felipe): Do not require CString everywhere (because it stores the
		// data in an string table)
		result->setStr(CSTRING(*lhs->getStr() + *rhs->getStr()));
	}
}

CLEVER_TYPE_OPERATOR(StrType::sub)
{
}

CLEVER_TYPE_OPERATOR(StrType::mul)
{
	if (rhs->getType() == CLEVER_INT_TYPE) {
		std::ostringstream os;

		for (long i = 0, j = rhs->getInt(); i < j; ++i) {
			os << *lhs->getStr();
		}

		result->setStr(CSTRING(os.str()));
	}
}

CLEVER_TYPE_OPERATOR(StrType::div)
{
}

CLEVER_TYPE_OPERATOR(StrType::mod)
{
}

// String.subString(string str, [int start, [int count]])
// String.subString(int start, [int count])
// Returns a substring of the argument or string object referenced using bounds provided
CLEVER_METHOD(StrType::subString)
{
	const CString *of = NULL;
	int bounds[2];

	bounds[0]=-1;
	bounds[1]=-1;

	if (CLEVER_THIS()) {
		of = (const CString*) CLEVER_THIS()->getStr();
		switch(CLEVER_ARG_COUNT()) {
			case 2:
				bounds[0]=CLEVER_ARG_INT(0);
				bounds[1]=CLEVER_ARG_INT(1);
			break;
			case 1:
				bounds[0]=CLEVER_ARG_INT(0);
			break;
			default: std::cerr << "String.subString expected at least one argument";
		}
	} else if (CLEVER_ARG_COUNT()) {
		of = (const CString*) CLEVER_ARG_CSTR(0);
		switch(CLEVER_ARG_COUNT()) {
			case 3:
				bounds[0]=CLEVER_ARG_INT(1);
				bounds[1]=CLEVER_ARG_INT(2);
			break;
			case 2: bounds[0]=CLEVER_ARG_INT(1); break;

			default: std::cerr << "String.subString expected at least two arguments";
		}
	}

	if (of && bounds[0]>-1) {
		if (bounds[1]>-1) {
			result->setStr(CSTRING(of->substr(bounds[0], bounds[1])));
		} else result->setStr(CSTRING(of->substr(bounds[0])));
	}
}

// String.find(string haystack, string needle, [int position, [int count]])
// String.find(string needle, [int position, [int count]])
// Finds a string in a string returning the position
CLEVER_METHOD(StrType::find)
{
	const char *needle;
	const CString *haystack;
	int bounds[2];

	bounds[0]=-1;
	bounds[1]=-1;

	if (CLEVER_THIS()) {
		haystack = (const CString*) CLEVER_THIS()->getStr();
		switch (CLEVER_ARG_COUNT()) {
			case 1:
				needle = CLEVER_ARG_PSTR(0);
			break;
			case 2:
				needle = CLEVER_ARG_PSTR(0);
				bounds[0] = CLEVER_ARG_INT(1);
			break;
			case 3:
				needle = CLEVER_ARG_PSTR(0);
				bounds[0] = CLEVER_ARG_INT(1);
				bounds[1] = CLEVER_ARG_INT(2);
			break;
			default: std::cerr << "String.find expected a maximum of 2 arguments";
		}
	} else if(CLEVER_ARG_COUNT()) {
		haystack = (const CString*) CLEVER_ARG_CSTR(0);
		switch (CLEVER_ARG_COUNT()) {
			case 4:
				needle = CLEVER_ARG_PSTR(1);
				bounds[0] = CLEVER_ARG_INT(2);
				bounds[1] = CLEVER_ARG_INT(3);
			break;
			case 3:
				needle = CLEVER_ARG_PSTR(1);
				bounds[0] = CLEVER_ARG_INT(2);
			break;
			case 2:
				needle = CLEVER_ARG_PSTR(1);
			break;
			default: std::cerr << "String.find expected at least two arguments";
		}
	}

	if (needle && haystack) {
		if (bounds[0]>-1) {
			if (bounds[1]>-1) {
				result->setInt(haystack->find((const char*)needle, bounds[0], bounds[1]));
			} else result->setInt(haystack->find((const char*)needle, bounds[0]));
		} else result->setInt(haystack->find((const char*)needle));
	}
}

// String.findFirst(string haystack, string needle, [int position, [int count]])
// String.findFirst(string needle, [int position, [int count]])
// Finds the first occurence of a string in a string returning the position
CLEVER_METHOD(StrType::findFirst)
{
	const char *needle;
	const CString *haystack;
	int bounds[2];

	bounds[0]=-1;
	bounds[1]=-1;

	if (CLEVER_THIS()) {
		haystack = (const CString*) CLEVER_THIS()->getStr();
		switch (CLEVER_ARG_COUNT()) {
			case 1:
				needle = CLEVER_ARG_PSTR(0);
			break;
			case 2:
				needle = CLEVER_ARG_PSTR(0);
				bounds[0] = CLEVER_ARG_INT(1);
			break;
			case 3:
				needle = CLEVER_ARG_PSTR(0);
				bounds[0] = CLEVER_ARG_INT(1);
				bounds[1] = CLEVER_ARG_INT(2);
			break;
			default: std::cerr << "String.findFirst expected a maximum of 2 arguments";
		}
	} else if(CLEVER_ARG_COUNT()) {
		haystack = (const CString*) CLEVER_ARG_CSTR(0);
		switch (CLEVER_ARG_COUNT()) {
			case 4:
				needle = CLEVER_ARG_PSTR(1);
				bounds[0] = CLEVER_ARG_INT(2);
				bounds[1] = CLEVER_ARG_INT(3);
			break;
			case 3:
				needle = CLEVER_ARG_PSTR(1);
				bounds[0] = CLEVER_ARG_INT(2);
			break;
			case 2:
				needle = CLEVER_ARG_PSTR(1);
			break;
			default: std::cerr << "String.findFirst expected at least two arguments";
		}
	}

	if (needle && haystack) {
		if (bounds[0]>-1) {
			if (bounds[1]>-1) {
				result->setInt(haystack->find_first_of((const char*)needle, bounds[0], bounds[1]));
			} else result->setInt(haystack->find_first_of((const char*)needle, bounds[0]));
		} else result->setInt(haystack->find_first_of((const char*)needle));
	}
}
// String.findLast(string haystack, string needle, [int position, [int count]])
// String.findLast(string needle, [int position, [int count]])
// Finds the last occurence of a string in a string returning the position
CLEVER_METHOD(StrType::findLast)
{
	const char *needle;
	const CString *haystack;
	int bounds[2];

	bounds[0]=-1;
	bounds[1]=-1;

	if (CLEVER_THIS()) {
		haystack = (const CString*) CLEVER_THIS()->getStr();
		switch (CLEVER_ARG_COUNT()) {
			case 1:
				needle = CLEVER_ARG_PSTR(0);
			break;
			case 2:
				needle = CLEVER_ARG_PSTR(0);
				bounds[0] = CLEVER_ARG_INT(1);
			break;
			case 3:
				needle = CLEVER_ARG_PSTR(0);
				bounds[0] = CLEVER_ARG_INT(1);
				bounds[1] = CLEVER_ARG_INT(2);
			break;
			default: std::cerr << "String.findLast expected a maximum of 2 arguments";
		}
	} else if(CLEVER_ARG_COUNT()) {
		haystack = (const CString*) CLEVER_ARG_CSTR(0);
		switch (CLEVER_ARG_COUNT()) {
			case 4:
				needle = CLEVER_ARG_PSTR(1);
				bounds[0] = CLEVER_ARG_INT(2);
				bounds[1] = CLEVER_ARG_INT(3);
			break;
			case 3:
				needle = CLEVER_ARG_PSTR(1);
				bounds[0] = CLEVER_ARG_INT(2);
			break;
			case 2:
				needle = CLEVER_ARG_PSTR(1);
			break;
			default: std::cerr << "String.findLast expected at least two arguments";
		}
	}

	if (needle && haystack) {
		if (bounds[0]>-1) {
			if (bounds[1]>-1) {
				result->setInt(haystack->find_last_of((const char*)needle, bounds[0], bounds[1]));
			} else result->setInt(haystack->find_last_of((const char*)needle, bounds[0]));
		} else result->setInt(haystack->find_last_of((const char*)needle));
	}
}

// String.getLength(string str)
// String.getLength()
// Returns the length of the string
CLEVER_METHOD(StrType::getLength)
{
	if (CLEVER_THIS()) {
		result->setInt(((const CString*) CLEVER_THIS()->getStr())->length());
	} else {
		if(CLEVER_ARG_COUNT()) {
			result->setInt(((const CString*) CLEVER_ARG_CSTR(0))->length());
		} else std::cerr << "String.getLength expected a string argument";
	}
}

CLEVER_TYPE_INIT(StrType::init)
{
	addMethod(CSTRING("subString"),  	(MethodPtr) &StrType::subString);
	addMethod(CSTRING("find"), 			(MethodPtr) &StrType::find);
	addMethod(CSTRING("findFirst"), 	(MethodPtr) &StrType::findFirst);
	addMethod(CSTRING("findLast"), 		(MethodPtr) &StrType::findLast);
	addMethod(CSTRING("getLength"),		(MethodPtr) &StrType::getLength);
}

} // clever
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: anminfo.cxx,v $
 *
 *  $Revision: 1.14 $
 *
 *  last change: $Author: ihi $ $Date: 2006-11-14 14:20:48 $
 *
 *  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_sd.hxx"

#ifndef _URLOBJ_HXX
#include <tools/urlobj.hxx>
#endif
#ifndef _SFXSMPLHINT_HXX //autogen
#include <svtools/smplhint.hxx>
#endif
#include "svx/xtable.hxx"
#ifndef _SVDOPATH_HXX //autogen
#include <svx/svdopath.hxx>
#endif
#include <svtools/urihelper.hxx>

#include "anminfo.hxx"
#include "glob.hxx"
#include "sdiocmpt.hxx"
#include "drawdoc.hxx"

// #90477#
#ifndef _TOOLS_TENCCVT_HXX
#include <tools/tenccvt.hxx>
#endif

using namespace ::com::sun::star;

SdAnimationInfo::SdAnimationInfo()
               : SdrObjUserData(SdUDInventor, SD_ANIMATIONINFO_ID, 0),
                 mePresObjKind              (PRESOBJ_NONE),
                 eEffect                    (presentation::AnimationEffect_NONE),
                 eTextEffect                (presentation::AnimationEffect_NONE),
                 eSpeed                     (presentation::AnimationSpeed_SLOW),
                 bActive                    (TRUE),
                 bDimPrevious               (FALSE),
                 bIsMovie                   (FALSE),
                 bDimHide                   (FALSE),
                 bSoundOn                   (FALSE),
                 bPlayFull                  (FALSE),
                 pPathObj                   (NULL),
                 eClickAction               (presentation::ClickAction_NONE),
                 eSecondEffect              (presentation::AnimationEffect_NONE),
                 eSecondSpeed               (presentation::AnimationSpeed_SLOW),
                 bSecondSoundOn             (FALSE),
                 bSecondPlayFull            (FALSE),
                 nVerb                      (0),
                 nPresOrder                 (LIST_APPEND)
{
    aBlueScreen = RGB_Color(COL_LIGHTMAGENTA);
    aDimColor = RGB_Color(COL_LIGHTGRAY);
}

SdAnimationInfo::SdAnimationInfo(const SdAnimationInfo& rAnmInfo)
               : SdrObjUserData             (rAnmInfo),
                    mePresObjKind               (PRESOBJ_NONE),
                 eEffect                    (rAnmInfo.eEffect),
                 eTextEffect                (rAnmInfo.eTextEffect),
                 eSpeed                     (rAnmInfo.eSpeed),
                 bActive                    (rAnmInfo.bActive),
                 bDimPrevious               (rAnmInfo.bDimPrevious),
                 bIsMovie                   (rAnmInfo.bIsMovie),
                 bDimHide                   (rAnmInfo.bDimHide),
                 aBlueScreen                (rAnmInfo.aBlueScreen),
                 aDimColor                  (rAnmInfo.aDimColor),
                 aSoundFile                 (rAnmInfo.aSoundFile),
                 bSoundOn                   (rAnmInfo.bSoundOn),
                 bPlayFull                  (rAnmInfo.bPlayFull),
                 pPathObj                   (NULL),
                 eClickAction               (rAnmInfo.eClickAction),
                 eSecondEffect              (rAnmInfo.eSecondEffect),
                 eSecondSpeed               (rAnmInfo.eSecondSpeed),
                 bSecondSoundOn             (rAnmInfo.bSecondSoundOn),
                 bSecondPlayFull            (rAnmInfo.bSecondPlayFull),
                 nVerb                      (rAnmInfo.nVerb),
                 aBookmark                  (rAnmInfo.aBookmark),
                 aSecondSoundFile           (rAnmInfo.aSecondSoundFile),
                 nPresOrder                 (LIST_APPEND)
{
    // can not be copied
    if (eEffect == presentation::AnimationEffect_PATH)
        eEffect =  presentation::AnimationEffect_NONE;
}

SdAnimationInfo::~SdAnimationInfo()
{
}

SdrObjUserData* SdAnimationInfo::Clone(SdrObject* pObj) const
{
    return new SdAnimationInfo(*this);
}
<commit_msg>INTEGRATION: CWS sdwarningsbegone (1.13.36); FILE MERGED 2006/11/22 14:57:16 cl 1.13.36.2: RESYNC: (1.13-1.14); FILE MERGED 2006/11/22 12:41:31 cl 1.13.36.1: #i69285# warning free code changes for unxlngi6.pro<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: anminfo.cxx,v $
 *
 *  $Revision: 1.15 $
 *
 *  last change: $Author: kz $ $Date: 2006-12-12 16:30:40 $
 *
 *  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_sd.hxx"

#ifndef _URLOBJ_HXX
#include <tools/urlobj.hxx>
#endif
#ifndef _SFXSMPLHINT_HXX //autogen
#include <svtools/smplhint.hxx>
#endif
#include "svx/xtable.hxx"
#ifndef _SVDOPATH_HXX //autogen
#include <svx/svdopath.hxx>
#endif
#include <svtools/urihelper.hxx>

#include "anminfo.hxx"
#include "glob.hxx"
#include "sdiocmpt.hxx"
#include "drawdoc.hxx"

// #90477#
#ifndef _TOOLS_TENCCVT_HXX
#include <tools/tenccvt.hxx>
#endif

using namespace ::com::sun::star;

SdAnimationInfo::SdAnimationInfo()
               : SdrObjUserData(SdUDInventor, SD_ANIMATIONINFO_ID, 0),
                 mePresObjKind              (PRESOBJ_NONE),
                 meEffect                   (presentation::AnimationEffect_NONE),
                 meTextEffect               (presentation::AnimationEffect_NONE),
                 meSpeed                    (presentation::AnimationSpeed_SLOW),
                 mbActive                   (TRUE),
                 mbDimPrevious              (FALSE),
                 mbIsMovie                  (FALSE),
                 mbDimHide                  (FALSE),
                 mbSoundOn                  (FALSE),
                 mbPlayFull                 (FALSE),
                 mpPathObj                  (NULL),
                 meClickAction              (presentation::ClickAction_NONE),
                 meSecondEffect             (presentation::AnimationEffect_NONE),
                 meSecondSpeed              (presentation::AnimationSpeed_SLOW),
                 mbSecondSoundOn            (FALSE),
                 mbSecondPlayFull           (FALSE),
                 mnVerb                     (0),
                 mnPresOrder                (LIST_APPEND)
{
    maBlueScreen = RGB_Color(COL_LIGHTMAGENTA);
    maDimColor = RGB_Color(COL_LIGHTGRAY);
}

SdAnimationInfo::SdAnimationInfo(const SdAnimationInfo& rAnmInfo)
               : SdrObjUserData             (rAnmInfo),
                    mePresObjKind               (PRESOBJ_NONE),
                 meEffect                   (rAnmInfo.meEffect),
                 meTextEffect               (rAnmInfo.meTextEffect),
                 meSpeed                    (rAnmInfo.meSpeed),
                 mbActive                   (rAnmInfo.mbActive),
                 mbDimPrevious              (rAnmInfo.mbDimPrevious),
                 mbIsMovie                  (rAnmInfo.mbIsMovie),
                 mbDimHide                  (rAnmInfo.mbDimHide),
                 maBlueScreen               (rAnmInfo.maBlueScreen),
                 maDimColor                 (rAnmInfo.maDimColor),
                 maSoundFile                (rAnmInfo.maSoundFile),
                 mbSoundOn                  (rAnmInfo.mbSoundOn),
                 mbPlayFull                 (rAnmInfo.mbPlayFull),
                 mpPathObj                  (NULL),
                 meClickAction              (rAnmInfo.meClickAction),
                 meSecondEffect             (rAnmInfo.meSecondEffect),
                 meSecondSpeed              (rAnmInfo.meSecondSpeed),
                 maSecondSoundFile          (rAnmInfo.maSecondSoundFile),
                 mbSecondSoundOn            (rAnmInfo.mbSecondSoundOn),
                 mbSecondPlayFull           (rAnmInfo.mbSecondPlayFull),
                 maBookmark                 (rAnmInfo.maBookmark),
                 mnVerb                     (rAnmInfo.mnVerb),
                 mnPresOrder                (LIST_APPEND)
{
    // can not be copied
    if(meEffect == presentation::AnimationEffect_PATH)
        meEffect =  presentation::AnimationEffect_NONE;
}

SdAnimationInfo::~SdAnimationInfo()
{
}

SdrObjUserData* SdAnimationInfo::Clone(SdrObject*) const
{
    return new SdAnimationInfo(*this);
}
<|endoftext|>