<commit_before>#ifndef SOLAIRE_ENCODER_HPP
#define SOLAIRE_ENCODER_HPP

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

// Contact :
// Email             : solairelibrary@mail.com
// GitHub repository : https://github.com/SolaireLibrary/SolaireCPP

/*!
	\file Encoder.hpp
	\brief
	\author
	Created			: Adam Smith
	Last modified	: Adam Smith
	\version 1.0
	\date
	Created			: 16th January 2016
	Last Modified	: 16th January 2016
*/

#include "Solaire/Data/ArrayList.hpp"
#include "Solaire/Encode/GenericValue.hpp"

namespace Solaire {

	template<class T, typename ENABLE = void>
	struct Encoder {
	    typedef T DecodeType;

	    static DecodeType decode(Allocator&, const GenericValue&) throw();
	    static GenericValue encode(Allocator&, const T&) throw();
	};

	template<class T>
	static typename Encoder<T>::DecodeType decode(Allocator& aAllocator, const GenericValue& aValue) {
	    return Encoder<T>::decode(aAllocator, aValue);
	}

	template<class T>
	static GenericValue decode(Allocator& aAllocator, const T& aValue) {
	    return Encoder<T>::encode(aAllocator, aValue);
	}

	////

    template<>
	struct Encoder<char>{
	    typedef char DecodeType;

	    static DecodeType decode(Allocator& aAllocator, const GenericValue& aValue) throw() {
            return aValue.getChar();
	    }

	    static GenericValue encode(Allocator& aAllocator, const char aValue) throw() {
            return GenericValue(aValue);
	    }
	};

    template<>
	struct Encoder<bool>{
	    typedef bool DecodeType;

	    static DecodeType decode(Allocator& aAllocator, const GenericValue& aValue) throw() {
            return aValue.getBool();
	    }

	    static GenericValue encode(Allocator& aAllocator, const bool aValue) throw() {
            return GenericValue(aValue);
	    }
	};

    template<class T>
	struct Encoder<T, typename std::enable_if<
        std::is_same<T, uint8_t>::value ||
        std::is_same<T, uint16_t>::value ||
        std::is_same<T, uint32_t>::value ||
        std::is_same<T, uint64_t>::value
    >::type>{
	    typedef T DecodeType;

	    static DecodeType decode(Allocator& aAllocator, const GenericValue& aValue) throw() {
            return static_cast<T>(aValue.getUnsigned());
	    }

	    static GenericValue encode(Allocator& aAllocator, const T aValue) throw() {
            return GenericValue(static_cast<uint64_t>(aValue));
	    }
	};

    template<class T>
	struct Encoder<T, typename std::enable_if<
        std::is_same<T, int8_t>::value ||
        std::is_same<T, int16_t>::value ||
        std::is_same<T, int32_t>::value ||
        std::is_same<T, int64_t>::value
    >::type>{
	    typedef T DecodeType;

	    static DecodeType decode(Allocator& aAllocator, const GenericValue& aValue) throw() {
            return static_cast<T>(aValue.getSigned());
	    }

	    static GenericValue encode(Allocator& aAllocator, const T aValue) throw() {
            return GenericValue(static_cast<int64_t>(aValue));
	    }
	};

    template<class T>
	struct Encoder<T, typename std::enable_if<
        std::is_same<T, float>::value ||
        std::is_same<T, double>::value
    >::type>{
	    typedef T DecodeType;

	    static DecodeType decode(Allocator& aAllocator, const GenericValue& aValue) throw() {
            return static_cast<T>(aValue.getDouble());
	    }

	    static GenericValue encode(Allocator& aAllocator, const T aValue) throw() {
            return GenericValue(static_cast<double>(aValue));
	    }
	};

    template<>
	struct Encoder<String<char>>{
	    typedef CString DecodeType;

	    static DecodeType decode(Allocator& aAllocator, const GenericValue& aValue) throw() {
            return CString(aValue.getString());
	    }

	    static GenericValue encode(Allocator& aAllocator, const StringConstant<char>& aValue) throw() {
            GenericValue value;
            //! \todo Assign string
            //value.setString() = aValue;
            return value;
	    }
	};

	////

	template<class T>
	struct Encoder<StaticContainer<T>>{
	    typedef ArrayList<T> DecodeType;

	    static DecodeType decode(Allocator& aAllocator, const GenericValue& aValue) throw() {
            ArrayList<T> container(aAllocator);
            if(aValue.isArray()){
                const GenericArray& array_ = aValue.getArray();
                const int32_t size = array_.size();
                for(int32_t i = 0; i < size; ++i) {
                    container.pushBack(Encoder<T>::decode(aAllocator, array_[i]));
                }
            }
            return container;
	    }

	    static GenericValue encode(Allocator& aAllocator, const StaticContainer<T>& aContainer) throw() {
            GenericValue value;
            const GenericArray& array_ = value.setArray();
            const int32_t size = aContainer.size();
            for(int32_t i = 0; i < size; ++i) {
                array_.pushBack(Encoder<T>::encode(aAllocator, aContainer[i]));
            }
            return value;
	    }
	};
}

#endif
<commit_msg>Generic container encoder<commit_after>#ifndef SOLAIRE_ENCODER_HPP
#define SOLAIRE_ENCODER_HPP

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

// Contact :
// Email             : solairelibrary@mail.com
// GitHub repository : https://github.com/SolaireLibrary/SolaireCPP

/*!
	\file Encoder.hpp
	\brief
	\author
	Created			: Adam Smith
	Last modified	: Adam Smith
	\version 1.0
	\date
	Created			: 16th January 2016
	Last Modified	: 16th January 2016
*/

#include "Solaire/Data/ArrayList.hpp"
#include "Solaire/Encode/GenericValue.hpp"

namespace Solaire {

	template<class T, typename ENABLE = void>
	struct Encoder {
	    typedef T DecodeType;

	    static DecodeType decode(Allocator&, const GenericValue&) throw();
	    static GenericValue encode(Allocator&, const T&) throw();
	};

	template<class T>
	static typename Encoder<T>::DecodeType decode(Allocator& aAllocator, const GenericValue& aValue) {
	    return Encoder<T>::decode(aAllocator, aValue);
	}

	template<class T>
	static GenericValue decode(Allocator& aAllocator, const T& aValue) {
	    return Encoder<T>::encode(aAllocator, aValue);
	}

	////

    template<>
	struct Encoder<char>{
	    typedef char DecodeType;

	    static DecodeType decode(Allocator& aAllocator, const GenericValue& aValue) throw() {
            return aValue.getChar();
	    }

	    static GenericValue encode(Allocator& aAllocator, const char aValue) throw() {
            return GenericValue(aValue);
	    }
	};

    template<>
	struct Encoder<bool>{
	    typedef bool DecodeType;

	    static DecodeType decode(Allocator& aAllocator, const GenericValue& aValue) throw() {
            return aValue.getBool();
	    }

	    static GenericValue encode(Allocator& aAllocator, const bool aValue) throw() {
            return GenericValue(aValue);
	    }
	};

    template<class T>
	struct Encoder<T, typename std::enable_if<
        std::is_same<T, uint8_t>::value ||
        std::is_same<T, uint16_t>::value ||
        std::is_same<T, uint32_t>::value ||
        std::is_same<T, uint64_t>::value
    >::type>{
	    typedef T DecodeType;

	    static DecodeType decode(Allocator& aAllocator, const GenericValue& aValue) throw() {
            return static_cast<T>(aValue.getUnsigned());
	    }

	    static GenericValue encode(Allocator& aAllocator, const T aValue) throw() {
            return GenericValue(static_cast<uint64_t>(aValue));
	    }
	};

    template<class T>
	struct Encoder<T, typename std::enable_if<
        std::is_same<T, int8_t>::value ||
        std::is_same<T, int16_t>::value ||
        std::is_same<T, int32_t>::value ||
        std::is_same<T, int64_t>::value
    >::type>{
	    typedef T DecodeType;

	    static DecodeType decode(Allocator& aAllocator, const GenericValue& aValue) throw() {
            return static_cast<T>(aValue.getSigned());
	    }

	    static GenericValue encode(Allocator& aAllocator, const T aValue) throw() {
            return GenericValue(static_cast<int64_t>(aValue));
	    }
	};

    template<class T>
	struct Encoder<T, typename std::enable_if<
        std::is_same<T, float>::value ||
        std::is_same<T, double>::value
    >::type>{
	    typedef T DecodeType;

	    static DecodeType decode(Allocator& aAllocator, const GenericValue& aValue) throw() {
            return static_cast<T>(aValue.getDouble());
	    }

	    static GenericValue encode(Allocator& aAllocator, const T aValue) throw() {
            return GenericValue(static_cast<double>(aValue));
	    }
	};

    template<>
	struct Encoder<String<char>>{
	    typedef CString DecodeType;

	    static DecodeType decode(Allocator& aAllocator, const GenericValue& aValue) throw() {
            return CString(aValue.getString());
	    }

	    static GenericValue encode(Allocator& aAllocator, const StringConstant<char>& aValue) throw() {
            GenericValue value;
            //! \todo Assign string
            //value.setString() = aValue;
            return value;
	    }
	};

	////

	template<class T>
	struct Encoder<StaticContainer<T>>{
	    typedef ArrayList<T> DecodeType;

	    static DecodeType decode(Allocator& aAllocator, const GenericValue& aValue) throw() {
            ArrayList<T> container(aAllocator);
            if(aValue.isArray()){
                const GenericArray& array_ = aValue.getArray();
                const int32_t size = array_.size();
                for(int32_t i = 0; i < size; ++i) {
                    container.pushBack(Encoder<T>::decode(aAllocator, array_[i]));
                }
            }
            return container;
	    }

	    static GenericValue encode(Allocator& aAllocator, const StaticContainer<T>& aContainer) throw() {
            GenericValue value;
            const GenericArray& array_ = value.setArray();
            const int32_t size = aContainer.size();
            for(int32_t i = 0; i < size; ++i) {
                array_.pushBack(Encoder<T>::encode(aAllocator, aContainer[i]));
            }
            return value;
	    }
	};

	template<class T>
	struct Encoder<T, typename std::enable_if<
        std::is_base_of<StaticContainer<typename T::Type>, T>::value
    >::type>{
	    typedef Encoder<StaticContainer<typename T::Value>> ValueEncoder;
	    typedef T DecodeType;

	    static DecodeType decode(Allocator& aAllocator, const GenericValue& aValue) throw() {
            return T(ValueEncoder::decode(aAllocator, aValue));
	    }

	    static GenericValue encode(Allocator& aAllocator, const T& aContainer) throw() {
            return ValueEncoder::encode(aAllocator, aContainer);
	    }
	};
}

#endif
<|endoftext|>


<commit_before>// System.hpp

/*
* (C) Copyright 2015 Noah Roth
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser General Public License
* (LGPL) version 2.1 which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-2.1.html
*
* 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.
*/

#pragma once

#include <msclr/marshal.h>
#include <msclr/marshal_cppstd.h>
#include <msclr/gcroot.h>

using namespace msclr::interop;
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Collections::Generic;
using namespace System::IO;
using namespace System::Text;
using namespace System::Runtime::InteropServices;
using namespace System::Runtime::CompilerServices;<commit_msg>Added an Initialize function to initialize GraphicsMagick<commit_after>// System.hpp

/*
* (C) Copyright 2015 Noah Roth
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser General Public License
* (LGPL) version 2.1 which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-2.1.html
*
* 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.
*/

#pragma once

#include <msclr/marshal.h>
#include <msclr/marshal_cppstd.h>
#include <msclr/gcroot.h>

#include <OvlFile.hpp>

using namespace msclr::interop;
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Collections::Generic;
using namespace System::IO;
using namespace System::Text;
using namespace System::Runtime::InteropServices;
using namespace System::Runtime::CompilerServices;

namespace R3ALInterop
{

	public ref class RCT3AssetLibrary
	{
	public:

		static void Initialize(array<wchar_t>^ args)
		{
			if (args == nullptr)
			{
				RCT3Asset::InitializeRCT3AssetLibrary(nullptr);
				return;
			}

			if (args->Length)
			{
				IntPtr p = Marshal::StringToHGlobalAnsi(gcnew String(args));
				RCT3Asset::InitializeRCT3AssetLibrary(static_cast<const char*>(p.ToPointer()));
				Marshal::FreeHGlobal(p);
			}
			else
			{
				RCT3Asset::InitializeRCT3AssetLibrary(nullptr);
			}
		}

	};

}<|endoftext|>