Sha256: 6fa4ed9eea5cb285bc792472613b70697e6e021eaaeb2df2d4271d43553f93c2

Contents?: true

Size: 1.46 KB

Versions: 5

Compression:

Stored size: 1.46 KB

Contents

//
//  refract/AppendDecorator.h
//  librefract
//
//  Created by Jiri Kratochvil on 17/06/15.
//  Copyright (c) 2015 Apiary Inc. All rights reserved.
//
#ifndef REFRACT_APPENDDECORATOR_H
#define REFRACT_APPENDDECORATOR_H

#include <iterator>

namespace refract
{

    // Forward declarations of Elements
    struct IElement;

    template <typename T, typename V = typename T::ValueType>
    struct AppendDecorator {
        typedef T ElementType;
        typedef V ValueType;
        ElementType*& element;
        AppendDecorator(ElementType*& e) : element(e)
        {
        }

        void operator()(const V& value)
        {
            // FIXME: snowcrash warn about "Primitive type can not have member"
            // but in real it create "empty" member
            //
            // solution for now: set if element has no already value, otherwise silently ignore
            if (element->empty()) {
                element->set(value);
            }
        }
    };

    template <typename T>
    struct AppendDecorator<T, std::vector<refract::IElement*> > {
        typedef T ElementType;
        typedef typename T::ValueType ValueType;
        ElementType*& element;

        AppendDecorator(ElementType*& e) : element(e)
        {
        }

        void operator()(const ValueType& value)
        {
            std::transform(value.begin(), value.end(), std::back_inserter(element));
        }
    };

}; // namespace refract

#endif // #ifndef REFRACT_APPENDDECORATOR_H

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
lounge_lizard-0.1.4 ext/drafter/src/refract/AppendDecorator.h
lounge_lizard-0.1.3 ext/drafter/src/refract/AppendDecorator.h
lounge_lizard-0.1.2 ext/drafter/src/refract/AppendDecorator.h
lounge_lizard-0.1.1 ext/drafter/src/refract/AppendDecorator.h
lounge_lizard-0.1.0 ext/drafter/src/refract/AppendDecorator.h