<commit_before>#include <iostream>
#include <stdlib.h>
#include "io/PPMLoader.hpp"
#include "converter/RGBToYCbCrConverter.hpp"
#include "converter/YCbCrToRGBConverter.hpp"
#include "helper/Test.hpp"
#include "Huffman.hpp"
#include "DCT.hpp"
#include "Arai.hpp"
#include <math.h>

#include "bitstream/Bitstream.hpp"

#include "segments/JPEGSegments.hpp"

using namespace JPEGSegments;

#define TEST_ITERATIONS 10000000
#define TEST_REPEAT 10

std::vector<int> generateTestHuffman();

//  ---------------------------------------------------------------
// |
// |  PPM Image Processing
// |
//  ---------------------------------------------------------------

void testImage() {
	std::cout << "Loading image ..." << std::endl;
	Test::performance([]{
		PPMLoader loader;
		auto image = loader.load("../data/singapore4k.test.ppm");

		//		RGBToYCbCrConverter converter1;
		//		converter1.convert(image);
		//
		//		image->print();
		//
		//		image->channel2->reduceBySubSampling( image->imageSize.width, image->imageSize.height );
		//		image->channel3->reduceBySubSampling( image->imageSize.width, image->imageSize.height );
		//
		//		YCbCrToRGBConverter converter2;
		//		converter2.convert(image);
		//
		//		image->reduceBySubSample(2, 2);
		//		image->reduceByAverage(2, 2);
		//		image->print();

		//		Test::performance([&loader, &image]{
		//			loader.write("data/output.test.ppm", image);
		//		});
	});
}

//  ---------------------------------------------------------------
// |
// |  JPEG Writer
// |
//  ---------------------------------------------------------------

void testJPEGWriter() {

//	Bitstream bitStream;
//	bitStream.add(1);
//	bitStream.add(0);
//	bitStream.add(1);
//	bitStream.add(1);
//	bitStream.add(0);
//	bitStream.print();
//	bitStream.fillup(1);
//	bitStream.print();
//	bitStream.saveToFile("out.txt");
//
//
//	std::cout << "Testing, Bitstream" << std::endl;
//
//	std::cout << "Write single bit: ";
//	Test::performance(TEST_ITERATIONS, TEST_REPEAT, [](size_t numberOfElements){
//		Bitstream bitstream;
//		while (numberOfElements--) {
//			bitstream.add(numberOfElements % 2);
//		}
//	});
//
//
//	std::cout << "Write byte bits: ";
//	Test::performance(TEST_ITERATIONS, TEST_REPEAT, [](size_t numberOfElements){
//		Bitstream bitstream;
//		// bitstream.add(1);
//		while (numberOfElements--) {
//			bitstream.add(0xd2, 8);
//		}
//	});
//
//
//	// create random bitstream for reading
//	Bitstream testStream;
//	size_t fillRandom = TEST_ITERATIONS;
//	while (fillRandom--)
//		testStream.add( arc4random() % 2 );
//
//
//	std::cout << "Read single bit: ";
//	Test::performance(TEST_ITERATIONS, TEST_REPEAT, [&testStream](size_t numberOfElements){
//		size_t maxRead = testStream.numberOfBits() - 2;
//		size_t idx = 0;
//		while (numberOfElements--) {
//			testStream.read(idx++);
//			if (idx > maxRead)
//				idx = 0;
//		}
//	});
//
//
//	std::cout << "Write file: ";
//	Test::performance([&testStream] {
//		testStream.saveToFile("../data/writeOleg.txt");
//	});
//

	PPMLoader loader;
	auto image = loader.load("../data/very_small.ppm");

	JPEGWriter writer;
	auto testData = generateTestHuffman();
	Huffman huffman(testData);

	writer.writeJPEGImage(image, "../data/Test1.test.jpg", huffman.canonicalEncoding(16));
}

std::vector<Symbol> getWord() {
	std::vector<Symbol> input;
	input.push_back(1);
	input.push_back(4);
	input.push_back(6);

	return input;
}

void addTestSymbol(int amount, int symbol, std::vector<int> &input) {
	for (int i = 0; i < amount; ++i) {
		input.push_back(symbol);
	}
}

std::vector<int> generateTestHuffman() {
	std::vector<int>input;
	addTestSymbol(5, 1, input);
	addTestSymbol(12, 5, input);
	addTestSymbol(13, 6, input);
	addTestSymbol(6, 2, input);
	addTestSymbol(8, 3, input);
	addTestSymbol(8, 4, input);
	return input;
}

std::vector<int> generateTestHuffman2() {
	std::vector<int>input;
	addTestSymbol(5, 1, input);
	addTestSymbol(5, 2, input);
	addTestSymbol(6, 3, input);
	addTestSymbol(11, 4, input);
	addTestSymbol(12, 5, input);
	addTestSymbol(12, 6, input);
	addTestSymbol(26, 7, input);
	return input;
}

void testhuffmann() {
	std::vector<Symbol> testData;

	auto input = generateTestHuffman();

	Huffman huffman = Huffman(input);
	huffman.preventAllOnesPath(true);
	//	auto encodingTable = huffman.canonicalEncoding();
	auto encodingTable = huffman.canonicalEncoding(4);
	//	Node* rootTree = huffman.standardTree();
	Node* rootTree = huffman.treeFromEncodingTable(encodingTable);

	for (auto pair: encodingTable) {
		std::cout << pair.first << ": " << pair.second << std::endl;
	}
	rootTree->print();
	rootTree->exportTree();
	Bitstream bitsteam;
	std::vector<Symbol> word = getWord();
	for (int i = 0; i < word.size(); ++i) {
		Encoding enc = encodingTable.at(word[i]);
		std::cout << "füge " << enc << " hinzu (" << word[i] << ")" << std::endl;
		bitsteam.add(enc.code, enc.numberOfBits);
	}
	bitsteam.print();
}

void testDirectDCT() {
	Mat input;
	input.initiate((float[]){
		2, 2,
		2, 2
	}, 2, 2);

	Mat out = DCT::transform(input);

	out.print();
}

void testIDCT() {
	Mat input;
	input.initiate((float[]){
		2, 2, 2,
		2, 2, 2,
		2, 2, 2
	}, 3, 3);

	Mat out = DCT::transform2(input);
	std::cout << "DCT Mat:" << std::endl;
	out.print();

	Mat inverse = DCT::inverse(out);
	std::cout << "Inverse Mat:" << std::endl;
	inverse.print();
}

void testMat() {
	Mat a;
	a.initiate((float[]){
		1, 0, 0,
		0, 1, 0,
		0, 0, 1}, 3 , 3);

	Mat b;
	b.initiate((float[]){
		1, 2, 3,
		0, 1, 4,
		0, 5, 1}, 3 , 3);

	Mat c = a * b;
	c.print();
}

void testAraiLine()
{
    float *values = new float[8];

    values[0] = 1;
    values[1] = 7;
    values[2] = 3;
    values[3] = 4;
    values[4] = 5;
    values[5] = 4;
    values[6] = 3;
    values[7] = 2;

    Arai::transformLine(values);

    bool test = true;
    float tolerance = 0.0001;

    test = test && (fabsf(values[0] - (10.253f))     < tolerance);
    test = test && (fabsf(values[1] - (0.797218f))   < tolerance);
    test = test && (fabsf(values[2] - (-2.19761f))   < tolerance);
    test = test && (fabsf(values[3] - (-0.0377379f)) < tolerance);
    test = test && (fabsf(values[4] - (-1.76777f))   < tolerance);
    test = test && (fabsf(values[5] - (-2.75264f))   < tolerance);
    test = test && (fabsf(values[6] - (-2.53387f))   < tolerance);
    test = test && (fabsf(values[7] - (-1.13403f))   < tolerance);

    if ( test )
    {
        std::cout << "All values are correct." << std::endl;
    }
    else
    {
        std::cout << "Something went wrong." << std::endl;
    }
}

void testAraiMatrix()
{
    Mat matrix;

    matrix.initiate((float[]) {
        1, 7, 3, 4, 5, 4, 3, 2,
        7, 0, 0, 0, 0, 0, 0, 0,
        3, 0, 0, 0, 0, 0, 0, 0,
        4, 0, 0, 0, 0, 0, 0, 0,
        5, 0, 0, 0, 0, 0, 0, 0,
        4, 0, 0, 0, 0, 0, 0, 0,
        3, 0, 0, 0, 0, 0, 0, 0,
        2, 0, 0, 0, 0, 0, 0, 0
    }, 8, 8);

    matrix = Arai::transform(matrix);
    matrix.print();

    std::cout << std::endl;

    matrix = DCT::inverse(matrix);
    matrix.print();
}

void testTransformations()
{
    Mat matrix;

    matrix.initiate((float[]) {
        1, 7, 3, 4, 5, 4, 3, 2,
        7, 0, 0, 0, 0, 0, 0, 0,
        3, 0, 0, 0, 0, 0, 0, 0,
        4, 0, 0, 0, 0, 0, 0, 0,
        5, 0, 0, 0, 0, 0, 0, 0,
        4, 0, 0, 0, 0, 0, 0, 0,
        3, 0, 0, 0, 0, 0, 0, 0,
        2, 0, 0, 0, 0, 0, 0, 0
    }, 8, 8);

    matrix = DCT::transform(matrix);
    matrix.print();
    std::cout << std::endl;

    matrix = DCT::inverse(matrix);
    matrix.print();
    std::cout << std::endl;

    matrix = DCT::transform2(matrix);
    matrix.print();
    std::cout << std::endl;

    matrix = DCT::inverse(matrix);
    matrix.print();
    std::cout << std::endl;

    matrix = Arai::transform(matrix);
    matrix.print();
    std::cout << std::endl;

    matrix = DCT::inverse(matrix);
    matrix.print();
    std::cout << std::endl;
}

// ################################################################
// #
// #  Main
// #
// ################################################################

int main(int argc, const char *argv[]) {

	//testhuffmann();
    //testJPEGWriter();
	//testDirectDCT();
    //testIDCT();
	//testMat();
	//testImage();
    testAraiLine();
    testAraiMatrix();

	return 0;
}
<commit_msg>Modified main method<commit_after>#include <iostream>
#include <stdlib.h>
#include "io/PPMLoader.hpp"
#include "converter/RGBToYCbCrConverter.hpp"
#include "converter/YCbCrToRGBConverter.hpp"
#include "helper/Test.hpp"
#include "Huffman.hpp"
#include "DCT.hpp"
#include "Arai.hpp"
#include <math.h>

#include "bitstream/Bitstream.hpp"

#include "segments/JPEGSegments.hpp"

using namespace JPEGSegments;

#define TEST_ITERATIONS 10000000
#define TEST_REPEAT 10

std::vector<int> generateTestHuffman();

//  ---------------------------------------------------------------
// |
// |  PPM Image Processing
// |
//  ---------------------------------------------------------------

void testImage() {
	std::cout << "Loading image ..." << std::endl;
	Test::performance([]{
		PPMLoader loader;
		auto image = loader.load("../data/singapore4k.test.ppm");

		//		RGBToYCbCrConverter converter1;
		//		converter1.convert(image);
		//
		//		image->print();
		//
		//		image->channel2->reduceBySubSampling( image->imageSize.width, image->imageSize.height );
		//		image->channel3->reduceBySubSampling( image->imageSize.width, image->imageSize.height );
		//
		//		YCbCrToRGBConverter converter2;
		//		converter2.convert(image);
		//
		//		image->reduceBySubSample(2, 2);
		//		image->reduceByAverage(2, 2);
		//		image->print();

		//		Test::performance([&loader, &image]{
		//			loader.write("data/output.test.ppm", image);
		//		});
	});
}

//  ---------------------------------------------------------------
// |
// |  JPEG Writer
// |
//  ---------------------------------------------------------------

void testJPEGWriter() {

//	Bitstream bitStream;
//	bitStream.add(1);
//	bitStream.add(0);
//	bitStream.add(1);
//	bitStream.add(1);
//	bitStream.add(0);
//	bitStream.print();
//	bitStream.fillup(1);
//	bitStream.print();
//	bitStream.saveToFile("out.txt");
//
//
//	std::cout << "Testing, Bitstream" << std::endl;
//
//	std::cout << "Write single bit: ";
//	Test::performance(TEST_ITERATIONS, TEST_REPEAT, [](size_t numberOfElements){
//		Bitstream bitstream;
//		while (numberOfElements--) {
//			bitstream.add(numberOfElements % 2);
//		}
//	});
//
//
//	std::cout << "Write byte bits: ";
//	Test::performance(TEST_ITERATIONS, TEST_REPEAT, [](size_t numberOfElements){
//		Bitstream bitstream;
//		// bitstream.add(1);
//		while (numberOfElements--) {
//			bitstream.add(0xd2, 8);
//		}
//	});
//
//
//	// create random bitstream for reading
//	Bitstream testStream;
//	size_t fillRandom = TEST_ITERATIONS;
//	while (fillRandom--)
//		testStream.add( arc4random() % 2 );
//
//
//	std::cout << "Read single bit: ";
//	Test::performance(TEST_ITERATIONS, TEST_REPEAT, [&testStream](size_t numberOfElements){
//		size_t maxRead = testStream.numberOfBits() - 2;
//		size_t idx = 0;
//		while (numberOfElements--) {
//			testStream.read(idx++);
//			if (idx > maxRead)
//				idx = 0;
//		}
//	});
//
//
//	std::cout << "Write file: ";
//	Test::performance([&testStream] {
//		testStream.saveToFile("../data/writeOleg.txt");
//	});
//

	PPMLoader loader;
	auto image = loader.load("../data/very_small.ppm");

	JPEGWriter writer;
	auto testData = generateTestHuffman();
	Huffman huffman(testData);

	writer.writeJPEGImage(image, "../data/Test1.test.jpg", huffman.canonicalEncoding(16));
}

std::vector<Symbol> getWord() {
	std::vector<Symbol> input;
	input.push_back(1);
	input.push_back(4);
	input.push_back(6);

	return input;
}

void addTestSymbol(int amount, int symbol, std::vector<int> &input) {
	for (int i = 0; i < amount; ++i) {
		input.push_back(symbol);
	}
}

std::vector<int> generateTestHuffman() {
	std::vector<int>input;
	addTestSymbol(5, 1, input);
	addTestSymbol(12, 5, input);
	addTestSymbol(13, 6, input);
	addTestSymbol(6, 2, input);
	addTestSymbol(8, 3, input);
	addTestSymbol(8, 4, input);
	return input;
}

std::vector<int> generateTestHuffman2() {
	std::vector<int>input;
	addTestSymbol(5, 1, input);
	addTestSymbol(5, 2, input);
	addTestSymbol(6, 3, input);
	addTestSymbol(11, 4, input);
	addTestSymbol(12, 5, input);
	addTestSymbol(12, 6, input);
	addTestSymbol(26, 7, input);
	return input;
}

void testhuffmann() {
	std::vector<Symbol> testData;

	auto input = generateTestHuffman();

	Huffman huffman = Huffman(input);
	huffman.preventAllOnesPath(true);
	//	auto encodingTable = huffman.canonicalEncoding();
	auto encodingTable = huffman.canonicalEncoding(4);
	//	Node* rootTree = huffman.standardTree();
	Node* rootTree = huffman.treeFromEncodingTable(encodingTable);

	for (auto pair: encodingTable) {
		std::cout << pair.first << ": " << pair.second << std::endl;
	}
	rootTree->print();
	rootTree->exportTree();
	Bitstream bitsteam;
	std::vector<Symbol> word = getWord();
	for (int i = 0; i < word.size(); ++i) {
		Encoding enc = encodingTable.at(word[i]);
		std::cout << "füge " << enc << " hinzu (" << word[i] << ")" << std::endl;
		bitsteam.add(enc.code, enc.numberOfBits);
	}
	bitsteam.print();
}

void testDirectDCT() {
	Mat input;
	input.initiate((float[]){
		2, 2,
		2, 2
	}, 2, 2);

	Mat out = DCT::transform(input);

	out.print();
}

void testIDCT() {
	Mat input;
	input.initiate((float[]){
		2, 2, 2,
		2, 2, 2,
		2, 2, 2
	}, 3, 3);

	Mat out = DCT::transform2(input);
	std::cout << "DCT Mat:" << std::endl;
	out.print();

	Mat inverse = DCT::inverse(out);
	std::cout << "Inverse Mat:" << std::endl;
	inverse.print();
}

void testMat() {
	Mat a;
	a.initiate((float[]){
		1, 0, 0,
		0, 1, 0,
		0, 0, 1}, 3 , 3);

	Mat b;
	b.initiate((float[]){
		1, 2, 3,
		0, 1, 4,
		0, 5, 1}, 3 , 3);

	Mat c = a * b;
	c.print();
}

void testAraiLine()
{
    float *values = new float[8];

    values[0] = 1;
    values[1] = 7;
    values[2] = 3;
    values[3] = 4;
    values[4] = 5;
    values[5] = 4;
    values[6] = 3;
    values[7] = 2;

    Arai::transformLine(values);

    bool test = true;
    float tolerance = 0.0001;

    test = test && (fabsf(values[0] - (10.253f))     < tolerance);
    test = test && (fabsf(values[1] - (0.797218f))   < tolerance);
    test = test && (fabsf(values[2] - (-2.19761f))   < tolerance);
    test = test && (fabsf(values[3] - (-0.0377379f)) < tolerance);
    test = test && (fabsf(values[4] - (-1.76777f))   < tolerance);
    test = test && (fabsf(values[5] - (-2.75264f))   < tolerance);
    test = test && (fabsf(values[6] - (-2.53387f))   < tolerance);
    test = test && (fabsf(values[7] - (-1.13403f))   < tolerance);

    if ( test )
    {
        std::cout << "All values are correct." << std::endl;
    }
    else
    {
        std::cout << "Something went wrong." << std::endl;
    }
}

void testAraiMatrix()
{
    Mat matrix;

    matrix.initiate((float[]) {
        1, 7, 3, 4, 5, 4, 3, 2,
        7, 0, 0, 0, 0, 0, 0, 0,
        3, 0, 0, 0, 0, 0, 0, 0,
        4, 0, 0, 0, 0, 0, 0, 0,
        5, 0, 0, 0, 0, 0, 0, 0,
        4, 0, 0, 0, 0, 0, 0, 0,
        3, 0, 0, 0, 0, 0, 0, 0,
        2, 0, 0, 0, 0, 0, 0, 0
    }, 8, 8);

    matrix = Arai::transform(matrix);
    matrix.print();

    std::cout << std::endl;

    matrix = DCT::inverse(matrix);
    matrix.print();
}

void testTransformations(int digits = 5)
{
    Mat matrix;

    matrix.initiate((float[]) {
        1, 7, 3, 4, 5, 4, 3, 2,
        7, 0, 0, 0, 0, 0, 0, 0,
        3, 0, 0, 0, 0, 0, 0, 0,
        4, 0, 0, 0, 0, 0, 0, 0,
        5, 0, 0, 0, 0, 0, 0, 0,
        4, 0, 0, 0, 0, 0, 0, 0,
        3, 0, 0, 0, 0, 0, 0, 0,
        2, 0, 0, 0, 0, 0, 0, 0
    }, 8, 8);

    matrix = DCT::transform(matrix);
    matrix.print(digits);
    std::cout << std::endl;

    matrix = DCT::inverse(matrix);
    matrix.print(digits);
    std::cout << std::endl;

    matrix = DCT::transform2(matrix);
    matrix.print(digits);
    std::cout << std::endl;

    matrix = DCT::inverse(matrix);
    matrix.print(digits);
    std::cout << std::endl;

    matrix = Arai::transform(matrix);
    matrix.print(digits);
    std::cout << std::endl;

    matrix = DCT::inverse(matrix);
    matrix.print(digits);
    std::cout << std::endl;
}

// ################################################################
// #
// #  Main
// #
// ################################################################

int main(int argc, const char *argv[]) {

	//testhuffmann();
    //testJPEGWriter();
	//testDirectDCT();
    //testIDCT();
	//testMat();
	//testImage();
//    testAraiLine();
//    testAraiMatrix();
	testTransformations(0);

	return 0;
}
<|endoftext|>


<commit_before>//===--- Alloc.cpp - Swift Language ABI Allocation Support ----------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// Allocation ABI Shims While the Language is Bootstrapped
//
//===----------------------------------------------------------------------===//

#include "Alloc.h"
#include <stdlib.h>
#include <unistd.h>

struct SwiftHeapObject *
swift_alloc(struct SwiftHeapMetadata *metadata,
            size_t requiredSize,
            size_t requiredAlignment)
{
  size_t mask = requiredAlignment - 1;
  struct SwiftHeapMetadata **object;
  for (;;) {
    object = reinterpret_cast<struct SwiftHeapMetadata **>(
      calloc(1, (requiredSize + mask) & ~mask));
    if (object) {
      break;
    }
    sleep(1); // XXX FIXME -- Enqueue this thread and resume after free()
  }
  *object = metadata;
  return reinterpret_cast<struct SwiftHeapObject *>(object);
}

struct SwiftHeapObject *
swift_retain(struct SwiftHeapObject *object)
{
  if (!object) {
    return NULL;
  }
  ++object->runtimePrivateData;
  return object;
}

void
swift_release(struct SwiftHeapObject *object)
{
  if (!object) {
    return;
  }
  if (--object->runtimePrivateData > 0) {
    return;
  }
  size_t allocSize = object->metadata->destroy(object);
  if (allocSize) {
    swift_dealloc(object, allocSize);
  }
}

void
swift_dealloc(struct SwiftHeapObject *object, size_t allocatedSize)
{
  free(object);
}
<commit_msg>switch to c++-style standard header.<commit_after>//===--- Alloc.cpp - Swift Language ABI Allocation Support ----------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// Allocation ABI Shims While the Language is Bootstrapped
//
//===----------------------------------------------------------------------===//

#include "Alloc.h"
#include <cstdlib>
#include <unistd.h>

struct SwiftHeapObject *
swift_alloc(struct SwiftHeapMetadata *metadata,
            size_t requiredSize,
            size_t requiredAlignment)
{
  size_t mask = requiredAlignment - 1;
  struct SwiftHeapMetadata **object;
  for (;;) {
    object = reinterpret_cast<struct SwiftHeapMetadata **>(
      calloc(1, (requiredSize + mask) & ~mask));
    if (object) {
      break;
    }
    sleep(1); // XXX FIXME -- Enqueue this thread and resume after free()
  }
  *object = metadata;
  return reinterpret_cast<struct SwiftHeapObject *>(object);
}

struct SwiftHeapObject *
swift_retain(struct SwiftHeapObject *object)
{
  if (!object) {
    return NULL;
  }
  ++object->runtimePrivateData;
  return object;
}

void
swift_release(struct SwiftHeapObject *object)
{
  if (!object) {
    return;
  }
  if (--object->runtimePrivateData > 0) {
    return;
  }
  size_t allocSize = object->metadata->destroy(object);
  if (allocSize) {
    swift_dealloc(object, allocSize);
  }
}

void
swift_dealloc(struct SwiftHeapObject *object, size_t allocatedSize)
{
  free(object);
}
<|endoftext|>


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

class SvXMLExport;
namespace com { namespace sun { namespace star {
    namespace uno { template<typename T> class Reference; }
    namespace frame { class XModel; }
    namespace beans { class XPropertySet; }
} } }
namespace rtl { class OUString; }

/** export an XForms model. */
void SAL_DLLPRIVATE exportXForms( SvXMLExport& );

rtl::OUString SAL_DLLPRIVATE getXFormsBindName( const com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet>& xBinding );

rtl::OUString SAL_DLLPRIVATE getXFormsListBindName( const com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet>& xBinding );

rtl::OUString SAL_DLLPRIVATE getXFormsSubmissionName( const com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet>& xBinding );

#endif
<commit_msg>INTEGRATION: CWS warnings01 (1.4.34); FILE MERGED 2005/11/04 14:50:28 cl 1.4.34.1: warning free code changes<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: xformsexport.hxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: hr $ $Date: 2006-06-19 17:57:59 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/
#ifndef _XMLOFF_XFORMSEXPORT_HXX
#define _XMLOFF_XFORMSEXPORT_HXX

#ifndef INCLUDED_XMLOFF_DLLAPI_H
#include "xmloff/dllapi.h"
#endif

class SvXMLExport;
namespace com { namespace sun { namespace star {
    namespace uno { template<typename T> class Reference; }
    namespace frame { class XModel; }
    namespace beans { class XPropertySet; }
} } }
namespace rtl { class OUString; }

/** export an XForms model. */
void SAL_DLLPRIVATE exportXForms( SvXMLExport& );

rtl::OUString SAL_DLLPRIVATE getXFormsBindName( const com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet>& xBinding );

rtl::OUString SAL_DLLPRIVATE getXFormsListBindName( const com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet>& xBinding );

rtl::OUString SAL_DLLPRIVATE getXFormsSubmissionName( const com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet>& xBinding );

#endif
<|endoftext|>


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

#ifndef __FRAMEWORK_MACROS_REGISTRATION_HXX_
#include <macros/registration.hxx>
#endif

/*=================================================================================================================
    Add new include and new register info to for new services.

    Example:

        #ifndef __YOUR_SERVICE_1_HXX_
        #include <service1.hxx>
        #endif

        #ifndef __YOUR_SERVICE_2_HXX_
        #include <service2.hxx>
        #endif

        COMPONENTGETIMPLEMENTATIONENVIRONMENT

        COMPONENTWRITEINFO  (   COMPONENTINFO( Service1 )
                                 COMPONENTINFO( Service2 )
                            )

        COMPONENTGETFACTORY (   IFFACTORIE( Service1 )
                                 else
                                IFFACTORIE( Service2 )
                             )
=================================================================================================================*/

#ifndef __FRAMEWORK_SERVICES_URLTRANSFORMER_HXX_
#include <services/urltransformer.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_DESKTOP_HXX_
#include <services/desktop.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_DOCUMENTPROPERTIES_HXX_
#include <services/documentproperties.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_FRAME_HXX_
#include <services/frame.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_MODULEMANAGER_HXX_
#include <services/modulemanager.hxx>
#endif

#ifndef __FRAMEWORK_JOBS_JOBEXECUTOR_HXX_
#include <jobs/jobexecutor.hxx>
#endif

#ifndef __FRAMEWORK_DISPATCH_SOUNDHANDLER_HXX_
#include <dispatch/soundhandler.hxx>
#endif

#ifndef __FRAMEWORK_RECORDING_DISPATCHRECORDERSUPPLIER_HXX_
#include <recording/dispatchrecordersupplier.hxx>
#endif

#ifndef __FRAMEWORK_RECORDING_DISPATCHRECORDER_HXX_
#include <recording/dispatchrecorder.hxx>
#endif

#ifndef __FRAMEWORK_DISPATCH_MAILTODISPATCHER_HXX_
#include <dispatch/mailtodispatcher.hxx>
#endif

#ifndef __FRAMEWORK_DISPATCH_SERVICEHANDLER_HXX_
#include <dispatch/servicehandler.hxx>
#endif

#ifndef __FRAMEWORK_JOBS_JOBDISPATCH_HXX_
#include <jobs/jobdispatch.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_BACKINGCOMP_HXX_
#include <services/backingcomp.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_DISPATCHHELPER_HXX_
#include <services/dispatchhelper.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_LAYOUTMANAGER_HXX_
#include <services/layoutmanager.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_LICENSE_HXX_
#include <services/license.hxx>
#endif

#ifndef __FRAMEWORK_UIFACTORY_UIELEMENTFACTORYMANAGER_HXX_
#include <uifactory/uielementfactorymanager.hxx>
#endif

#ifndef __FRAMEWORK_UIFACTORY_POPUPMENUCONTROLLERFACTORY_HXX_
#include <uifactory/popupmenucontrollerfactory.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_FONTMENUCONTROLLER_HXX_
#include <uielement/fontmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_FONTSIZEMENUCONTROLLER_HXX_
#include <uielement/fontsizemenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_OBJECTMENUCONTROLLER_HXX_
#include <uielement/objectmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_HEADERMENUCONTROLLER_HXX_
#include <uielement/headermenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_FOOTERMENUCONTROLLER_HXX_
#include <uielement/footermenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_CONTROLMENUCONTROLLER_HXX_
#include <uielement/controlmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_MACROSMENUCONTROLLER_HXX_
#include <uielement/macrosmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_UICOMMANDDESCRIPTION_HXX_
#include <uielement/uicommanddescription.hxx>
#endif

#ifndef __FRAMEWORK_UICONFIGURATION_UICONFIGMANAGER_HXX_
#include <uiconfiguration/uiconfigurationmanager.hxx>
#endif

#ifndef __FRAMEWORK_UICONFIGURATION_MODULEUICFGSUPPLIER_HXX_
#include <uiconfiguration/moduleuicfgsupplier.hxx>
#endif

#ifndef __FRAMEWORK_UICONFIGURATION_MODULEUICONFIGMANAGER_HXX_
#include <uiconfiguration/moduleuiconfigurationmanager.hxx>
#endif

#ifndef __FRAMEWORK_UIFACTORY_MENUBARFACTORY_HXX_
#include <uifactory/menubarfactory.hxx>
#endif

#ifndef __FRAMEWORK_ACCELERATORS_GLOBALACCELERATORCONFIGURATION_HXX_
#include <accelerators/globalacceleratorconfiguration.hxx>
#endif

#ifndef __FRAMEWORK_ACCELERATORS_MODULEACCELERATORCONFIGURATION_HXX_
#include <accelerators/moduleacceleratorconfiguration.hxx>
#endif

#ifndef __FRAMEWORK_ACCELERATORS_DOCUMENTACCELERATORCONFIGURATION_HXX_
#include <accelerators/documentacceleratorconfiguration.hxx>
#endif

#ifndef __FRAMEWORK_UIFACTORY_TOOLBOXFACTORY_HXX_
#include <uifactory/toolboxfactory.hxx>
#endif

#ifndef __FRAMEWORK_UIFACTORY_ADDONSTOOLBOXFACTORY_HXX_
#include <uifactory/addonstoolboxfactory.hxx>
#endif

#ifndef __FRAMEWORK_UICONFIGURATION_WINDOWSTATECONFIGURATION_HXX_
#include "uiconfiguration/windowstateconfiguration.hxx"
#endif

#ifndef __FRAMEWORK_UIELEMENT_TOOLBARSMENUCONTROLLER_HXX_
#include <uielement/toolbarsmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIFACTORY_TOOLBARCONTROLLERFACTORY_HXX_
#include "uifactory/toolbarcontrollerfactory.hxx"
#endif

#ifndef __FRAMEWORK_UIFACTORY_STATUSBARCONTROLLERFACTORY_HXX_
#include "uifactory/statusbarcontrollerfactory.hxx"
#endif

#ifndef __FRAMEWORK_UIELEMENT_TOOLBARSMENUCONTROLLER_HXX_
#include <uielement/toolbarsmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_AUTORECOVERY_HXX_
#include <services/autorecovery.hxx>
#endif

#ifndef __FRAMEWORK_HELPER_STATUSINDICATORFACTORY_HXX_
#include <helper/statusindicatorfactory.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_RECENTFILESMENUCONTROLLER_HXX_
#include <uielement/recentfilesmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIFACTORY_STATUSBARFACTORY_HXX_
#include <uifactory/statusbarfactory.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_UICATEGORYDESCRPTION_HXX_
#include <uiconfiguration/uicategorydescription.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_SESSIONLISTENER_HXX_
#include <services/sessionlistener.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_NEWMENUCONTROLLER_HXX_
#include <uielement/newmenucontroller.hxx>
#endif

COMPONENTGETIMPLEMENTATIONENVIRONMENT

COMPONENTWRITEINFO  (   COMPONENTINFO( ::framework::URLTransformer                          )
                        COMPONENTINFO( ::framework::Desktop                                 )
                        COMPONENTINFO( ::framework::Frame                                   )
                        COMPONENTINFO( ::framework::DocumentProperties                      )
                        COMPONENTINFO( ::framework::SoundHandler                            )
                        COMPONENTINFO( ::framework::JobExecutor                             )
                        COMPONENTINFO( ::framework::DispatchRecorderSupplier                )
                        COMPONENTINFO( ::framework::DispatchRecorder                        )
                        COMPONENTINFO( ::framework::MailToDispatcher                        )
                        COMPONENTINFO( ::framework::ServiceHandler                          )
                        COMPONENTINFO( ::framework::JobDispatch                             )
                        COMPONENTINFO( ::framework::BackingComp                             )
                        COMPONENTINFO( ::framework::DispatchHelper                          )
                        COMPONENTINFO( ::framework::LayoutManager                           )
                        COMPONENTINFO( ::framework::License                                 )
                        COMPONENTINFO( ::framework::UIElementFactoryManager                 )
                        COMPONENTINFO( ::framework::PopupMenuControllerFactory              )
                        COMPONENTINFO( ::framework::FontMenuController                      )
                        COMPONENTINFO( ::framework::FontSizeMenuController                  )
                        COMPONENTINFO( ::framework::ObjectMenuController                    )
                        COMPONENTINFO( ::framework::HeaderMenuController                    )
                        COMPONENTINFO( ::framework::FooterMenuController                    )
                        COMPONENTINFO( ::framework::ControlMenuController                   )
                        COMPONENTINFO( ::framework::MacrosMenuController                    )
                        COMPONENTINFO( ::framework::UICommandDescription                    )
                        COMPONENTINFO( ::framework::ModuleManager                           )
                        COMPONENTINFO( ::framework::UIConfigurationManager                  )
                        COMPONENTINFO( ::framework::ModuleUIConfigurationManagerSupplier    )
                        COMPONENTINFO( ::framework::ModuleUIConfigurationManager            )
                        COMPONENTINFO( ::framework::MenuBarFactory                          )
                        COMPONENTINFO( ::framework::GlobalAcceleratorConfiguration          )
                        COMPONENTINFO( ::framework::ModuleAcceleratorConfiguration          )
                        COMPONENTINFO( ::framework::DocumentAcceleratorConfiguration        )
                        COMPONENTINFO( ::framework::ToolBoxFactory                          )
                        COMPONENTINFO( ::framework::AddonsToolBoxFactory                    )
                        COMPONENTINFO( ::framework::WindowStateConfiguration                )
                        COMPONENTINFO( ::framework::ToolbarControllerFactory                )
                        COMPONENTINFO( ::framework::ToolbarsMenuController                  )
                        COMPONENTINFO( ::framework::AutoRecovery                            )
                        COMPONENTINFO( ::framework::StatusIndicatorFactory                  )
                        COMPONENTINFO( ::framework::RecentFilesMenuController               )
                        COMPONENTINFO( ::framework::StatusBarFactory                        )
                        COMPONENTINFO( ::framework::UICategoryDescription                   )
                        COMPONENTINFO( ::framework::StatusbarControllerFactory              )
                        COMPONENTINFO( ::framework::SessionListener                         )
                        COMPONENTINFO( ::framework::NewMenuController                       )
                    )

COMPONENTGETFACTORY (   IFFACTORY( ::framework::URLTransformer                          )   else
                        IFFACTORY( ::framework::Desktop                                 )   else
                        IFFACTORY( ::framework::Frame                                   )   else
                        IFFACTORY( ::framework::DocumentProperties                      )   else
                        IFFACTORY( ::framework::SoundHandler                            )   else
                        IFFACTORY( ::framework::JobExecutor                             )   else
                        IFFACTORY( ::framework::DispatchRecorderSupplier                )   else
                        IFFACTORY( ::framework::DispatchRecorder                        )   else
                        IFFACTORY( ::framework::MailToDispatcher                        )   else
                        IFFACTORY( ::framework::ServiceHandler                          )   else
                        IFFACTORY( ::framework::JobDispatch                             )   else
                        IFFACTORY( ::framework::BackingComp                             )   else
                        IFFACTORY( ::framework::DispatchHelper                          )   else
                        IFFACTORY( ::framework::LayoutManager                           )   else
                        IFFACTORY( ::framework::License                                 )   else
                        IFFACTORY( ::framework::UIElementFactoryManager                 )   else
                        IFFACTORY( ::framework::PopupMenuControllerFactory              )   else
                        IFFACTORY( ::framework::FontMenuController                      )   else
                        IFFACTORY( ::framework::FontSizeMenuController                  )   else
                        IFFACTORY( ::framework::ObjectMenuController                    )   else
                        IFFACTORY( ::framework::HeaderMenuController                    )   else
                        IFFACTORY( ::framework::FooterMenuController                    )   else
                        IFFACTORY( ::framework::ControlMenuController                   )   else
                        IFFACTORY( ::framework::MacrosMenuController                    )   else
                        IFFACTORY( ::framework::UICommandDescription                    )   else
                        IFFACTORY( ::framework::ModuleManager                           )   else
                        IFFACTORY( ::framework::UIConfigurationManager                  )   else
                        IFFACTORY( ::framework::ModuleUIConfigurationManagerSupplier    )   else
                        IFFACTORY( ::framework::ModuleUIConfigurationManager            )   else
                        IFFACTORY( ::framework::MenuBarFactory                          )   else
                        IFFACTORY( ::framework::GlobalAcceleratorConfiguration          )   else
                        IFFACTORY( ::framework::ModuleAcceleratorConfiguration          )   else
                        IFFACTORY( ::framework::DocumentAcceleratorConfiguration        )   else
                        IFFACTORY( ::framework::ToolBoxFactory                          )   else
                        IFFACTORY( ::framework::AddonsToolBoxFactory                    )   else
                        IFFACTORY( ::framework::WindowStateConfiguration                )   else
                        IFFACTORY( ::framework::ToolbarControllerFactory                )   else
                        IFFACTORY( ::framework::ToolbarsMenuController                  )   else
                        IFFACTORY( ::framework::AutoRecovery                            )   else
                        IFFACTORY( ::framework::StatusIndicatorFactory                  )   else
                        IFFACTORY( ::framework::RecentFilesMenuController               )   else
                        IFFACTORY( ::framework::StatusBarFactory                        )   else
                        IFFACTORY( ::framework::UICategoryDescription                   )   else
                        IFFACTORY( ::framework::SessionListener                         )
else
                        IFFACTORY( ::framework::StatusbarControllerFactory              )   else
                        IFFACTORY( ::framework::NewMenuController                       )
            )

<commit_msg>INTEGRATION: CWS c01v005 (1.29.26); FILE MERGED 2005/03/05 00:31:27 hjs 1.29.26.2: RESYNC: (1.29-1.30); FILE MERGED 2005/02/22 17:01:19 cd 1.29.26.1: #119876# new statusbar logo controllers<commit_after>/*************************************************************************
 *
 *  $RCSfile: registerservices.cxx,v $
 *
 *  $Revision: 1.31 $
 *
 *  last change: $Author: obo $ $Date: 2005-03-15 12:57:01 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/
//_________________________________________________________________________________________________________________
//  includes of my own project
//_________________________________________________________________________________________________________________

#ifndef __FRAMEWORK_MACROS_REGISTRATION_HXX_
#include <macros/registration.hxx>
#endif

/*=================================================================================================================
    Add new include and new register info to for new services.

    Example:

        #ifndef __YOUR_SERVICE_1_HXX_
        #include <service1.hxx>
        #endif

        #ifndef __YOUR_SERVICE_2_HXX_
        #include <service2.hxx>
        #endif

        COMPONENTGETIMPLEMENTATIONENVIRONMENT

        COMPONENTWRITEINFO  (   COMPONENTINFO( Service1 )
                                 COMPONENTINFO( Service2 )
                            )

        COMPONENTGETFACTORY (   IFFACTORIE( Service1 )
                                 else
                                IFFACTORIE( Service2 )
                             )
=================================================================================================================*/

#ifndef __FRAMEWORK_SERVICES_URLTRANSFORMER_HXX_
#include <services/urltransformer.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_DESKTOP_HXX_
#include <services/desktop.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_DOCUMENTPROPERTIES_HXX_
#include <services/documentproperties.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_FRAME_HXX_
#include <services/frame.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_MODULEMANAGER_HXX_
#include <services/modulemanager.hxx>
#endif

#ifndef __FRAMEWORK_JOBS_JOBEXECUTOR_HXX_
#include <jobs/jobexecutor.hxx>
#endif

#ifndef __FRAMEWORK_DISPATCH_SOUNDHANDLER_HXX_
#include <dispatch/soundhandler.hxx>
#endif

#ifndef __FRAMEWORK_RECORDING_DISPATCHRECORDERSUPPLIER_HXX_
#include <recording/dispatchrecordersupplier.hxx>
#endif

#ifndef __FRAMEWORK_RECORDING_DISPATCHRECORDER_HXX_
#include <recording/dispatchrecorder.hxx>
#endif

#ifndef __FRAMEWORK_DISPATCH_MAILTODISPATCHER_HXX_
#include <dispatch/mailtodispatcher.hxx>
#endif

#ifndef __FRAMEWORK_DISPATCH_SERVICEHANDLER_HXX_
#include <dispatch/servicehandler.hxx>
#endif

#ifndef __FRAMEWORK_JOBS_JOBDISPATCH_HXX_
#include <jobs/jobdispatch.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_BACKINGCOMP_HXX_
#include <services/backingcomp.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_DISPATCHHELPER_HXX_
#include <services/dispatchhelper.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_LAYOUTMANAGER_HXX_
#include <services/layoutmanager.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_LICENSE_HXX_
#include <services/license.hxx>
#endif

#ifndef __FRAMEWORK_UIFACTORY_UIELEMENTFACTORYMANAGER_HXX_
#include <uifactory/uielementfactorymanager.hxx>
#endif

#ifndef __FRAMEWORK_UIFACTORY_POPUPMENUCONTROLLERFACTORY_HXX_
#include <uifactory/popupmenucontrollerfactory.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_FONTMENUCONTROLLER_HXX_
#include <uielement/fontmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_FONTSIZEMENUCONTROLLER_HXX_
#include <uielement/fontsizemenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_OBJECTMENUCONTROLLER_HXX_
#include <uielement/objectmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_HEADERMENUCONTROLLER_HXX_
#include <uielement/headermenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_FOOTERMENUCONTROLLER_HXX_
#include <uielement/footermenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_CONTROLMENUCONTROLLER_HXX_
#include <uielement/controlmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_MACROSMENUCONTROLLER_HXX_
#include <uielement/macrosmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_UICOMMANDDESCRIPTION_HXX_
#include <uielement/uicommanddescription.hxx>
#endif

#ifndef __FRAMEWORK_UICONFIGURATION_UICONFIGMANAGER_HXX_
#include <uiconfiguration/uiconfigurationmanager.hxx>
#endif

#ifndef __FRAMEWORK_UICONFIGURATION_MODULEUICFGSUPPLIER_HXX_
#include <uiconfiguration/moduleuicfgsupplier.hxx>
#endif

#ifndef __FRAMEWORK_UICONFIGURATION_MODULEUICONFIGMANAGER_HXX_
#include <uiconfiguration/moduleuiconfigurationmanager.hxx>
#endif

#ifndef __FRAMEWORK_UIFACTORY_MENUBARFACTORY_HXX_
#include <uifactory/menubarfactory.hxx>
#endif

#ifndef __FRAMEWORK_ACCELERATORS_GLOBALACCELERATORCONFIGURATION_HXX_
#include <accelerators/globalacceleratorconfiguration.hxx>
#endif

#ifndef __FRAMEWORK_ACCELERATORS_MODULEACCELERATORCONFIGURATION_HXX_
#include <accelerators/moduleacceleratorconfiguration.hxx>
#endif

#ifndef __FRAMEWORK_ACCELERATORS_DOCUMENTACCELERATORCONFIGURATION_HXX_
#include <accelerators/documentacceleratorconfiguration.hxx>
#endif

#ifndef __FRAMEWORK_UIFACTORY_TOOLBOXFACTORY_HXX_
#include <uifactory/toolboxfactory.hxx>
#endif

#ifndef __FRAMEWORK_UIFACTORY_ADDONSTOOLBOXFACTORY_HXX_
#include <uifactory/addonstoolboxfactory.hxx>
#endif

#ifndef __FRAMEWORK_UICONFIGURATION_WINDOWSTATECONFIGURATION_HXX_
#include "uiconfiguration/windowstateconfiguration.hxx"
#endif

#ifndef __FRAMEWORK_UIELEMENT_TOOLBARSMENUCONTROLLER_HXX_
#include <uielement/toolbarsmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIFACTORY_TOOLBARCONTROLLERFACTORY_HXX_
#include "uifactory/toolbarcontrollerfactory.hxx"
#endif

#ifndef __FRAMEWORK_UIFACTORY_STATUSBARCONTROLLERFACTORY_HXX_
#include "uifactory/statusbarcontrollerfactory.hxx"
#endif

#ifndef __FRAMEWORK_UIELEMENT_TOOLBARSMENUCONTROLLER_HXX_
#include <uielement/toolbarsmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_AUTORECOVERY_HXX_
#include <services/autorecovery.hxx>
#endif

#ifndef __FRAMEWORK_HELPER_STATUSINDICATORFACTORY_HXX_
#include <helper/statusindicatorfactory.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_RECENTFILESMENUCONTROLLER_HXX_
#include <uielement/recentfilesmenucontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIFACTORY_STATUSBARFACTORY_HXX_
#include <uifactory/statusbarfactory.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_UICATEGORYDESCRPTION_HXX_
#include <uiconfiguration/uicategorydescription.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_SESSIONLISTENER_HXX_
#include <services/sessionlistener.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_LOGOIMAGESTATUSBARCONTROLLER_HXX_
#include <uielement/logoimagestatusbarcontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_LOGOTEXTSTATUSBARCONTROLLER_HXX_
#include <uielement/logotextstatusbarcontroller.hxx>
#endif

#ifndef __FRAMEWORK_UIELEMENT_NEWMENUCONTROLLER_HXX_
#include <uielement/newmenucontroller.hxx>
#endif

COMPONENTGETIMPLEMENTATIONENVIRONMENT

COMPONENTWRITEINFO  (   COMPONENTINFO( ::framework::URLTransformer                          )
                        COMPONENTINFO( ::framework::Desktop                                 )
                        COMPONENTINFO( ::framework::Frame                                   )
                        COMPONENTINFO( ::framework::DocumentProperties                      )
                        COMPONENTINFO( ::framework::SoundHandler                            )
                        COMPONENTINFO( ::framework::JobExecutor                             )
                        COMPONENTINFO( ::framework::DispatchRecorderSupplier                )
                        COMPONENTINFO( ::framework::DispatchRecorder                        )
                        COMPONENTINFO( ::framework::MailToDispatcher                        )
                        COMPONENTINFO( ::framework::ServiceHandler                          )
                        COMPONENTINFO( ::framework::JobDispatch                             )
                        COMPONENTINFO( ::framework::BackingComp                             )
                        COMPONENTINFO( ::framework::DispatchHelper                          )
                        COMPONENTINFO( ::framework::LayoutManager                           )
                        COMPONENTINFO( ::framework::License                                 )
                        COMPONENTINFO( ::framework::UIElementFactoryManager                 )
                        COMPONENTINFO( ::framework::PopupMenuControllerFactory              )
                        COMPONENTINFO( ::framework::FontMenuController                      )
                        COMPONENTINFO( ::framework::FontSizeMenuController                  )
                        COMPONENTINFO( ::framework::ObjectMenuController                    )
                        COMPONENTINFO( ::framework::HeaderMenuController                    )
                        COMPONENTINFO( ::framework::FooterMenuController                    )
                        COMPONENTINFO( ::framework::ControlMenuController                   )
                        COMPONENTINFO( ::framework::MacrosMenuController                    )
                        COMPONENTINFO( ::framework::UICommandDescription                    )
                        COMPONENTINFO( ::framework::ModuleManager                           )
                        COMPONENTINFO( ::framework::UIConfigurationManager                  )
                        COMPONENTINFO( ::framework::ModuleUIConfigurationManagerSupplier    )
                        COMPONENTINFO( ::framework::ModuleUIConfigurationManager            )
                        COMPONENTINFO( ::framework::MenuBarFactory                          )
                        COMPONENTINFO( ::framework::GlobalAcceleratorConfiguration          )
                        COMPONENTINFO( ::framework::ModuleAcceleratorConfiguration          )
                        COMPONENTINFO( ::framework::DocumentAcceleratorConfiguration        )
                        COMPONENTINFO( ::framework::ToolBoxFactory                          )
                        COMPONENTINFO( ::framework::AddonsToolBoxFactory                    )
                        COMPONENTINFO( ::framework::WindowStateConfiguration                )
                        COMPONENTINFO( ::framework::ToolbarControllerFactory                )
                        COMPONENTINFO( ::framework::ToolbarsMenuController                  )
                        COMPONENTINFO( ::framework::AutoRecovery                            )
                        COMPONENTINFO( ::framework::StatusIndicatorFactory                  )
                        COMPONENTINFO( ::framework::RecentFilesMenuController               )
                        COMPONENTINFO( ::framework::StatusBarFactory                        )
                        COMPONENTINFO( ::framework::UICategoryDescription                   )
                        COMPONENTINFO( ::framework::StatusbarControllerFactory              )
                        COMPONENTINFO( ::framework::SessionListener                         )
                        COMPONENTINFO( ::framework::LogoImageStatusbarController            )
                        COMPONENTINFO( ::framework::LogoTextStatusbarController             )
                        COMPONENTINFO( ::framework::NewMenuController                       )
                    )

COMPONENTGETFACTORY (   IFFACTORY( ::framework::URLTransformer                          )   else
                        IFFACTORY( ::framework::Desktop                                 )   else
                        IFFACTORY( ::framework::Frame                                   )   else
                        IFFACTORY( ::framework::DocumentProperties                      )   else
                        IFFACTORY( ::framework::SoundHandler                            )   else
                        IFFACTORY( ::framework::JobExecutor                             )   else
                        IFFACTORY( ::framework::DispatchRecorderSupplier                )   else
                        IFFACTORY( ::framework::DispatchRecorder                        )   else
                        IFFACTORY( ::framework::MailToDispatcher                        )   else
                        IFFACTORY( ::framework::ServiceHandler                          )   else
                        IFFACTORY( ::framework::JobDispatch                             )   else
                        IFFACTORY( ::framework::BackingComp                             )   else
                        IFFACTORY( ::framework::DispatchHelper                          )   else
                        IFFACTORY( ::framework::LayoutManager                           )   else
                        IFFACTORY( ::framework::License                                 )   else
                        IFFACTORY( ::framework::UIElementFactoryManager                 )   else
                        IFFACTORY( ::framework::PopupMenuControllerFactory              )   else
                        IFFACTORY( ::framework::FontMenuController                      )   else
                        IFFACTORY( ::framework::FontSizeMenuController                  )   else
                        IFFACTORY( ::framework::ObjectMenuController                    )   else
                        IFFACTORY( ::framework::HeaderMenuController                    )   else
                        IFFACTORY( ::framework::FooterMenuController                    )   else
                        IFFACTORY( ::framework::ControlMenuController                   )   else
                        IFFACTORY( ::framework::MacrosMenuController                    )   else
                        IFFACTORY( ::framework::UICommandDescription                    )   else
                        IFFACTORY( ::framework::ModuleManager                           )   else
                        IFFACTORY( ::framework::UIConfigurationManager                  )   else
                        IFFACTORY( ::framework::ModuleUIConfigurationManagerSupplier    )   else
                        IFFACTORY( ::framework::ModuleUIConfigurationManager            )   else
                        IFFACTORY( ::framework::MenuBarFactory                          )   else
                        IFFACTORY( ::framework::GlobalAcceleratorConfiguration          )   else
                        IFFACTORY( ::framework::ModuleAcceleratorConfiguration          )   else
                        IFFACTORY( ::framework::DocumentAcceleratorConfiguration        )   else
                        IFFACTORY( ::framework::ToolBoxFactory                          )   else
                        IFFACTORY( ::framework::AddonsToolBoxFactory                    )   else
                        IFFACTORY( ::framework::WindowStateConfiguration                )   else
                        IFFACTORY( ::framework::ToolbarControllerFactory                )   else
                        IFFACTORY( ::framework::ToolbarsMenuController                  )   else
                        IFFACTORY( ::framework::AutoRecovery                            )   else
                        IFFACTORY( ::framework::StatusIndicatorFactory                  )   else
                        IFFACTORY( ::framework::RecentFilesMenuController               )   else
                        IFFACTORY( ::framework::StatusBarFactory                        )   else
                        IFFACTORY( ::framework::UICategoryDescription                   )   else
                        IFFACTORY( ::framework::SessionListener                         )   else
                        IFFACTORY( ::framework::StatusbarControllerFactory              )   else
                        IFFACTORY( ::framework::SessionListener                         )   else
                        IFFACTORY( ::framework::LogoImageStatusbarController            )   else
                        IFFACTORY( ::framework::LogoTextStatusbarController             )   else
                        IFFACTORY( ::framework::NewMenuController                       )
            )

<|endoftext|>


<commit_before>//
// Copyright (c) 2015 CNRS
//
// This file is part of Pinocchio
// Pinocchio is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// Pinocchio 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
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// Pinocchio If not, see
// <http://www.gnu.org/licenses/>.

#ifndef __math_explog_hpp__
# define __math_explog_hpp__

# include <Eigen/Geometry>

# include "pinocchio/math/sincos.hpp"
# include "pinocchio/spatial/motion.hpp"
# include "pinocchio/spatial/skew.hpp"
# include "pinocchio/spatial/se3.hpp"

namespace se3
{
  /// \brief Exp: so3 -> SO3.
  ///
  /// Return the integral of the input angular velocity during time 1.
  template <typename D> Eigen::Matrix<typename D::Scalar,3,3,D::Options>
  exp3(const Eigen::MatrixBase<D> & v)
  {
    EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(D,3);
    return Eigen::AngleAxis<typename D::Scalar>(v.norm(), v).matrix();
  }

  /// \brief Log: SO3 -> so3.
  ///
  /// Pseudo-inverse of log from SO3 -> { v \in so3, ||v|| < 2pi }.
  template <typename D> Eigen::Matrix<typename D::Scalar,3,1,D::Options>
  log3(const Eigen::MatrixBase<D> & R)
  {
    EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(D, 3, 3);
    Eigen::AngleAxis<typename D::Scalar> angleAxis(R);
    return angleAxis.axis() * angleAxis.angle();
  }

  /// \brief Exp: se3 -> SE3.
  ///
  /// Return the integral of the input spatial velocity during time 1.
  template <typename _Scalar, int _Options> SE3Tpl<_Scalar, _Options>
  exp6(const MotionTpl<_Scalar,_Options> & nu)
  {
    typedef _Scalar Scalar;
    typedef typename MotionTpl<Scalar,_Options>::Vector3 Vector3;
    typedef typename MotionTpl<Scalar,_Options>::Matrix3 Matrix3;

    const Vector3 & w = nu.angular();
    const Vector3 & v = nu.linear();
    Scalar t = w.norm();
    if (t > 1e-15)
    {
      Matrix3 R(exp3(w));
      Matrix3 S(skew(w));
      Matrix3 V(
        Matrix3::Identity() +
        (1 - cos(t)) / (t * t) * S + (t - sin(t)) / (t * t * t) * S * S);
      Vector3 p(V * v);
      return SE3Tpl<_Scalar, _Options>(R, p);
    }
    else
    {
      return SE3Tpl<_Scalar, _Options>(Matrix3::Identity(), v);
    }
  }

  /// \brief Exp: se3 -> SE3.
  ///
  /// Return the integral of the input spatial velocity during time 1.
  template <typename D> Eigen::Matrix<typename D::Scalar,6,6,D::Options>
  exp6(const Eigen::MatrixBase<D> & v)
  {
    EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(D,6);
    MotionTpl<typename D::Scalar,D::Options> nu(v);
    SE3Tpl<typename D::Scalar,D::Options> m(exp6(nu));
    return m.toActionMatrix();
  }

  /// \brief Log: SE3 -> se3.
  ///
  /// Pseudo-inverse of exp from SE3 -> { v,w \in se3, ||w|| < 2pi }.
  template <typename _Scalar, int _Options> MotionTpl<_Scalar,_Options>
  log6(const SE3Tpl<_Scalar, _Options> & m)
  {
    typedef _Scalar Scalar;
    typedef typename SE3Tpl<Scalar,_Options>::Vector3 Vector3;
    typedef typename SE3Tpl<Scalar,_Options>::Matrix3 Matrix3;

    const Matrix3 & R = m.rotation();
    const Vector3 & p = m.translation();
    Vector3 w(log3(R));
    Vector3 v;
    Scalar t = w.norm();
    if (t > 1e-15)
    {
      Matrix3 S(skew(w));
      Matrix3 V(
        Matrix3::Identity() +
        (1 - cos(t)) / (t * t) * S + (t - sin(t)) / (t * t * t) * S * S);
      v = V.inverse() * p;
    }
    else
    {
      v = p;
    }
    return MotionTpl<_Scalar,_Options>(v, w);
  }

  /// \brief Log: SE3 -> se3.
  ///
  /// Pseudo-inverse of exp from SE3 -> { v,w \in se3, ||w|| < 2pi }.
  template <typename D> Eigen::Matrix<typename D::Scalar,6,1,D::Options>
  log6(const Eigen::MatrixBase<D> & M)
  {
    EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(D, 6, 6);
    typedef typename SE3Tpl<typename D::Scalar,D::Options>::Vector3 Vector3;
    typedef typename SE3Tpl<typename D::Scalar,D::Options>::Matrix3 Matrix3;
    enum {
      LINEAR = SE3Tpl<typename D::Scalar,D::Options>::LINEAR,
      ANGULAR = SE3Tpl<typename D::Scalar,D::Options>::ANGULAR
    };

    Matrix3 rot(M.template block<3,3>(ANGULAR,ANGULAR));
    Matrix3 skew(M.template block<3,3>(LINEAR,ANGULAR) * rot.transpose());
    Vector3 trans(skew(2,1), skew(0,2), skew(1,0));
    SE3Tpl<typename D::Scalar,D::Options> m(rot, trans);
    MotionTpl<typename D::Scalar,D::Options> nu(log6(m));
    return nu.toVector();
  }
} // namespace se3

#endif //#ifndef __math_explog_hpp__
<commit_msg>[Minor] Update copyright in explog.hpp.<commit_after>//
// Copyright (c) 2015 CNRS
// Copyright (c) 2015 Wandercraft, 86 rue de Paris 91400 Orsay, France.
//
// This file is part of Pinocchio
// Pinocchio is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// Pinocchio 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
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// Pinocchio If not, see
// <http://www.gnu.org/licenses/>.

#ifndef __math_explog_hpp__
# define __math_explog_hpp__

# include <Eigen/Geometry>

# include "pinocchio/math/sincos.hpp"
# include "pinocchio/spatial/motion.hpp"
# include "pinocchio/spatial/skew.hpp"
# include "pinocchio/spatial/se3.hpp"

namespace se3
{
  /// \brief Exp: so3 -> SO3.
  ///
  /// Return the integral of the input angular velocity during time 1.
  template <typename D> Eigen::Matrix<typename D::Scalar,3,3,D::Options>
  exp3(const Eigen::MatrixBase<D> & v)
  {
    EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(D,3);
    return Eigen::AngleAxis<typename D::Scalar>(v.norm(), v).matrix();
  }

  /// \brief Log: SO3 -> so3.
  ///
  /// Pseudo-inverse of log from SO3 -> { v \in so3, ||v|| < 2pi }.
  template <typename D> Eigen::Matrix<typename D::Scalar,3,1,D::Options>
  log3(const Eigen::MatrixBase<D> & R)
  {
    EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(D, 3, 3);
    Eigen::AngleAxis<typename D::Scalar> angleAxis(R);
    return angleAxis.axis() * angleAxis.angle();
  }

  /// \brief Exp: se3 -> SE3.
  ///
  /// Return the integral of the input spatial velocity during time 1.
  template <typename _Scalar, int _Options> SE3Tpl<_Scalar, _Options>
  exp6(const MotionTpl<_Scalar,_Options> & nu)
  {
    typedef _Scalar Scalar;
    typedef typename MotionTpl<Scalar,_Options>::Vector3 Vector3;
    typedef typename MotionTpl<Scalar,_Options>::Matrix3 Matrix3;

    const Vector3 & w = nu.angular();
    const Vector3 & v = nu.linear();
    Scalar t = w.norm();
    if (t > 1e-15)
    {
      Matrix3 R(exp3(w));
      Matrix3 S(skew(w));
      Matrix3 V(
        Matrix3::Identity() +
        (1 - cos(t)) / (t * t) * S + (t - sin(t)) / (t * t * t) * S * S);
      Vector3 p(V * v);
      return SE3Tpl<_Scalar, _Options>(R, p);
    }
    else
    {
      return SE3Tpl<_Scalar, _Options>(Matrix3::Identity(), v);
    }
  }

  /// \brief Exp: se3 -> SE3.
  ///
  /// Return the integral of the input spatial velocity during time 1.
  template <typename D> Eigen::Matrix<typename D::Scalar,6,6,D::Options>
  exp6(const Eigen::MatrixBase<D> & v)
  {
    EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(D,6);
    MotionTpl<typename D::Scalar,D::Options> nu(v);
    SE3Tpl<typename D::Scalar,D::Options> m(exp6(nu));
    return m.toActionMatrix();
  }

  /// \brief Log: SE3 -> se3.
  ///
  /// Pseudo-inverse of exp from SE3 -> { v,w \in se3, ||w|| < 2pi }.
  template <typename _Scalar, int _Options> MotionTpl<_Scalar,_Options>
  log6(const SE3Tpl<_Scalar, _Options> & m)
  {
    typedef _Scalar Scalar;
    typedef typename SE3Tpl<Scalar,_Options>::Vector3 Vector3;
    typedef typename SE3Tpl<Scalar,_Options>::Matrix3 Matrix3;

    const Matrix3 & R = m.rotation();
    const Vector3 & p = m.translation();
    Vector3 w(log3(R));
    Vector3 v;
    Scalar t = w.norm();
    if (t > 1e-15)
    {
      Matrix3 S(skew(w));
      Matrix3 V(
        Matrix3::Identity() +
        (1 - cos(t)) / (t * t) * S + (t - sin(t)) / (t * t * t) * S * S);
      v = V.inverse() * p;
    }
    else
    {
      v = p;
    }
    return MotionTpl<_Scalar,_Options>(v, w);
  }

  /// \brief Log: SE3 -> se3.
  ///
  /// Pseudo-inverse of exp from SE3 -> { v,w \in se3, ||w|| < 2pi }.
  template <typename D> Eigen::Matrix<typename D::Scalar,6,1,D::Options>
  log6(const Eigen::MatrixBase<D> & M)
  {
    EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(D, 6, 6);
    typedef typename SE3Tpl<typename D::Scalar,D::Options>::Vector3 Vector3;
    typedef typename SE3Tpl<typename D::Scalar,D::Options>::Matrix3 Matrix3;
    enum {
      LINEAR = SE3Tpl<typename D::Scalar,D::Options>::LINEAR,
      ANGULAR = SE3Tpl<typename D::Scalar,D::Options>::ANGULAR
    };

    Matrix3 rot(M.template block<3,3>(ANGULAR,ANGULAR));
    Matrix3 skew(M.template block<3,3>(LINEAR,ANGULAR) * rot.transpose());
    Vector3 trans(skew(2,1), skew(0,2), skew(1,0));
    SE3Tpl<typename D::Scalar,D::Options> m(rot, trans);
    MotionTpl<typename D::Scalar,D::Options> nu(log6(m));
    return nu.toVector();
  }
} // namespace se3

#endif //#ifndef __math_explog_hpp__
<|endoftext|>


<commit_before>#include <stdio.h>

#include "sprocket.h"

#define DEBUG	0

int main(int argc, char ** argv)
{
	int i;
	char mode;
	char origin;
	char input[128];
	char outfile[128];
	char infile[128];
	FILE * source;
	FILE * dest;

	for(i = 0; i < 25; i++)
		printf("\n");

	printf("Welcome to Sprocket\n-------------------\n\n");

	while(1)
	{
		printf("What do you want to do?\n\n\t1. Reverse File\n\t2. Binary to ASM\n\t9. Quit\n\n");

		mode = getMode();

		if(mode == '9')
		{
			break;
		}

		printf("Enter the name of the file to process (.bin):\n");
		scanf("%s", input);
		sprintf(infile, "%s.bin", input);

		source = fopen(infile, "rb");

		if(!source)
		{
			printf("Could not open file: %s", input[1]);
			getchar();
			return 0;
		}

		if(mode == '1')
		{
			sprintf(outfile, "%s_r.bin", input);

			dest = fopen(outfile, "wb");

			if(!dest)
			{
				printf("Could not open file for output: %s", outfile);
				getchar();
				return 0;
			}
		}
		else if(mode == '2')
		{
			printf("Enter the name of the file to create:\n");
			scanf("%s", outfile);

			dest = fopen(outfile, "wb");

			if(!dest)
			{
				printf("Could not open file for output: %s", outfile);
				getchar();
				return 0;
			}

			printf("Top left origin (1) or centered (2)?\n");
			origin = getMode();
		}

		if(mode == '1')
			reverseFile(source, dest);
		else if(mode == '2')
			bin2asm(input, source, dest, origin);

		fclose(source);
		fclose(dest);
	}

	printf("\n\nDone. Hit enter to exit.\n");
	getchar();
	getchar();

	return 0;
}

char getMode(void)
{
	char mode = 0;

	while(mode < '1' || mode > '9')
	{
		mode = getchar();
	}

	return mode;
}

void reverseFile(FILE * source, FILE * dest)
{
	long location;
	char byte;

	fseek(source, -1, SEEK_END);

	/* want to include the last byte! */
	location = 1 + ftell(source);

	while(location)
	{
		byte = fgetc(source);
		fputc(byte, dest);

		fseek(source, -2, SEEK_CUR);
		location--;
	}
}

void bin2asm(char * name, FILE * source, FILE * dest, char origin)
{
	printf("Writing sprite routine...\n");
 	writeSprite(name, source, dest, origin, 0);

 	printf("Writing sprite clear routine...\n");
 	fseek(source, 0, SEEK_SET);
 	writeSprite(name, source, dest, origin, 1);
}

void writeSprite(char * name, FILE * source, FILE * dest, char origin, int clear)
{
	unsigned short int pixel = 0;
	int working = 1;
	int clearCount = 0;
	int count = 0;
	int totalCount = 0;
	int lineOffset = 0;
	int spriteCount = 0;

	/* skip the sprite mask
	fseek(source, 16*16*2, SEEK_SET);*/

	if(clear)
	{
		fprintf(dest, "\t\tsection text\r\n%s%iclear:\r\n", name, spriteCount);
	}
	else
	{
		fprintf(dest, "\t\tsection text\r\n%s%i:\r\n", name, spriteCount);
	}

	while(working)
	{
		working = fread(&pixel, 1, 2, source);
		count ++;
		totalCount++;

		if(!working)
		{
			break;
		}

		if(pixel)
		{
			if(clearCount)
			{
				fprintf(dest, "\t\tadda.l\t#%i+(scr_w-16)*%i,a0\r\n", (clearCount * 2), (lineOffset * 2));

				if(clear)
				{
					fprintf(dest, "\t\tadda.l\t#%i+(scr_w-16)*%i,a1\r\n", (clearCount * 2), (lineOffset * 2));
				}

				clearCount = 0;
				lineOffset = 0;

				if(DEBUG)
					fprintf(dest, "; reset clear and offset\r\n");
			}

			if(lineOffset)
			{
				fprintf(dest, "\t\tadda.l\t#(scr_w-16)*%i,a0\r\n", lineOffset * 2);

				if(clear)
				{
					fprintf(dest, "\t\tadda.l\t#(scr_w-16)*%i,a1\r\n", lineOffset * 2);
				}

				lineOffset = 0;

				if(DEBUG)
					fprintf(dest, "; reset offset\r\n");
			}

			if(clear)
			{
				fprintf(dest, "\t\tmove.w\t(a1)+,(a0)+\r\n");
			}
			else
			{
				fprintf(dest, "\t\tmove.w\t#$%04X,(a0)+\r\n", pixel);
			}
		}
		else
		{
			clearCount ++;
		}

		if(count == 16)
		{
			count = 0;
			lineOffset ++;

			if(DEBUG)
				fprintf(dest, "; set offset\r\n");
		}

		if(totalCount == 16*16)
		{
			fprintf(dest, "\t\trts\r\n\r\n");

			if(clear)
			{
				fprintf(dest, "\t\tsection text\r\n%s%iclear:\r\n", name, ++spriteCount);
			}
			else
			{
				fprintf(dest, "\t\tsection text\r\n%s%i:\r\n", name, ++spriteCount);
			}

			totalCount = 0;
			clearCount = 0;
			lineOffset = 0;
			count = 0;
		}
	}

	fprintf(dest, "\t\trts\r\n\r\n");
}
<commit_msg>Modified pixel writing to support long words reducing the output size.<commit_after>#include <stdio.h>

#include "sprocket.h"

#define DEBUG	0

int main(int argc, char ** argv)
{
	int i;
	char mode;
	char origin;
	char input[128];
	char outfile[128];
	char infile[128];
	FILE * source;
	FILE * dest;

	for(i = 0; i < 25; i++)
		printf("\n");

	printf("Welcome to Sprocket\n-------------------\n\n");

	while(1)
	{
		printf("What do you want to do?\n\n\t1. Reverse File\n\t2. Binary to ASM\n\t9. Quit\n\n");

		mode = getMode();

		if(mode == '9')
		{
			break;
		}

		printf("Enter the name of the file to process (.bin):\n");
		scanf("%s", input);
		sprintf(infile, "%s.bin", input);

		source = fopen(infile, "rb");

		if(!source)
		{
			printf("Could not open file: %s", input[1]);
			getchar();
			return 0;
		}

		if(mode == '1')
		{
			sprintf(outfile, "%s_r.bin", input);

			dest = fopen(outfile, "wb");

			if(!dest)
			{
				printf("Could not open file for output: %s", outfile);
				getchar();
				return 0;
			}
		}
		else if(mode == '2')
		{
			printf("Enter the name of the file to create:\n");
			scanf("%s", outfile);

			dest = fopen(outfile, "wb");

			if(!dest)
			{
				printf("Could not open file for output: %s", outfile);
				getchar();
				return 0;
			}

			printf("Top left origin (1) or centered (2)?\n");
			origin = getMode();
		}

		if(mode == '1')
			reverseFile(source, dest);
		else if(mode == '2')
			bin2asm(input, source, dest, origin);

		fclose(source);
		fclose(dest);
	}

	printf("\n\nDone. Hit enter to exit.\n");
	getchar();
	getchar();

	return 0;
}

char getMode(void)
{
	char mode = 0;

	while(mode < '1' || mode > '9')
	{
		mode = getchar();
	}

	return mode;
}

void reverseFile(FILE * source, FILE * dest)
{
	long location;
	char byte;

	fseek(source, -1, SEEK_END);

	/* want to include the last byte! */
	location = 1 + ftell(source);

	while(location)
	{
		byte = fgetc(source);
		fputc(byte, dest);

		fseek(source, -2, SEEK_CUR);
		location--;
	}
}

void bin2asm(char * name, FILE * source, FILE * dest, char origin)
{
	printf("Writing sprite routine...\n");
 	writeSprite(name, source, dest, origin, 0);

 	printf("Writing sprite clear routine...\n");
 	fseek(source, 0, SEEK_SET);
 	writeSprite(name, source, dest, origin, 1);
}

void writeSprite(char * name, FILE * source, FILE * dest, char origin, int clear)
{
	unsigned short int pixel = 0;
	unsigned short int pixel2 = 0;

	int working = 1;
	int clearCount = 0;
	int count = 0;
	int totalCount = 0;
	int lineOffset = 0;
	int spriteCount = 0;

	/* skip the sprite mask
	fseek(source, 16*16*2, SEEK_SET);*/

	if(clear)
	{
		fprintf(dest, "\t\tsection text\r\n%s%iclear:\r\n", name, spriteCount);
	}
	else
	{
		fprintf(dest, "\t\tsection text\r\n%s%i:\r\n", name, spriteCount);
	}

	while(working)
	{
		working = fread(&pixel, 1, 2, source);
		working |= fread(&pixel2, 1, 2, source);

		count += 2;
		totalCount += 2;

		if(!working)
		{
			break;
		}

		// if the first pixel is blank we need to allow for that
		if(!pixel && pixel2)
		{
			clearCount++;
		}

		// if there's a value in one and we were previously processing blank pixels then
		// offset the memory address accordingly
		if(pixel || pixel2)
		{
			if(clearCount)
			{
				fprintf(dest, "\t\tadda.l\t#%i+(scr_w-16)*%i,a0\r\n", (clearCount * 2), (lineOffset * 2));

				if(clear)
				{
					fprintf(dest, "\t\tadda.l\t#%i+(scr_w-16)*%i,a1\r\n", (clearCount * 2), (lineOffset * 2));
				}

				clearCount = 0;
				lineOffset = 0;

				if(DEBUG)
					fprintf(dest, "; reset clear and offset\r\n");
			}

			if(lineOffset)
			{
				fprintf(dest, "\t\tadda.l\t#(scr_w-16)*%i,a0\r\n", lineOffset * 2);

				if(clear)
				{
					fprintf(dest, "\t\tadda.l\t#(scr_w-16)*%i,a1\r\n", lineOffset * 2);
				}

				lineOffset = 0;

				if(DEBUG)
					fprintf(dest, "; reset offset\r\n");
			}
		}

		if(pixel && pixel2)
		{
			if(clear)
			{
				fprintf(dest, "\t\tmove.l\t(a1)+,(a0)+\r\n");
			}
			else
			{
				fprintf(dest, "\t\tmove.l\t#$%04X%04X,(a0)+\r\n", pixel, pixel2);
			}
		}
		else if(pixel || pixel2)
		{
			if(clear)
			{
				fprintf(dest, "\t\tmove.w\t(a1)+,(a0)+\r\n");
			}
			else
			{
				fprintf(dest, "\t\tmove.w\t#$%04X,(a0)+\r\n", pixel | pixel2);
			}

			if(pixel)
			{
				clearCount ++;
			}
		}
		else
		{
			clearCount += 2;
		}

		if(count == 16)
		{
			count = 0;
			lineOffset ++;

			if(DEBUG)
				fprintf(dest, "; set offset\r\n");
		}

		if(totalCount == 16*16)
		{
			fprintf(dest, "\t\trts\r\n\r\n");

			if(clear)
			{
				fprintf(dest, "\t\tsection text\r\n%s%iclear:\r\n", name, ++spriteCount);
			}
			else
			{
				fprintf(dest, "\t\tsection text\r\n%s%i:\r\n", name, ++spriteCount);
			}

			totalCount = 0;
			clearCount = 0;
			lineOffset = 0;
			count = 0;
		}
	}

	fprintf(dest, "\t\trts\r\n\r\n");
}
<|endoftext|>


<commit_before>#include "config.h"

#include "vm.hpp"
#include "vm/object_utils.hpp"
#include "objectmemory.hpp"
#include "primitives.hpp"

#include "builtin/array.hpp"
#include "builtin/class.hpp"
#include "builtin/exception.hpp"
#include "builtin/integer.hpp"
#include "builtin/string.hpp"
#include "builtin/time.hpp"

#include "ontology.hpp"

#include "util/time.h"

#include <sys/time.h>
#include <time.h>

#include "windows_compat.h"
#include "configuration.hpp"

namespace rubinius {
  void Time::init(STATE) {
    GO(time_class).set(ontology::new_class(state, "Time", G(object)));
    G(time_class)->set_object_type(state, TimeType);
  }

  Time* Time::now(STATE, Object* self) {
    Time* tm = state->new_object<Time>(as<Class>(self));

#ifdef HAVE_CLOCK_GETTIME
    struct timespec ts;

    ::clock_gettime(CLOCK_REALTIME, &ts);

    tm->seconds_ = ts.tv_sec;
    tm->nanoseconds_ = ts.tv_nsec;
#else
    struct timeval tv;

    /* don't fill in the 2nd argument here. getting the timezone here
     * this way is not portable and broken anyway.
     */
    ::gettimeofday(&tv, NULL);

    tm->seconds_ = tv.tv_sec;
    tm->nanoseconds_ = tv.tv_usec * 1000;
#endif

    tm->is_gmt(state, cFalse);

    return tm;
  }

  // Taken from MRI
#define NDIV(x,y) (-(-((x)+1)/(y))-1)
#define NMOD(x,y) ((y)-(-((x)+1)%(y))-1)

  Time* Time::specific(STATE, Object* self, Integer* sec, Integer* nsec,
                       Object* gmt, Object* offset)
  {
    Time* tm = state->new_object<Time>(as<Class>(self));

    if(sizeof(time_t) == sizeof(long long)) {
      tm->seconds_ = sec->to_long_long();
      tm->nanoseconds_ = nsec->to_long_long();
    } else {
      tm->seconds_ = sec->to_native();
      tm->nanoseconds_ = nsec->to_native();
    }

    // Do a little overflow cleanup.
    if(tm->nanoseconds_ >= 1000000000) {
      tm->seconds_ += tm->nanoseconds_ / 1000000000;
      tm->nanoseconds_ %= 1000000000;
    }

    if(tm->nanoseconds_ < 0) {
      tm->seconds_ += NDIV(tm->nanoseconds_, 1000000000);
      tm->nanoseconds_ = NMOD(tm->nanoseconds_, 1000000000);
    }

    if(LANGUAGE_18_ENABLED(state)) {
      tm->nanoseconds_ -= (tm->nanoseconds_ % 1000);
    }

    tm->is_gmt(state, CBOOL(gmt) ? cTrue : cFalse);
    tm->offset(state, offset);

    return tm;
  }

  Time* Time::from_array(STATE, Object* self,
                         Fixnum* sec, Fixnum* min, Fixnum* hour,
                         Fixnum* mday, Fixnum* mon, Fixnum* year, Fixnum* nsec,
                         Fixnum* isdst, Object* from_gmt, Object* offset) {
    struct tm tm;

    tm.tm_sec = sec->to_native();
    if(tm.tm_sec < 0 || tm.tm_sec > 60) {
      Exception::argument_error(state, "sec must be in 0..60");
    }

    tm.tm_min = min->to_native();
    if(tm.tm_min < 0 || tm.tm_min > 60) {
      Exception::argument_error(state, "min must be in 0..60");
    }

    tm.tm_hour = hour->to_native();
    if(tm.tm_hour < 0 || tm.tm_hour > 24) {
      Exception::argument_error(state, "hour must be in 0..24");
    }

    tm.tm_mday = mday->to_native();
    if(tm.tm_mday < 1 || tm.tm_mday > 31) {
      Exception::argument_error(state, "mday must be in 1..31");
    }

    tm.tm_mon = mon->to_native() - 1;
    if(tm.tm_mon < 0 || tm.tm_mon > 11) {
      Exception::argument_error(state, "mon must be in 0..11");
    }

    tm.tm_wday = -1;
#ifdef HAVE_TM_GMTOFF
    tm.tm_gmtoff = 0;
#endif
#ifdef HAVE_TM_ZONE
    tm.tm_zone = 0;
#endif
    tm.tm_year = year->to_native() - 1900;

    tm.tm_isdst = isdst->to_native();

    time_t seconds = -1;

    if(CBOOL(from_gmt) || !offset->nil_p()) {
      seconds = ::timegm(&tm);
    } else {
      tzset();
      seconds = ::mktime(&tm);
    }

    int err = 0;

    if(seconds == -1) {
      int utc_p = (CBOOL(from_gmt) || !offset->nil_p()) ? 1 : 0;
      seconds = mktime_extended(&tm, utc_p, &err);
    }

    if(err) Exception::argument_error(state, "time out of range");

    Time* obj = state->new_object<Time>(as<Class>(self));
    obj->seconds_ = seconds;
    obj->nanoseconds_ = nsec->to_native();
    obj->is_gmt(state, CBOOL(from_gmt) ? cTrue : cFalse);

    if(Fixnum* off = try_as<Fixnum>(offset)) {
      obj->seconds_ -= off->to_native();
      obj->offset(state, offset);
    }

    return obj;
  }

  Time* Time::dup(STATE, Object* self, Time* other) {
    Time* tm = state->new_object<Time>(as<Class>(self));
    tm->seconds_ = other->seconds_;
    tm->nanoseconds_ = other->nanoseconds_;
    tm->is_gmt(state, other->is_gmt_);
    return tm;
  }

  struct tm Time::get_tm() {
    time_t seconds = seconds_;
    struct tm tm = {0};

    if(Fixnum* off = try_as<Fixnum>(offset_)) {
      seconds += off->to_native();
      gmtime_r(&seconds, &tm);
    } else if(CBOOL(is_gmt_)) {
      gmtime_r(&seconds, &tm);
    } else {
      tzset();
      localtime_r(&seconds, &tm);
    }

    return tm;
  }

  Object* Time::utc_offset(STATE) {
    if(CBOOL(is_gmt_)) {
      return Fixnum::from(0);
    } else if(!offset_->nil_p()) {
      return offset_;
    }

    native_int off;

#ifdef HAVE_TM_NAME
    struct tm tm = get_tm();
    off = -tm.tm_tzadj;
#else /* !HAVE_TM_NAME */
#ifdef HAVE_TM_ZONE
#ifdef HAVE_TM_GMTOFF
    struct tm tm = get_tm();
    off = tm.tm_gmtoff;
#else
    off = _timezone;
#endif
#else /* !HAVE_TM_ZONE */
#if HAVE_VAR_TIMEZONE
#if HAVE_VAR_ALTZONE
    off = -(daylight ? timezone : altzone);
#else
    off = -timezone;
#endif
#else /* !HAVE_VAR_TIMEZONE */
#ifdef HAVE_GETTIMEOFDAY
    gettimeofday(&tv, &zone);
    off = -zone.tz_minuteswest * 60;
#else
    /* no timezone info, then calc by myself */
    {
      struct tm utc;
      time_t now;
      time(&now);
      utc = *gmtime(&now);
      off = (now - mktime(&utc));
    }
#endif
#endif /* !HAVE_VAR_TIMEZONE */
#endif /* !HAVE_TM_ZONE */
#endif /* !HAVE_TM_NAME */

    return Fixnum::from(off);
  }

  Array* Time::calculate_decompose(STATE) {
    if(!decomposed_->nil_p()) return decomposed_;

    struct tm tm = get_tm();

    /* update Time::TM_FIELDS when changing order of fields */
    Array* ary = Array::create(state, 11);
    ary->set(state, 0, Integer::from(state, tm.tm_sec));
    ary->set(state, 1, Integer::from(state, tm.tm_min));
    ary->set(state, 2, Integer::from(state, tm.tm_hour));
    ary->set(state, 3, Integer::from(state, tm.tm_mday));
    ary->set(state, 4, Integer::from(state, tm.tm_mon + 1));
    ary->set(state, 5, Integer::from(state, tm.tm_year + 1900));
    ary->set(state, 6, Integer::from(state, tm.tm_wday));
    ary->set(state, 7, Integer::from(state, tm.tm_yday + 1));
    ary->set(state, 8, tm.tm_isdst ? cTrue : cFalse);

    const char* tmzone;
    if(offset_->nil_p() && (tmzone = timezone_extended(&tm))) {
      ary->set(state, 9, String::create(state, tmzone));
    } else {
      ary->set(state, 9, cNil);
    }

    // Cache it.
    decomposed(state, ary);
    return ary;
  }

#define STRFTIME_OUTPUT_BUF 128

  String* Time::strftime(STATE, String* format) {
    struct tm tm = get_tm();

    struct timespec ts;
    ts.tv_sec = seconds_;
    ts.tv_nsec = nanoseconds_;

    int off = 0;
    if(Fixnum* offset = try_as<Fixnum>(utc_offset(state))) {
      off = offset->to_int();
    }

    size_t buf_size = STRFTIME_OUTPUT_BUF;
    char* str = (char*)malloc(buf_size);

    size_t chars = ::strftime_extended(str, buf_size,
                       format->c_str(state), &tm, &ts, CBOOL(is_gmt_) ? 1 : 0,
                       off);

    while (chars == 0 && format->byte_size() > 0) {
      buf_size *= 2;
      str = (char*)realloc(str, buf_size);

      chars = ::strftime_extended(str, buf_size,
                  format->c_str(state), &tm, &ts, CBOOL(is_gmt_) ? 1 : 0,
                  off);
    }

    String* result = String::create(state, str, chars);

    free(str);

    return result;
  }
}
<commit_msg>Use stack allocated + dynamic allocated buffers<commit_after>#include "config.h"

#include "vm.hpp"
#include "vm/object_utils.hpp"
#include "objectmemory.hpp"
#include "primitives.hpp"

#include "builtin/array.hpp"
#include "builtin/class.hpp"
#include "builtin/exception.hpp"
#include "builtin/integer.hpp"
#include "builtin/string.hpp"
#include "builtin/time.hpp"

#include "ontology.hpp"

#include "util/time.h"

#include <sys/time.h>
#include <time.h>

#include "windows_compat.h"
#include "configuration.hpp"

namespace rubinius {
  void Time::init(STATE) {
    GO(time_class).set(ontology::new_class(state, "Time", G(object)));
    G(time_class)->set_object_type(state, TimeType);
  }

  Time* Time::now(STATE, Object* self) {
    Time* tm = state->new_object<Time>(as<Class>(self));

#ifdef HAVE_CLOCK_GETTIME
    struct timespec ts;

    ::clock_gettime(CLOCK_REALTIME, &ts);

    tm->seconds_ = ts.tv_sec;
    tm->nanoseconds_ = ts.tv_nsec;
#else
    struct timeval tv;

    /* don't fill in the 2nd argument here. getting the timezone here
     * this way is not portable and broken anyway.
     */
    ::gettimeofday(&tv, NULL);

    tm->seconds_ = tv.tv_sec;
    tm->nanoseconds_ = tv.tv_usec * 1000;
#endif

    tm->is_gmt(state, cFalse);

    return tm;
  }

  // Taken from MRI
#define NDIV(x,y) (-(-((x)+1)/(y))-1)
#define NMOD(x,y) ((y)-(-((x)+1)%(y))-1)

  Time* Time::specific(STATE, Object* self, Integer* sec, Integer* nsec,
                       Object* gmt, Object* offset)
  {
    Time* tm = state->new_object<Time>(as<Class>(self));

    if(sizeof(time_t) == sizeof(long long)) {
      tm->seconds_ = sec->to_long_long();
      tm->nanoseconds_ = nsec->to_long_long();
    } else {
      tm->seconds_ = sec->to_native();
      tm->nanoseconds_ = nsec->to_native();
    }

    // Do a little overflow cleanup.
    if(tm->nanoseconds_ >= 1000000000) {
      tm->seconds_ += tm->nanoseconds_ / 1000000000;
      tm->nanoseconds_ %= 1000000000;
    }

    if(tm->nanoseconds_ < 0) {
      tm->seconds_ += NDIV(tm->nanoseconds_, 1000000000);
      tm->nanoseconds_ = NMOD(tm->nanoseconds_, 1000000000);
    }

    if(LANGUAGE_18_ENABLED(state)) {
      tm->nanoseconds_ -= (tm->nanoseconds_ % 1000);
    }

    tm->is_gmt(state, CBOOL(gmt) ? cTrue : cFalse);
    tm->offset(state, offset);

    return tm;
  }

  Time* Time::from_array(STATE, Object* self,
                         Fixnum* sec, Fixnum* min, Fixnum* hour,
                         Fixnum* mday, Fixnum* mon, Fixnum* year, Fixnum* nsec,
                         Fixnum* isdst, Object* from_gmt, Object* offset) {
    struct tm tm;

    tm.tm_sec = sec->to_native();
    if(tm.tm_sec < 0 || tm.tm_sec > 60) {
      Exception::argument_error(state, "sec must be in 0..60");
    }

    tm.tm_min = min->to_native();
    if(tm.tm_min < 0 || tm.tm_min > 60) {
      Exception::argument_error(state, "min must be in 0..60");
    }

    tm.tm_hour = hour->to_native();
    if(tm.tm_hour < 0 || tm.tm_hour > 24) {
      Exception::argument_error(state, "hour must be in 0..24");
    }

    tm.tm_mday = mday->to_native();
    if(tm.tm_mday < 1 || tm.tm_mday > 31) {
      Exception::argument_error(state, "mday must be in 1..31");
    }

    tm.tm_mon = mon->to_native() - 1;
    if(tm.tm_mon < 0 || tm.tm_mon > 11) {
      Exception::argument_error(state, "mon must be in 0..11");
    }

    tm.tm_wday = -1;
#ifdef HAVE_TM_GMTOFF
    tm.tm_gmtoff = 0;
#endif
#ifdef HAVE_TM_ZONE
    tm.tm_zone = 0;
#endif
    tm.tm_year = year->to_native() - 1900;

    tm.tm_isdst = isdst->to_native();

    time_t seconds = -1;

    if(CBOOL(from_gmt) || !offset->nil_p()) {
      seconds = ::timegm(&tm);
    } else {
      tzset();
      seconds = ::mktime(&tm);
    }

    int err = 0;

    if(seconds == -1) {
      int utc_p = (CBOOL(from_gmt) || !offset->nil_p()) ? 1 : 0;
      seconds = mktime_extended(&tm, utc_p, &err);
    }

    if(err) Exception::argument_error(state, "time out of range");

    Time* obj = state->new_object<Time>(as<Class>(self));
    obj->seconds_ = seconds;
    obj->nanoseconds_ = nsec->to_native();
    obj->is_gmt(state, CBOOL(from_gmt) ? cTrue : cFalse);

    if(Fixnum* off = try_as<Fixnum>(offset)) {
      obj->seconds_ -= off->to_native();
      obj->offset(state, offset);
    }

    return obj;
  }

  Time* Time::dup(STATE, Object* self, Time* other) {
    Time* tm = state->new_object<Time>(as<Class>(self));
    tm->seconds_ = other->seconds_;
    tm->nanoseconds_ = other->nanoseconds_;
    tm->is_gmt(state, other->is_gmt_);
    return tm;
  }

  struct tm Time::get_tm() {
    time_t seconds = seconds_;
    struct tm tm = {0};

    if(Fixnum* off = try_as<Fixnum>(offset_)) {
      seconds += off->to_native();
      gmtime_r(&seconds, &tm);
    } else if(CBOOL(is_gmt_)) {
      gmtime_r(&seconds, &tm);
    } else {
      tzset();
      localtime_r(&seconds, &tm);
    }

    return tm;
  }

  Object* Time::utc_offset(STATE) {
    if(CBOOL(is_gmt_)) {
      return Fixnum::from(0);
    } else if(!offset_->nil_p()) {
      return offset_;
    }

    native_int off;

#ifdef HAVE_TM_NAME
    struct tm tm = get_tm();
    off = -tm.tm_tzadj;
#else /* !HAVE_TM_NAME */
#ifdef HAVE_TM_ZONE
#ifdef HAVE_TM_GMTOFF
    struct tm tm = get_tm();
    off = tm.tm_gmtoff;
#else
    off = _timezone;
#endif
#else /* !HAVE_TM_ZONE */
#if HAVE_VAR_TIMEZONE
#if HAVE_VAR_ALTZONE
    off = -(daylight ? timezone : altzone);
#else
    off = -timezone;
#endif
#else /* !HAVE_VAR_TIMEZONE */
#ifdef HAVE_GETTIMEOFDAY
    gettimeofday(&tv, &zone);
    off = -zone.tz_minuteswest * 60;
#else
    /* no timezone info, then calc by myself */
    {
      struct tm utc;
      time_t now;
      time(&now);
      utc = *gmtime(&now);
      off = (now - mktime(&utc));
    }
#endif
#endif /* !HAVE_VAR_TIMEZONE */
#endif /* !HAVE_TM_ZONE */
#endif /* !HAVE_TM_NAME */

    return Fixnum::from(off);
  }

  Array* Time::calculate_decompose(STATE) {
    if(!decomposed_->nil_p()) return decomposed_;

    struct tm tm = get_tm();

    /* update Time::TM_FIELDS when changing order of fields */
    Array* ary = Array::create(state, 11);
    ary->set(state, 0, Integer::from(state, tm.tm_sec));
    ary->set(state, 1, Integer::from(state, tm.tm_min));
    ary->set(state, 2, Integer::from(state, tm.tm_hour));
    ary->set(state, 3, Integer::from(state, tm.tm_mday));
    ary->set(state, 4, Integer::from(state, tm.tm_mon + 1));
    ary->set(state, 5, Integer::from(state, tm.tm_year + 1900));
    ary->set(state, 6, Integer::from(state, tm.tm_wday));
    ary->set(state, 7, Integer::from(state, tm.tm_yday + 1));
    ary->set(state, 8, tm.tm_isdst ? cTrue : cFalse);

    const char* tmzone;
    if(offset_->nil_p() && (tmzone = timezone_extended(&tm))) {
      ary->set(state, 9, String::create(state, tmzone));
    } else {
      ary->set(state, 9, cNil);
    }

    // Cache it.
    decomposed(state, ary);
    return ary;
  }

#define STRFTIME_STACK_BUF 128

  String* Time::strftime(STATE, String* format) {
    struct tm tm = get_tm();

    struct timespec ts;
    ts.tv_sec = seconds_;
    ts.tv_nsec = nanoseconds_;

    int off = 0;
    if(Fixnum* offset = try_as<Fixnum>(utc_offset(state))) {
      off = offset->to_int();
    }

    char stack_str[STRFTIME_STACK_BUF];
    char* malloc_str = 0;

    size_t chars = ::strftime_extended(stack_str, STRFTIME_STACK_BUF,
                       format->c_str(state), &tm, &ts, CBOOL(is_gmt_) ? 1 : 0,
                       off);

    size_t buf_size = format->byte_size();

    String* result = 0;

    if (chars == 0 && format->byte_size() > 0) {
      malloc_str = (char*)malloc(buf_size);

      chars = ::strftime_extended(malloc_str, buf_size,
                  format->c_str(state), &tm, &ts, CBOOL(is_gmt_) ? 1 : 0,
                  off);

      while (chars == 0 && format->byte_size() > 0) {
        buf_size *= 2;
        malloc_str = (char*)realloc(malloc_str, buf_size);

        chars = ::strftime_extended(malloc_str, buf_size,
                    format->c_str(state), &tm, &ts, CBOOL(is_gmt_) ? 1 : 0,
                    off);
      }

      result = String::create(state, malloc_str, chars);

      free(malloc_str);
    } else {
      result = String::create(state, stack_str, chars);
    }

    return result;
  }
}
<|endoftext|>