/**
 * Perform an interpret call where we want to return a container that 
 * contains flattened containers (flattened by 1).
 *
 * @param environment Not used.
 * @param parms The parameters passed to the builtin function.
 * @param additional_parameter Not used.
 * @return a container of elements.
 *
 * @version
 * - JR Lewis       2012.06.01
 *   - Initial version.
 */
Element ConcatBuiltinImplementation::Interpret_( Environment& /* environment */ 
                                               , std::vector<Element> const& parms
                                               , Element const& /* additional_parameter */ )
{
    typedef std::vector<Element>::const_iterator Iterator;

    Container C;

    Iterator iter = parms.begin();
    Iterator end = parms.end();
    for(; iter != end; ++iter)
    {
        bool isAContainer  = false;
        Container current = CastToContainer(*iter, isAContainer);
        if (isAContainer)
        {
            int const NUMBER_OF_ELEMENTS = current.NumberOfElements();
            for(int i=0; i<NUMBER_OF_ELEMENTS; ++i)
            {
                C.Add(current.Get(i));
            }
        } 
        else
        {
            C.Add(*iter);
        }
    }

    return C;
}
예제 #2
0
파일: visitor.cpp 프로젝트: signatal/strine
void Visitor::RecurseContainer(Container const& container)
{
    int const SIZE = container.NumberOfElements();
    for(int i=0; i<SIZE; ++i)
    {
        Visit(container.Get(i));
    } 
}
예제 #3
0
 Element InterpretContainer_(Container container)
 {
     Element out = Nil();
     if (container.NumberOfElements() > 0)
     {
         out = container.Get(0);
     } 
     return out;
 } 
예제 #4
0
        /**
         * Interpret an "at" with a given container.
         * @param container Container to look through.
         * @param index The index in the container.
         * @return the element at an index in the container.
         */
        Element InterpretContainer_( Container container, Number index)
        {

            if (index.IntValue() < container.NumberOfElements() && index.IntValue() >= 0)
            {
                 return container.Get(index.IntValue());         
            }
            else
            {
                 std::stringstream ss;
                 ss << "the index given is out of range: index=" << index.IntValue() << ", max=" << container.NumberOfElements();
                 return Error(ss.str());
            }
        }
    bool PropertyRestrictions<Key, KeyValue, Container>::Qualifies( const Container& rPropertiesContainer )
    {
        bool qualifies = true;

        // individual has to have one of these properties
        for( Container& container : _restrictions)
        {
            qualifies = false;
            bool meets_property_restriction_criteria = true;
            for( auto kv : container )
            {
                if( rPropertiesContainer.Contains( kv ) )
                {
                    LOG_DEBUG_F( "Partial property restriction: constraint is %s.\n", kv.ToString().c_str() );
                    continue; // we're good
                }
                else
                {
                    meets_property_restriction_criteria = false;
#ifdef WIN32
                    LOG_DEBUG_F( "Person does not get the intervention because the allowed property is %s and the person is %s.\n", 
                                 kv.ToString().c_str(), rPropertiesContainer.Get( kv.GetKey<Key>() ).ToString().c_str() );
#endif
                    break;
                }
            }
            // If verified, we're done since these are OR-ed together
            if( meets_property_restriction_criteria )
            {
                qualifies = true;
                LOG_DEBUG_F( "Individual meets at least 1 of the OR-ed together property restriction conditions. Not checking the rest.\n" );
                break;
            }
        }

        return qualifies;
    }