text:
/* -*- mode: c++; fill-column: 132; c-basic-offset: 4; indent-tabs-mode: nil -*- */

/*** Copyright (c), The Regents of the University of California            ***
 *** For more information please refer to files in the COPYRIGHT directory ***/
/*****************************************************************************/

#ifndef ICAT_HIGHLEVEL_ROUTINES_HPP
#define ICAT_HIGHLEVEL_ROUTINES_HPP

#include "objInfo.hpp"
#include "ruleExecSubmit.hpp"
#include "rcConnect.hpp"
#include "icatStructs.hpp"
#include "rodsGeneralUpdate.hpp"
#include "specificQuery.hpp"
#include "phyBundleColl.hpp"
#include "readServerConfig.hpp"

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#include <string>
#include <vector>
#include <map>

#include <boost/tuple/tuple.hpp>

extern icatSessionStruct icss;

int chlOpen();
int chlClose();
int chlIsConnected();
int chlModDataObjMeta( rsComm_t *rsComm, dataObjInfo_t *dataObjInfo,
                       keyValPair_t *regParam );
int chlUpdateRescObjCount( const std::string& _resc, int _delta );
int chlRegDataObj( rsComm_t *rsComm, dataObjInfo_t *dataObjInfo );
int chlRegRuleExecObj( rsComm_t *rsComm,
                       ruleExecSubmitInp_t *ruleExecSubmitInp );
int chlRegReplica( rsComm_t *rsComm, dataObjInfo_t *srcDataObjInfo,
                   dataObjInfo_t *dstDataObjInfo, keyValPair_t *condInput );
int chlUnregDataObj( rsComm_t *rsComm, dataObjInfo_t *dataObjInfo,
                     keyValPair_t *condInput );
int chlRegResc( rsComm_t *rsComm, rescInfo_t *rescInfo );
int chlAddChildResc( rsComm_t* rsComm, rescInfo_t* rescInfo );
int chlDelResc( rsComm_t *rsComm, rescInfo_t *rescInfo, int _dryrun = 0 ); // JMC
int chlDelChildResc( rsComm_t* rsComm, rescInfo_t* rescInfo );
int chlRollback( rsComm_t *rsComm );
int chlCommit( rsComm_t *rsComm );
int chlDelUserRE( rsComm_t *rsComm, userInfo_t *userInfo );
int chlRegCollByAdmin( rsComm_t *rsComm, collInfo_t *collInfo );
int chlRegColl( rsComm_t *rsComm, collInfo_t *collInfo );
int chlModColl( rsComm_t *rsComm, collInfo_t *collInfo );

int chlSimpleQuery( rsComm_t *rsComm, char *sql,
                    char *arg1, char *arg2, char *arg3, char *arg4,
                    int format,
                    int *control, char *outBuf, int maxOutBuf );
int chlGenQuery( genQueryInp_t genQueryInp, genQueryOut_t *result );
int chlGenQueryAccessControlSetup( char *user, char *zone, char *host,
                                   int priv, int controlFlag );
int chlGenQueryTicketSetup( char *ticket, char *clientAddr );
int chlSpecificQuery( specificQueryInp_t specificQueryInp,
                      genQueryOut_t *genQueryOut );

int chlGeneralUpdate( generalUpdateInp_t generalUpdateInp );

int chlDelCollByAdmin( rsComm_t *rsComm, collInfo_t *collInfo );
int chlDelColl( rsComm_t *rsComm, collInfo_t *collInfo );
int chlCheckAuth( rsComm_t *rsComm, const char* scheme, char *challenge, char *response,
                  char *username, int *userPrivLevel, int *clientPrivLevel );
int chlMakeTempPw( rsComm_t *rsComm, char *pwValueToHash, char *otherUser );
int chlMakeLimitedPw( rsComm_t *rsComm, int ttl, char *pwValueToHash );
int decodePw( rsComm_t *rsComm, char *in, char *out );
int chlModUser( rsComm_t *rsComm, char *userName, char *option,
                char *newValue );
int chlModGroup( rsComm_t *rsComm, char *groupName, char *option,
                 char *userName, char *userZone );
int chlModResc( rsComm_t *rsComm, char *rescName, char *option,
                char *optionValue );
int chlModRescDataPaths( rsComm_t *rsComm, char *rescName, char *oldPath,
                         char *newPath, char *userName );
int chlModRescFreeSpace( rsComm_t *rsComm, char *rescName,
                         int updateValue );
int chlRegUserRE( rsComm_t *rsComm, userInfo_t *userInfo );
rodsLong_t checkAndGetObjectId( rsComm_t *rsComm, char *type,
                                char *name, char *access );
int chlAddAVUMetadata( rsComm_t *rsComm, int adminMode, char *type,
                       char *name, char *attribute, char *value,  char *units );
int chlAddAVUMetadataWild( rsComm_t *rsComm, int adminMode, char *type,
                           char *name, char *attribute, char *value,  char *units );
int chlDeleteAVUMetadata( rsComm_t *rsComm, int option, char *type,
                          char *name, char *attribute, char *value,  char *units, int noCommit );
int chlSetAVUMetadata( rsComm_t *rsComm, char *type, // JMC - backport 4836
                       char *name, char *attribute, char *newValue, char *newUnit );
int chlCopyAVUMetadata( rsComm_t *rsComm, char *type1,  char *type2,
                        char *name1, char *name2 );
int chlModAVUMetadata( rsComm_t *rsComm, char *type, char *name,
                       char *attribute, char *value, char *unitsOrChange0,
                       char *change1, char *change2, char *change3 );
int chlModAccessControl( rsComm_t *rsComm, int recursiveFlag,
                         char* accessLevel, char *userName, char *zone,
                         char* pathName );

int chlRegRuleExec( rsComm_t *rsComm, ruleExecSubmitInp_t *ruleExecSubmitInp );
int chlModRuleExec( rsComm_t *rsComm, char *ruleExecId, keyValPair_t *regParam );
int chlDelRuleExec( rsComm_t *rsComm, char *ruleExecId );

int chlRenameObject( rsComm_t *rsComm, rodsLong_t objId, char *newName );
int chlMoveObject( rsComm_t *rsComm, rodsLong_t objId, rodsLong_t targetCollId );

int chlRegToken( rsComm_t *rsComm, char *nameSpace, char *name, char *value,
                 char *value2, char *value3, char *comment );
int chlDelToken( rsComm_t *rsComm, char *nameSpace, char *Name );

int chlRegZone( rsComm_t *rsComm, char *zoneName, char *zoneType,
                char *zoneConnInfo, char *zoneComment );
int chlModZone( rsComm_t *rsComm, char *zoneName, char *option,
                char *optionValue );
int chlModZoneCollAcl( rsComm_t *rsComm, char* accessLevel, char *userName,
                       char* pathName );
int chlDelZone( rsComm_t *rsComm, char *zoneName );
int chlRenameLocalZone( rsComm_t *rsComm, char *oldZoneName, char *newZoneName );
int chlRenameColl( rsComm_t *rsComm, char *oldName, char *newName );

int chlRegServerLoad( rsComm_t *rsComm,
                      char *hostName, char *rescName,
                      char *cpuUsed, char *memUsed, char *swapUsed, char *runqLoad,
                      char *diskSpace, char *netInput, char *netOutput );
int chlPurgeServerLoad( rsComm_t *rsComm, char *secondsAgo );
int chlRegServerLoadDigest( rsComm_t *rsComm, char *rescName, char *loadFactor );
int chlPurgeServerLoadDigest( rsComm_t *rsComm, char *secondsAgo );

int chlCalcUsageAndQuota( rsComm_t *rsComm );
int chlSetQuota( rsComm_t *rsComm, char *type, char *name, char *rescName,
                 char *limit );
int chlCheckQuota( rsComm_t *rsComm, char *userName, char *rescName,
                   rodsLong_t *userQuota, int *quotaStatus );
int chlDelUnusedAVUs( rsComm_t *rsComm );
int chlAddSpecificQuery( rsComm_t *rsComm, char *alias, char *sql );
int chlDelSpecificQuery( rsComm_t *rsComm, char *sqlOrAlias );

int chlGetLocalZone( std::string& );

int sTableInit();
int sFklink( char *table1, char *table2, char *connectingSQL );
int sTable( char *tableName, char *tableAlias, int cycler );
int sColumn( int defineVal, char *tableName, char *columnName );

int chlDebug( char *debugMode );
int chlDebugGenQuery( int mode );
int chlDebugGenUpdate( int mode );
int chlInsRuleTable( rsComm_t *rsComm,
                     char *baseName, char *priorityStr, char *ruleName,
                     char *ruleHead, char *ruleCondition,
                     char *ruleAction,
                     char *ruleRecovery, char *ruleIdStr, char *myTime );
int chlVersionRuleBase( rsComm_t *rsComm,
                        char *baseName, char *myTime );
int chlVersionDvmBase( rsComm_t *rsComm,
                       char *baseName, char *myTime );
/*int chlDatabaseObjectAdmin(rsComm_t *rsComm,
  databaseObjectAdminInp_t *databaseObjectAdminInp,
  databaseObjectAdminOut_t *databaseObjectAdminOut);*/
int chlInsDvmTable( rsComm_t *rsComm,
                    char *baseName, char *varName, char *action,
                    char *var2CMap, char *myTime );
int chlInsFnmTable( rsComm_t *rsComm,
                    char *baseName, char *funcName,
                    char *func2CMap, char *myTime );
int chlInsMsrvcTable( rsComm_t *rsComm,
                      char *moduleName,
                      char *msrvcName,
                      char *msrvcSignature,
                      char *msrvcVersion,
                      char *msrvcHost,
                      char *msrvcLocation,
                      char *msrvcLanguage,
                      char *msrvcTypeName,
                      char *msrvcStatus,
                      char *myTime );
int chlVersionDvmBase( rsComm_t *rsComm,
                       char *baseName, char *myTime );
int chlVersionFnmBase( rsComm_t *rsComm,
                       char *baseName, char *myTime );
int chlModTicket( rsComm_t *rsComm, char *opName, char *ticket,
                  char *arg1, char *arg2, char *arg3 );
int chlUpdateIrodsPamPassword( rsComm_t *rsComm, char *userName,
                               int timeToLive, char *testTime,
                               char **irodsPassword );

irods::error chlRescObjCount( const std::string& _resc_name, int& _rtn_obj_count );

int chlSubstituteResourceHierarchies( rsComm_t *rsComm, const char *old_hier, const char *new_hier );

/// =-=-=-=-=-=-=-
/// @brief typedefs and prototype for query used for rebalancing operation
typedef std::vector< int > dist_child_result_t;

/// =-=-=-=-=-=-=-
/// @brief query which distinct data objects do not existin on a
///        given child resource which do exist on the parent
int chlGetDistinctDataObjsMissingFromChildGivenParent(
    const std::string&   _parent,
    const std::string&   _child,
    int                  _limit,
    dist_child_result_t& _results );

/// =-=-=-=-=-=-=-
/// @brief the the distinct data object count for a resource
int chlGetDistinctDataObjCountOnResource(
    const std::string&   _resc_name,
    long long&           _count );

int chlGetHierarchyForResc(
    const std::string&	resc_name,
    const std::string&	zone_name,
    std::string& hierarchy );

int chlCheckAndGetObjectID(
    rsComm_t*, // comm
    char*,     // type
    char*,     // name
    char* );   // access

int chlGetRcs( icatSessionStruct** );

#endif /* ICAT_HIGHLEVEL_ROUTINES_H */

max_stars_repo_name: PlantandFoodResearch/irods

max_issues_repo_name: PlantandFoodResearch/irods

max_forks_repo_name: PlantandFoodResearch/irods


text:
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// basic_xml_grammar.ipp:

// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

//  See http://www.boost.org for updates, documentation, and revision history.

#if (defined _MSC_VER) && (_MSC_VER == 1200)
#  pragma warning (disable : 4786) // too long name, harmless warning
#endif

#include <istream>
#include <algorithm>
#include <boost/config.hpp> // BOOST_DEDUCED_TYPENAME

#ifdef BOOST_MSVC
#  pragma warning(push)
#  pragma warning(disable : 4511 4512)
#endif

// spirit stuff
#include <boost/spirit/include/classic_operators.hpp>
#include <boost/spirit/include/classic_actions.hpp>
#include <boost/spirit/include/classic_numerics.hpp>

#ifdef BOOST_MSVC
#pragma warning(pop)
#endif

// for head_iterator test
//#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/serialization/pfto.hpp>

#include <boost/io/ios_state.hpp>
#include <boost/serialization/throw_exception.hpp>
#include <boost/archive/impl/basic_xml_grammar.hpp>
#include <boost/archive/xml_archive_exception.hpp>
#include <boost/archive/basic_xml_archive.hpp>
#include <boost/archive/iterators/xml_unescape.hpp>

using namespace boost::spirit::classic;

namespace boost {
namespace archive {

/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// template code for basic_xml_grammar of both wchar_t and char types

namespace xml { // anonymous

#ifdef BOOST_MSVC
#  pragma warning(push)
#  pragma warning(disable : 4511 4512)
#endif

template<class T>
struct assign_impl {
    T & t;
    void operator()(const T t_) const {
        t = t_;
    }
    assign_impl(T &  t_)
        : t(t_)
    {}
};

template<>
struct assign_impl<std::string> {
    std::string & t;
    void operator()(
        std::string::const_iterator b,
        std::string::const_iterator e
    ) const {
        t.resize(0);
        while(b != e){
            t += * b;
            ++b;
        }
    }
    assign_impl<std::string> & operator=(
        assign_impl<std::string> & rhs
    );
    assign_impl(std::string & t_)
        : t(t_)
    {}
};

#ifndef BOOST_NO_STD_WSTRING
template<>
struct assign_impl<std::wstring> {
    std::wstring & t;
    void operator()(
        std::wstring::const_iterator b,
        std::wstring::const_iterator e
    ) const {
        t.resize(0);
        while(b != e){
            t += * b;
            ++b;
        }
    }
    assign_impl(std::wstring & t_)
        : t(t_)
    {}
};
#endif

template<class T>
assign_impl<T> assign_object(T &t){
    return assign_impl<T>(t);
}

struct assign_level {
    tracking_type & tracking_level;
    void operator()(const unsigned int tracking_level_) const {
        tracking_level = (0 == tracking_level_) ? false : true;
    }
    assign_level(tracking_type &  tracking_level_)
        : tracking_level(tracking_level_)
    {}
};

template<class String, class Iterator>
struct append_string {
    String & contents;
    void operator()(Iterator start, Iterator end) const {
    #if 0
        typedef boost::archive::iterators::xml_unescape<Iterator> translator;
        contents.append(
            translator(BOOST_MAKE_PFTO_WRAPPER(start)),
            translator(BOOST_MAKE_PFTO_WRAPPER(end))
        );
    #endif
        contents.append(start, end);
    }
    append_string(String & contents_)
        : contents(contents_)
    {}
};

template<class String>
struct append_char {
    String & contents;
    void operator()(const unsigned int char_value) const {
        const BOOST_DEDUCED_TYPENAME String::value_type z = char_value;
        contents += z;
    }
    append_char(String & contents_)
        : contents(contents_)
    {}
};

template<class String, unsigned int c>
struct append_lit {
    String & contents;
    template<class X, class Y>
    void operator()(const X & /*x*/, const Y & /*y*/) const {
        const BOOST_DEDUCED_TYPENAME String::value_type z = c;
        contents += z;
    }
    append_lit(String & contents_)
        : contents(contents_)
    {}
};

#ifdef BOOST_MSVC
#pragma warning(pop)
#endif

} // namespace anonymous

template<class CharType>
bool basic_xml_grammar<CharType>::my_parse(
    BOOST_DEDUCED_TYPENAME basic_xml_grammar<CharType>::IStream & is,
    const rule_t & rule_,
    CharType delimiter
) const {
    if(is.fail()){
        boost::serialization::throw_exception(
            archive_exception(archive_exception::input_stream_error)
        );
    }

    boost::io::ios_flags_saver ifs(is);
    is >> std::noskipws;

    std::basic_string<CharType> arg;

    CharType val;
    do{
        BOOST_DEDUCED_TYPENAME basic_xml_grammar<CharType>::IStream::int_type
            result = is.get();
        if(is.fail())
            return false;
        val = static_cast<CharType>(result);
        arg += val;
    }
    while(val != delimiter);

    // read just one more character.  This will be the newline after the tag
    // this is so that the next operation will return fail if the archive
    // is terminated.  This will permit the archive to be used for debug
    // and transaction data logging in the standard way.

    parse_info<BOOST_DEDUCED_TYPENAME std::basic_string<CharType>::iterator>
        result = boost::spirit::classic::parse(arg.begin(), arg.end(), rule_);
    return result.hit;
}

template<class CharType>
bool basic_xml_grammar<CharType>::parse_start_tag(
    BOOST_DEDUCED_TYPENAME basic_xml_grammar<CharType>::IStream & is
){
    rv.class_name.resize(0);
    return my_parse(is, STag);
}

template<class CharType>
bool basic_xml_grammar<CharType>::parse_end_tag(IStream & is) const {
    return my_parse(is, ETag);
}

template<class CharType>
bool basic_xml_grammar<CharType>::parse_string(IStream & is, StringType & s){
    rv.contents.resize(0);
    bool result = my_parse(is, content, '<');
    // note: unget caused a problem with dinkumware.  replace with
 // is.unget();
    // putback another dilimiter instead
    is.putback('<');
    if(result)
        s = rv.contents;
    return result;
}

template<class CharType>
basic_xml_grammar<CharType>::basic_xml_grammar(){
    init_chset();

    S =
        +(Sch)
    ;

    // refactoring to workaround template depth on darwin
    NameHead = (Letter | '_' | ':');
    NameTail = *NameChar ;
    Name =
      NameHead >> NameTail
    ;

    Eq =
        !S >> '=' >> !S
    ;

    AttributeList =
        *(S >> Attribute)
    ;

    STag =
        !S
        >> '<'
        >> Name  [xml::assign_object(rv.object_name)]
        >> AttributeList
        >> !S
        >> '>'
    ;

    ETag =
        !S
        >> "</"
        >> Name [xml::assign_object(rv.object_name)]
        >> !S
        >> '>'
    ;

    // refactoring to workaround template depth on darwin
    CharDataChars = +(anychar_p - chset_p(L"&<"));
    CharData =
        CharDataChars [
            xml::append_string<
                StringType,
                BOOST_DEDUCED_TYPENAME std::basic_string<CharType>::const_iterator
            >(rv.contents)
        ]
    ;

    // slight factoring works around ICE in msvc 6.0
    CharRef1 =
        str_p(L"&#") >> uint_p [xml::append_char<StringType>(rv.contents)] >> L';'
    ;
    CharRef2 =
        str_p(L"&#x") >> hex_p [xml::append_char<StringType>(rv.contents)] >> L';'
    ;
    CharRef = CharRef1 | CharRef2 ;

    AmpRef = str_p(L"&")[xml::append_lit<StringType, L'&'>(rv.contents)];
    LTRef = str_p(L"<")[xml::append_lit<StringType, L'<'>(rv.contents)];
    GTRef = str_p(L">")[xml::append_lit<StringType, L'>'>(rv.contents)];
    AposRef = str_p(L"'")[xml::append_lit<StringType, L'\''>(rv.contents)];
    QuoteRef = str_p(L""")[xml::append_lit<StringType, L'"'>(rv.contents)];

    Reference =
        AmpRef
        | LTRef
        | GTRef
        | AposRef
        | QuoteRef
        | CharRef
    ;

    content =
        L"<" // should be end_p
        | +(Reference | CharData) >> L"<"
    ;

    ClassIDAttribute =
        str_p(BOOST_ARCHIVE_XML_CLASS_ID()) >> NameTail
        >> Eq
        >> L'"'
        >> int_p [xml::assign_object(rv.class_id)]
        >> L'"'
      ;

    ObjectIDAttribute = (
        str_p(BOOST_ARCHIVE_XML_OBJECT_ID())
        |
        str_p(BOOST_ARCHIVE_XML_OBJECT_REFERENCE())
        )
        >> NameTail
        >> Eq
        >> L'"'
        >> L'_'
        >> uint_p [xml::assign_object(rv.object_id)]
        >> L'"'
    ;

    AmpName = str_p(L"&")[xml::append_lit<StringType, L'&'>(rv.class_name)];
    LTName = str_p(L"<")[xml::append_lit<StringType, L'<'>(rv.class_name)];
    GTName = str_p(L">")[xml::append_lit<StringType, L'>'>(rv.class_name)];
    ClassNameChar =
        AmpName
        | LTName
        | GTName
        | (anychar_p - chset_p(L"\"")) [xml::append_char<StringType>(rv.class_name)]
    ;

    ClassName =
        * ClassNameChar
    ;

    ClassNameAttribute =
        str_p(BOOST_ARCHIVE_XML_CLASS_NAME())
        >> Eq
        >> L'"'
        >> ClassName
        >> L'"'
    ;

    TrackingAttribute =
        str_p(BOOST_ARCHIVE_XML_TRACKING())
        >> Eq
        >> L'"'
        >> uint_p [xml::assign_level(rv.tracking_level)]
        >> L'"'
    ;

    VersionAttribute =
        str_p(BOOST_ARCHIVE_XML_VERSION())
        >> Eq
        >> L'"'
        >> uint_p [xml::assign_object(rv.version)]
        >> L'"'
    ;

    UnusedAttribute =
        Name
        >> Eq
        >> L'"'
        >> !CharData
        >> L'"'
    ;

    Attribute =
        ClassIDAttribute
        | ObjectIDAttribute
        | ClassNameAttribute
        | TrackingAttribute
        | VersionAttribute
        | UnusedAttribute
    ;

    XMLDeclChars = *(anychar_p - chset_p(L"?>"));
    XMLDecl =
        !S
        >> str_p(L"<?xml")
        >> S
        >> str_p(L"version")
        >> Eq
        >> str_p(L"\"1.0\"")
        >> XMLDeclChars
        >> !S
        >> str_p(L"?>")
    ;

    DocTypeDeclChars = *(anychar_p - chset_p(L">"));
    DocTypeDecl =
        !S
        >> str_p(L"<!DOCTYPE")
        >> DocTypeDeclChars
        >> L'>'
    ;

    SignatureAttribute =
        str_p(L"signature")
        >> Eq
        >> L'"'
        >> Name [xml::assign_object(rv.class_name)]
        >> L'"'
    ;

    SerializationWrapper =
        !S
        >> str_p(L"<boost_serialization")
        >> S
        >> ( (SignatureAttribute >> S >> VersionAttribute)
           | (VersionAttribute >> S >> SignatureAttribute)
           )
        >> !S
        >> L'>'
    ;
}

template<class CharType>
void basic_xml_grammar<CharType>::init(IStream & is){
    init_chset();
    if(! my_parse(is, XMLDecl))
        boost::serialization::throw_exception(
            xml_archive_exception(xml_archive_exception::xml_archive_parsing_error)
        );
    if(! my_parse(is, DocTypeDecl))
        boost::serialization::throw_exception(
            xml_archive_exception(xml_archive_exception::xml_archive_parsing_error)
        );
    if(! my_parse(is, SerializationWrapper))
        boost::serialization::throw_exception(
            xml_archive_exception(xml_archive_exception::xml_archive_parsing_error)
        );
    if(! std::equal(rv.class_name.begin(), rv.class_name.end(), BOOST_ARCHIVE_SIGNATURE()))
        boost::serialization::throw_exception(
            archive_exception(archive_exception::invalid_signature)
        );
}

template<class CharType>
void basic_xml_grammar<CharType>::windup(IStream & is){
    if(is.fail() || is.eof())
        return;
    // uh-oh - don't throw exception from code called by a destructor !
    // so just ignore any failure.
    my_parse(is, ETag);
}

} // namespace archive
} // namespace boost

ext: ipp


text:
//  Copyright (c) 2001 Daniel C. Nuffer
//  Copyright (c) 2001-2011 Hartmut Kaiser
//
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#if !defined(BOOST_SPIRIT_ITERATOR_FIXED_SIZE_QUEUE_POLICY_MAR_16_2007_1134AM)
#define BOOST_SPIRIT_ITERATOR_FIXED_SIZE_QUEUE_POLICY_MAR_16_2007_1134AM

#include <boost/spirit/home/support/iterators/detail/multi_pass.hpp>
#include <boost/spirit/home/support/iterators/detail/fixed_size_queue.hpp>
#include <boost/assert.hpp>
#include <cstdlib>

namespace boost { namespace spirit { namespace iterator_policies
{
    ///////////////////////////////////////////////////////////////////////////
    //  class fixed_size_queue
    //  Implementation of the StoragePolicy used by multi_pass
    //  fixed_size_queue keeps a circular buffer (implemented by
    //  boost::spirit::fixed_size_queue class) that is size N+1 and stores N
    //  elements.
    //
    //  It is up to the user to ensure that there is enough look ahead for
    //  their grammar. Currently there is no way to tell if an iterator is
    //  pointing to forgotten data. The leading iterator will put an item in
    //  the queue and remove one when it is incremented. No dynamic allocation
    //  is done, except on creation of the queue (fixed_size_queue constructor).
    ///////////////////////////////////////////////////////////////////////////
    template <std::size_t N>
    struct fixed_size_queue
    {
        ///////////////////////////////////////////////////////////////////////
        template <typename Value>
        class unique : public detail::default_storage_policy
        {
        private:
            typedef detail::fixed_size_queue<Value, N> queue_type;

        protected:
            unique() {}

            unique(unique const& x)
              : queued_position(x.queued_position) {}

            void swap(unique& x)
            {
                boost::swap(queued_position, x.queued_position);
            }

            //  This is called when the iterator is dereferenced. It's a
            //  template method so we can recover the type of the multi_pass
            //  iterator and access the m_input data member.
            template <typename MultiPass>
            static typename MultiPass::reference
            dereference(MultiPass const& mp)
            {
                if (!mp.queued_position.get_position().is_initialized())
                   mp.queued_position.get_position().set_queue(&mp.shared()->queued_elements);

                if (mp.queued_position == mp.shared()->queued_elements.end())
                    return MultiPass::get_input(mp);

                return *mp.queued_position;
            }

            //  This is called when the iterator is incremented. It's a
            //  template method so we can recover the type of the multi_pass
            //  iterator and access the m_input data member.
            template <typename MultiPass>
            static void increment(MultiPass& mp)
            {
                if (!mp.queued_position.get_position().is_initialized())
                    mp.queued_position.get_position().set_queue(&mp.shared()->queued_elements);

                if (mp.queued_position == mp.shared()->queued_elements.end())
                {
                    // don't let the queue get larger than N
                    if (mp.shared()->queued_elements.size() >= N)
                        mp.shared()->queued_elements.pop_front();

                    mp.shared()->queued_elements.push_back(
                        MultiPass::get_input(mp));
                    MultiPass::advance_input(mp);
                }
                ++mp.queued_position;
            }

            // clear_queue is a no-op

            // called to determine whether the iterator is an eof iterator
            template <typename MultiPass>
            static bool is_eof(MultiPass const& mp)
            {
                return mp.queued_position == mp.shared()->queued_elements.end() &&
                       MultiPass::input_at_eof(mp);
            }

            // called by operator==
            template <typename MultiPass>
            static bool equal_to(MultiPass const& mp, MultiPass const& x)
            {
                return mp.queued_position == x.queued_position;
            }

            // called by operator<
            template <typename MultiPass>
            static bool less_than(MultiPass const& mp, MultiPass const& x)
            {
                return mp.queued_position < x.queued_position;
            }

        protected:
            mutable typename queue_type::iterator queued_position;
        };

        ///////////////////////////////////////////////////////////////////////
        template <typename Value>
        struct shared
        {
            typedef detail::fixed_size_queue<Value, N> queue_type;
            queue_type queued_elements;
        };
    };

}}}

#endif

ext: hpp

max_stars_repo_name: randolphwong/mcsema

max_issues_repo_name: randolphwong/mcsema

max_forks_repo_name: randolphwong/mcsema


text:
/**************************************************************
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.
 *
 *************************************************************/

#ifndef SVT_UNO_WIZARD_SHELL
#define SVT_UNO_WIZARD_SHELL

/** === begin UNO includes === **/
#include <com/sun/star/ui/dialogs/XWizardController.hpp>
#include <com/sun/star/ui/dialogs/XWizard.hpp>
/** === end UNO includes === **/

#include <svtools/roadmapwizard.hxx>

#include <boost/shared_ptr.hpp>
#include <map>

//......................................................................................................................
namespace svt { namespace uno
{
//......................................................................................................................

    class WizardPageController;
    typedef ::boost::shared_ptr< WizardPageController > PWizardPageController;

	//==================================================================================================================
	//= WizardShell
	//==================================================================================================================
    typedef ::svt::RoadmapWizard    WizardShell_Base;
    class WizardShell : public WizardShell_Base
	{
    public:
        WizardShell(
            Window* _pParent,
            const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XWizardController >& i_rController,
            const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< sal_Int16 > >& i_rPaths
        );
        virtual ~WizardShell();

        // Dialog overridables
	    virtual short	Execute();

        // OWizardMachine overridables
		virtual TabPage*	createPage( WizardState i_nState );
	    virtual void        enterState( WizardState i_nState );
		virtual	sal_Bool	leaveState( WizardState i_nState );
        virtual String      getStateDisplayName( WizardState i_nState ) const;
        virtual bool        canAdvance() const;
		virtual sal_Bool    onFinish();
		virtual IWizardPageController*
                            getPageController( TabPage* _pCurrentPage ) const;

        static sal_Int16 convertCommitReasonToTravelType( const CommitPageReason i_eReason );

        // operations
        sal_Bool    advanceTo( const sal_Int16 i_nPageId )
        {
            return skipUntil( impl_pageIdToState( i_nPageId ) );
        }
        sal_Bool    goBackTo( const sal_Int16 i_nPageId )
        {
            return skipBackwardUntil( impl_pageIdToState( i_nPageId ) );
        }
		sal_Bool    travelNext()        { return WizardShell_Base::travelNext(); }
		sal_Bool    travelPrevious()    { return WizardShell_Base::travelPrevious(); }

        void        activatePath( const sal_Int16 i_nPathID, const sal_Bool i_bFinal )
        {
            WizardShell_Base::activatePath( PathId( i_nPathID ), i_bFinal );
        }

        ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XWizardPage >
                    getCurrentWizardPage() const;

        sal_Int16   getCurrentPage() const
        {
            return impl_stateToPageId( getCurrentState() );
        }

        void        enablePage( const sal_Int16 i_PageID, const sal_Bool i_Enable );

        bool        knowsPage( const sal_Int16 i_nPageID ) const
        {
            return knowsState( impl_pageIdToState( i_nPageID ) );
        }

    private:
        sal_Int16   impl_stateToPageId( const WizardTypes::WizardState i_nState ) const
        {
            return static_cast< sal_Int16 >( i_nState + m_nFirstPageID );
        }

        WizardState impl_pageIdToState( const sal_Int16 i_nPageId ) const
        {
            return static_cast< WizardState >( i_nPageId - m_nFirstPageID );
        }

        PWizardPageController impl_getController( TabPage* i_pPage ) const;

        // prevent outside access to some base class members
        using WizardShell_Base::skip;
        using WizardShell_Base::skipUntil;
        using WizardShell_Base::skipBackwardUntil;
        using WizardShell_Base::getCurrentState;
        using WizardShell_Base::activatePath;

    private:
        typedef ::std::map< TabPage*, PWizardPageController > Page2ControllerMap;

        const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XWizardController >  m_xController;
        const sal_Int16                                                                             m_nFirstPageID;
        Page2ControllerMap                                                                          m_aPageControllers;
	};

//......................................................................................................................
} } // namespace svt::uno
//......................................................................................................................

#endif // SVT_UNO_WIZARD_SHELL

ext: hxx

max_stars_repo_name: Grosskopf/openoffice

max_issues_repo_name: Grosskopf/openoffice

max_forks_repo_name: Grosskopf/openoffice


text:
#ifndef STAN_LANG_GENERATOR_GENERATE_EXPRESSION_HPP
#define STAN_LANG_GENERATOR_GENERATE_EXPRESSION_HPP

#include "expression_visgen.hpp"
#include "stan/language/ast.hpp"
#include <boost/variant/apply_visitor.hpp>
#include <ostream>

namespace stan {
namespace lang {

/**
 * Generate the specified expression to the specified stream with
 * user-facing/C++ format and parameter/data format controlled by
 * the flags.
 *
 * @param[in] e expression to generate
 * @param[in] user_facing true if expression might be reported to user
 * @param[in,out] o stream for generating
 */
void generate_expression(const expression& e, bool user_facing,
                         std::ostream& o) {
  expression_visgen vis(o, user_facing);
  boost::apply_visitor(vis, e.expr_);
}

}  // namespace lang
}  // namespace stan
#endif

max_stars_repo_name: alashworth/stan-monorepo

max_issues_repo_name: alashworth/stan-monorepo

max_forks_repo_name: alashworth/stan-monorepo


text:
#include "stdafx.h"
#include "qmath.h"
#include "config.h"

#include <vector>
#include <ctime>
#include <sstream>
#include <iostream>
#include <boost/test/unit_test.hpp>

namespace boost
{
	void throw_exception(class std::exception const &e)
	{
		throw e;
	}
}

using namespace math;

#ifdef NDEBUG
static const int TIMES = 1000;
#else
static const int TIMES = 10;
#endif

static const int COUNT = 1024;

// #define BOOST_AUTO_TEST_CASE(X) void X()
// #define BOOST_FAIL(X)
// #define BOOST_CHECK(X)

	std::vector<vec4f> vec4_src(COUNT);
	std::vector<vec4f> vec4_ref(COUNT);
	std::vector<vec4f> vec4_dst1(COUNT);
	std::vector<vec4f> vec4_dst2(COUNT);

	std::vector<vec3f> vec3_src(COUNT);
	std::vector<vec3f> vec3_ref(COUNT);
	std::vector<vec3f> vec3_dst1(COUNT);
	std::vector<vec3f> vec3_dst2(COUNT);

	std::vector<vec3f> mat4_vec3_src(COUNT);
	std::vector<vec3f> mat4_vec3_ref(COUNT);
	std::vector<vec3f> mat4_vec3_dst1(COUNT);
	std::vector<vec3f> mat4_vec3_dst2(COUNT);

	//////////////////////////////////////////////////////////////////////////

	BOOST_AUTO_TEST_CASE(BENCHMARK_MAT4_VEC4_1)
	{
#ifdef MATH_USE_SIMD
		std::cout << "SIMD" << std::endl;
#else
		std::cout << "SCALAR" << std::endl;
#endif
		std::cout << COUNT << "x" << TIMES << std::endl;

// 		size_t al = std::alignment_of<vec4<float>>();
// 		al = std::alignment_of<vec4f>();
// 		al = __alignof(vec4<float>);
// 		al = __alignof(vec4f);
// 		al = __alignof(std::max_align_t);

		for (uint32_t i = 0; i < COUNT; i++)
		{
			vec4_src[i] = vec4f(vec4s32(i % 7, i % 23 - 100, i / 5, i / 32));
		}
		for (uint32_t i = 0; i < COUNT; i++)
		{
			vec3_src[i] = vec3f(vec3s32(i % 7, i % 23 - 100, i / 5));
		}

		mat4f mat(quat_axis_z(1.27f).get_as_mat3());

		std::cout << std::endl;

		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES; x++)
			{
				for (uint32_t i = 0; i < COUNT; i++)
				{
					auto const& vect = vec4_src[i];
					vec4_ref[i].set(
						vect.x*mat.m[0] + vect.y*mat.m[4] + vect.z*mat.m[ 8] + vect.w*mat.m[12],
						vect.x*mat.m[1] + vect.y*mat.m[5] + vect.z*mat.m[ 9] + vect.w*mat.m[13],
						vect.x*mat.m[2] + vect.y*mat.m[6] + vect.z*mat.m[10] + vect.w*mat.m[14],
						vect.x*mat.m[3] + vect.y*mat.m[7] + vect.z*mat.m[11] + vect.w*mat.m[15]
					);
				}
			}
			std::cout << "scalar mat4*vec4 " << clock() - start << std::endl;
		}

		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES; x++)
			{
				for (uint32_t i = 0; i < COUNT; i++)
				{
					vec4_dst2[i] = math::transform(mat, vec4_src[i]);
				}
			}
			std::cout << "math::transform mat4*vec4 " << clock() - start << std::endl;
		}

		BOOST_CHECK(vec4_ref == vec4_dst2);
	}

	//////////////////////////////////////////////////////////////////////////

	BOOST_AUTO_TEST_CASE(BENCHMARK_MAT4_VEC4_2)
	{
		mat4f mat;
		mat = quat_axis_z(1.27f).get_as_mat3();

		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES; x++)
			{
				math::batch::transform(mat, vec4_dst2.data(), sizeof(vec4f), vec4_src.data(), sizeof(vec4f), COUNT);
			}
			std::cout << "math::batch::transform vec4 " << clock() - start << std::endl;
		}

		BOOST_CHECK(vec4_ref == vec4_dst2);
	}

	//////////////////////////////////////////////////////////////////////////

	BOOST_AUTO_TEST_CASE(BENCHMARK_MAT4_VEC3)
	{
		for (uint32_t i = 0; i < COUNT; i++)
		{
			mat4_vec3_src[i] = vec3f(vec3s32(i % 7, i % 23 - 100, i / 5));
		}

		mat4f mat;
		mat = quat_axis_z(1.27f).get_as_mat3();

		std::cout << std::endl;

		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES; x++)
			{
				for (uint32_t i = 0; i < COUNT; i++)
				{
					mat4_vec3_dst1[i] = math::transform(mat, mat4_vec3_src[i]);
				}
			}
			std::cout << "math::transform vec3 " << clock() - start << std::endl;
		}
		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES; x++)
			{
				math::batch::transform(mat, mat4_vec3_dst2.data(), sizeof(vec3f), mat4_vec3_src.data(), sizeof(vec3f), COUNT);
			}
			std::cout << "math::batch::transform vec3 " << clock() - start << std::endl;
		}

		for (uint32_t i = 0; i < mat4_vec3_dst1.size(); i++)
		{
			if (mat4_vec3_dst1[i] != mat4_vec3_dst2[i])
			{
				BOOST_FAIL("Different transform product");
				break;
			}
		}
		BOOST_CHECK(mat4_vec3_dst1 == mat4_vec3_dst2);
	}

	//////////////////////////////////////////////////////////////////////////

	BOOST_AUTO_TEST_CASE(BENCHMARK_MAT4_MAT4)
	{
		std::vector<mat4f> src(COUNT);
		std::vector<mat4f> dst1(COUNT);
		std::vector<mat4f> dst2(COUNT);

		for (uint32_t i = 0; i < COUNT; i++)
		{
			auto mat = quat_axis_x(1.27f).get_as_mat3();
			src[i] = mat;
		}

		mat4f mat;
		mat = quat_axis_z(1.27f).get_as_mat3();

		std::cout << std::endl;

		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES/10; x++)
			{
				for (uint32_t i = 0; i < COUNT; i++)
				{
					const float* m1 = mat.m;
					const float* m2 = src[i].m;
					float* m3 = dst2[i].m;

					// using this code only on release and when on the iphone
					m3[0] = m1[0]*m2[0] + m1[4]*m2[1] + m1[8]*m2[2] + m1[12]*m2[3];
					m3[1] = m1[1]*m2[0] + m1[5]*m2[1] + m1[9]*m2[2] + m1[13]*m2[3];
					m3[2] = m1[2]*m2[0] + m1[6]*m2[1] + m1[10]*m2[2] + m1[14]*m2[3];
					m3[3] = m1[3]*m2[0] + m1[7]*m2[1] + m1[11]*m2[2] + m1[15]*m2[3];

					m3[4] = m1[0]*m2[4] + m1[4]*m2[5] + m1[8]*m2[6] + m1[12]*m2[7];
					m3[5] = m1[1]*m2[4] + m1[5]*m2[5] + m1[9]*m2[6] + m1[13]*m2[7];
					m3[6] = m1[2]*m2[4] + m1[6]*m2[5] + m1[10]*m2[6] + m1[14]*m2[7];
					m3[7] = m1[3]*m2[4] + m1[7]*m2[5] + m1[11]*m2[6] + m1[15]*m2[7];

					m3[8] = m1[0]*m2[8] + m1[4]*m2[9] + m1[8]*m2[10] + m1[12]*m2[11];
					m3[9] = m1[1]*m2[8] + m1[5]*m2[9] + m1[9]*m2[10] + m1[13]*m2[11];
					m3[10] = m1[2]*m2[8] + m1[6]*m2[9] + m1[10]*m2[10] + m1[14]*m2[11];
					m3[11] = m1[3]*m2[8] + m1[7]*m2[9] + m1[11]*m2[10] + m1[15]*m2[11];

					m3[12] = m1[0]*m2[12] + m1[4]*m2[13] + m1[8]*m2[14] + m1[12]*m2[15];
					m3[13] = m1[1]*m2[12] + m1[5]*m2[13] + m1[9]*m2[14] + m1[13]*m2[15];
					m3[14] = m1[2]*m2[12] + m1[6]*m2[13] + m1[10]*m2[14] + m1[14]*m2[15];
					m3[15] = m1[3]*m2[12] + m1[7]*m2[13] + m1[11]*m2[14] + m1[15]*m2[15];
				}
			}
			std::cout << "scalar mat4f * mat4f " << clock() - start << std::endl;
		}
		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES/10; x++)
			{
				for (uint32_t i = 0; i < COUNT; i++)
				{
					multiply(dst1[i], mat, src[i]);
				}
			}
			std::cout << "math::multiply mat4f " << clock() - start << std::endl;
		}
		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES/10; x++)
			{
				math::batch::multiply(mat, dst1.data(), sizeof(math::mat4f), src.data(), sizeof(math::mat4f), COUNT);
			}
			std::cout << "math::batch::multiply mat4f " << clock() - start << std::endl;
		}
		BOOST_CHECK(dst1 == dst2);
	}

	//////////////////////////////////////////////////////////////////////////

	BOOST_AUTO_TEST_CASE(BENCHMARK_VEC4_VEC4)
	{
		std::vector<vec4f> src(COUNT);
		std::vector<vec4f> dst1(COUNT);
		std::vector<vec4f> dst2(COUNT);

		for (uint32_t i = 0; i < COUNT; i++)
		{
			src[i] = vec4f(vec4s32(i % 7, i % 23 - 100, i / 5, i / 32));
		}

		vec4f xxx(12.f, 4.f, 7.f, 1.3f);

		std::cout << std::endl;

		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES; x++)
			{
				for (uint32_t i = 0; i < COUNT; i++)
				{
					vec4f const& v = src[i];
					float x = v.x;
					float y = v.y;
					float z = v.z;
					float w = v.w;
					dst2[i] = vec4f(x * xxx.x, y * xxx.y, z * xxx.z, w * xxx.w);
				}
			}
			std::cout << "scalar vec4*vec4 " << clock() - start << std::endl;
		}
		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES; x++)
			{
				for (uint32_t i = 0; i < COUNT; i++)
				{
					dst1[i] = src[i] * xxx;
				}
			}
			std::cout << "math vec4*vec4 " << clock() - start << std::endl;
		}

		BOOST_CHECK(dst1 == dst2);
	}

	//////////////////////////////////////////////////////////////////////////

	BOOST_AUTO_TEST_CASE(BENCHMARK_VEC4_LERP_VEC4)
	{
		vec4f xxx(12.f, 4.f, 7.f, 1.3f);

		std::cout << std::endl;

		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES; x++)
			{
				for (uint32_t i = 0; i < COUNT; i++)
				{
					float t = 0.72f;
					vec4f const& v = vec4_src[i];
					float x = v.x;
					float y = v.y;
					float z = v.z;
					float w = v.w;
					vec4_dst2[i] = vec4f(x + (xxx.x - x)*t, y + (xxx.y - y)*t, z + (xxx.z - z)*t, w + (xxx.w - w)*t);
				}
			}
			std::cout << "scalar vec4 lerp vec4 " << clock() - start << std::endl;
		}
		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES; x++)
			{
				for (uint32_t i = 0; i < COUNT; i++)
				{
					vec4_dst1[i] = math::lerp(vec4_src[i], xxx, 0.72f);
				}
			}
			std::cout << "math vec4 lerp vec4 " << clock() - start << std::endl;
		}

		for (uint32_t i = 0; i < COUNT; i++)
		{
			BOOST_CHECK(equals(vec4_dst1[i], vec4_dst2[i], 0.001f));
		}
	}

	//////////////////////////////////////////////////////////////////////////

	BOOST_AUTO_TEST_CASE(BENCHMARK_CLAMP_VEC4)
	{
		vec4f xxx(12.f, 4.f, 7.f, 1.3f);

		std::cout << std::endl;

		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES; x++)
			{
				for (uint32_t i = 0; i < COUNT; i++)
				{
					vec4f const& v = vec4_src[i];
					float x = v.x;
					float y = v.y;
					float z = v.z;
					float w = v.w;
					vec4_dst2[i] = vec4f(math::clamp(x, -3.f, 2.23f), math::clamp(y, -3.f, 2.23f), math::clamp(z, -3.f, 2.23f), math::clamp(w, -3.f, 2.23f));
				}
			}
			std::cout << "scalar clamp vec4 " << clock() - start << std::endl;
		}
		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES; x++)
			{
				math::vec4f min(-3.f);
				math::vec4f max(2.23f);
				for (uint32_t i = 0; i < COUNT; i++)
				{
					vec4_dst1[i] = math::clamp(vec4_src[i], min, max);
				}
			}
			std::cout << "math clamp vec4 " << clock() - start << std::endl;
		}

		for (uint32_t i = 0; i < COUNT; i++)
		{
			if (vec4_dst1[i] != vec4_dst2[i])
			{
				int a = 0;
			}
			BOOST_CHECK(vec4_dst1[i] == vec4_dst2[i]);
		}
	}

	//////////////////////////////////////////////////////////////////////////

	BOOST_AUTO_TEST_CASE(BENCHMARK_ABS_VEC4)
	{
		vec4f xxx(12.f, 4.f, 7.f, 1.3f);

		std::cout << std::endl;

		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES; x++)
			{
				for (uint32_t i = 0; i < COUNT; i++)
				{
					vec4f const& v = vec4_src[i];
					float x = v.x;
					float y = v.y;
					float z = v.z;
					float w = v.w;
					vec4_dst2[i] = vec4f(std::abs(x), std::abs(y), std::abs(z), std::abs(w));
				}
			}
			std::cout << "scalar abs vec4 " << clock() - start << std::endl;
		}
		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES; x++)
			{
				for (uint32_t i = 0; i < COUNT; i++)
				{
					vec4_dst1[i] = math::abs(vec4_src[i]);
				}
			}
			std::cout << "math abs vec4 " << clock() - start << std::endl;
		}

		BOOST_CHECK(vec4_dst1 == vec4_dst2);
	}

	//////////////////////////////////////////////////////////////////////////

	BOOST_AUTO_TEST_CASE(BENCHMARK_VEC4_DOT)
	{
		std::vector<vec4f> src(COUNT);
		std::vector<float> dst1(COUNT);
		std::vector<float> dst2(COUNT);

		for (uint32_t i = 0; i < COUNT; i++)
		{
			src[i] = vec4f(vec4s32(i % 7, i % 23 - 100, i / 5, i / 32));
		}

		vec4f xxx(12.f, 4.f, 7.f, 1.3f);

		std::cout << std::endl;

		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES; x++)
			{
				for (uint32_t i = 0; i < COUNT; i++)
				{
					vec4f const& v = src[i];
					float x = v.x;
					float y = v.y;
					float z = v.z;
					float w = v.w;
					dst2[i] = xxx.x*x + xxx.y*y + xxx.z*z + xxx.w*w;
				}
			}
			std::cout << "scalar dot vec4 " << clock() - start << std::endl;
		}
		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES; x++)
			{
				for (uint32_t i = 0; i < COUNT; i++)
				{
					dst1[i] = math::dot(src[i], xxx);
				}
			}
			std::cout << "math dot vec4 " << clock() - start << std::endl;
		}

		for (uint32_t i = 0; i < dst1.size(); i++)
		{
			if (!math::equals(dst1[i], dst2[i], 0.0001f))
			{
				BOOST_FAIL("Different dot product");
				break;
			}
		}
		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES; x++)
			{
				math::batch::dot(dst1.data(), sizeof(float), src.data(), sizeof(math::vec4f), &xxx, 0, COUNT);
			}
			std::cout << "math::batch dot vec4 " << clock() - start << std::endl;
		}

		for (uint32_t i = 0; i < dst1.size(); i++)
		{
			if (!math::equals(dst1[i], dst2[i], 0.0001f))
			{
				BOOST_FAIL("Different dot product");
				break;
			}
		}
	}

	//////////////////////////////////////////////////////////////////////////

	BOOST_AUTO_TEST_CASE(BENCHMARK_VEC4_DISTANCE)
	{
		std::vector<vec4f> src(COUNT);
		std::vector<float> dst1(COUNT);
		std::vector<float> dst2(COUNT);

		for (uint32_t i = 0; i < COUNT; i++)
		{
			src[i] = vec4f(vec4s32(i % 7, i % 23 - 100, i / 5, i / 32));
		}

		vec4f xxx(12.f, 4.f, 7.f, 1.3f);

		std::cout << std::endl;

		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES; x++)
			{
				for (uint32_t i = 0; i < COUNT; i++)
				{
					vec4f const& v = src[i];
					float x = v.x-xxx.x;
					float y = v.y-xxx.y;
					float z = v.z-xxx.z;
					float w = v.w-xxx.w;
					dst2[i] = math::sqrt(x*x + y*y + z*z + w*w);
				}
			}
			std::cout << "scalar distance vec4 " << clock() - start << std::endl;
		}
		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES; x++)
			{
				for (uint32_t i = 0; i < COUNT; i++)
				{
					dst1[i] = math::distance(src[i], xxx);
				}
			}
			std::cout << "math distance vec4 " << clock() - start << std::endl;
		}
		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES; x++)
			{
				for (uint32_t i = 0; i < COUNT; i++)
				{
					dst1[i] = math::distance<float, math::fast>(src[i], xxx);
				}
			}
			std::cout << "math fast distance vec4 " << clock() - start << std::endl;
		}
	}

	//////////////////////////////////////////////////////////////////////////

	BOOST_AUTO_TEST_CASE(BENCHMARK_VEC4_LENGTH)
	{
		std::vector<vec4f> src(COUNT);
		std::vector<float> dst1(COUNT);
		std::vector<float> dst2(COUNT);

		for (uint32_t i = 0; i < COUNT; i++)
		{
			src[i] = vec4f(vec4s32(i % 7, i % 23 - 100, i / 5, i / 32));
		}

		std::cout << std::endl;

		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES; x++)
			{
				for (uint32_t i = 0; i < COUNT; i++)
				{
					vec4f const& v = src[i];
					float x = v.x;
					float y = v.y;
					float z = v.z;
					float w = v.w;
					dst2[i] = math::sqrt(x*x + y*y + z*z + w*w);
				}
			}
			std::cout << "scalar length vec4 " << clock() - start << std::endl;
		}
		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES; x++)
			{
				for (uint32_t i = 0; i < COUNT; i++)
				{
					dst1[i] = math::length(src[i]);
				}
			}
			std::cout << "math length vec4 " << clock() - start << std::endl;
		}
		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES; x++)
			{
				for (uint32_t i = 0; i < COUNT; i++)
				{
					dst1[i] = math::length<float, math::fast>(src[i]);
				}
			}
			std::cout << "math fast length vec4 " << clock() - start << std::endl;
		}
	}

	//////////////////////////////////////////////////////////////////////////

	BOOST_AUTO_TEST_CASE(BENCHMARK_VEC4_NORMALIZE)
	{
		vec4f xxx(12.f, 4.f, 7.f, 1.3f);

		std::cout << std::endl;

		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES; x++)
			{
				for (uint32_t i = 0; i < COUNT; i++)
				{
					vec4f const& v = vec4_src[i];
					float x = v.x;
					float y = v.y;
					float z = v.z;
					float w = v.w;
					float d = 1.f / math::sqrt(x*x + y*y + z*z + w*w);
					vec4_dst2[i].set(x*d, y*d, z*d, w*d);
				}
			}
			std::cout << "scalar normalize vec4 " << clock() - start << std::endl;
		}
		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES; x++)
			{
				for (uint32_t i = 0; i < COUNT; i++)
				{
					vec4_dst1[i] = math::normalized(vec4_src[i]);
				}
			}
			std::cout << "math normalize vec4 " << clock() - start << std::endl;
		}
		for (uint32_t i = 0; i < vec4_dst1.size(); i++)
		{
			if (!math::equals(vec4_dst1[i], vec4_dst2[i], 0.0001f))
			{
				BOOST_FAIL("Different normalize");
				break;
			}
		}
		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES; x++)
			{
				for (uint32_t i = 0; i < COUNT; i++)
				{
					vec4_dst1[i] = math::normalized<float, math::fast>(vec4_src[i]);
				}
			}
			std::cout << "math fast normalize vec4 " << clock() - start << std::endl;
		}
	}
	//////////////////////////////////////////////////////////////////////////

	BOOST_AUTO_TEST_CASE(BENCHMARK_VEC3_NORMALIZE)
	{
		vec3f xxx(12.f, 4.f, 7.f);

		std::cout << std::endl;

		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES; x++)
			{
				for (uint32_t i = 0; i < COUNT; i++)
				{
					vec3f const& v = vec3_src[i];
					float x = v.x;
					float y = v.y;
					float z = v.z;
					float d = 1.f / math::sqrt(x*x + y*y + z*z);
					vec3_dst2[i].set(x*d, y*d, z*d);
				}
			}
			std::cout << "scalar normalize vec3 " << clock() - start << std::endl;
		}
		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES; x++)
			{
				for (uint32_t i = 0; i < COUNT; i++)
				{
					vec3_dst1[i] = math::normalized(vec3_src[i]);
				}
			}
			std::cout << "math normalize vec3 " << clock() - start << std::endl;
		}
		for (uint32_t i = 0; i < vec3_dst1.size(); i++)
		{
			if (!math::equals(vec3_dst1[i], vec3_dst2[i], 0.0001f))
			{
				BOOST_FAIL("Different normalize");
				break;
			}
		}
		{
			std::clock_t start = std::clock();
			for (uint32_t x = 0; x < TIMES; x++)
			{
				for (uint32_t i = 0; i < COUNT; i++)
				{
					vec3_dst1[i] = math::normalized<float, math::fast>(vec3_src[i]);
				}
			}
			std::cout << "math fast normalize vec3 " << clock() - start << std::endl;
		}
	}

ext: cpp

max_stars_repo_name: jeanleflambeur/silkopter

max_issues_repo_name: jeanlemotan/silkopter

max_forks_repo_name: jeanleflambeur/silkopter


text:
/*
 * proc/integrator_wrapper.hpp --
 *
 * This file is part of nettcl2d application.
 *
 * Copyright (c) 2012 Andrey V. Nakin <andrey.nakin@gmail.com>
 * All rights reserved.
 *
 * See the file "COPYING" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 */

#ifndef PROC_INTEGRATOR_WRAPPER_HPP_
#define PROC_INTEGRATOR_WRAPPER_HPP_

#include <boost/shared_ptr.hpp>
#include "wrapper.hpp"
#include "../calc/integrator.hpp"
#include "network_wrapper.hpp"
#include "tracer_wrapper.hpp"
#include "perturbator_wrapper.hpp"

namespace proc {

	namespace type {
		extern const char* integrator;
	}

	class IntegratorWrapper : public Wrapper<&type::integrator> {

		typedef Wrapper<&type::integrator> Base;

		boost::shared_ptr<Integrator> engine;
		VarRefVector perturbatorRefs;

		explicit IntegratorWrapper(const IntegratorWrapper& src) :
			engine(dynamic_cast<Integrator*>(src.engine->clone())),
			perturbatorRefs(src.perturbatorRefs) {}

		explicit IntegratorWrapper(Integrator* const engine) :
			engine(engine) {}

		static IntegratorWrapper* validateArg(Tcl_Interp *interp, const Tcl_Obj* arg) {
			return static_cast<IntegratorWrapper*>(Base::validateArg(interp, arg));
		}

		virtual Base* clone() const {
			return new IntegratorWrapper(*this);
		}

		static int doMain(ClientData clientData, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]) {
			return process(clientData, interp, objc, objv, main);
		}

		static int main(ClientData clientData, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]) {
			if (objc < 2)
				throw WrongNumArgs(interp, 1, objv, "command");

			const std::string cmd = Tcl_GetStringFromObj(objv[1], NULL);

			try {
				if ("create" == cmd) {
					return create(interp, objc - 2, objv + 2);
				}

				else if ("exists" == cmd) {
					return exists(interp, objc - 2, objv + 2);
				}

				else if ("get" == cmd) {
					return processInstance(clientData, interp, objc - 2, objv + 2, static_cast<InstanceHandler>(&IntegratorWrapper::get));
				}

				else if ("set" == cmd) {
					return processInstance(clientData, interp, objc - 2, objv + 2, static_cast<InstanceHandler>(&IntegratorWrapper::set));
				}

				else if ("run" == cmd) {
					return processInstance(clientData, interp, objc - 2, objv + 2, static_cast<InstanceHandler>(&IntegratorWrapper::run));
				}

				else if ("add-tracer" == cmd) {
					return processInstance(clientData, interp, objc - 2, objv + 2, static_cast<InstanceHandler>(&IntegratorWrapper::addTracer));
				}

				else if ("purge-tracers" == cmd) {
					return processInstance(clientData, interp, objc - 2, objv + 2, static_cast<InstanceHandler>(&IntegratorWrapper::purgeTracers));
				}

				else if ("add-perturbator" == cmd) {
					return processInstance(clientData, interp, objc - 2, objv + 2, static_cast<InstanceHandler>(&IntegratorWrapper::addPerturbator));
				}

				else if ("purge-perturbators" == cmd) {
					return processInstance(clientData, interp, objc - 2, objv + 2, static_cast<InstanceHandler>(&IntegratorWrapper::purgePerturbators));
				}

				else
					throw WrongArgValue(interp, "create | exists | get | set | run | add-tracer | purge-tracers | add-perturbator | purge-perturbators");
			} catch (WrongNumArgs& ex) {
				throw WrongNumArgs(interp, 2 + ex.objc, objv, ex.message);
			}

			return TCL_OK;
		}

		static int create(Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]) {
			if (objc > 2)
				throw WrongNumArgs(interp, 0, objv, "?step? ?delta?");

			Integrator::Params params;
			if (objc > 0) {
				params.step = phlib::TclUtils::getDouble(interp, objv[0]);
			}
			if (objc > 1) {
				params.delta = phlib::TclUtils::getDouble(interp, objv[1]);
			}

			// instantiate new TCL object
			Tcl_Obj* const w = Tcl_NewObj();
			w->typePtr = IntegratorWrapper::type();
			w->internalRep.otherValuePtr = new IntegratorWrapper(new Integrator(params));
			::Tcl_SetObjResult(interp, w);

			return TCL_OK;
		}

		int get(ClientData /* clientData */, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]) {
			if (objc < 1)
				throw WrongNumArgs(interp, 0, objv, "parameter");

			const std::string param = Tcl_GetStringFromObj(objv[0], NULL);

			if ("step" == param) {
				Tcl_SetObjResult(interp, Tcl_NewDoubleObj(engine->getParams().step));
			} else if ("delta" == param) {
				Tcl_SetObjResult(interp, Tcl_NewDoubleObj(engine->getParams().delta));
			} else {
				throw WrongArgValue(interp, "step | delta");
			}

			return TCL_OK;
		}

		int set(ClientData /* clientData */, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]) {
			if (objc != 2)
				throw WrongNumArgs(interp, 0, objv, "parameter value");

			const std::string param = Tcl_GetStringFromObj(objv[0], NULL);

			if ("step" == param) {
				engine->getParams().step = phlib::TclUtils::getDouble(interp, objv[1]);
			} else if ("delta" == param) {
				engine->getParams().delta = phlib::TclUtils::getDouble(interp, objv[1]);
			} else {
				throw WrongArgValue(interp, "step | delta");
			}

			return TCL_OK;
		}

		int run(ClientData /* clientData */, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]) {
			if (objc != 4)
				throw WrongNumArgs(interp, 0, objv, "networkInst startTime endTime dt");

			engine->run(
				*NetworkWrapper::validateArg(interp, objv[0])->engine,
				phlib::TclUtils::getDouble(interp, objv[1]),
				phlib::TclUtils::getDouble(interp, objv[2]),
				phlib::TclUtils::getDouble(interp, objv[3]));

			return TCL_OK;
		}

		int addTracer(ClientData /* clientData */, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]) {
			if (objc != 1)
				throw WrongNumArgs(interp, 0, objv, "tracerInst");

			engine->addTracer(*TracerWrapper::validateArg(interp, objv[0])->engine);
			addVarRef(objv[0]);

			return TCL_OK;
		}

		int purgeTracers(ClientData /* clientData */, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]) {
			if (objc != 0)
				throw WrongNumArgs(interp, 0, objv, "");

			engine->purgeTracers();
			purgeVarRefs();

			return TCL_OK;
		}

		int addPerturbator(ClientData /* clientData */, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]) {
			if (objc != 1)
				throw WrongNumArgs(interp, 0, objv, "perturbatorInst");

			engine->addPerturbator(*PerturbatorWrapper::validateArg(interp, objv[0])->engine);
			perturbatorRefs.push_back(VarRef(objv[0]));

			return TCL_OK;
		}

		int purgePerturbators(ClientData /* clientData */, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]) {
			if (objc != 0)
				throw WrongNumArgs(interp, 0, objv, "");

			engine->purgePerturbators();
			perturbatorRefs.clear();

			return TCL_OK;
		}

	public:

		static void registerCommands(Tcl_Interp * interp) {
			registerCommand(interp, doMain);
		}

	};

}

#endif /* PROC_INTEGRATOR_WRAPPER_HPP_ */


text:
#ifndef PRE_VARIANT_DETAIL_ASSIGNABLE_FROM_HPP
#define PRE_VARIANT_DETAIL_ASSIGNABLE_FROM_HPP

#include <boost/mpl/contains.hpp>

namespace pre { namespace variant { namespace detail {

  namespace mpl = boost::mpl;

  template <class SelectedTypeVariant, class T>
  using assignable_from  =
    typename mpl::contains<typename SelectedTypeVariant::types, T>::type;

}}}

#endif

max_stars_repo_name: xplorfin/lib-cpp-pre

max_issues_repo_name: xplorfin/lib-cpp-pre

max_forks_repo_name: xplorfin/lib-cpp-pre


text:
//////////////////////////////////////////////////////////////////////////////
// I, Howard Hinnant, hereby place this code in the public domain.
//////////////////////////////////////////////////////////////////////////////
//
// This file is the adaptation for Interprocess of
// Howard Hinnant's unique_ptr emulation code.
//
// (C) Copyright Ion Gaztanaga 2006-2012. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/interprocess for documentation.
//
//////////////////////////////////////////////////////////////////////////////

#ifndef BOOST_INTERPROCESS_UNIQUE_PTR_HPP_INCLUDED
#define BOOST_INTERPROCESS_UNIQUE_PTR_HPP_INCLUDED

#include <boost/interprocess/detail/config_begin.hpp>
#include <boost/interprocess/detail/workaround.hpp>
#include <boost/assert.hpp>
#include <boost/interprocess/detail/utilities.hpp>
#include <boost/interprocess/detail/pointer_type.hpp>
#include <boost/move/move.hpp>
#include <boost/compressed_pair.hpp>
#include <boost/static_assert.hpp>
#include <boost/interprocess/detail/mpl.hpp>
#include <boost/interprocess/detail/type_traits.hpp>
#include <boost/interprocess/smart_ptr/deleter.hpp>
#include <cstddef>

//!\file
//!Describes the smart pointer unique_ptr

namespace boost{
namespace interprocess{

/// @cond
template <class T, class D> class unique_ptr;

namespace ipcdetail {

template <class T> struct unique_ptr_error;

template <class T, class D>
struct unique_ptr_error<const unique_ptr<T, D> >
{
    typedef unique_ptr<T, D> type;
};

}  //namespace ipcdetail {
/// @endcond

//!Template unique_ptr stores a pointer to an object and deletes that object
//!using the associated deleter when it is itself destroyed (such as when
//!leaving block scope.
//!
//!The unique_ptr provides a semantics of strict ownership. A unique_ptr owns the
//!object it holds a pointer to.
//!
//!A unique_ptr is not CopyConstructible, nor CopyAssignable, however it is
//!MoveConstructible and Move-Assignable.
//!
//!The uses of unique_ptr include providing exception safety for dynamically
//!allocated memory, passing ownership of dynamically allocated memory to a
//!function, and returning dynamically allocated memory from a function
//!
//!A client-supplied template argument D must be a
//!function pointer or functor for which, given a value d of type D and a pointer
//!ptr to a type T*, the expression d(ptr) is
//!valid and has the effect of deallocating the pointer as appropriate for that
//!deleter. D may also be an lvalue-reference to a deleter.
//!
//!If the deleter D maintains state, it is intended that this state stay with
//!the associated pointer as ownership is transferred
//!from unique_ptr to unique_ptr. The deleter state need never be copied,
//!only moved or swapped as pointer ownership
//!is moved around. That is, the deleter need only be MoveConstructible,
//!MoveAssignable, and Swappable, and need not be CopyConstructible
//!(unless copied into the unique_ptr) nor CopyAssignable.
template <class T, class D>
class unique_ptr
{
   /// @cond
   struct nat  {int for_bool;};
   struct nat2 {int for_nullptr;};
   typedef int nat2::*nullptr_t;
   typedef typename ipcdetail::add_reference<D>::type deleter_reference;
   typedef typename ipcdetail::add_reference<const D>::type deleter_const_reference;
   /// @endcond

   public:

   typedef T element_type;
   typedef D deleter_type;
   typedef typename ipcdetail::pointer_type<T, D>::type pointer;

   //!Requires: D must be default constructible, and that construction must not
   //!throw an exception. D must not be a reference type.
   //!
   //!Effects: Constructs a unique_ptr which owns nothing.
   //!
   //!Postconditions: get() == 0. get_deleter() returns a reference to a
   //!default constructed deleter D.
   //!
   //!Throws: nothing.
   unique_ptr()
      :  ptr_(pointer(0))
   {}

   //!Requires: The expression D()(p) must be well formed. The default constructor
   //!of D must not throw an exception.
   //!
   //!D must not be a reference type.
   //!
   //!Effects: Constructs a unique_ptr which owns p.
   //!
   //!Postconditions: get() == p. get_deleter() returns a reference to a default constructed deleter D.
   //!
   //!Throws: nothing.
   explicit unique_ptr(pointer p)
      :  ptr_(p)
   {}

   //!Requires: The expression d(p) must be well formed.
   //!
   //!Postconditions: get() == p. get_deleter() returns a reference to the
   //!internally stored deleter. If D is a
   //!reference type then get_deleter() returns a reference to the lvalue d.
   //!
   //!Throws: nothing.
   unique_ptr(pointer p
             ,typename ipcdetail::if_<ipcdetail::is_reference<D>
                  ,D
                  ,typename ipcdetail::add_reference<const D>::type>::type d)
      : ptr_(p, d)
   {}

   //!Requires: If the deleter is not a reference type, construction of the
   //!deleter D from an lvalue D must not throw an exception.
   //!
   //!Effects: Constructs a unique_ptr which owns the pointer which u owns
   //!(if any). If the deleter is not a reference type, it is move constructed
   //!from u's deleter, otherwise the reference is copy constructed from u's deleter.
   //!
   //!After the construction, u no longer owns a pointer.
   //![ Note: The deleter constructor can be implemented with
   //!   boost::forward<D>. -end note ]
   //!
   //!Postconditions: get() == value u.get() had before the construction.
   //!get_deleter() returns a reference to the internally stored deleter which
   //!was constructed from u.get_deleter(). If D is a reference type then get_-
   //!deleter() and u.get_deleter() both reference the same lvalue deleter.
   //!
   //!Throws: nothing.
   unique_ptr(BOOST_RV_REF(unique_ptr) u)
      : ptr_(u.release(), boost::forward<D>(u.get_deleter()))
   {}

   //!Requires: If D is not a reference type, construction of the deleter
   //!D from an rvalue of type E must be well formed
   //!and not throw an exception. If D is a reference type, then E must be
   //!the same type as D (diagnostic required). unique_ptr<U, E>::pointer
   //!must be implicitly convertible to pointer.
   //!
   //!Effects: Constructs a unique_ptr which owns the pointer which u owns
   //!(if any). If the deleter is not a reference
   //!type, it is move constructed from u's deleter, otherwise the reference
   //!is copy constructed from u's deleter.
   //!
   //!After the construction, u no longer owns a pointer.
   //!
   //!postconditions get() == value u.get() had before the construction,
   //!modulo any required offset adjustments
   //!resulting from the cast from U* to T*. get_deleter() returns a reference to the internally stored deleter which
   //!was constructed from u.get_deleter().
   //!
   //!Throws: nothing.
   template <class U, class E>
   unique_ptr(BOOST_RV_REF_BEG unique_ptr<U, E> BOOST_RV_REF_END u,
      typename ipcdetail::enable_if_c<
            ipcdetail::is_convertible<typename unique_ptr<U, E>::pointer, pointer>::value &&
            ipcdetail::is_convertible<E, D>::value &&
            (
               !ipcdetail::is_reference<D>::value ||
               ipcdetail::is_same<D, E>::value
            )
            ,
            nat
            >::type = nat())
      : ptr_(const_cast<unique_ptr<U,E>&>(u).release(), boost::move<D>(u.get_deleter()))
   {}

   //!Effects: If get() == 0 there are no effects. Otherwise get_deleter()(get()).
   //!
   //!Throws: nothing.
   ~unique_ptr()
   {  reset(); }

   // assignment

   //!Requires: Assignment of the deleter D from an rvalue D must not throw an exception.
   //!
   //!Effects: reset(u.release()) followed by a move assignment from u's deleter to
   //!this deleter.
   //!
   //!Postconditions: This unique_ptr now owns the pointer which u owned, and u no
   //!longer owns it.
   //!
   //!Returns: *this.
   //!
   //!Throws: nothing.
   unique_ptr& operator=(BOOST_RV_REF(unique_ptr) u)
   {
      reset(u.release());
      ptr_.second() = boost::move(u.get_deleter());
      return *this;
   }

   //!Requires: Assignment of the deleter D from an rvalue D must not
   //!throw an exception. U* must be implicitly convertible to T*.
   //!
   //!Effects: reset(u.release()) followed by a move assignment from
   //!u's deleter to this deleter. If either D or E is
   //!a reference type, then the referenced lvalue deleter participates
   //!in the move assignment.
   //!
   //!Postconditions: This unique_ptr now owns the pointer which u owned,
   //!and u no longer owns it.
   //!
   //!Returns: *this.
   //!
   //!Throws: nothing.
   template <class U, class E>
   unique_ptr& operator=(BOOST_RV_REF_BEG unique_ptr<U, E> BOOST_RV_REF_END u)
   {
      reset(u.release());
      ptr_.second() = boost::move(u.get_deleter());
      return *this;
   }

   //!Assigns from the literal 0 or NULL.
   //!
   //!Effects: reset().
   //!
   //!Postcondition: get() == 0
   //!
   //!Returns: *this.
   //!
   //!Throws: nothing.
   unique_ptr& operator=(nullptr_t)
   {
      reset();
      return *this;
   }

   //!Requires: get() != 0.
   //!Returns: *get().
   //!Throws: nothing.
   typename ipcdetail::add_reference<T>::type operator*()  const
   {  return *ptr_.first();   }

   //!Requires: get() != 0.
   //!Returns: get().
   //!Throws: nothing.
   pointer operator->() const
   {  return ptr_.first(); }

   //!Returns: The stored pointer.
   //!Throws: nothing.
   pointer get()        const
   {  return ptr_.first(); }

   //!Returns: A reference to the stored deleter.
   //!
   //!Throws: nothing.
   deleter_reference       get_deleter()
   {  return ptr_.second();   }

   //!Returns: A const reference to the stored deleter.
   //!
   //!Throws: nothing.
   deleter_const_reference get_deleter() const
   {  return ptr_.second();   }

   //!Returns: An unspecified value that, when used in boolean
   //!contexts, is equivalent to get() != 0.
   //!
   //!Throws: nothing.
   operator int nat::*() const
   {  return ptr_.first() ? &nat::for_bool : 0;   }

   //!Postcondition: get() == 0.
   //!
   //!Returns: The value get() had at the start of the call to release.
   //!
   //!Throws: nothing.
   pointer release()
   {
      pointer tmp = ptr_.first();
      ptr_.first() = 0;
      return tmp;
   }

   //!Effects: If p == get() there are no effects. Otherwise get_deleter()(get()).
   //!
   //!Postconditions: get() == p.
   //!
   //!Throws: nothing.
   void reset(pointer p = 0)
   {
      if (ptr_.first() != p){
         if (ptr_.first())
            ptr_.second()(ptr_.first());
         ptr_.first() = p;
      }
   }

   //!Requires: The deleter D is Swappable and will not throw an exception under swap.
   //!
   //!Effects: The stored pointers of this and u are exchanged.
   //!   The stored deleters are swapped (unqualified).
   //!Throws: nothing.
   void swap(unique_ptr& u)
   {  ptr_.swap(u.ptr_);   }

   /// @cond
   private:
   boost::compressed_pair<pointer, D> ptr_;
   BOOST_MOVABLE_BUT_NOT_COPYABLE(unique_ptr)
   template <class U, class E> unique_ptr(unique_ptr<U, E>&);
   template <class U> unique_ptr(U&, typename ipcdetail::unique_ptr_error<U>::type = 0);

   template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&);
   template <class U> typename ipcdetail::unique_ptr_error<U>::type operator=(U&);
   /// @endcond
};
/*
template <class T, class D>
class unique_ptr<T[], D>
{
    struct nat {int for_bool_;};
    typedef typename ipcdetail::add_reference<D>::type deleter_reference;
    typedef typename ipcdetail::add_reference<const D>::type deleter_const_reference;
public:
    typedef T element_type;
    typedef D deleter_type;
    typedef typename ipcdetail::pointer_type<T, D>::type pointer;

    // constructors
    unique_ptr() : ptr_(pointer()) {}
    explicit unique_ptr(pointer p) : ptr_(p) {}
    unique_ptr(pointer p, typename if_<
                          boost::is_reference<D>,
                          D,
                          typename ipcdetail::add_reference<const D>::type>::type d)
        : ptr_(p, d) {}
    unique_ptr(const unique_ptr& u)
        : ptr_(const_cast<unique_ptr&>(u).release(), u.get_deleter()) {}

    // destructor
    ~unique_ptr() {reset();}

    // assignment
    unique_ptr& operator=(const unique_ptr& cu)
    {
        unique_ptr& u = const_cast<unique_ptr&>(cu);
        reset(u.release());
        ptr_.second() = u.get_deleter();
        return *this;
    }
    unique_ptr& operator=(int nat::*)
    {
        reset();
        return *this;
    }

    // observers
    typename ipcdetail::add_reference<T>::type operator[](std::size_t i)  const {return ptr_.first()[i];}
    pointer get()        const {return ptr_.first();}
    deleter_reference       get_deleter()       {return ptr_.second();}
    deleter_const_reference get_deleter() const {return ptr_.second();}
    operator int nat::*() const {return ptr_.first() ? &nat::for_bool_ : 0;}

    // modifiers
    pointer release()
    {
        pointer tmp = ptr_.first();
        ptr_.first() = 0;
        return tmp;
    }
    void reset(pointer p = 0)
    {
        if (ptr_.first() != p)
        {
            if (ptr_.first())
                ptr_.second()(ptr_.first());
            ptr_.first() = p;
        }
    }
    void swap(unique_ptr& u) {ptr_.swap(u.ptr_);}
private:
    boost::compressed_pair<pointer, D> ptr_;

    template <class U, class E> unique_ptr(U p, E,
        typename boost::enable_if<boost::is_convertible<U, pointer> >::type* = 0);
    template <class U> explicit unique_ptr(U,
        typename boost::enable_if<boost::is_convertible<U, pointer> >::type* = 0);

    unique_ptr(unique_ptr&);
    template <class U> unique_ptr(U&, typename ipcdetail::unique_ptr_error<U>::type = 0);

    unique_ptr& operator=(unique_ptr&);
    template <class U> typename ipcdetail::unique_ptr_error<U>::type operator=(U&);
};

template <class T, class D, std::size_t N>
class unique_ptr<T[N], D>
{
    struct nat {int for_bool_;};
    typedef typename ipcdetail::add_reference<D>::type deleter_reference;
    typedef typename ipcdetail::add_reference<const D>::type deleter_const_reference;
public:
    typedef T element_type;
    typedef D deleter_type;
    typedef typename ipcdetail::pointer_type<T, D>::type pointer;
    static const std::size_t size = N;

    // constructors
    unique_ptr() : ptr_(0) {}
    explicit unique_ptr(pointer p) : ptr_(p) {}
    unique_ptr(pointer p, typename if_<
                         boost::is_reference<D>,
                         D,
                         typename ipcdetail::add_reference<const D>::type>::type d)
        : ptr_(p, d) {}
    unique_ptr(const unique_ptr& u)
        : ptr_(const_cast<unique_ptr&>(u).release(), u.get_deleter()) {}

    // destructor
    ~unique_ptr() {reset();}

    // assignment
    unique_ptr& operator=(const unique_ptr& cu)
    {
        unique_ptr& u = const_cast<unique_ptr&>(cu);
        reset(u.release());
        ptr_.second() = u.get_deleter();
        return *this;
    }
    unique_ptr& operator=(int nat::*)
    {
        reset();
        return *this;
    }

    // observers
    typename ipcdetail::add_reference<T>::type operator[](std::size_t i)  const {return ptr_.first()[i];}
    pointer get()        const {return ptr_.first();}
    deleter_reference       get_deleter()       {return ptr_.second();}
    deleter_const_reference get_deleter() const {return ptr_.second();}
    operator int nat::*() const {return ptr_.first() ? &nat::for_bool : 0;}

    // modifiers
    pointer release()
    {
        pointer tmp = ptr_.first();
        ptr_.first() = 0;
        return tmp;
    }
    void reset(pointer p = 0)
    {
        if (ptr_.first() != p)
        {
            if (ptr_.first())
                ptr_.second()(ptr_.first(), N);
            ptr_.first() = p;
        }
    }
    void swap(unique_ptr& u) {ptr_.swap(u.ptr_);}
private:
    boost::compressed_pair<pointer, D> ptr_;

    template <class U, class E> unique_ptr(U p, E,
        typename boost::enable_if<boost::is_convertible<U, pointer> >::type* = 0);
    template <class U> explicit unique_ptr(U,
        typename boost::enable_if<boost::is_convertible<U, pointer> >::type* = 0);

    unique_ptr(unique_ptr&);
    template <class U> unique_ptr(U&, typename ipcdetail::unique_ptr_error<U>::type = 0);

    unique_ptr& operator=(unique_ptr&);
    template <class U> typename ipcdetail::unique_ptr_error<U>::type operator=(U&);
};
*/
template <class T, class D> inline
void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y)
{  x.swap(y);  }

template <class T1, class D1, class T2, class D2> inline
bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y)
{  return x.get() == y.get(); }

template <class T1, class D1, class T2, class D2> inline
bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y)
{  return x.get() != y.get(); }

template <class T1, class D1, class T2, class D2> inline
bool operator <(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y)
{  return x.get() < y.get();  }

template <class T1, class D1, class T2, class D2> inline
bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y)
{  return x.get() <= y.get(); }

template <class T1, class D1, class T2, class D2> inline
bool operator >(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y)
{  return x.get() > y.get();  }

template <class T1, class D1, class T2, class D2> inline
bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y)
{  return x.get() >= y.get(); }

//!Returns the type of a unique pointer
//!of type T with boost::interprocess::deleter deleter
//!that can be constructed in the given managed segment type.
template<class T, class ManagedMemory>
struct managed_unique_ptr
{
   typedef unique_ptr
   < T
   , typename ManagedMemory::template deleter<T>::type
   > type;
};

//!Returns an instance of a unique pointer constructed
//!with boost::interproces::deleter from a pointer
//!of type T that has been allocated in the passed managed segment
template<class T, class ManagedMemory>
inline typename managed_unique_ptr<T, ManagedMemory>::type
   make_managed_unique_ptr(T *constructed_object, ManagedMemory &managed_memory)
{
   return typename managed_unique_ptr<T, ManagedMemory>::type
      (constructed_object, managed_memory.template get_deleter<T>());
}

}  //namespace interprocess{
}  //namespace boost{

#include <boost/interprocess/detail/config_end.hpp>

#endif   //#ifndef BOOST_INTERPROCESS_UNIQUE_PTR_HPP_INCLUDED

max_stars_repo_name: bowlofstew/omim

max_issues_repo_name: wujf/mongo

max_forks_repo_name: wujf/mongo