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

#ifndef _SVX_STDDLG_HXX //autogen
#include <svx/stddlg.hxx>
#endif

#ifndef _FIXED_HXX //autogen
#include <vcl/fixed.hxx>
#endif

#ifndef _LSTBOX_HXX //autogen
#include <vcl/lstbox.hxx>
#endif

#ifndef _EDIT_HXX //autogen
#include <vcl/edit.hxx>
#endif

#ifndef _GROUP_HXX //autogen
#include <vcl/group.hxx>
#endif

#ifndef _BUTTON_HXX //autogen
#include <vcl/button.hxx>
#endif
#ifndef _ACTCTRL_HXX //autogen
#include <actctrl.hxx>
#endif

#ifndef _COM_SUN_STAR_CONTAINER_XENUMERATIONACCESS_HPP_
#include <com/sun/star/container/XEnumerationAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMEACCESS_HPP_
#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
#include <com/sun/star/container/XNameAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XCONTENTENUMERATIONACCESS_HPP_
#include <com/sun/star/container/XContentEnumerationAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XENUMERATION_HPP_
#include <com/sun/star/container/XEnumeration.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XELEMENTACCESS_HPP_
#include <com/sun/star/container/XElementAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XINDEXACCESS_HPP_
#include <com/sun/star/container/XIndexAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XNAMED_HPP_
#include <com/sun/star/container/XNamed.hpp>
#endif

class SwFldMgr;
class SwView;

#include <wrtsh.hxx>
#include "optload.hxx"
#include "swlbox.hxx"

class SwCaptionDialog : public SvxStandardDialog
{
    class CategoryBox : public ComboBox
    {
    public:
        CategoryBox( Window* pParent, const ResId& rResId )
            : ComboBox( pParent, rResId )
        {}

        virtual long    PreNotify( NotifyEvent& rNEvt );
    };

    FixedText    aTextText;
    Edit         aTextEdit;
    FixedLine    aSettingsFL;
    FixedText    aCategoryText;
    CategoryBox  aCategoryBox;
    FixedText    aFormatText;
    ListBox      aFormatBox;
    FixedText    aSepText;
    Edit         aSepEdit;
    FixedText    aPosText;
    ListBox      aPosBox;
    OKButton     aOKButton;
    CancelButton aCancelButton;
    HelpButton   aHelpButton;
    PushButton   aAutoCaptionButton;
    PushButton   aOptionButton;

    String       sNone;

    SwCaptionPreview    aPrevWin;

    SwView       &rView; //Suchen per aktive ::com::sun::star::sdbcx::View vermeiden.
    SwFldMgr     *pMgr;      //Ptr um das include zu sparen
    SelectionType eType;

    String       sCharacterStyle;
    String       sObjectName;
    bool         bCopyAttributes;

    ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >    xNameAccess;
    ::com::sun::star::uno::Reference< ::com::sun::star::container::XNamed >         xNamed;

    DECL_LINK( SelectHdl, ListBox * );
    DECL_LINK( ModifyHdl, Edit * );
    DECL_LINK( OptionHdl, Button * );
    DECL_LINK( CaptionHdl, PushButton*);

    virtual void Apply();

    void    DrawSample();
    void    CheckButtonWidth();

public:
     SwCaptionDialog( Window *pParent, SwView &rV );
    ~SwCaptionDialog();
};

#endif

<commit_msg>INTEGRATION: CWS os107 (1.9.76); FILE MERGED 2007/11/07 10:19:37 os 1.9.76.1: #i61007# caption localisable<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: cption.hxx,v $
 *
 *  $Revision: 1.10 $
 *
 *  last change: $Author: ihi $ $Date: 2007-11-21 18:23:20 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/
#ifndef _CPTION_HXX
#define _CPTION_HXX

#ifndef _SVX_STDDLG_HXX //autogen
#include <svx/stddlg.hxx>
#endif

#ifndef _FIXED_HXX //autogen
#include <vcl/fixed.hxx>
#endif

#ifndef _LSTBOX_HXX //autogen
#include <vcl/lstbox.hxx>
#endif

#ifndef _EDIT_HXX //autogen
#include <vcl/edit.hxx>
#endif

#ifndef _GROUP_HXX //autogen
#include <vcl/group.hxx>
#endif

#ifndef _BUTTON_HXX //autogen
#include <vcl/button.hxx>
#endif
#ifndef _ACTCTRL_HXX //autogen
#include <actctrl.hxx>
#endif

#ifndef _COM_SUN_STAR_CONTAINER_XENUMERATIONACCESS_HPP_
#include <com/sun/star/container/XEnumerationAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMEACCESS_HPP_
#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
#include <com/sun/star/container/XNameAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XCONTENTENUMERATIONACCESS_HPP_
#include <com/sun/star/container/XContentEnumerationAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XENUMERATION_HPP_
#include <com/sun/star/container/XEnumeration.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XELEMENTACCESS_HPP_
#include <com/sun/star/container/XElementAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XINDEXACCESS_HPP_
#include <com/sun/star/container/XIndexAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XNAMED_HPP_
#include <com/sun/star/container/XNamed.hpp>
#endif

class SwFldMgr;
class SwView;

#include <wrtsh.hxx>
#include "optload.hxx"
#include "swlbox.hxx"

class SwCaptionDialog : public SvxStandardDialog
{
    class CategoryBox : public ComboBox
    {
    public:
        CategoryBox( Window* pParent, const ResId& rResId )
            : ComboBox( pParent, rResId )
        {}

        virtual long    PreNotify( NotifyEvent& rNEvt );
    };

    FixedText    aTextText;
    Edit         aTextEdit;
    FixedLine    aSettingsFL;
    FixedText    aCategoryText;
    CategoryBox  aCategoryBox;
    FixedText    aFormatText;
    ListBox      aFormatBox;
    //#i61007# order of captions
    FixedText    aNumberingSeparatorFT;
    Edit         aNumberingSeparatorED;
    FixedText    aSepText;
    Edit         aSepEdit;
    FixedText    aPosText;
    ListBox      aPosBox;
    OKButton     aOKButton;
    CancelButton aCancelButton;
    HelpButton   aHelpButton;
    PushButton   aAutoCaptionButton;
    PushButton   aOptionButton;

    String       sNone;

    SwCaptionPreview    aPrevWin;

    SwView       &rView; //Suchen per aktive ::com::sun::star::sdbcx::View vermeiden.
    SwFldMgr     *pMgr;      //Ptr um das include zu sparen
    SelectionType eType;

    String       sCharacterStyle;
    String       sObjectName;
    bool         bCopyAttributes;
    bool        bOrderNumberingFirst; //#i61007# order of captions

    ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >    xNameAccess;
    ::com::sun::star::uno::Reference< ::com::sun::star::container::XNamed >         xNamed;

    DECL_LINK( SelectHdl, ListBox * );
    DECL_LINK( ModifyHdl, Edit * );
    DECL_LINK( OptionHdl, Button * );
    DECL_LINK( CaptionHdl, PushButton*);

    virtual void Apply();

    void    DrawSample();
    void    CheckButtonWidth();
    void    ApplyCaptionOrder(); //#i61007# order of captions

public:
     SwCaptionDialog( Window *pParent, SwView &rV );
    ~SwCaptionDialog();
};

#endif

<|endoftext|>


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

#ifndef _SVTREEBOX_HXX
#include <svtools/svtreebx.hxx>
#endif

#ifndef _COM_SUN_STAR_UNO_REFERENCE_H_
#include <com/sun/star/uno/Reference.h>
#endif
namespace com{namespace sun{namespace star{namespace container{
    class XNameAccess;
}}}}

#ifndef _SWTYPES_HXX
#include <swtypes.hxx>
#endif
#ifndef _SWUNODEF_HXX
#include <swunodef.hxx>
#endif
class SwDBTreeList_Impl;
class SwWrtShell;
class SwDBTreeList : public SvTreeListBox
{
    ImageList       aImageList;
    ImageList       aImageListHC;
    Image           aDBBMP;
    Image           aTableBMP;
    Image           aQueryBMP;

    String          sDefDBName;
    BOOL            bInitialized;
    BOOL            bShowColumns;

    SwDBTreeList_Impl* pImpl;

    DECL_LINK( DBCompare, SvSortData* );

    void            InitTreeList();
    virtual void    RequestingChilds( SvLBoxEntry* pParent );

    virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt );
    virtual void    StartDrag( sal_Int8 nAction, const Point& rPosPixel );

public:
     SwDBTreeList( Window* pParent, const ResId& rResId,
                    SwWrtShell* pSh,
                    const String& rDefDBName = aEmptyStr,
                    const BOOL bShowCol = FALSE );
    virtual ~SwDBTreeList();

    String  GetDBName( String& rTableName, String& rColumnName, BOOL* pbIsTable = 0);
    void    Select( const String& rDBName, const String& rTableName,
                    const String& rColumnName );

    void    ShowColumns(BOOL bShowCol);
    void    SetWrtShell(SwWrtShell& rSh);

    void    AddDataSource(const String& rSource);
};

#endif

<commit_msg>INTEGRATION: CWS tune03 (1.7.268); FILE MERGED 2004/08/09 21:49:49 mhu 1.7.268.2: RESYNC: (1.7-1.8); FILE MERGED 2004/07/19 19:11:26 mhu 1.7.268.1: #i29979# Added SW_DLLPUBLIC/PRIVATE (see swdllapi.h) to exported symbols/classes.<commit_after>/*************************************************************************
 *
 *  $RCSfile: dbtree.hxx,v $
 *
 *  $Revision: 1.10 $
 *
 *  last change: $Author: rt $ $Date: 2004-08-23 08:58:14 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/
#ifndef _DBTREE_HXX
#define _DBTREE_HXX

#ifndef _SVTREEBOX_HXX
#include <svtools/svtreebx.hxx>
#endif

#ifndef _COM_SUN_STAR_UNO_REFERENCE_H_
#include <com/sun/star/uno/Reference.h>
#endif

namespace com{namespace sun{namespace star{namespace container{
    class XNameAccess;
}}}}

#ifndef INCLUDED_SWDLLAPI_H
#include "swdllapi.h"
#endif
#ifndef _SWTYPES_HXX
#include <swtypes.hxx>
#endif
#ifndef _SWUNODEF_HXX
#include <swunodef.hxx>
#endif

class SwDBTreeList_Impl;
class SwWrtShell;

class SW_DLLPUBLIC SwDBTreeList : public SvTreeListBox
{
    ImageList       aImageList;
    ImageList       aImageListHC;
    Image           aDBBMP;
    Image           aTableBMP;
    Image           aQueryBMP;

    String          sDefDBName;
    BOOL            bInitialized;
    BOOL            bShowColumns;

    SwDBTreeList_Impl* pImpl;

    SW_DLLPRIVATE DECL_LINK( DBCompare, SvSortData* );

    SW_DLLPRIVATE void          InitTreeList();
    SW_DLLPRIVATE virtual void  RequestingChilds( SvLBoxEntry* pParent );

    SW_DLLPRIVATE virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt );
    SW_DLLPRIVATE virtual void  StartDrag( sal_Int8 nAction, const Point& rPosPixel );

public:
     SwDBTreeList( Window* pParent, const ResId& rResId,
                    SwWrtShell* pSh,
                    const String& rDefDBName = aEmptyStr,
                    const BOOL bShowCol = FALSE );
    virtual ~SwDBTreeList();

    String  GetDBName( String& rTableName, String& rColumnName, BOOL* pbIsTable = 0);
    void    Select( const String& rDBName, const String& rTableName,
                    const String& rColumnName );

    void    ShowColumns(BOOL bShowCol);
    void    SetWrtShell(SwWrtShell& rSh);

    void    AddDataSource(const String& rSource);
};

#endif

<|endoftext|>


<commit_before>#include <string.h>
#include <signal.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <thread>
#include <set>
#include "msg_filter.hpp"
#include "io_policy/line.hpp"
#include "io_policy/sysv_mq.hpp"
#include "io_policy/tcp.hpp"
#include "sub_entry.hpp"
#include "util.hpp"

using namespace std;
using namespace wissbi;

bool run = true;

void exit_signal_handler(int signum) {
    run = false;
}

int main(int argc, char* argv[]){
    signal(SIGINT, exit_signal_handler);
    signal(SIGTERM, exit_signal_handler);

    if(getenv("WISSBI_PID_FILE") != NULL) {
        ofstream ofs(getenv("WISSBI_PID_FILE"));
        ofs << getpid() << endl;
    }

    int serv = socket(AF_INET, SOCK_STREAM, 0);
    sockaddr serv_addr;
    util::ConnectStringToSockaddr("0.0.0.0:0", reinterpret_cast<sockaddr_in*>(&serv_addr));
    if(-1 == ::bind(serv, &serv_addr, sizeof(serv_addr))) {
        cerr << "bind error" << endl;
        return -1;
    }
    if(-1 == listen(serv, 10)) {
        cerr << "listen error" << endl;
        return -1;
    }
    socklen_t len = sizeof(serv_addr);;
    getsockname(serv, &serv_addr, &len);
    cerr <<"after listen port "<<ntohs(((sockaddr_in*)&serv_addr)->sin_port)<<endl;

    ostringstream tmp;
    tmp << util::GetHostIP() << ":" << ntohs(((sockaddr_in*)&serv_addr)->sin_port);

    SubEntry sub_entry(getenv("WISSBI_META_DIR") != NULL ? getenv("WISSBI_META_DIR") : "/var/lib/wissbi", argv[1], tmp.str());

    MsgFilter<io_policy::SysvMq, io_policy::Line> output_writer;
    output_writer.mq_init("");
    output_writer.auto_flush();
    thread* output_th = new thread([&output_writer](){
        output_writer.FilterLoop();
    });

    struct timeval tv;
    tv.tv_sec = 1;
    tv.tv_usec = 0;
    setsockopt(serv, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));

    while(run) {
        sockaddr other_addr;
        socklen_t len;
        int res = accept(serv, &other_addr, &len);
        if(res > 0){
            cerr << "connected " << res << endl;
            struct timeval tv;
            tv.tv_sec = 0;
            tv.tv_usec = 0;
            setsockopt(res, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
            thread([res]{
                MsgFilter<io_policy::TCP, io_policy::SysvMq> filter;
                filter.mq_init("");
                filter.set_cleanup(false);
                filter.AttachConnectedSock(res);
                filter.FilterLoop();
            }).detach();
        }
        sub_entry.renew();
    }

    return 0;
}

<commit_msg>make wissbi-sub support length message format<commit_after>#include <string.h>
#include <signal.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <thread>
#include <set>
#include "msg_filter.hpp"
#include "io_policy/line.hpp"
#include "io_policy/length.hpp"
#include "io_policy/sysv_mq.hpp"
#include "io_policy/tcp.hpp"
#include "sub_entry.hpp"
#include "util.hpp"

using namespace std;
using namespace wissbi;

bool run = true;

void exit_signal_handler(int signum) {
    run = false;
}

template<class OutputWriter>
void run_sub(const std::string& src) {
    int serv = socket(AF_INET, SOCK_STREAM, 0);
    sockaddr serv_addr;
    util::ConnectStringToSockaddr("0.0.0.0:0", reinterpret_cast<sockaddr_in*>(&serv_addr));
    if(-1 == ::bind(serv, &serv_addr, sizeof(serv_addr))) {
        cerr << "bind error" << endl;
        throw std::runtime_error("bind error");
    }
    if(-1 == listen(serv, 10)) {
        cerr << "listen error" << endl;
        throw std::runtime_error("listen error");
    }
    socklen_t len = sizeof(serv_addr);;
    getsockname(serv, &serv_addr, &len);
    cerr <<"after listen port "<<ntohs(((sockaddr_in*)&serv_addr)->sin_port)<<endl;

    ostringstream tmp;
    tmp << util::GetHostIP() << ":" << ntohs(((sockaddr_in*)&serv_addr)->sin_port);

    SubEntry sub_entry(getenv("WISSBI_META_DIR") != NULL ? getenv("WISSBI_META_DIR") : "/var/lib/wissbi", src, tmp.str());

    OutputWriter output_writer;
    output_writer.mq_init("");
    output_writer.auto_flush();
    thread* output_th = new thread([&output_writer](){
        output_writer.FilterLoop();
    });

    struct timeval tv;
    tv.tv_sec = 1;
    tv.tv_usec = 0;
    setsockopt(serv, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));

    while(run) {
        sockaddr other_addr;
        socklen_t len;
        int res = accept(serv, &other_addr, &len);
        if(res > 0){
            cerr << "connected " << res << endl;
            struct timeval tv;
            tv.tv_sec = 0;
            tv.tv_usec = 0;
            setsockopt(res, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
            thread([res]{
                MsgFilter<io_policy::TCP, io_policy::SysvMq> filter;
                filter.mq_init("");
                filter.set_cleanup(false);
                filter.AttachConnectedSock(res);
                filter.FilterLoop();
            }).detach();
        }
        sub_entry.renew();
    }
}

int main(int argc, char* argv[]){
    signal(SIGINT, exit_signal_handler);
    signal(SIGTERM, exit_signal_handler);

    std::string src(argv[1]);

    if(getenv("WISSBI_PID_FILE") != NULL) {
        ofstream ofs(getenv("WISSBI_PID_FILE"));
        ofs << getpid() << endl;
    }

    char* msg_format = getenv("WISSBI_MESSAGE_FORMAT");
    if(msg_format) {
        if(std::string(msg_format) == "line") {
            run_sub<MsgFilter<io_policy::SysvMq, io_policy::Line>>(src);
        }
        else if(std::string(msg_format) == "length") {
            run_sub<MsgFilter<io_policy::SysvMq, io_policy::Length>>(src);
        }
        else {
            std::cerr << "unknown message format: " << msg_format << std::endl;
            return 1;
        }
    }
    else {
        run_sub<MsgFilter<io_policy::SysvMq, io_policy::Line>>(src);
    }

    return 0;
}

<|endoftext|>


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

#include "swtypes.hxx"
#include "frmatr.hxx"

#ifndef _SVX_SVXENUM_HXX //autogen
#include <svx/svxenum.hxx>
#endif
#ifndef _GEN_HXX //autogen
#include <tools/gen.hxx>
#endif
#ifndef _FMTFSIZE_HXX //autogen
#include <fmtfsize.hxx>
#endif
#ifndef _FMTSRND_HXX //autogen
#include <fmtsrnd.hxx>
#endif
#ifndef _FMTORNT_HXX //autogen
#include <fmtornt.hxx>
#endif
#ifndef _FMTANCHR_HXX //autogen
#include <fmtanchr.hxx>
#endif

class   SwWrtShell;
struct  SwFrmValid;

class   SwFmt;
class   SwFmtCol;

const SwTwips   DFLT_WIDTH      = MM50 * 4;
const SwTwips   DFLT_HEIGHT     = MM50;

#define FULL_ATTRSET    0xffff

#define FRMMGR_TYPE_NONE    0x00
#define FRMMGR_TYPE_TEXT    0x01
#define FRMMGR_TYPE_GRF     0x02
#define FRMMGR_TYPE_OLE     0x04
#define FRMMGR_TYPE_LABEL   0x08
#define FRMMGR_TYPE_ENVELP  0x10

class SwFlyFrmAttrMgr
{
    SfxItemSet  aSet;
    Point       aAbsPos;
    SwWrtShell  *pOwnSh;

    BOOL        bAbsPos,
                bNewFrm;
    BOOL        bIsInVertical;

    // interne Verrechnung fuer Umrandung
    SwTwips             CalcTopSpace();
    SwTwips             CalcBottomSpace();
    SwTwips             CalcLeftSpace();
    SwTwips             CalcRightSpace();

    void _UpdateFlyFrm();   //Nacharbeit nach Einfuegen oder Update

public:
    SwFlyFrmAttrMgr( BOOL bNew, SwWrtShell* pSh, BYTE nType );

    //CopyCtor fuer die Dialoge, zum Pruefen der Metrics
    SwFlyFrmAttrMgr( BOOL bNew, SwWrtShell *pSh, const SfxItemSet &rSet );

    inline SwWrtShell*  GetShell() { return pOwnSh; }

    void                SetAnchor(RndStdIds eId);
    inline RndStdIds    GetAnchor()  const;

    void                SetHorzOrientation(SwHoriOrient eOrient);
    void                SetVertOrientation(SvxFrameVertOrient eOrient);

    // Absolute Position
    void                SetAbsPos(const Point& rLPoint);

    // Relative Position vom Anker
    void                SetPos(const Point& rLPoint);
    inline Point        GetPos() const;

    // Groesse
    void                SetSize(const Size& rLSize);
    inline const Size&  GetSize() const;
    void                SetFrmSize(const SwFmtFrmSize& rFrmSize);

    inline USHORT       GetHeightPercent() const;

    void                SetHeightSizeType(SwFrmSize eType);

    // Abstand zum Inhalt
    void                SetLRSpace( long nLeft  = LONG_MAX,
                                    long nRight = LONG_MAX );
    void                SetULSpace( long nTop   = LONG_MAX,
                                    long nBottom= LONG_MAX );

    void                SetWrapType(SwSurround eSurround);

    void                SetAnchorOnly(BOOL bSet);
    void                SetContour( BOOL bSet);
    void                SetTransparent(BOOL bTrans);

    void                ProtectPosSize(BOOL bProt);

    void                SetCol( const SwFmtCol &rCol);

    // Attribute aendern und erfragen
    void                UpdateAttrMgr();
    void                UpdateFlyFrm();

    // neuen Rahmen erzeugen
    BOOL                InsertFlyFrm();
    void                InsertFlyFrm(RndStdIds      eAnchorType,
                                   const Point    &rPos,
                                   const Size     &rSize,
                                   BOOL           bAbsPos = FALSE);

    // Metriken pruefen und  aendern
    void                ValidateMetrics(SwFrmValid& rVal, BOOL bOnlyPercentRefValue = FALSE);

    void                DelAttr(USHORT nId);

    // Set rausreichen
    inline const SfxItemSet &GetAttrSet() const { return aSet; }
    inline       SfxItemSet &GetAttrSet()       { return aSet; }
    void                     SetAttrSet(const SfxItemSet& rSet);

    inline const SwFmtVertOrient &GetVertOrient() const;
    inline const SwFmtHoriOrient &GetHoriOrient() const;
    inline const SvxShadowItem   &GetShadow() const;
    inline const SvxBoxItem      &GetBox() const;
    inline const SwFmtSurround   &GetSurround() const;
    inline const SwFmtFrmSize    &GetFrmSize() const;

    long CalcWidthSpace();
    long CalcHeightSpace();

    long CalcWidthBorder()  { return CalcLeftSpace()+CalcRightSpace(); }
    long CalcHeightBorder() { return CalcTopSpace()+CalcBottomSpace(); }
};

/*--------------------------------------------------------------------
    Beschreibung: Validierung von Metriken
 --------------------------------------------------------------------*/

// OD 18.09.2003 #i18732# - extend by new member <bFollowTextFlow>
// OD 12.11.2003 #i22341# - extend by new member <pToCharCntntPos>
struct SwFrmValid
{
    RndStdIds           eArea;
    SwHoriOrient        eHori;
    SvxFrameVertOrient  eVert;
    SwRelationOrient    eHRel;
    SwRelationOrient    eVRel;
    BOOL                bAutoHeight;
    BOOL                bAutoWidth;
    BOOL                bMirror;
    // OD 18.09.2003 #i18732#
    bool                bFollowTextFlow;
    // OD 12.11.2003 #i22341# - proposed content position of character for
    // to character anchored objects horizontal/vertical aligned at character
    // respectively vertical aligned at top of line
    const SwPosition* pToCharCntntPos;

    SwTwips nHPos;
    SwTwips nMaxHPos;
    SwTwips nMinHPos;

    SwTwips nVPos;
    SwTwips nMaxVPos;
    SwTwips nMinVPos;

    SwTwips nWidth;
    SwTwips nMinWidth;
    SwTwips nMaxWidth;

    SwTwips nHeight;
    SwTwips nMinHeight;
    SwTwips nMaxHeight;

    Size    aPercentSize;   // Size fuer 100%-Wert

    SwFrmValid();
};

inline const Size& SwFlyFrmAttrMgr::GetSize() const
{
    return ((SwFmtFrmSize&)aSet.Get(RES_FRM_SIZE)).GetSize();
}

inline const SwFmtVertOrient &SwFlyFrmAttrMgr::GetVertOrient() const
{
    return ((SwFmtVertOrient&)aSet.Get(RES_VERT_ORIENT));
}
inline const SwFmtHoriOrient &SwFlyFrmAttrMgr::GetHoriOrient() const
{
    return ((SwFmtHoriOrient &)aSet.Get(RES_HORI_ORIENT));
}
inline const SwFmtFrmSize& SwFlyFrmAttrMgr::GetFrmSize() const
{
    return ((SwFmtFrmSize&)aSet.Get(RES_FRM_SIZE));
}
inline const SvxShadowItem &SwFlyFrmAttrMgr::GetShadow() const
{
    return ((SvxShadowItem&)aSet.Get(RES_SHADOW));
}
inline const SvxBoxItem &SwFlyFrmAttrMgr::GetBox() const
{
    return ((SvxBoxItem&)aSet.Get(RES_BOX));
}
inline const SwFmtSurround &SwFlyFrmAttrMgr::GetSurround() const
{
    return ((SwFmtSurround&)aSet.Get(RES_SURROUND));
}

inline Point SwFlyFrmAttrMgr::GetPos() const
{
    return Point( GetHoriOrient().GetPos(), GetVertOrient().GetPos() );
}

inline RndStdIds SwFlyFrmAttrMgr::GetAnchor()  const
{
    return ((SwFmtAnchor&)aSet.Get(RES_ANCHOR)).GetAnchorId();
}

inline USHORT SwFlyFrmAttrMgr::GetHeightPercent() const
{
    return GetFrmSize().GetHeightPercent();
}

#endif
<commit_msg>INTEGRATION: CWS swdrawpositioning (1.3.82); FILE MERGED 2004/06/21 08:03:18 od 1.3.82.3: RESYNC: (1.4-1.5); FILE MERGED resolve merge conflict. 2004/03/30 15:02:05 os 1.3.82.2: #i26173# SwFrmMgr::ValidateMetrics changed 2004/03/08 09:05:55 os 1.3.82.1: #i26173# draw positioning TabPage in svx created -> strings moved to svx<commit_after>/*************************************************************************
 *
 *  $RCSfile: frmmgr.hxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: hjs $ $Date: 2004-06-28 13:49:33 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/
#ifndef _FRMMGR_HXX
#define _FRMMGR_HXX

#include "swtypes.hxx"
#include "frmatr.hxx"

#ifndef _SVX_SVXENUM_HXX //autogen
#include <svx/svxenum.hxx>
#endif
#ifndef _GEN_HXX //autogen
#include <tools/gen.hxx>
#endif
#ifndef _FMTFSIZE_HXX //autogen
#include <fmtfsize.hxx>
#endif
#ifndef _FMTSRND_HXX //autogen
#include <fmtsrnd.hxx>
#endif
#ifndef _FMTORNT_HXX //autogen
#include <fmtornt.hxx>
#endif
#ifndef _FMTANCHR_HXX //autogen
#include <fmtanchr.hxx>
#endif

class   SwWrtShell;
struct  SvxSwFrameValidation;
struct  SwPosition;

class   SwFmt;
class   SwFmtCol;

const SwTwips   DFLT_WIDTH      = MM50 * 4;
const SwTwips   DFLT_HEIGHT     = MM50;

#define FULL_ATTRSET    0xffff

#define FRMMGR_TYPE_NONE    0x00
#define FRMMGR_TYPE_TEXT    0x01
#define FRMMGR_TYPE_GRF     0x02
#define FRMMGR_TYPE_OLE     0x04
#define FRMMGR_TYPE_LABEL   0x08
#define FRMMGR_TYPE_ENVELP  0x10

class SwFlyFrmAttrMgr
{
    SfxItemSet  aSet;
    Point       aAbsPos;
    SwWrtShell  *pOwnSh;

    BOOL        bAbsPos,
                bNewFrm;
    BOOL        bIsInVertical;

    // interne Verrechnung fuer Umrandung
    SwTwips             CalcTopSpace();
    SwTwips             CalcBottomSpace();
    SwTwips             CalcLeftSpace();
    SwTwips             CalcRightSpace();

    void _UpdateFlyFrm();   //Nacharbeit nach Einfuegen oder Update

public:
    SwFlyFrmAttrMgr( BOOL bNew, SwWrtShell* pSh, BYTE nType );

    //CopyCtor fuer die Dialoge, zum Pruefen der Metrics
    SwFlyFrmAttrMgr( BOOL bNew, SwWrtShell *pSh, const SfxItemSet &rSet );

    inline SwWrtShell*  GetShell() { return pOwnSh; }

    void                SetAnchor(RndStdIds eId);
    inline RndStdIds    GetAnchor()  const;

    void                SetHorzOrientation(SwHoriOrient eOrient);
    void                SetVertOrientation(SvxFrameVertOrient eOrient);

    // Absolute Position
    void                SetAbsPos(const Point& rLPoint);

    // Relative Position vom Anker
    void                SetPos(const Point& rLPoint);
    inline Point        GetPos() const;

    // Groesse
    void                SetSize(const Size& rLSize);
    inline const Size&  GetSize() const;
    void                SetFrmSize(const SwFmtFrmSize& rFrmSize);

    inline USHORT       GetHeightPercent() const;

    void                SetHeightSizeType(SwFrmSize eType);

    // Abstand zum Inhalt
    void                SetLRSpace( long nLeft  = LONG_MAX,
                                    long nRight = LONG_MAX );
    void                SetULSpace( long nTop   = LONG_MAX,
                                    long nBottom= LONG_MAX );

    void                SetWrapType(SwSurround eSurround);

    void                SetAnchorOnly(BOOL bSet);
    void                SetContour( BOOL bSet);
    void                SetTransparent(BOOL bTrans);

    void                ProtectPosSize(BOOL bProt);

    void                SetCol( const SwFmtCol &rCol);

    // Attribute aendern und erfragen
    void                UpdateAttrMgr();
    void                UpdateFlyFrm();

    // neuen Rahmen erzeugen
    BOOL                InsertFlyFrm();
    void                InsertFlyFrm(RndStdIds      eAnchorType,
                                   const Point    &rPos,
                                   const Size     &rSize,
                                   BOOL           bAbsPos = FALSE);

    // Metriken pruefen und  aendern
    void                ValidateMetrics(SvxSwFrameValidation& rVal,
                            const SwPosition* pToCharCntntPos,
                            BOOL bOnlyPercentRefValue = FALSE);

    void                DelAttr(USHORT nId);

    // Set rausreichen
    inline const SfxItemSet &GetAttrSet() const { return aSet; }
    inline       SfxItemSet &GetAttrSet()       { return aSet; }
    void                     SetAttrSet(const SfxItemSet& rSet);

    inline const SwFmtVertOrient &GetVertOrient() const;
    inline const SwFmtHoriOrient &GetHoriOrient() const;
    inline const SvxShadowItem   &GetShadow() const;
    inline const SvxBoxItem      &GetBox() const;
    inline const SwFmtSurround   &GetSurround() const;
    inline const SwFmtFrmSize    &GetFrmSize() const;

    long CalcWidthSpace();
    long CalcHeightSpace();

    long CalcWidthBorder()  { return CalcLeftSpace()+CalcRightSpace(); }
    long CalcHeightBorder() { return CalcTopSpace()+CalcBottomSpace(); }
};

inline const Size& SwFlyFrmAttrMgr::GetSize() const
{
    return ((SwFmtFrmSize&)aSet.Get(RES_FRM_SIZE)).GetSize();
}

inline const SwFmtVertOrient &SwFlyFrmAttrMgr::GetVertOrient() const
{
    return ((SwFmtVertOrient&)aSet.Get(RES_VERT_ORIENT));
}
inline const SwFmtHoriOrient &SwFlyFrmAttrMgr::GetHoriOrient() const
{
    return ((SwFmtHoriOrient &)aSet.Get(RES_HORI_ORIENT));
}
inline const SwFmtFrmSize& SwFlyFrmAttrMgr::GetFrmSize() const
{
    return ((SwFmtFrmSize&)aSet.Get(RES_FRM_SIZE));
}
inline const SvxShadowItem &SwFlyFrmAttrMgr::GetShadow() const
{
    return ((SvxShadowItem&)aSet.Get(RES_SHADOW));
}
inline const SvxBoxItem &SwFlyFrmAttrMgr::GetBox() const
{
    return ((SvxBoxItem&)aSet.Get(RES_BOX));
}
inline const SwFmtSurround &SwFlyFrmAttrMgr::GetSurround() const
{
    return ((SwFmtSurround&)aSet.Get(RES_SURROUND));
}

inline Point SwFlyFrmAttrMgr::GetPos() const
{
    return Point( GetHoriOrient().GetPos(), GetVertOrient().GetPos() );
}

inline RndStdIds SwFlyFrmAttrMgr::GetAnchor()  const
{
    return ((SwFmtAnchor&)aSet.Get(RES_ANCHOR)).GetAnchorId();
}

inline USHORT SwFlyFrmAttrMgr::GetHeightPercent() const
{
    return GetFrmSize().GetHeightPercent();
}

#endif
<|endoftext|>


<commit_before>#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<thread>
#include<dirent.h>
#include<chrono>
#include<sys/socket.h>
#include<netinet/in.h>
#include<sys/types.h>
#include<arpa/inet.h>
#include<fcntl.h>
#include<unistd.h>
#include<cstdlib>
#include<sys/wait.h>
#include<string.h>
#include<mutex>
#define SUCCESS 0
#define FAILURE 1
#define BCAST_PORT 5000
#define REQ_LISTNER_PORT 6000
#define MAX_SIZE 1024
#define CLI_ID "101"
#define TOKEN "#"
#define PORT 54545
std::mutex listner_mutex;

void file_bcast()
{
	//Current Client Socket
	int bcast_sockfd;

	bcast_sockfd = socket(AF_INET, SOCK_DGRAM, 0);

	struct sockaddr_in new_addr;
	memset(&new_addr, 0, sizeof(new_addr));
	new_addr.sin_family = AF_INET;
	new_addr.sin_port = PORT;
	new_addr.sin_addr.s_addr = htonl(INADDR_ANY);

	while(1)
	{
		std::this_thread::sleep_for(std::chrono::milliseconds(5000));
		DIR *dir;
		struct dirent *ent;
		char fs_data[MAX_SIZE];
		memset(fs_data, 0, MAX_SIZE);
		strcpy(fs_data, CLI_ID);

		if ((dir = opendir ("./")) != NULL)
		{
  			while((ent = readdir (dir)) != NULL)
 			{
				if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
          			{continue;}
				else
				{
					strcat(fs_data, TOKEN);
  					strcat(fs_data, ent->d_name);
          			}
			}
		}
  		closedir (dir);
		std::cout << fs_data << std::endl;
		sendto(bcast_sockfd, fs_data, strlen(fs_data), 0, (struct sockaddr *)&new_addr, sizeof(struct sockaddr_in));

	}
}

int main(int argc, char **argv)
{

	std::thread broadcaster(file_bcast);
//	std::thread listener(bcast_listener);
	broadcaster.detach();

//	listener.detach();
	while(1){}

	return SUCCESS;
}

<commit_msg>Base app<commit_after>#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<thread>
#include<dirent.h>
#include<chrono>
#include<sys/socket.h>
#include<netinet/in.h>
#include<sys/types.h>
#include<arpa/inet.h>
#include<fcntl.h>
#include<unistd.h>
#include<cstdlib>
#include<sys/wait.h>
#include<string.h>
#include<mutex>
#define SUCCESS 0
#define FAILURE 1
#define MAX_SIZE 1024
#define CLI_ID "101"
#define TOKEN "#"
#define BCAST_PORT 6000
#define LISTENER_PORT 54545

void fs_bcast()
{
	//Current Client Socket
	int bcast_sockfd;

	bcast_sockfd = socket(AF_INET, SOCK_DGRAM, 0);

	struct sockaddr_in new_addr;
	memset(&new_addr, 0, sizeof(new_addr));
	new_addr.sin_family = AF_INET;
	new_addr.sin_port = BCAST_PORT;
	new_addr.sin_addr.s_addr = htonl(INADDR_ANY);

	while(1)
	{
		std::this_thread::sleep_for(std::chrono::milliseconds(5000));
		DIR *dir;
		struct dirent *ent;
		char fs_data[MAX_SIZE];
		memset(fs_data, 0, MAX_SIZE);
		strcpy(fs_data, CLI_ID);
		if ((dir = opendir ("./")) != NULL)
		{
  			while((ent = readdir (dir)) != NULL)
 			{
				if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
          			{continue;}
				else
				{
					strcat(fs_data, TOKEN);
  					strcat(fs_data, ent->d_name);
          			}
			}
		}
  		closedir (dir);
		std::cout << fs_data << std::endl;
		sendto(bcast_sockfd, fs_data, strlen(fs_data), 0, (struct sockaddr *)&new_addr, sizeof(struct sockaddr_in));
	}
}

void bcast_listener()
{
	int sockfd;
	std::cout<<"Hello"<<std::endl;
	struct sockaddr_in new_addr;
	struct sockaddr_in cli_addr;
	unsigned slen = sizeof(cli_addr);

	sockfd = socket(AF_INET, SOCK_DGRAM, 0);

	memset(&new_addr, 0, sizeof(new_addr));
	new_addr.sin_family = AF_INET;
	new_addr.sin_port = LISTENER_PORT;
	new_addr.sin_addr.s_addr = htonl(INADDR_ANY);

	int bind_status = bind(sockfd, (struct sockaddr*)&new_addr, sizeof(new_addr));

	while(1)
	{
		char bcast_buffer[1024];
		memset(bcast_buffer, 0, sizeof(bcast_buffer));
		recvfrom(sockfd, bcast_buffer, sizeof(bcast_buffer)-1, 0, (sockaddr *)&cli_addr, &slen);
		std::cout << "Listening.." <<std::endl;
		std::cout << "GOT FS" << bcast_buffer << std::endl;
	}
}

int main(int argc, char **argv)
{

	std::thread broadcaster(fs_bcast);
	std::thread listener(bcast_listener);
	broadcaster.detach();
	listener.detach();
	while(1){}
	return SUCCESS;
}

<|endoftext|>


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

#ifndef _TOOLBOX_HXX
#include <vcl/toolbox.hxx>
#endif
#ifndef _TRANSFER_HXX
#include <svtools/transfer.hxx>
#endif

class SwNavigationPI;

class SwHelpToolBox: public ToolBox, public DropTargetHelper
{
    Link aDoubleClickLink;
    Link aRightClickLink;       // Link bekommt MouseEvent als Parameter !!!

    using ToolBox::DoubleClick;

protected:
    virtual void MouseButtonDown(const MouseEvent &rEvt);
    virtual long DoubleClick(ToolBox *);
    virtual sal_Int8    AcceptDrop( const AcceptDropEvent& rEvt );
    virtual sal_Int8    ExecuteDrop( const ExecuteDropEvent& rEvt );

public:
    SwHelpToolBox(SwNavigationPI* pParent, const ResId &);
    ~SwHelpToolBox();
    void SetDoubleClickLink(const Link &);      // inline
    void SetRightClickLink(const Link &);       // inline
};

inline void SwHelpToolBox::SetDoubleClickLink(const Link &rLink) {
    aDoubleClickLink = rLink;
}

inline void SwHelpToolBox::SetRightClickLink(const Link &rLink) {
    aRightClickLink = rLink;
}

#endif
<commit_msg>INTEGRATION: CWS changefileheader (1.6.216); FILE MERGED 2008/04/01 15:59:18 thb 1.6.216.2: #i85898# Stripping all external header guards 2008/03/31 16:58:38 rt 1.6.216.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: popbox.hxx,v $
 * $Revision: 1.7 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org 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 version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/
#ifndef _POPBOX_HXX
#define _POPBOX_HXX

#ifndef _TOOLBOX_HXX
#include <vcl/toolbox.hxx>
#endif
#include <svtools/transfer.hxx>

class SwNavigationPI;

class SwHelpToolBox: public ToolBox, public DropTargetHelper
{
    Link aDoubleClickLink;
    Link aRightClickLink;       // Link bekommt MouseEvent als Parameter !!!

    using ToolBox::DoubleClick;

protected:
    virtual void MouseButtonDown(const MouseEvent &rEvt);
    virtual long DoubleClick(ToolBox *);
    virtual sal_Int8    AcceptDrop( const AcceptDropEvent& rEvt );
    virtual sal_Int8    ExecuteDrop( const ExecuteDropEvent& rEvt );

public:
    SwHelpToolBox(SwNavigationPI* pParent, const ResId &);
    ~SwHelpToolBox();
    void SetDoubleClickLink(const Link &);      // inline
    void SetRightClickLink(const Link &);       // inline
};

inline void SwHelpToolBox::SetDoubleClickLink(const Link &rLink) {
    aDoubleClickLink = rLink;
}

inline void SwHelpToolBox::SetRightClickLink(const Link &rLink) {
    aRightClickLink = rLink;
}

#endif
<|endoftext|>


<commit_before>/*
MIT License

Copyright (c) 2017 CPirc
Copyright (c) 2018 CPirc
Copyright (c) 2019 CPirc

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#include <iostream>
#include <sstream>
#include <thread>
#include <chrono>

#include "uci.h"
#include "position.h"
#include "move.h"
#include "search.h"

static SearchController sc;

namespace UCI
{
    namespace Extension
    {
        void print()
        {
            print_position(sc.pos);
        }

        void perft(std::stringstream &ss)
        {
            int depth = 0;
            ss >> depth;
            if(depth < 1) {depth = 1;}

            std::uint64_t nodes = 0ULL;
            for(int i = 1; i <= depth; ++i)
            {
                auto start = std::chrono::high_resolution_clock::now();
                nodes = perft(sc.pos, i);
                auto finish = std::chrono::high_resolution_clock::now();
                std::chrono::duration<double> elapsed = finish - start;

                std::cout << "info"
                          << " depth " << i
                          << " nodes " << nodes
                          << " time " << static_cast<int>(elapsed.count()*1000)
                          << " nps " << static_cast<int>(nodes/elapsed.count())
                          << std::endl;
            }

            std::cout << "nodes " << nodes << std::endl;
        }

        void ttperft(std::stringstream &ss)
        {
            int depth = 0;
            ss >> depth;
            if(depth < 1) {depth = 1;}

            std::uint64_t nodes = 0ULL;
            for(int i = 1; i <= depth; ++i)
            {
                auto start = std::chrono::high_resolution_clock::now();
                nodes = perft_tt(&sc.tt, sc.pos, i);
                auto finish = std::chrono::high_resolution_clock::now();
                std::chrono::duration<double> elapsed = finish - start;

                std::cout << "info"
                          << " depth " << i
                          << " nodes " << nodes
                          << " time " << static_cast<int>(elapsed.count()*1000)
                          << " nps " << static_cast<int>(nodes/elapsed.count())
                          << std::endl;
            }

            std::cout << "nodes " << nodes << std::endl;
        }
    }

    void ucinewgame()
    {
        parse_fen_to_position(
            "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
            sc.pos
        );
        tt_clear(&sc.tt);
    }

    void isready()
    {
        std::cout << "readyok" << std::endl;
    }

    // setoption name Some Name value Some Value
    void setoption(std::stringstream &ss)
    {
        std::string word;
        std::string name = "";
        std::string value = "";

        if (ss >> word && word != "name") {
            return;
        }

        // Collect the name
        while (ss >> word && word != "value") {
            if (name != "") {name += " ";}
            name += word;
        }

        // Collect the value
        while (ss >> word) {
            if (value != "") {value += " ";}
            value += word;
        }

        // Set the option
        if (name != "" && value != "") {
            // TODO:
            // Set the option if found
        }
    }

    void go(std::stringstream &ss)
    {
        sc.max_depth = MAX_PLY;
        sc.moves_per_session = 0;
        sc.increment = 0;
        sc.search_start_time = 0;
        sc.search_end_time = 0;
        sc.movetime = 0;

        int wtime = -1;
        int btime = -1;
        int winc = -1;
        int binc = -1;

        std::string word;
        while (ss >> word) {
            if (word == "wtime")          {ss >> wtime;}
            else if (word == "btime")     {ss >> btime;}
            else if (word == "winc")      {ss >> winc;}
            else if (word == "binc")      {ss >> binc;}
            else if (word == "depth")     {ss >> sc.max_depth;}
            else if (word == "movetime")  {ss >> sc.movetime;}
            else if (word == "movestogo") {ss >> sc.moves_per_session;}
        }

        if (sc.pos.flipped) {
            sc.our_clock = btime;
            sc.increment = binc;
        } else {
            sc.our_clock = wtime;
            sc.increment = winc;
        }

        std::thread search(search_thread, &sc);
        search.detach();
    }

    void moves(std::stringstream &ss)
    {
        std::string word;
        while (ss >> word) {
            Move move;
            if (!lan_to_move(sc.pos, word.c_str(), move)) {
                return;
            }

            char move_str[5];
            move_to_lan(move_str, move);

            if (sc.pos.flipped) {
                move = flip_move(move);
            }

            make_move(sc.pos, move);
        }
    }

    void position(std::stringstream &ss)
    {
        std::string fen = "";

        std::string word;
        while (ss >> word && word != "moves") {
            if (word == "startpos") {
                fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
            } else if (word != "fen") {
                fen += word;
            }
        }

        if (fen != "") {
            parse_fen_to_position(fen.c_str(), sc.pos);
        }

        moves(ss);
    }

    void listen()
    {
        std::cout << "id name Monochrome" << std::endl;
        std::cout << "id author flok Gikoskos kz04px mkchan ZirconiumX" << std::endl;
        std::cout << "uciok" << std::endl;

        std::string word;
        std::string line;
        while (true) {
            std::getline(std::cin, line);
            std::stringstream ss {line};
            ss >> word;

            if (word == "isready")         {isready(); break;}
            else if (word == "setoption")  {setoption(ss);}
            else if (word == "quit")       {return;}
        }

        tt_create(&sc.tt, 128);
        ucinewgame();

        bool quit = false;
        while (!quit) {
            std::getline(std::cin, line);
            std::stringstream ss {line};
            ss >> word;

            if (word == "isready")         {isready();}
            else if (word == "ucinewgame") {ucinewgame();}
            else if (word == "position")   {position(ss);}
            else if (word == "go")         {go(ss);}
            else if (word == "print")      {Extension::print();}
            else if (word == "perft")      {Extension::perft(ss);}
            else if (word == "ttperft")    {Extension::ttperft(ss);}
            else if (word == "moves")      {moves(ss);}
            else if (word == "quit")       {quit = true;}
        }
    }
}
<commit_msg>Parsing fix<commit_after>/*
MIT License

Copyright (c) 2017 CPirc
Copyright (c) 2018 CPirc
Copyright (c) 2019 CPirc

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#include <iostream>
#include <sstream>
#include <thread>
#include <chrono>

#include "uci.h"
#include "position.h"
#include "move.h"
#include "search.h"

static SearchController sc;

namespace UCI
{
    namespace Extension
    {
        void print()
        {
            print_position(sc.pos);
        }

        void perft(std::stringstream &ss)
        {
            int depth = 0;
            ss >> depth;
            if(depth < 1) {depth = 1;}

            std::uint64_t nodes = 0ULL;
            for(int i = 1; i <= depth; ++i)
            {
                auto start = std::chrono::high_resolution_clock::now();
                nodes = perft(sc.pos, i);
                auto finish = std::chrono::high_resolution_clock::now();
                std::chrono::duration<double> elapsed = finish - start;

                std::cout << "info"
                          << " depth " << i
                          << " nodes " << nodes
                          << " time " << static_cast<int>(elapsed.count()*1000)
                          << " nps " << static_cast<int>(nodes/elapsed.count())
                          << std::endl;
            }

            std::cout << "nodes " << nodes << std::endl;
        }

        void ttperft(std::stringstream &ss)
        {
            int depth = 0;
            ss >> depth;
            if(depth < 1) {depth = 1;}

            std::uint64_t nodes = 0ULL;
            for(int i = 1; i <= depth; ++i)
            {
                auto start = std::chrono::high_resolution_clock::now();
                nodes = perft_tt(&sc.tt, sc.pos, i);
                auto finish = std::chrono::high_resolution_clock::now();
                std::chrono::duration<double> elapsed = finish - start;

                std::cout << "info"
                          << " depth " << i
                          << " nodes " << nodes
                          << " time " << static_cast<int>(elapsed.count()*1000)
                          << " nps " << static_cast<int>(nodes/elapsed.count())
                          << std::endl;
            }

            std::cout << "nodes " << nodes << std::endl;
        }
    }

    void ucinewgame()
    {
        parse_fen_to_position(
            "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
            sc.pos
        );
        tt_clear(&sc.tt);
    }

    void isready()
    {
        std::cout << "readyok" << std::endl;
    }

    // setoption name Some Name value Some Value
    void setoption(std::stringstream &ss)
    {
        std::string word;
        std::string name = "";
        std::string value = "";

        if (ss >> word && word != "name") {
            return;
        }

        // Collect the name
        while (ss >> word && word != "value") {
            if (name != "") {name += " ";}
            name += word;
        }

        // Collect the value
        while (ss >> word) {
            if (value != "") {value += " ";}
            value += word;
        }

        // Set the option
        if (name != "" && value != "") {
            // TODO:
            // Set the option if found
        }
    }

    void go(std::stringstream &ss)
    {
        sc.max_depth = MAX_PLY;
        sc.moves_per_session = 0;
        sc.increment = 0;
        sc.search_start_time = 0;
        sc.search_end_time = 0;
        sc.movetime = 0;

        int wtime = -1;
        int btime = -1;
        int winc = -1;
        int binc = -1;

        std::string word;
        while (ss >> word) {
            if (word == "wtime")          {ss >> wtime;}
            else if (word == "btime")     {ss >> btime;}
            else if (word == "winc")      {ss >> winc;}
            else if (word == "binc")      {ss >> binc;}
            else if (word == "depth")     {ss >> sc.max_depth;}
            else if (word == "movetime")  {ss >> sc.movetime;}
            else if (word == "movestogo") {ss >> sc.moves_per_session;}
        }

        if (sc.pos.flipped) {
            sc.our_clock = btime;
            sc.increment = binc;
        } else {
            sc.our_clock = wtime;
            sc.increment = winc;
        }

        std::thread search(search_thread, &sc);
        search.detach();
    }

    void moves(std::stringstream &ss)
    {
        std::string word;
        while (ss >> word) {
            Move move;
            if (!lan_to_move(sc.pos, word.c_str(), move)) {
                return;
            }

            char move_str[5];
            move_to_lan(move_str, move);

            if (sc.pos.flipped) {
                move = flip_move(move);
            }

            make_move(sc.pos, move);
        }
    }

    void position(std::stringstream &ss)
    {
        std::string fen = "";

        std::string word;
        while (ss >> word && word != "moves") {
            if (word == "startpos") {
                fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
            } else if (word != "fen") {
                if (fen != "") {fen += " ";}
                fen += word;
            }
        }

        if (fen != "") {
            parse_fen_to_position(fen.c_str(), sc.pos);
        }

        moves(ss);
    }

    void listen()
    {
        std::cout << "id name Monochrome" << std::endl;
        std::cout << "id author flok Gikoskos kz04px mkchan ZirconiumX" << std::endl;
        std::cout << "uciok" << std::endl;

        std::string word;
        std::string line;
        while (true) {
            std::getline(std::cin, line);
            std::stringstream ss {line};
            ss >> word;

            if (word == "isready")         {isready(); break;}
            else if (word == "setoption")  {setoption(ss);}
            else if (word == "quit")       {return;}
        }

        tt_create(&sc.tt, 128);
        ucinewgame();

        bool quit = false;
        while (!quit) {
            std::getline(std::cin, line);
            std::stringstream ss {line};
            ss >> word;

            if (word == "isready")         {isready();}
            else if (word == "ucinewgame") {ucinewgame();}
            else if (word == "position")   {position(ss);}
            else if (word == "go")         {go(ss);}
            else if (word == "print")      {Extension::print();}
            else if (word == "perft")      {Extension::perft(ss);}
            else if (word == "ttperft")    {Extension::ttperft(ss);}
            else if (word == "moves")      {moves(ss);}
            else if (word == "quit")       {quit = true;}
        }
    }
}
<|endoftext|>


<commit_before>#include <uri>
#include <regex>
#include <iostream>

using namespace uri;

///////////////////////////////////////////////////////////////////////////////
const URI::Span_t URI::zero_span_;

///////////////////////////////////////////////////////////////////////////////
URI::URI(const char* uri)
  : URI{std::string{uri}}
{}

///////////////////////////////////////////////////////////////////////////////
URI::URI(const std::string& uri)
  : uri_str_{uri}
  , port_{}
{
  parse(uri_str_);
  load_queries();
}

///////////////////////////////////////////////////////////////////////////////
const std::string& URI::scheme() const {
  static std::string scheme;

  if (scheme.empty()) {
    scheme = uri_str_.substr(scheme_.begin, scheme_.end);
  }

  return scheme;
}

///////////////////////////////////////////////////////////////////////////////
const std::string& URI::userinfo() const {
  static std::string userinfo;

  if (userinfo.empty()) {
    userinfo = uri_str_.substr(userinfo_.begin, userinfo_.end);
  }

  return userinfo;
}

///////////////////////////////////////////////////////////////////////////////
const std::string& URI::host() const {
  static std::string host;

  if (host.empty()) {
    host = uri_str_.substr(host_.begin, host_.end);
  }

  return host;
}

///////////////////////////////////////////////////////////////////////////////
const std::string& URI::port_str() const {
  static std::string port;

  if (port.empty()) {
    port = uri_str_.substr(port_str_.begin, port_str_.end);
  }

  return port;
}

///////////////////////////////////////////////////////////////////////////////
uint16_t URI::port() const noexcept {
  if (not port_) {
    port_ = port_str_.begin ? static_cast<uint16_t>(std::stoi(port_str())) : 0;
  }
  return port_;
}

///////////////////////////////////////////////////////////////////////////////
const std::string& URI::path() const {
  static std::string path;

  if (path.empty()) {
    path = uri_str_.substr(path_.begin, path_.end);
  }

  return path;
}

///////////////////////////////////////////////////////////////////////////////
const std::string& URI::query() const {
  static std::string query;

  if (query.empty()){
    query = uri_str_.substr(query_.begin, query_.end);
  }

  return query;
}

///////////////////////////////////////////////////////////////////////////////
const std::string& URI::fragment() const {
  static std::string fragment;

  if (fragment.empty()) {
    fragment = uri_str_.substr(fragment_.begin, fragment_.end);
  }

  return fragment;
}

///////////////////////////////////////////////////////////////////////////////
std::string URI::query(const std::string& key) {
  static std::string no_entry_value;
  auto target = queries_.find(key);
  return (target not_eq queries_.end()) ? decode(target->second) : no_entry_value;
}

///////////////////////////////////////////////////////////////////////////////
std::string URI::to_string() const{
  return uri_str_;
}

///////////////////////////////////////////////////////////////////////////////
URI::operator std::string () const {
  return uri_str_;
}

///////////////////////////////////////////////////////////////////////////////
void URI::parse(const std::string& uri) {
  static const std::regex uri_pattern_matcher
  {
    "^([a-zA-z]+[\\w\\+\\-\\.]+)?(\\://)?" //< scheme
    "(([^:@]+)(\\:([^@]+))?@)?"            //< username && password
    "([^/:?#]+)?(\\:(\\d+))?"              //< hostname && port
    "([^?#]+)"                             //< path
    "(\\?([^#]*))?"                        //< query
    "(#(.*))?$"                            //< fragment
  };

  static std::smatch uri_parts;

  if (std::regex_match(uri, uri_parts, uri_pattern_matcher)) {
    path_     = Span_t(uri_parts.position(10), uri_parts.length(10));

    scheme_   = uri_parts.length(1)  ? Span_t(uri_parts.position(1),  uri_parts.length(1))  : zero_span_;
    userinfo_ = uri_parts.length(3)  ? Span_t(uri_parts.position(3),  uri_parts.length(3))  : zero_span_;
    host_     = uri_parts.length(7)  ? Span_t(uri_parts.position(7),  uri_parts.length(7))  : zero_span_;
    port_str_ = uri_parts.length(9)  ? Span_t(uri_parts.position(9),  uri_parts.length(9))  : zero_span_;
    query_    = uri_parts.length(11) ? Span_t(uri_parts.position(11), uri_parts.length(11)) : zero_span_;
    fragment_ = uri_parts.length(13) ? Span_t(uri_parts.position(13), uri_parts.length(13)) : zero_span_;
  }
}

///////////////////////////////////////////////////////////////////////////////
void URI::load_queries() {
  static const std::regex queries_matcher {"[^?=&]+"};

  auto& queries = query();

  auto position = std::sregex_iterator(queries.begin(), queries.end(), queries_matcher);
  auto end      = std::sregex_iterator();

  while (position not_eq end) {
    auto key = (*position).str();

    if ((++position) not_eq end) {
      queries_[key] = (*position++).str();
      continue;
    } else {
      queries_[key];
    }
  }
}

///////////////////////////////////////////////////////////////////////////////
std::ostream& uri::operator<< (std::ostream& out, const URI& uri) {
  return out << uri.to_string();
}
<commit_msg>Renamed queries_matcher to queries_tokenizer<commit_after>#include <uri>
#include <regex>
#include <iostream>

using namespace uri;

///////////////////////////////////////////////////////////////////////////////
const URI::Span_t URI::zero_span_;

///////////////////////////////////////////////////////////////////////////////
URI::URI(const char* uri)
  : URI{std::string{uri}}
{}

///////////////////////////////////////////////////////////////////////////////
URI::URI(const std::string& uri)
  : uri_str_{uri}
  , port_{}
{
  parse(uri_str_);
  load_queries();
}

///////////////////////////////////////////////////////////////////////////////
const std::string& URI::scheme() const {
  static std::string scheme;

  if (scheme.empty()) {
    scheme = uri_str_.substr(scheme_.begin, scheme_.end);
  }

  return scheme;
}

///////////////////////////////////////////////////////////////////////////////
const std::string& URI::userinfo() const {
  static std::string userinfo;

  if (userinfo.empty()) {
    userinfo = uri_str_.substr(userinfo_.begin, userinfo_.end);
  }

  return userinfo;
}

///////////////////////////////////////////////////////////////////////////////
const std::string& URI::host() const {
  static std::string host;

  if (host.empty()) {
    host = uri_str_.substr(host_.begin, host_.end);
  }

  return host;
}

///////////////////////////////////////////////////////////////////////////////
const std::string& URI::port_str() const {
  static std::string port;

  if (port.empty()) {
    port = uri_str_.substr(port_str_.begin, port_str_.end);
  }

  return port;
}

///////////////////////////////////////////////////////////////////////////////
uint16_t URI::port() const noexcept {
  if (not port_) {
    port_ = port_str_.begin ? static_cast<uint16_t>(std::stoi(port_str())) : 0;
  }
  return port_;
}

///////////////////////////////////////////////////////////////////////////////
const std::string& URI::path() const {
  static std::string path;

  if (path.empty()) {
    path = uri_str_.substr(path_.begin, path_.end);
  }

  return path;
}

///////////////////////////////////////////////////////////////////////////////
const std::string& URI::query() const {
  static std::string query;

  if (query.empty()){
    query = uri_str_.substr(query_.begin, query_.end);
  }

  return query;
}

///////////////////////////////////////////////////////////////////////////////
const std::string& URI::fragment() const {
  static std::string fragment;

  if (fragment.empty()) {
    fragment = uri_str_.substr(fragment_.begin, fragment_.end);
  }

  return fragment;
}

///////////////////////////////////////////////////////////////////////////////
std::string URI::query(const std::string& key) {
  static std::string no_entry_value;
  auto target = queries_.find(key);
  return (target not_eq queries_.end()) ? decode(target->second) : no_entry_value;
}

///////////////////////////////////////////////////////////////////////////////
std::string URI::to_string() const{
  return uri_str_;
}

///////////////////////////////////////////////////////////////////////////////
URI::operator std::string () const {
  return uri_str_;
}

///////////////////////////////////////////////////////////////////////////////
void URI::parse(const std::string& uri) {
  static const std::regex uri_pattern_matcher
  {
    "^([a-zA-z]+[\\w\\+\\-\\.]+)?(\\://)?" //< scheme
    "(([^:@]+)(\\:([^@]+))?@)?"            //< username && password
    "([^/:?#]+)?(\\:(\\d+))?"              //< hostname && port
    "([^?#]+)"                             //< path
    "(\\?([^#]*))?"                        //< query
    "(#(.*))?$"                            //< fragment
  };

  static std::smatch uri_parts;

  if (std::regex_match(uri, uri_parts, uri_pattern_matcher)) {
    path_     = Span_t(uri_parts.position(10), uri_parts.length(10));

    scheme_   = uri_parts.length(1)  ? Span_t(uri_parts.position(1),  uri_parts.length(1))  : zero_span_;
    userinfo_ = uri_parts.length(3)  ? Span_t(uri_parts.position(3),  uri_parts.length(3))  : zero_span_;
    host_     = uri_parts.length(7)  ? Span_t(uri_parts.position(7),  uri_parts.length(7))  : zero_span_;
    port_str_ = uri_parts.length(9)  ? Span_t(uri_parts.position(9),  uri_parts.length(9))  : zero_span_;
    query_    = uri_parts.length(11) ? Span_t(uri_parts.position(11), uri_parts.length(11)) : zero_span_;
    fragment_ = uri_parts.length(13) ? Span_t(uri_parts.position(13), uri_parts.length(13)) : zero_span_;
  }
}

///////////////////////////////////////////////////////////////////////////////
void URI::load_queries() {
  static const std::regex queries_tokenizer {"[^?=&]+"};

  auto& queries = query();

  auto position = std::sregex_iterator(queries.begin(), queries.end(), queries_tokenizer);
  auto end      = std::sregex_iterator();

  while (position not_eq end) {
    auto key = (*position).str();

    if ((++position) not_eq end) {
      queries_[key] = (*position++).str();
      continue;
    } else {
      queries_[key];
    }
  }
}

///////////////////////////////////////////////////////////////////////////////
std::ostream& uri::operator<< (std::ostream& out, const URI& uri) {
  return out << uri.to_string();
}
<|endoftext|>


<commit_before>//-----------------------------------------------------------------------bl-
//--------------------------------------------------------------------------
//
// GRINS - General Reacting Incompressible Navier-Stokes
//
// Copyright (C) 2010-2013 The PECOS Development Team
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the Version 2.1 GNU Lesser General
// Public License as published by the Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc. 51 Franklin Street, Fifth Floor,
// Boston, MA  02110-1301  USA
//
//-----------------------------------------------------------------------el-

// This class
#include "grins/inc_navier_stokes_bc_handling.h"

// GRINS
#include "grins/parabolic_profile.h"

// libMesh
#include "libmesh/zero_function.h"
#include "libmesh/dirichlet_boundaries.h"
#include "libmesh/dof_map.h"
#include "libmesh/fem_system.h"

namespace GRINS
{

  IncompressibleNavierStokesBCHandling::IncompressibleNavierStokesBCHandling(const std::string& physics_name,
									     const GetPot& input)
    : BCHandlingBase(physics_name),
      _flow_vars(input)
  {
    std::string id_str = "Physics/"+_physics_name+"/bc_ids";
    std::string bc_str = "Physics/"+_physics_name+"/bc_types";
    std::string var_str = "Physics/"+_physics_name+"/bc_variables";
    std::string val_str = "Physics/"+_physics_name+"/bc_values";

    this->read_bc_data( input, id_str, bc_str, var_str, val_str );

    return;
  }

  IncompressibleNavierStokesBCHandling::~IncompressibleNavierStokesBCHandling()
  {
    return;
  }

  int IncompressibleNavierStokesBCHandling::string_to_int( const std::string& bc_type ) const
  {
    int bc_type_out;

    if( bc_type == "no_slip" )
      bc_type_out = NO_SLIP;

    else if( bc_type == "prescribed_vel" )
      bc_type_out = PRESCRIBED_VELOCITY;

    else if( bc_type == "parabolic_profile" )
      bc_type_out = PARABOLIC_PROFILE;

    else if( bc_type == "general_velocity" )
      bc_type_out = GENERAL_VELOCITY;

    else
      {
	// Call base class to detect any physics-common boundary conditions
	bc_type_out = BCHandlingBase::string_to_int( bc_type );
      }

    return bc_type_out;
  }

  void IncompressibleNavierStokesBCHandling::init_bc_data( const libMesh::FEMSystem& system )
  {
    _flow_vars.init(const_cast<libMesh::FEMSystem*>(&system));

    return;
  }

  void IncompressibleNavierStokesBCHandling::init_bc_types( const BoundaryID bc_id,
							    const std::string& bc_id_string,
							    const int bc_type,
					                    const std::string& bc_vars,
							    const std::string& bc_value,
							    const GetPot& input )
  {
    switch(bc_type)
      {
      case(NO_SLIP):
	{
	  this->set_dirichlet_bc_type( bc_id, bc_type );
	}
	break;
      case(PRESCRIBED_VELOCITY):
	{
	  this->set_dirichlet_bc_type( bc_id, bc_type );

	  /* Force the user to specify 3 velocity components regardless of dimension.
	     This should make it easier to keep things correct if we want to have
	     2D flow not be in the x-y plane. */
	  int n_vel_comps = input.vector_variable_size("Physics/"+_physics_name+"/bound_vel_"+bc_id_string);
	  if( n_vel_comps != 3 )
	    {
	      std::cerr << "Error: Must specify 3 velocity components when inputting"
			<< std::endl
			<< "       prescribed velocities. Found " << n_vel_comps
			<< " velocity components."
			<< std::endl;
	      libmesh_error();
	    }

	  this->set_dirichlet_bc_value( bc_id,
					input("Physics/"+_physics_name+"/bound_vel_"+bc_id_string, 0.0, 0 ),
					0 );

	  this->set_dirichlet_bc_value( bc_id,
					input("Physics/"+_physics_name+"/bound_vel_"+bc_id_string, 0.0, 1 ),
					1 );

	  this->set_dirichlet_bc_value( bc_id,
					input("Physics/"+_physics_name+"/bound_vel_"+bc_id_string, 0.0, 2 ),
					2 );
	}
	break;
      case(PARABOLIC_PROFILE):
	{
	  this->set_dirichlet_bc_type( bc_id, bc_type );

	  // Make sure all 6 components are there
	  if( input.vector_variable_size("Physics/"+_physics_name+"/parabolic_profile_coeffs_"+bc_id_string) != 6 )
	    {
	      std::cerr << "Error: Must specify 6 components when inputting"
			<< std::endl
			<< "       coefficients for a parabolic profile. Found "
			<< input.vector_variable_size("Physics/"+_physics_name+"/parabolic_profile_"+bc_id_string)
			<< " components."
			<< std::endl;
	      libmesh_error();
	    }

	  libMesh::Real a = input( "Physics/"+_physics_name+"/parabolic_profile_coeffs_"+bc_id_string, 0.0, 0 );
	  libMesh::Real b = input( "Physics/"+_physics_name+"/parabolic_profile_coeffs_"+bc_id_string, 0.0, 1 );
	  libMesh::Real c = input( "Physics/"+_physics_name+"/parabolic_profile_coeffs_"+bc_id_string, 0.0, 2 );
	  libMesh::Real d = input( "Physics/"+_physics_name+"/parabolic_profile_coeffs_"+bc_id_string, 0.0, 3 );
	  libMesh::Real e = input( "Physics/"+_physics_name+"/parabolic_profile_coeffs_"+bc_id_string, 0.0, 4 );
	  libMesh::Real f = input( "Physics/"+_physics_name+"/parabolic_profile_coeffs_"+bc_id_string, 0.0, 5 );

	  std::string var = input( "Physics/"+_physics_name+"/parabolic_profile_var_"+bc_id_string, "DIE!" );

	  if( var == "DIE!" )
	    {
	      std::cerr << "Error: Mush specify a variable name to which apply parabolic profile through parabolic_profile_var input option." << std::endl;
	      libmesh_error();
	    }

	  DBCContainer cont;
	  cont.add_var_name( var );
	  cont.add_bc_id( bc_id );

	  std::tr1::shared_ptr<libMesh::FunctionBase<libMesh::Number> > func( new ParabolicProfile(a,b,c,d,e,f) );
	  cont.set_func( func );
	  this->attach_dirichlet_bound_func( cont );

	  // Set specified components of Dirichlet data to zero
	  std::string fix_var = input( "Physics/"+_physics_name+"/parabolic_profile_fix_"+bc_id_string, "DIE!" );

	  if( fix_var == "DIE!" )
	    {
	      std::cerr << "Error: Mush specify a variable name to fix for parabolic profile through parabolic_profile_fix input option." << std::endl;
	      libmesh_error();
	    }

	  DBCContainer cont_fix;
	  cont_fix.add_var_name( fix_var );
	  cont_fix.add_bc_id( bc_id );

          std::tr1::shared_ptr<libMesh::FunctionBase<libMesh::Number> >
            func_fix( new libMesh::ZeroFunction<libMesh::Number>() );
	  cont_fix.set_func( func_fix );
	  this->attach_dirichlet_bound_func( cont_fix );
	}
	break;

      case(GENERAL_VELOCITY):
	{
	  this->set_dirichlet_bc_type( bc_id, bc_type );
	}
	break;

      case(AXISYMMETRIC):
        {
	  this->set_dirichlet_bc_type( bc_id, bc_type );
	}
	break;

      default:
	{
	  // Call base class to detect any physics-common boundary conditions
	  BCHandlingBase::init_bc_types( bc_id, bc_id_string, bc_type,
                                         bc_vars, bc_value, input );
	}
      } // End switch(bc_type)

    return;
  }

  void IncompressibleNavierStokesBCHandling::user_init_dirichlet_bcs( libMesh::FEMSystem* system,
								      libMesh::DofMap& dof_map,
								      BoundaryID bc_id,
								      BCType bc_type ) const
  {
    int dim = system->get_mesh().mesh_dimension();

    VariableIndex u_var = _flow_vars.u_var();
    VariableIndex v_var = _flow_vars.v_var();
    VariableIndex w_var = -1;
    if( dim == 3 )
      w_var = _flow_vars.w_var();

    switch( bc_type )
      {
      case(NO_SLIP):
	{
	  std::set<BoundaryID> dbc_ids;
	  dbc_ids.insert(bc_id);

	  std::vector<VariableIndex> dbc_vars;
	  dbc_vars.push_back(u_var);
	  dbc_vars.push_back(v_var);
	  if(dim == 3)
	    dbc_vars.push_back(w_var);

          libMesh::ZeroFunction<libMesh::Number> zero;

	  libMesh::DirichletBoundary no_slip_dbc(dbc_ids,
						 dbc_vars,
						 &zero );

	  dof_map.add_dirichlet_boundary( no_slip_dbc );
	}
	break;
      case(PRESCRIBED_VELOCITY):
	{
	  std::set<BoundaryID> dbc_ids;
	  dbc_ids.insert(bc_id);

	  std::vector<VariableIndex> dbc_vars;

	  // This is inefficient, but it shouldn't matter because
	  // everything gets cached on the libMesh side so it should
	  // only affect performance at startup.
	  {
	    dbc_vars.push_back(u_var);
            libMesh::ConstFunction<libMesh::Number>
              vel_func( this->get_dirichlet_bc_value(bc_id,0) );

	    libMesh::DirichletBoundary vel_dbc(dbc_ids,
					       dbc_vars,
					       &vel_func );

	    dof_map.add_dirichlet_boundary( vel_dbc );
	    dbc_vars.clear();
	  }

	  {
	    dbc_vars.push_back(v_var);
            libMesh::ConstFunction<libMesh::Number>
              vel_func( this->get_dirichlet_bc_value(bc_id,1) );

	    libMesh::DirichletBoundary vel_dbc(dbc_ids,
					       dbc_vars,
					       &vel_func );

	    dof_map.add_dirichlet_boundary( vel_dbc );
	    dbc_vars.clear();
	  }
	  if( dim == 3 )
	    {
	      dbc_vars.push_back(w_var);
              libMesh::ConstFunction<libMesh::Number>
                vel_func( this->get_dirichlet_bc_value(bc_id,2) );

	      libMesh::DirichletBoundary vel_dbc(dbc_ids,
						 dbc_vars,
						 &vel_func );

	      dof_map.add_dirichlet_boundary( vel_dbc );
	    }
	}
	break;
      case(PARABOLIC_PROFILE):
	// This case is handled init_dirichlet_bc_func_objs
	break;

      case(GENERAL_VELOCITY):
	// This case is handled in the init_dirichlet_bc_func_objs
	break;

      case(AXISYMMETRIC):
	{
	  std::set<BoundaryID> dbc_ids;
	  dbc_ids.insert(bc_id);

	  std::vector<VariableIndex> dbc_vars;
	  dbc_vars.push_back(u_var);

          libMesh::ZeroFunction<libMesh::Number> zero;

	  libMesh::DirichletBoundary no_slip_dbc( dbc_ids,
						  dbc_vars,
						  &zero );

	  dof_map.add_dirichlet_boundary( no_slip_dbc );
	}
      break;

      default:
	{
	  std::cerr << "Invalid BCType " << bc_type << std::endl;
	  libmesh_error();
	}

      }// end switch

    return;
  }

} // namespace GRINS
<commit_msg>We can't add z-component of BC if LIBMESH_DIM < 3<commit_after>//-----------------------------------------------------------------------bl-
//--------------------------------------------------------------------------
//
// GRINS - General Reacting Incompressible Navier-Stokes
//
// Copyright (C) 2010-2013 The PECOS Development Team
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the Version 2.1 GNU Lesser General
// Public License as published by the Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc. 51 Franklin Street, Fifth Floor,
// Boston, MA  02110-1301  USA
//
//-----------------------------------------------------------------------el-

// This class
#include "grins/inc_navier_stokes_bc_handling.h"

// GRINS
#include "grins/parabolic_profile.h"

// libMesh
#include "libmesh/zero_function.h"
#include "libmesh/dirichlet_boundaries.h"
#include "libmesh/dof_map.h"
#include "libmesh/fem_system.h"

namespace GRINS
{

  IncompressibleNavierStokesBCHandling::IncompressibleNavierStokesBCHandling(const std::string& physics_name,
									     const GetPot& input)
    : BCHandlingBase(physics_name),
      _flow_vars(input)
  {
    std::string id_str = "Physics/"+_physics_name+"/bc_ids";
    std::string bc_str = "Physics/"+_physics_name+"/bc_types";
    std::string var_str = "Physics/"+_physics_name+"/bc_variables";
    std::string val_str = "Physics/"+_physics_name+"/bc_values";

    this->read_bc_data( input, id_str, bc_str, var_str, val_str );

    return;
  }

  IncompressibleNavierStokesBCHandling::~IncompressibleNavierStokesBCHandling()
  {
    return;
  }

  int IncompressibleNavierStokesBCHandling::string_to_int( const std::string& bc_type ) const
  {
    int bc_type_out;

    if( bc_type == "no_slip" )
      bc_type_out = NO_SLIP;

    else if( bc_type == "prescribed_vel" )
      bc_type_out = PRESCRIBED_VELOCITY;

    else if( bc_type == "parabolic_profile" )
      bc_type_out = PARABOLIC_PROFILE;

    else if( bc_type == "general_velocity" )
      bc_type_out = GENERAL_VELOCITY;

    else
      {
	// Call base class to detect any physics-common boundary conditions
	bc_type_out = BCHandlingBase::string_to_int( bc_type );
      }

    return bc_type_out;
  }

  void IncompressibleNavierStokesBCHandling::init_bc_data( const libMesh::FEMSystem& system )
  {
    _flow_vars.init(const_cast<libMesh::FEMSystem*>(&system));

    return;
  }

  void IncompressibleNavierStokesBCHandling::init_bc_types( const BoundaryID bc_id,
							    const std::string& bc_id_string,
							    const int bc_type,
					                    const std::string& bc_vars,
							    const std::string& bc_value,
							    const GetPot& input )
  {
    switch(bc_type)
      {
      case(NO_SLIP):
	{
	  this->set_dirichlet_bc_type( bc_id, bc_type );
	}
	break;
      case(PRESCRIBED_VELOCITY):
	{
	  this->set_dirichlet_bc_type( bc_id, bc_type );

	  /* Force the user to specify 3 velocity components regardless of dimension.
	     This should make it easier to keep things correct if we want to have
	     2D flow not be in the x-y plane. */
	  int n_vel_comps = input.vector_variable_size("Physics/"+_physics_name+"/bound_vel_"+bc_id_string);
	  if( n_vel_comps != 3 )
	    {
	      std::cerr << "Error: Must specify 3 velocity components when inputting"
			<< std::endl
			<< "       prescribed velocities. Found " << n_vel_comps
			<< " velocity components."
			<< std::endl;
	      libmesh_error();
	    }

	  this->set_dirichlet_bc_value( bc_id,
					input("Physics/"+_physics_name+"/bound_vel_"+bc_id_string, 0.0, 0 ),
					0 );

	  this->set_dirichlet_bc_value( bc_id,
					input("Physics/"+_physics_name+"/bound_vel_"+bc_id_string, 0.0, 1 ),
					1 );

#if LIBMESH_DIM > 2
	  this->set_dirichlet_bc_value( bc_id,
					input("Physics/"+_physics_name+"/bound_vel_"+bc_id_string, 0.0, 2 ),
					2 );
#endif
	}
	break;
      case(PARABOLIC_PROFILE):
	{
	  this->set_dirichlet_bc_type( bc_id, bc_type );

	  // Make sure all 6 components are there
	  if( input.vector_variable_size("Physics/"+_physics_name+"/parabolic_profile_coeffs_"+bc_id_string) != 6 )
	    {
	      std::cerr << "Error: Must specify 6 components when inputting"
			<< std::endl
			<< "       coefficients for a parabolic profile. Found "
			<< input.vector_variable_size("Physics/"+_physics_name+"/parabolic_profile_"+bc_id_string)
			<< " components."
			<< std::endl;
	      libmesh_error();
	    }

	  libMesh::Real a = input( "Physics/"+_physics_name+"/parabolic_profile_coeffs_"+bc_id_string, 0.0, 0 );
	  libMesh::Real b = input( "Physics/"+_physics_name+"/parabolic_profile_coeffs_"+bc_id_string, 0.0, 1 );
	  libMesh::Real c = input( "Physics/"+_physics_name+"/parabolic_profile_coeffs_"+bc_id_string, 0.0, 2 );
	  libMesh::Real d = input( "Physics/"+_physics_name+"/parabolic_profile_coeffs_"+bc_id_string, 0.0, 3 );
	  libMesh::Real e = input( "Physics/"+_physics_name+"/parabolic_profile_coeffs_"+bc_id_string, 0.0, 4 );
	  libMesh::Real f = input( "Physics/"+_physics_name+"/parabolic_profile_coeffs_"+bc_id_string, 0.0, 5 );

	  std::string var = input( "Physics/"+_physics_name+"/parabolic_profile_var_"+bc_id_string, "DIE!" );

	  if( var == "DIE!" )
	    {
	      std::cerr << "Error: Mush specify a variable name to which apply parabolic profile through parabolic_profile_var input option." << std::endl;
	      libmesh_error();
	    }

	  DBCContainer cont;
	  cont.add_var_name( var );
	  cont.add_bc_id( bc_id );

	  std::tr1::shared_ptr<libMesh::FunctionBase<libMesh::Number> > func( new ParabolicProfile(a,b,c,d,e,f) );
	  cont.set_func( func );
	  this->attach_dirichlet_bound_func( cont );

	  // Set specified components of Dirichlet data to zero
	  std::string fix_var = input( "Physics/"+_physics_name+"/parabolic_profile_fix_"+bc_id_string, "DIE!" );

	  if( fix_var == "DIE!" )
	    {
	      std::cerr << "Error: Mush specify a variable name to fix for parabolic profile through parabolic_profile_fix input option." << std::endl;
	      libmesh_error();
	    }

	  DBCContainer cont_fix;
	  cont_fix.add_var_name( fix_var );
	  cont_fix.add_bc_id( bc_id );

          std::tr1::shared_ptr<libMesh::FunctionBase<libMesh::Number> >
            func_fix( new libMesh::ZeroFunction<libMesh::Number>() );
	  cont_fix.set_func( func_fix );
	  this->attach_dirichlet_bound_func( cont_fix );
	}
	break;

      case(GENERAL_VELOCITY):
	{
	  this->set_dirichlet_bc_type( bc_id, bc_type );
	}
	break;

      case(AXISYMMETRIC):
        {
	  this->set_dirichlet_bc_type( bc_id, bc_type );
	}
	break;

      default:
	{
	  // Call base class to detect any physics-common boundary conditions
	  BCHandlingBase::init_bc_types( bc_id, bc_id_string, bc_type,
                                         bc_vars, bc_value, input );
	}
      } // End switch(bc_type)

    return;
  }

  void IncompressibleNavierStokesBCHandling::user_init_dirichlet_bcs( libMesh::FEMSystem* system,
								      libMesh::DofMap& dof_map,
								      BoundaryID bc_id,
								      BCType bc_type ) const
  {
    int dim = system->get_mesh().mesh_dimension();

    VariableIndex u_var = _flow_vars.u_var();
    VariableIndex v_var = _flow_vars.v_var();
    VariableIndex w_var = -1;
    if( dim == 3 )
      w_var = _flow_vars.w_var();

    switch( bc_type )
      {
      case(NO_SLIP):
	{
	  std::set<BoundaryID> dbc_ids;
	  dbc_ids.insert(bc_id);

	  std::vector<VariableIndex> dbc_vars;
	  dbc_vars.push_back(u_var);
	  dbc_vars.push_back(v_var);
	  if(dim == 3)
	    dbc_vars.push_back(w_var);

          libMesh::ZeroFunction<libMesh::Number> zero;

	  libMesh::DirichletBoundary no_slip_dbc(dbc_ids,
						 dbc_vars,
						 &zero );

	  dof_map.add_dirichlet_boundary( no_slip_dbc );
	}
	break;
      case(PRESCRIBED_VELOCITY):
	{
	  std::set<BoundaryID> dbc_ids;
	  dbc_ids.insert(bc_id);

	  std::vector<VariableIndex> dbc_vars;

	  // This is inefficient, but it shouldn't matter because
	  // everything gets cached on the libMesh side so it should
	  // only affect performance at startup.
	  {
	    dbc_vars.push_back(u_var);
            libMesh::ConstFunction<libMesh::Number>
              vel_func( this->get_dirichlet_bc_value(bc_id,0) );

	    libMesh::DirichletBoundary vel_dbc(dbc_ids,
					       dbc_vars,
					       &vel_func );

	    dof_map.add_dirichlet_boundary( vel_dbc );
	    dbc_vars.clear();
	  }

	  {
	    dbc_vars.push_back(v_var);
            libMesh::ConstFunction<libMesh::Number>
              vel_func( this->get_dirichlet_bc_value(bc_id,1) );

	    libMesh::DirichletBoundary vel_dbc(dbc_ids,
					       dbc_vars,
					       &vel_func );

	    dof_map.add_dirichlet_boundary( vel_dbc );
	    dbc_vars.clear();
	  }
	  if( dim == 3 )
	    {
	      dbc_vars.push_back(w_var);
              libMesh::ConstFunction<libMesh::Number>
                vel_func( this->get_dirichlet_bc_value(bc_id,2) );

	      libMesh::DirichletBoundary vel_dbc(dbc_ids,
						 dbc_vars,
						 &vel_func );

	      dof_map.add_dirichlet_boundary( vel_dbc );
	    }
	}
	break;
      case(PARABOLIC_PROFILE):
	// This case is handled init_dirichlet_bc_func_objs
	break;

      case(GENERAL_VELOCITY):
	// This case is handled in the init_dirichlet_bc_func_objs
	break;

      case(AXISYMMETRIC):
	{
	  std::set<BoundaryID> dbc_ids;
	  dbc_ids.insert(bc_id);

	  std::vector<VariableIndex> dbc_vars;
	  dbc_vars.push_back(u_var);

          libMesh::ZeroFunction<libMesh::Number> zero;

	  libMesh::DirichletBoundary no_slip_dbc( dbc_ids,
						  dbc_vars,
						  &zero );

	  dof_map.add_dirichlet_boundary( no_slip_dbc );
	}
      break;

      default:
	{
	  std::cerr << "Invalid BCType " << bc_type << std::endl;
	  libmesh_error();
	}

      }// end switch

    return;
  }

} // namespace GRINS
<|endoftext|>


<commit_before>#pragma once

#include <sstream>
#include <string>

#include "blackhole/attribute.hpp"
#include "blackhole/error.hpp"
#include "blackhole/formatter/map/value.hpp"

namespace blackhole {

namespace formatter {

namespace string {

static const char VARIADIC_KEY_PREFIX[] = "...";
static const std::size_t VARIADIC_KEY_PRFFIX_LENGTH = std::strlen(VARIADIC_KEY_PREFIX);

namespace builder {

struct variadic_t {
    typedef log::attribute::scope_underlying_type scope_underlying_type;

    const std::string placeholder;

    void operator ()(std::ostringstream& stream, const mapping::value_t&, const log::attributes_t& attributes) const {
        for (auto pit = placeholder.begin() + string::VARIADIC_KEY_PRFFIX_LENGTH; pit != placeholder.end(); ++pit) {
            const scope_underlying_type scope = *pit - '0';

            for (auto it = attributes.begin(); it != attributes.end(); it++) {
                const std::string& name = it->first;
                const log::attribute_t& attribute = it->second;
                if (static_cast<scope_underlying_type>(attribute.scope) & scope) {
                    //!@todo: Implement visitor to properly format int attributes (without quotes).
                    if (it != attributes.begin()) {
                        stream << ", ";
                    }
                    stream << "'" << name << "': '" << attribute.value << "'";
                }
            }
        }
    }
};

} // namespace builder

} // namespace string

} // namespace formatter

} // namespace blackhole
<commit_msg>Returning proper variadic joiner algorithm.<commit_after>#pragma once

#include <sstream>
#include <string>

#include <boost/algorithm/string.hpp>

#include "blackhole/attribute.hpp"
#include "blackhole/error.hpp"
#include "blackhole/formatter/map/value.hpp"

namespace blackhole {

namespace formatter {

namespace string {

static const char VARIADIC_KEY_PREFIX[] = "...";
static const std::size_t VARIADIC_KEY_PRFFIX_LENGTH = std::strlen(VARIADIC_KEY_PREFIX);

namespace builder {

struct variadic_t {
    typedef log::attribute::scope_underlying_type scope_underlying_type;

    const std::string placeholder;

    void operator ()(std::ostringstream& stream, const mapping::value_t&, const log::attributes_t& attributes) const {
        std::vector<std::string> passed;
        passed.reserve(attributes.size());

        for (auto pit = placeholder.begin() + string::VARIADIC_KEY_PRFFIX_LENGTH; pit != placeholder.end(); ++pit) {
            const scope_underlying_type scope = *pit - '0';

            for (auto it = attributes.begin(); it != attributes.end(); it++) {
                const std::string& name = it->first;
                const log::attribute_t& attribute = it->second;
                if (static_cast<scope_underlying_type>(attribute.scope) & scope) {
                    //!@todo: Implement visitor to properly format int attributes (without quotes).
                    std::ostringstream stream;
                    stream << "'" << name << "': '" << attribute.value << "'";
                    passed.push_back(stream.str());
                }
            }
        }
        stream << boost::algorithm::join(passed, ", ");
    }
};

} // namespace builder

} // namespace string

} // namespace formatter

} // namespace blackhole
<|endoftext|>