<commit_before>/*
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 1999 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Xerces" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact apache\@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation, and was
 * originally based on software copyright (c) 1999, International
 * Business Machines, Inc., http://www.ibm.com .  For more information
 * on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */

/**
 * $Log$
 * Revision 1.2  1999/12/23 01:43:37  aruna1
 * MsgCatalog support added for solaris
 *
 * Revision 1.1.1.1  1999/11/09 01:07:16  twl
 * Initial checkin
 *
 * Revision 1.2  1999/11/08 20:45:27  rahul
 * Swat for adding in Product name and CVS comment log variable.
 *
 */

// ---------------------------------------------------------------------------
//  Includes
// ---------------------------------------------------------------------------
#include <util/XML4CDefs.hpp>
#include <util/PlatformUtils.hpp>
#include <util/XMLMsgLoader.hpp>
#include <util/XMLString.hpp>
#include <util/XMLUni.hpp>
#include "MsgCatalogLoader.hpp"

#include <locale.h>
#include <stdlib.h>
#include <stdio.h>

// ---------------------------------------------------------------------------
//  Public Constructors and Destructor
// ---------------------------------------------------------------------------
MsgCatalogLoader::MsgCatalogLoader(const XMLCh* const msgDomain) :

    fCatalogHandle(0)
    , fMsgDomain(0)
{
    // Try to get the module handle
	char* tempLoc = setlocale(LC_ALL, "");
    char catfile[256];
    if (XMLPlatformUtils::fgLibLocation) {
        strcpy(catfile, XMLPlatformUtils::fgLibLocation);
        strcat(catfile, "/msg/");
        strcat(catfile, "XMLMessages.cat");
    }
	fCatalogHandle = catopen(catfile , 0);
    if ((int)fCatalogHandle == -1)
    {
        // Probably have to call panic here
		printf("Could not open catalog XMLMessages\n");
		// TBD: Tell user what the locale is
		exit(1);
    }

    fMsgDomain = XMLString::replicate(msgDomain);
}

MsgCatalogLoader::~MsgCatalogLoader()
{
    if (fCatalogHandle)
	catclose( fCatalogHandle );
    delete fMsgDomain;
}

// ---------------------------------------------------------------------------
//  Implementation of the virtual message loader API
// ---------------------------------------------------------------------------
bool MsgCatalogLoader::loadMsg(const  XMLMsgLoader::XMLMsgId  msgToLoad
                            ,       XMLCh* const            toFill
                            , const unsigned long           maxChars)
{
    int msgSet = 1;
    if (!XMLString::compareString(fMsgDomain, XMLUni::fgXMLErrDomain))
        msgSet = 1;
    else if (!XMLString::compareString(fMsgDomain, XMLUni::fgExceptDomain))
        msgSet = 2;
    else if (!XMLString::compareString(fMsgDomain, XMLUni::fgValidityDomain))
        msgSet = 3;

    char msgString[100];
    sprintf(msgString, "Could not find message ID %d from message set %d\n", msgToLoad, msgSet);
    char* catMessage = catgets( fCatalogHandle, msgSet, (int)msgToLoad, msgString);
    XMLString::copyString((XMLCh*)toFill,  XMLString::transcode(catMessage));

    return true;
}

bool MsgCatalogLoader::loadMsg(const  XMLMsgLoader::XMLMsgId  msgToLoad
                            ,       XMLCh* const            toFill
                            , const unsigned long           maxChars
                            , const XMLCh* const            repText1
                            , const XMLCh* const            repText2
                            , const XMLCh* const            repText3
                            , const XMLCh* const            repText4)
{
    // Call the other version to load up the message
    if (!loadMsg(msgToLoad, toFill, maxChars))
        return false;

    // And do the token replacement
    XMLString::replaceTokens(toFill, maxChars, repText1, repText2, repText3, repText4);
    return true;
}

bool MsgCatalogLoader::loadMsg(const  XMLMsgLoader::XMLMsgId  msgToLoad
                            ,       XMLCh* const            toFill
                            , const unsigned long           maxChars
                            , const char* const             repText1
                            , const char* const             repText2
                            , const char* const             repText3
                            , const char* const             repText4)
{
    //
    //  Transcode the provided parameters and call the other version,
    //  which will do the replacement work.
    //
    XMLCh* tmp1 = 0;
    XMLCh* tmp2 = 0;
    XMLCh* tmp3 = 0;
    XMLCh* tmp4 = 0;

    bool bRet = false;
    if (repText1)
        tmp1 = XMLString::transcode(repText1);
    if (repText2)
        tmp2 = XMLString::transcode(repText2);
    if (repText3)
        tmp3 = XMLString::transcode(repText3);
    if (repText4)
        tmp4 = XMLString::transcode(repText4);

    bRet = loadMsg(msgToLoad, toFill, maxChars, tmp1, tmp2, tmp3, tmp4);

    if (tmp1)
        delete [] tmp1;
    if (tmp2)
        delete [] tmp2;
    if (tmp3)
        delete [] tmp3;
    if (tmp4)
        delete [] tmp4;

    return bRet;
}
<commit_msg>Modified message 'set' attribute reading sequence. Removed dependencies on  hard coded constants<commit_after>/*
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 1999 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Xerces" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact apache\@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation, and was
 * originally based on software copyright (c) 1999, International
 * Business Machines, Inc., http://www.ibm.com .  For more information
 * on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */

/**
 * $Log$
 * Revision 1.3  2000/01/05 22:00:22  aruna1
 * Modified message 'set' attribute reading sequence. Removed dependencies on  hard coded constants
 *
 * Revision 1.2  1999/12/23 01:43:37  aruna1
 * MsgCatalog support added for solaris
 *
 * Revision 1.1.1.1  1999/11/09 01:07:16  twl
 * Initial checkin
 *
 * Revision 1.2  1999/11/08 20:45:27  rahul
 * Swat for adding in Product name and CVS comment log variable.
 *
 */

// ---------------------------------------------------------------------------
//  Includes
// ---------------------------------------------------------------------------
#include <util/XML4CDefs.hpp>
#include <util/PlatformUtils.hpp>
#include <util/XMLMsgLoader.hpp>
#include <util/XMLString.hpp>
#include <util/XMLUni.hpp>
#include "MsgCatalogLoader.hpp"
#include "XMLMsgCat_Ids.hpp"

#include <locale.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

// ---------------------------------------------------------------------------
//  Public Constructors and Destructor
// ---------------------------------------------------------------------------
MsgCatalogLoader::MsgCatalogLoader(const XMLCh* const msgDomain) :

    fCatalogHandle(0)
    , fMsgDomain(0)
{
    // Try to get the module handle
	char* tempLoc = setlocale(LC_ALL, "");
    char catfile[256];
    if (XMLPlatformUtils::fgLibLocation) {
        strcpy(catfile, XMLPlatformUtils::fgLibLocation);
        strcat(catfile, "/msg/");
        strcat(catfile, "XMLMessages.cat");
    }
	fCatalogHandle = catopen(catfile , 0);
    if ((int)fCatalogHandle == -1)
    {
        // Probably have to call panic here
		printf("Could not open catalog XMLMessages\n");
		// TBD: Tell user what the locale is
		exit(1);
    }

    fMsgDomain = XMLString::replicate(msgDomain);
}

MsgCatalogLoader::~MsgCatalogLoader()
{
    if (fCatalogHandle)
	catclose( fCatalogHandle );
    delete fMsgDomain;
}

// ---------------------------------------------------------------------------
//  Implementation of the virtual message loader API
// ---------------------------------------------------------------------------
bool MsgCatalogLoader::loadMsg(const  XMLMsgLoader::XMLMsgId  msgToLoad
                            ,       XMLCh* const            toFill
                            , const unsigned long           maxChars)
{
    int msgSet = CatId_XML4CErrs;
    if (!XMLString::compareString(fMsgDomain, XMLUni::fgXMLErrDomain))
        msgSet = CatId_XML4CErrs;
    else if (!XMLString::compareString(fMsgDomain, XMLUni::fgExceptDomain))
        msgSet = CatId_XML4CExcepts;
    else if (!XMLString::compareString(fMsgDomain, XMLUni::fgValidityDomain))
        msgSet = CatId_XML4CValid;

    char msgString[100];
    sprintf(msgString, "Could not find message ID %d from message set %d\n", msgToLoad, msgSet);
    char* catMessage = catgets( fCatalogHandle, msgSet, (int)msgToLoad, msgString);
    XMLString::copyString((XMLCh*)toFill,  XMLString::transcode(catMessage));

    return true;
}

bool MsgCatalogLoader::loadMsg(const  XMLMsgLoader::XMLMsgId  msgToLoad
                            ,       XMLCh* const            toFill
                            , const unsigned long           maxChars
                            , const XMLCh* const            repText1
                            , const XMLCh* const            repText2
                            , const XMLCh* const            repText3
                            , const XMLCh* const            repText4)
{
    // Call the other version to load up the message
    if (!loadMsg(msgToLoad, toFill, maxChars))
        return false;

    // And do the token replacement
    XMLString::replaceTokens(toFill, maxChars, repText1, repText2, repText3, repText4);
    return true;
}

bool MsgCatalogLoader::loadMsg(const  XMLMsgLoader::XMLMsgId  msgToLoad
                            ,       XMLCh* const            toFill
                            , const unsigned long           maxChars
                            , const char* const             repText1
                            , const char* const             repText2
                            , const char* const             repText3
                            , const char* const             repText4)
{
    //
    //  Transcode the provided parameters and call the other version,
    //  which will do the replacement work.
    //
    XMLCh* tmp1 = 0;
    XMLCh* tmp2 = 0;
    XMLCh* tmp3 = 0;
    XMLCh* tmp4 = 0;

    bool bRet = false;
    if (repText1)
        tmp1 = XMLString::transcode(repText1);
    if (repText2)
        tmp2 = XMLString::transcode(repText2);
    if (repText3)
        tmp3 = XMLString::transcode(repText3);
    if (repText4)
        tmp4 = XMLString::transcode(repText4);

    bRet = loadMsg(msgToLoad, toFill, maxChars, tmp1, tmp2, tmp3, tmp4);

    if (tmp1)
        delete [] tmp1;
    if (tmp2)
        delete [] tmp2;
    if (tmp3)
        delete [] tmp3;
    if (tmp4)
        delete [] tmp4;

    return bRet;
}
<|endoftext|>


<commit_before>/*
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 2001 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Xerces" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact apache\@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation, and was
 * originally based on software copyright (c) 2001, International
 * Business Machines, Inc., http://www.ibm.com .  For more information
 * on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */

/*
 * $Log$
 * Revision 1.3  2001/05/11 13:27:17  tng
 * Copyright update.
 *
 * Revision 1.2  2001/04/19 18:17:28  tng
 * Schema: SchemaValidator update, and use QName in Content Model
 *
 * Revision 1.1  2001/02/27 14:48:49  tng
 * Schema: Add CMAny and ContentLeafNameTypeVector, by Pei Yong Zhang
 *
 */

#if !defined(CONTENTLEAFNAMETYPEVECTOR_HPP)
#define CONTENTLEAFNAMETYPEVECTOR_HPP

#include <util/XercesDefs.hpp>
#include <util/ValueVectorOf.hpp>
#include <validators/common/ContentSpecNode.hpp>

class ContentLeafNameTypeVector
{
public :
    // -----------------------------------------------------------------------
    //  Class specific types
    // -----------------------------------------------------------------------

    // -----------------------------------------------------------------------
    //  Constructors and Destructor
    // -----------------------------------------------------------------------
    ContentLeafNameTypeVector();
    ContentLeafNameTypeVector
    (
        QName** const                      qName
      , ContentSpecNode::NodeTypes* const  types
      , const unsigned int                       count
    );

    ~ContentLeafNameTypeVector();

    ContentLeafNameTypeVector(const ContentLeafNameTypeVector&);

    // -----------------------------------------------------------------------
    //  Getter methods
    // -----------------------------------------------------------------------
    QName* getLeafNameAt(const unsigned int pos) const;

    const ContentSpecNode::NodeTypes getLeafTypeAt(const unsigned int pos) const;
    const unsigned int getLeafCount() const;

    // -----------------------------------------------------------------------
    //  Setter methods
    // -----------------------------------------------------------------------
    void setValues
    (
        QName** const                      qName
      , ContentSpecNode::NodeTypes* const  types
      , const unsigned int                       count
    );

    // -----------------------------------------------------------------------
    //  Miscellaneous
    // -----------------------------------------------------------------------

private :
    // -----------------------------------------------------------------------
    //  Unimplemented constructors and operators
    // -----------------------------------------------------------------------
    void operator=(const ContentLeafNameTypeVector&);

    // -----------------------------------------------------------------------
    //  helper methods
    // -----------------------------------------------------------------------
    void cleanUp();
    void init(const unsigned int);

    // -----------------------------------------------------------------------
    //  Private Data Members
    //
    // -----------------------------------------------------------------------
    QName**                       fLeafNames;
    ContentSpecNode::NodeTypes   *fLeafTypes;
    unsigned int                  fLeafCount;
};

inline void ContentLeafNameTypeVector::cleanUp()
{
	delete [] fLeafNames;
	delete [] fLeafTypes;
}

inline void ContentLeafNameTypeVector::init(const unsigned int size)
{
	fLeafNames = new QName*[size];
	fLeafTypes = new ContentSpecNode::NodeTypes [size];
}

#endif
<commit_msg>The value of 'fLeafCount' was not set.<commit_after>/*
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 2001 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Xerces" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact apache\@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation, and was
 * originally based on software copyright (c) 2001, International
 * Business Machines, Inc., http://www.ibm.com .  For more information
 * on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */

/*
 * $Log$
 * Revision 1.4  2001/08/07 15:21:20  knoaman
 * The value of 'fLeafCount' was not set.
 *
 * Revision 1.3  2001/05/11 13:27:17  tng
 * Copyright update.
 *
 * Revision 1.2  2001/04/19 18:17:28  tng
 * Schema: SchemaValidator update, and use QName in Content Model
 *
 * Revision 1.1  2001/02/27 14:48:49  tng
 * Schema: Add CMAny and ContentLeafNameTypeVector, by Pei Yong Zhang
 *
 */

#if !defined(CONTENTLEAFNAMETYPEVECTOR_HPP)
#define CONTENTLEAFNAMETYPEVECTOR_HPP

#include <util/XercesDefs.hpp>
#include <util/ValueVectorOf.hpp>
#include <validators/common/ContentSpecNode.hpp>

class ContentLeafNameTypeVector
{
public :
    // -----------------------------------------------------------------------
    //  Class specific types
    // -----------------------------------------------------------------------

    // -----------------------------------------------------------------------
    //  Constructors and Destructor
    // -----------------------------------------------------------------------
    ContentLeafNameTypeVector();
    ContentLeafNameTypeVector
    (
        QName** const                      qName
      , ContentSpecNode::NodeTypes* const  types
      , const unsigned int                       count
    );

    ~ContentLeafNameTypeVector();

    ContentLeafNameTypeVector(const ContentLeafNameTypeVector&);

    // -----------------------------------------------------------------------
    //  Getter methods
    // -----------------------------------------------------------------------
    QName* getLeafNameAt(const unsigned int pos) const;

    const ContentSpecNode::NodeTypes getLeafTypeAt(const unsigned int pos) const;
    const unsigned int getLeafCount() const;

    // -----------------------------------------------------------------------
    //  Setter methods
    // -----------------------------------------------------------------------
    void setValues
    (
        QName** const                      qName
      , ContentSpecNode::NodeTypes* const  types
      , const unsigned int                       count
    );

    // -----------------------------------------------------------------------
    //  Miscellaneous
    // -----------------------------------------------------------------------

private :
    // -----------------------------------------------------------------------
    //  Unimplemented constructors and operators
    // -----------------------------------------------------------------------
    void operator=(const ContentLeafNameTypeVector&);

    // -----------------------------------------------------------------------
    //  helper methods
    // -----------------------------------------------------------------------
    void cleanUp();
    void init(const unsigned int);

    // -----------------------------------------------------------------------
    //  Private Data Members
    //
    // -----------------------------------------------------------------------
    QName**                       fLeafNames;
    ContentSpecNode::NodeTypes   *fLeafTypes;
    unsigned int                  fLeafCount;
};

inline void ContentLeafNameTypeVector::cleanUp()
{
	delete [] fLeafNames;
	delete [] fLeafTypes;
}

inline void ContentLeafNameTypeVector::init(const unsigned int size)
{
	fLeafNames = new QName*[size];
	fLeafTypes = new ContentSpecNode::NodeTypes [size];
	fLeafCount = size;
}

#endif
<|endoftext|>


<commit_before>/******* COPYRIGHT ************************************************
*                                                                 *
*                         FlowVR Render                           *
*                   Parallel Rendering Modules                    *
*                                                                 *
*-----------------------------------------------------------------*
* COPYRIGHT (C) 2005 by                                           *
* Laboratoire Informatique et Distribution (UMR5132) and          *
* INRIA Project MOVI. ALL RIGHTS RESERVED.                        *
*                                                                 *
* This source is covered by the GNU GPL, please refer to the      *
* COPYING file for further information.                           *
*                                                                 *
*-----------------------------------------------------------------*
*                                                                 *
*  Original Contributors:                                         *
*    Jeremie Allard,                                              *
*    Clement Menier.                                              *
*                                                                 *
*******************************************************************
*                                                                 *
* File: ./src/utils/meshconv.cpp                                  *
*                                                                 *
* Contacts:                                                       *
*                                                                 *
******************************************************************/
#include <math.h>
#include <stdlib.h>
#include <stdio.h>

#include <ftl/cmdline.h>
#include <flowvr/render/mesh.h>

using namespace flowvr::render;

int main(int argc, char** argv)
{
    bool normalize = false;
    bool flip = false;
    bool wnormals = false;
    bool rnormals = false;
    bool rtexcoords = false;
    bool closemesh = false;
    Vec3f translation;
    Vec3f rotation;
    Vec3f scale(1,1,1);
    ftl::CmdLine cmd("Usage: meshconv [options] mesh.input [mesh.output]");
    cmd.opt("normalize",'n',"transform points so that the center is at <0,0,0> and the max coodinate is 1",&normalize);
    cmd.opt("flip",'f',"flip normals",&flip);
    cmd.opt("wnormals",'N',"force writing of normals",&wnormals);
    cmd.opt("rnormals",'O',"remove normals",&rnormals);
    cmd.opt("rtexcoords",'T',"remove texcoords",&rtexcoords);
    cmd.opt("close",'c',"close mesh",&closemesh);
    cmd.opt("translate",'t',"translate the mesh",&translation);
    cmd.opt("rotate",'r',"rotate the mesh using euler angles in degree",&rotation);
    cmd.opt("scale",'s',"scale the mesh using 3 coefficients",&scale);
    bool error=false;
    if (!cmd.parse(argc,argv,&error))
        return error?1:0;

    if (cmd.args.size()<1 || cmd.args.size()>2)
    {
        std::cerr << cmd.help() << std::endl;
        return 1;
    }

    std::string file_in = cmd.args[0];
    std::string file_out;
    if (cmd.args.size()>=2) file_out = cmd.args[1];

    Mesh obj;

    if (!obj.load(file_in.c_str()))
    {
        std::cerr << "Failed to read "<<file_in<<std::endl;
        return 1;
    }

    if (normalize)
    {
        BBox bb = obj.calcBBox();
        std::cout << "Mesh bbox="<<bb<<std::endl;
        std::cout << "Normalizing mesh..."<<std::endl;
        float size = 0;
        for (int i=0; i<3; i++)
        {
            float d = bb.b[i]-bb.a[i];
            if (d>size) size=d;
        }
        Vec3f center = (bb.a+bb.b)*0.5;
        float sc = 2/size;
        Mat4x4f m; m.identity();
        m(0,0)=sc; m(0,3) = -center[0]*sc;
        m(1,1)=sc; m(1,3) = -center[1]*sc;
        m(2,2)=sc; m(2,3) = -center[2]*sc;
        for (int i=0; i<obj.nbp(); i++)
            obj.PP(i) = transform(m,obj.getPP(i));
    }

    if (scale != Vec3f(1,1,1))
    {
        std::cout << "Scaling mesh..."<<std::endl;
        for (int i=0; i<obj.nbp(); i++)
        {
            Vec3f p = obj.getPP(i);
            p[0] *= scale[0];
            p[1] *= scale[1];
            p[2] *= scale[2];
            obj.PP(i) = p;
        }
    }

    if (rotation != Vec3f(0,0,0))
    {
        std::cout << "Rotating mesh..."<<std::endl;
        Mat3x3f mat;
        Quat qx,qy,qz;
        qx.fromDegreeAngAxis(rotation[0],Vec3f(1,0,0));
        qy.fromDegreeAngAxis(rotation[1],Vec3f(0,1,0));
        qz.fromDegreeAngAxis(rotation[2],Vec3f(0,0,1));
        Quat q = qx*qy*qz;
        q.toMatrix(&mat);
        for (int i=0; i<obj.nbp(); i++)
        {
            obj.PP(i) = mat*obj.getPP(i);
            obj.PN(i) = mat*obj.getPN(i);
        }
    }

    if (translation != Vec3f(0,0,0))
    {
        std::cout << "Translating mesh..."<<std::endl;
        for (int i=0; i<obj.nbp(); i++)
        {
            obj.PP(i) = obj.getPP(i) + translation;
        }
    }

    std::cout << "Mesh bbox="<<obj.calcBBox()<<std::endl;
    if (flip)
    {
        std::cout << "Flipping mesh..."<<std::endl;
        obj.flipAll();
        //obj.calcFlip();
    }
    if (closemesh)
    {
        bool closed = obj.isClosed();
        std::cout << "Mesh is "<<(closed?"":"NOT ")<<"closed."<<std::endl;
        if (!closed)
        {
            obj.calcFlip();
            std::cout << "Closing mesh..."<<std::endl;
            obj.close();
            std::cout << "Mesh is "<<(obj.isClosed()?"":"NOT ")<<"closed."<<std::endl;
        }
    }
    if (wnormals)
        obj.setAttrib(Mesh::MESH_POINTS_NORMAL,true);
    if (rnormals)
        obj.setAttrib(Mesh::MESH_POINTS_NORMAL,false);
    if (rtexcoords)
        obj.setAttrib(Mesh::MESH_POINTS_TEXCOORD,false);
    if (!file_out.empty())
    {
        std::cout << "Saving result..."<<std::endl;
        obj.save(file_out.c_str());
    }
    return 0;
}
<commit_msg>r1554/sofa-dev : ADD dilate option (-d) in meshconv<commit_after>/******* COPYRIGHT ************************************************
*                                                                 *
*                         FlowVR Render                           *
*                   Parallel Rendering Modules                    *
*                                                                 *
*-----------------------------------------------------------------*
* COPYRIGHT (C) 2005 by                                           *
* Laboratoire Informatique et Distribution (UMR5132) and          *
* INRIA Project MOVI. ALL RIGHTS RESERVED.                        *
*                                                                 *
* This source is covered by the GNU GPL, please refer to the      *
* COPYING file for further information.                           *
*                                                                 *
*-----------------------------------------------------------------*
*                                                                 *
*  Original Contributors:                                         *
*    Jeremie Allard,                                              *
*    Clement Menier.                                              *
*                                                                 *
*******************************************************************
*                                                                 *
* File: ./src/utils/meshconv.cpp                                  *
*                                                                 *
* Contacts:                                                       *
*                                                                 *
******************************************************************/
#include <math.h>
#include <stdlib.h>
#include <stdio.h>

#include <ftl/cmdline.h>
#include <flowvr/render/mesh.h>

using namespace flowvr::render;

int main(int argc, char** argv)
{
    bool normalize = false;
    bool flip = false;
    bool wnormals = false;
    bool rnormals = false;
    bool rtexcoords = false;
    bool closemesh = false;
    Vec3f translation;
    Vec3f rotation;
    Vec3f scale(1,1,1);
    float dilate = 0.0f;
    ftl::CmdLine cmd("Usage: meshconv [options] mesh.input [mesh.output]");
    cmd.opt("normalize",'n',"transform points so that the center is at <0,0,0> and the max coodinate is 1",&normalize);
    cmd.opt("flip",'f',"flip normals",&flip);
    cmd.opt("wnormals",'N',"force writing of normals",&wnormals);
    cmd.opt("rnormals",'O',"remove normals",&rnormals);
    cmd.opt("rtexcoords",'T',"remove texcoords",&rtexcoords);
    cmd.opt("close",'c',"close mesh",&closemesh);
    cmd.opt("translate",'t',"translate the mesh",&translation);
    cmd.opt("rotate",'r',"rotate the mesh using euler angles in degree",&rotation);
    cmd.opt("scale",'s',"scale the mesh using 3 coefficients",&scale);
    cmd.opt("dilate",'d',"dilate (i.e. displace vertices of the given distance along their normals)",&dilate);
    bool error=false;
    if (!cmd.parse(argc,argv,&error))
        return error?1:0;

    if (cmd.args.size()<1 || cmd.args.size()>2)
    {
        std::cerr << cmd.help() << std::endl;
        return 1;
    }

    std::string file_in = cmd.args[0];
    std::string file_out;
    if (cmd.args.size()>=2) file_out = cmd.args[1];

    Mesh obj;

    if (!obj.load(file_in.c_str()))
    {
        std::cerr << "Failed to read "<<file_in<<std::endl;
        return 1;
    }

    if (normalize)
    {
        BBox bb = obj.calcBBox();
        std::cout << "Mesh bbox="<<bb<<std::endl;
        std::cout << "Normalizing mesh..."<<std::endl;
        float size = 0;
        for (int i=0; i<3; i++)
        {
            float d = bb.b[i]-bb.a[i];
            if (d>size) size=d;
        }
        Vec3f center = (bb.a+bb.b)*0.5;
        float sc = 2/size;
        Mat4x4f m; m.identity();
        m(0,0)=sc; m(0,3) = -center[0]*sc;
        m(1,1)=sc; m(1,3) = -center[1]*sc;
        m(2,2)=sc; m(2,3) = -center[2]*sc;
        for (int i=0; i<obj.nbp(); i++)
            obj.PP(i) = transform(m,obj.getPP(i));
    }

    if (scale != Vec3f(1,1,1))
    {
        std::cout << "Scaling mesh..."<<std::endl;
        for (int i=0; i<obj.nbp(); i++)
        {
            Vec3f p = obj.getPP(i);
            p[0] *= scale[0];
            p[1] *= scale[1];
            p[2] *= scale[2];
            obj.PP(i) = p;
        }
    }

    if (rotation != Vec3f(0,0,0))
    {
        std::cout << "Rotating mesh..."<<std::endl;
        Mat3x3f mat;
        Quat qx,qy,qz;
        qx.fromDegreeAngAxis(rotation[0],Vec3f(1,0,0));
        qy.fromDegreeAngAxis(rotation[1],Vec3f(0,1,0));
        qz.fromDegreeAngAxis(rotation[2],Vec3f(0,0,1));
        Quat q = qx*qy*qz;
        q.toMatrix(&mat);
        for (int i=0; i<obj.nbp(); i++)
        {
            obj.PP(i) = mat*obj.getPP(i);
            obj.PN(i) = mat*obj.getPN(i);
        }
    }

    if (translation != Vec3f(0,0,0))
    {
        std::cout << "Translating mesh..."<<std::endl;
        for (int i=0; i<obj.nbp(); i++)
        {
            obj.PP(i) = obj.getPP(i) + translation;
        }
    }

    std::cout << "Mesh bbox="<<obj.calcBBox()<<std::endl;
    if (flip)
    {
        std::cout << "Flipping mesh..."<<std::endl;
        obj.flipAll();
        //obj.calcFlip();
    }
    if (closemesh)
    {
        bool closed = obj.isClosed();
        std::cout << "Mesh is "<<(closed?"":"NOT ")<<"closed."<<std::endl;
        if (!closed)
        {
            obj.calcFlip();
            std::cout << "Closing mesh..."<<std::endl;
            obj.close();
            std::cout << "Mesh is "<<(obj.isClosed()?"":"NOT ")<<"closed."<<std::endl;
        }
    }

    if (dilate != 0.0f)
        obj.dilate(dilate);

    if (wnormals)
        obj.setAttrib(Mesh::MESH_POINTS_NORMAL,true);
    if (rnormals)
        obj.setAttrib(Mesh::MESH_POINTS_NORMAL,false);
    if (rtexcoords)
        obj.setAttrib(Mesh::MESH_POINTS_TEXCOORD,false);
    if (!file_out.empty())
    {
        std::cout << "Saving result..."<<std::endl;
        obj.save(file_out.c_str());
    }
    return 0;
}
<|endoftext|>


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

// HEADER
#include <dali/internal/render/gl-resources/gl-call-debug.h>

// INTERNAL INCLUDES
#include <dali/public-api/common/dali-common.h>
#include <dali/integration-api/debug.h>
#include <dali/integration-api/gl-abstraction.h>
#include <dali/integration-api/gl-defines.h>

namespace
{
/**
 * GL error strings
 */
struct errorStrings
{
  const Dali::GLenum errorCode;
  const char* errorString;
};
errorStrings errors[] =
{
   { GL_NO_ERROR,           "GL_NO_ERROR" },
   { GL_INVALID_ENUM,       "GL_INVALID_ENUM" },
   { GL_INVALID_VALUE,      "GL_INVALID_VALUE" },
   { GL_INVALID_OPERATION,  "GL_INVALID_OPERATION" },
   { GL_OUT_OF_MEMORY,      "GL_OUT_OF_MEMORY" }
};

const char* ErrorToString( Dali::GLenum errorCode )
{
  for( unsigned int i = 0; i < sizeof(errors) / sizeof(errors[0]); ++i)
  {
    if (errorCode == errors[i].errorCode)
    {
      return errors[i].errorString;
    }
  }
  return "Unknown Open GLES error";
}

}

namespace Dali
{

namespace Internal
{

#ifdef DEBUG_ENABLED
/// Switch debug level to Concise to disable, General to enable. Note, enabling snapshot logging will do this on the fly.
Debug::Filter* gGlLogFilter = Debug::Filter::New(Debug::Concise, false, "LOG_CONTEXT");
#endif // DEBUG_ENABLED

void CheckGlError( Integration::GlAbstraction& glAbstraction, const char* operation )
{
  for( GLint error = glAbstraction.GetError(); error; error = glAbstraction.GetError() )
  {
    DALI_LOG_ERROR( "glError (0x%x) %s - after %s\n",  error, ErrorToString(error), operation );
    DALI_ASSERT_ALWAYS( error && "GL ERROR"); // if errors are being checked we should assert
  }
}

}

}
<commit_msg>Klockwork: Fix CheckGlError assert condition<commit_after>/*
 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

// HEADER
#include <dali/internal/render/gl-resources/gl-call-debug.h>

// INTERNAL INCLUDES
#include <dali/public-api/common/dali-common.h>
#include <dali/integration-api/debug.h>
#include <dali/integration-api/gl-abstraction.h>
#include <dali/integration-api/gl-defines.h>

namespace
{
/**
 * GL error strings
 */
struct errorStrings
{
  const Dali::GLenum errorCode;
  const char* errorString;
};
errorStrings errors[] =
{
   { GL_NO_ERROR,           "GL_NO_ERROR" },
   { GL_INVALID_ENUM,       "GL_INVALID_ENUM" },
   { GL_INVALID_VALUE,      "GL_INVALID_VALUE" },
   { GL_INVALID_OPERATION,  "GL_INVALID_OPERATION" },
   { GL_OUT_OF_MEMORY,      "GL_OUT_OF_MEMORY" }
};

const char* ErrorToString( Dali::GLenum errorCode )
{
  for( unsigned int i = 0; i < sizeof(errors) / sizeof(errors[0]); ++i)
  {
    if (errorCode == errors[i].errorCode)
    {
      return errors[i].errorString;
    }
  }
  return "Unknown Open GLES error";
}

}

namespace Dali
{

namespace Internal
{

#ifdef DEBUG_ENABLED
/// Switch debug level to Concise to disable, General to enable. Note, enabling snapshot logging will do this on the fly.
Debug::Filter* gGlLogFilter = Debug::Filter::New(Debug::Concise, false, "LOG_CONTEXT");
#endif // DEBUG_ENABLED

void CheckGlError( Integration::GlAbstraction& glAbstraction, const char* operation )
{
  for( GLint error = glAbstraction.GetError(); error; error = glAbstraction.GetError() )
  {
    DALI_LOG_ERROR( "glError (0x%x) %s - after %s\n",  error, ErrorToString(error), operation );
    DALI_ASSERT_ALWAYS( !error && "GL ERROR"); // if errors are being checked we should assert
  }
}

}

}
<|endoftext|>


<commit_before>#include <sstream>
#include <map>
#include <cassert>
#include <eiger.h>

#include "datakind.h"
#include "eigerbackend.h"

EigerBackend::EigerBackend(std::string sitename, std::string machine, bool append)
  : sitename_(sitename), dc_(sitename, sitename), app_(sitename, sitename), machine_(machine, machine)
{
		dc_.commit();
    app_.commit();
    machine_.commit();
}

void EigerBackend::addCol(const std::string& label, const enum datakind kind){
  eiger::metric_type_t etype;
  std::string slabel = sitename_ + "_"+label;
  switch(kind){
    case RESULT:
      etype = eiger::RESULT;
      break;
    case DETERMINISTIC:
      etype = eiger::DETERMINISTIC;
			break;
    case NONDETERMINISTIC:
      etype = eiger::NONDETERMINISTIC;
			break;
		default:
			throw "eigerbackend: addCol unhandled datakind";
  }
  eiger::Metric metric(etype, slabel, slabel);
  metric.commit();
  erow_.push_back(metric);
}

void EigerBackend::nextrow(const std::vector<std::pair<std::string, enum datakind> >& headers,
                           const std::vector<double>& row){
  // declare a trial, exec, etc and do all commits, then
  // do text since text handles row.clear().
  std::ostringstream dsbuf;
  std::ostringstream ddbuf;
  dsbuf << sitename_;
  ddbuf << sitename_;
  std::vector<std::pair<std::string, enum datakind> >::size_type len = headers.size();
  assert(row.size() == len && 0 != "eigerbackend::nextrow called with incomplete data");
  int i = 0;
  for(std::vector<std::pair<std::string, enum datakind> >::const_iterator it = headers.begin();
      it != headers.end(); ++it, ++i){
    dsbuf << "_" << row.at(i);
    ddbuf << " " << it->first <<  "=" << row.at(i);
  }
  std::string dsname = dsbuf.str();
  std::string dsdesc = ddbuf.str();

  eiger::ApplicationID aid = app_.getID();
  eiger::Dataset ds(aid, dsname, dsdesc, "nURL");
  ds.commit();
  eiger::DatasetID dsid = ds.getID();

  eiger::MachineID machid = machine_.getID();
  eiger::Trial trial(dc_.getID(), machid, aid, dsid, eiger::PropertiesID(0,0));
  trial.commit();
  eiger::Execution exec(trial.getID(),machid);
  exec.commit();
  eiger::ExecutionID eid = exec.getID();
  int j = 0;
  for(std::vector<std::pair<std::string, enum datakind> >::const_iterator it = headers.begin();
      it != headers.end(); ++it, ++j){
    eiger::MetricID mid = (erow_.at(j)).getID();
    switch(it->second){
    case DETERMINISTIC: {
      eiger::DeterministicMetric dmD(dsid, mid, row.at(j));
      dmD.commit();
      break;
      }
    case NONDETERMINISTIC: {
      eiger::NondeterministicMetric ndmD(eid, mid, row.at(j));
      ndmD.commit();
      break;
      }
    case RESULT: {
      eiger::NondeterministicMetric rdmD(eid, mid, row.at(j));
      rdmD.commit();
      break;
      }
    default:
      throw "unhandled htype in nextrow";
    }
  }
}

<commit_msg>allow lwperf to be used with fakeeiger<commit_after>#include <sstream>
#include <map>
#include <cassert>
#ifdef _USE_FAKEEIGER
#include <mpifakeeiger.h>
#else
#include <eiger.h>
#endif

#include "datakind.h"
#include "eigerbackend.h"

EigerBackend::EigerBackend(std::string sitename, std::string machine, bool append)
  : sitename_(sitename), dc_(sitename, sitename), app_(sitename, sitename), machine_(machine, machine)
{
		dc_.commit();
    app_.commit();
    machine_.commit();
}

void EigerBackend::addCol(const std::string& label, const enum datakind kind){
  eiger::metric_type_t etype;
  std::string slabel = sitename_ + "_"+label;
  switch(kind){
    case RESULT:
      etype = eiger::RESULT;
      break;
    case DETERMINISTIC:
      etype = eiger::DETERMINISTIC;
			break;
    case NONDETERMINISTIC:
      etype = eiger::NONDETERMINISTIC;
			break;
		default:
			throw "eigerbackend: addCol unhandled datakind";
  }
  eiger::Metric metric(etype, slabel, slabel);
  metric.commit();
  erow_.push_back(metric);
}

void EigerBackend::nextrow(const std::vector<std::pair<std::string, enum datakind> >& headers,
                           const std::vector<double>& row){
  // declare a trial, exec, etc and do all commits, then
  // do text since text handles row.clear().
  std::ostringstream dsbuf;
  std::ostringstream ddbuf;
  dsbuf << sitename_;
  ddbuf << sitename_;
  std::vector<std::pair<std::string, enum datakind> >::size_type len = headers.size();
  assert(row.size() == len && 0 != "eigerbackend::nextrow called with incomplete data");
  int i = 0;
  for(std::vector<std::pair<std::string, enum datakind> >::const_iterator it = headers.begin();
      it != headers.end(); ++it, ++i){
    dsbuf << "_" << row.at(i);
    ddbuf << " " << it->first <<  "=" << row.at(i);
  }
  std::string dsname = dsbuf.str();
  std::string dsdesc = ddbuf.str();

  eiger::ApplicationID aid = app_.getID();
  eiger::Dataset ds(aid, dsname, dsdesc, "nURL");
  ds.commit();
  eiger::DatasetID dsid = ds.getID();

  eiger::MachineID machid = machine_.getID();
  eiger::Trial trial(dc_.getID(), machid, aid, dsid, eiger::PropertiesID(0,0));
  trial.commit();
  eiger::Execution exec(trial.getID(),machid);
  exec.commit();
  eiger::ExecutionID eid = exec.getID();
  int j = 0;
  for(std::vector<std::pair<std::string, enum datakind> >::const_iterator it = headers.begin();
      it != headers.end(); ++it, ++j){
    eiger::MetricID mid = (erow_.at(j)).getID();
    switch(it->second){
    case DETERMINISTIC: {
      eiger::DeterministicMetric dmD(dsid, mid, row.at(j));
      dmD.commit();
      break;
      }
    case NONDETERMINISTIC: {
      eiger::NondeterministicMetric ndmD(eid, mid, row.at(j));
      ndmD.commit();
      break;
      }
    case RESULT: {
      eiger::NondeterministicMetric rdmD(eid, mid, row.at(j));
      rdmD.commit();
      break;
      }
    default:
      throw "unhandled htype in nextrow";
    }
  }
}

<|endoftext|>


<commit_before><commit_msg>Make geodesic work<commit_after><|endoftext|>


<commit_before>#ifndef YQVMC_NLOHMANN_JSON_EIGEN3_ADAPTOR_HPP
#define YQVMC_NLOHMANN_JSON_EIGEN3_ADAPTOR_HPP

#include <Eigen/Dense>

namespace nlohmann {
    //template <typename Derived>
    //struct adl_serializer<EigenBase<Derived>> {
    //};
    template <>
    struct adl_serializer<Eigen::ArrayXd> {
      static void to_json(json& j, const Eigen::ArrayXd& vec) {
        for (unsigned i = 0; i < vec.size(); i++) {
          j[i] = vec[i];
        }
      }
    };
}

#endif
<commit_msg>adding more interface for i/os of vectors and matrices (not done yet...)<commit_after>#ifndef YQVMC_NLOHMANN_JSON_EIGEN3_ADAPTOR_HPP
#define YQVMC_NLOHMANN_JSON_EIGEN3_ADAPTOR_HPP

#include <Eigen/Dense>

namespace nlohmann {
    //template <typename Derived>
    //struct adl_serializer<EigenBase<Derived>> {
    //};
    template <>
    struct adl_serializer<Eigen::ArrayXd> {
      static void to_json(json& j, const Eigen::ArrayXd& vec) {
        for (unsigned i = 0; i < vec.size(); i++) {
          j[i] = vec[i];
        }
      }

      static void from_json(const json& j, Eigen::ArrayXd& vec) {
        vec.resize(j.size());
        for (unsigned i = 0; i < j.size(); i++) {
          vec[i] = j[i];
        }
      }

      static void to_json(json& j, const Eigen::ArrayXXd& vec) {
      }

      static void from_json(const json& j, Eigen::ArrayXXd& vec) {
      }

    };
}

#endif
<|endoftext|>


<commit_before>/**
 * File    : A.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-11-10 15:20:13
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

int N, M, L;
string S[500];
string T[29];

void input()
{
  cin >> N >> M >> L;
  for (auto i = 0; i < N; i++)
  {
    cin >> S[i];
  }
}

void make_wall()
{
  string wall = "";
  for (auto i = 0; i < M; i++)
  {
    wall += "#";
  }
  for (auto i = 0; i < M; i++)
  {
    T[i] = wall;
  }
  T[14][14] = '.';
}

void flush()
{
  for (auto i = 0; i < M; i++)
  {
    cout << T[i] << endl;
  }
}

void solve(int k)
{
  assert(1 <= k && k <= 13);
  for (auto i = 1; i <= k; i++)
  {
    for (auto t = 0; t < 4; t++)
    {
      int x = M / 2 + dx[t] * i;
      int y = M / 2 + dy[t] * i;
      T[x][y] = '.';
    }
  }
}

int main()
{
  input();
  make_wall();
  solve(7);
  flush();
}<commit_msg>submit A.cpp to 'A - ばらばらロボット' (future-contest-2019-qual) [C++14 (GCC 5.4.1)]<commit_after>/**
 * File    : A.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-11-10 15:20:13
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

int N, M, L;
string S[500];
string T[29];

void input()
{
  cin >> N >> M >> L;
  for (auto i = 0; i < N; i++)
  {
    cin >> S[i];
  }
}

void make_wall()
{
  string wall = "";
  for (auto i = 0; i < M; i++)
  {
    wall += "#";
  }
  for (auto i = 0; i < M; i++)
  {
    T[i] = wall;
  }
  T[14][14] = '.';
}

void flush()
{
  for (auto i = 0; i < M; i++)
  {
    cout << T[i] << endl;
  }
}

void solve(int k)
{
  assert(1 <= k && k <= 13);
  for (auto i = 1; i <= k; i++)
  {
    for (auto t = 0; t < 4; t++)
    {
      int x = M / 2 + dx[t] * i;
      int y = M / 2 + dy[t] * i;
      T[x][y] = '.';
    }
  }
}

int main()
{
  input();
  make_wall();
  solve(8);
  flush();
}<|endoftext|>


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

#include <iostream>
#include <sstream>
#include <string>

#include <process/defer.hpp>
#include <process/dispatch.hpp>
#include <process/future.hpp>
#include <process/http.hpp>
#include <process/process.hpp>

using namespace process;

using namespace process::http;

using std::string;

class MyProcess : public Process<MyProcess>
{
public:
  MyProcess() {}
  virtual ~MyProcess() {}

  Future<int> func1()
  {
    promise.future().onAny(
        defer([=](const Future<int>& future) {
          terminate(self());
        }));
    return promise.future();
  }

  void func2(int i)
  {
    promise.set(i);
  }

  Future<Response> vars(const Request& request)
  {
    string body = "... vars here ...";
    OK response;
    response.headers["Content-Type"] = "text/plain";
    std::ostringstream out;
    out << body.size();
    response.headers["Content-Length"] = out.str();
    response.body = body;
    return response;
  }

  void stop(const UPID& from, const string& body)
  {
    terminate(self());
  }

protected:
  virtual void initialize()
  {
    // route("/vars", &MyProcess::vars);
    route("/vars", [=](const Request& request) {
      string body = "... vars here ...";
      OK response;
      response.headers["Content-Type"] = "text/plain";
      std::ostringstream out;
      out << body.size();
      response.headers["Content-Length"] = out.str();
      response.body = body;
      return response;
    });

    // install("stop", &MyProcess::stop);
    install("stop", [=](const UPID& from, const string& body) {
      terminate(self());
    });
  }

private:
  Promise<int> promise;
};

int main(int argc, char** argv)
{
  MyProcess process;
  PID<MyProcess> pid = spawn(&process);

  PID<> pid2 = pid;

  //// --------------------------------------

  // Future<int> future = dispatch(pid, &MyProcess::func1);
  // dispatch(pid, &MyProcess::func2, 42);

  // std::cout << future.get() << std::endl;

  // post(pid, "stop");

  //// --------------------------------------

  // Promise<bool> p;

  // dispatch(pid, &MyProcess::func1)
  //   .then([=, &p] (int i) {
  //       p.set(i == 42);
  //       return p.future();
  //     })
  //   .then([=] (bool b) {
  //       if (b) {
  //         post(pid, "stop");
  //       }
  //       return true; // No Future<void>.
  //     });

  // dispatch(pid, &MyProcess::func2, 42);

  //// --------------------------------------

  dispatch(pid, &MyProcess::func1);
  dispatch(pid, &MyProcess::func2, 42);

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

#include <iostream>
#include <string>

#include <process/defer.hpp>
#include <process/dispatch.hpp>
#include <process/future.hpp>
#include <process/http.hpp>
#include <process/process.hpp>

#include <stout/strings.hpp>

using namespace process;

using namespace process::http;

using std::string;

class MyProcess : public Process<MyProcess>
{
public:
  MyProcess(): ProcessBase("my-process") {}
  virtual ~MyProcess() {}

  Future<int> func1()
  {
    promise.future().onAny(
        defer([=](const Future<int>& future) {
          terminate(self());
        }));
    return promise.future();
  }

  void func2(int i)
  {
    promise.set(i);
  }

  Future<Response> vars(const Request& request)
  {
    // Response response;
    // response.code = Status::OK;
    // response.headers["Content-Type"] = "text/plain";
    // response.headers["Content-Length"] = stringify(body.size());
    // response.type = Response::BODY;
    // response.body = body;

    string body = "... vars here ...";
    return OK(body);
  }

  void stop(const UPID& from, const string& body)
  {
    terminate(self());
  }

protected:
  virtual void initialize()
  {
    // route("/vars", None(), &MyProcess::vars);
    route("/vars", None(), [=](const Request& request) {
      string body = "... vars here ...";
      return OK(body);
    });

    // install("stop", &MyProcess::stop);
    install("stop", [=](const UPID& from, const string& body) {
      terminate(self());
    });
  }

private:
  Promise<int> promise;
};

int main(int argc, char** argv)
{
  MyProcess process;
  PID<MyProcess> pid = spawn(&process);

  //// --------------------------------------

  // Future<int> future = dispatch(pid, &MyProcess::func1);
  // dispatch(pid, &MyProcess::func2, 42);

  // std::cout << future.get() << std::endl;

  // http::post(pid, "stop");

  //// --------------------------------------

  // Promise<bool> p;

  // dispatch(pid, &MyProcess::func1)
  //   .then([=, &p] (int i) {
  //       p.set(i == 42);
  //       return p.future();
  //     })
  //   .then([=] (bool b) {
  //       if (b) {
  //         http::post(pid, "stop");
  //       }
  //       return true; // No Future<void>.
  //     });

  // dispatch(pid, &MyProcess::func2, 42);

  //// --------------------------------------

  // dispatch(pid, &MyProcess::func1);
  // dispatch(pid, &MyProcess::func2, 42);

  //// --------------------------------------

  std::cout << strings::format("Endpoint listening on http://%s/%s/vars\n",
      process::address(),
      process.self().id).get();

  wait(pid);
  return 0;
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: TableWindowTitle.cxx,v $
 *
 *  $Revision: 1.23 $
 *
 *  last change: $Author: rt $ $Date: 2007-07-06 08:40:14 $
 *
 *  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
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_dbaccess.hxx"
#ifndef DBAUI_TABLEWINDOWTITLE_HXX
#include "TableWindowTitle.hxx"
#endif
#ifndef DBAUI_TABLEWINDOW_HXX
#include "TableWindow.hxx"
#endif
#ifndef DBAUI_QUERYTABLEVIEW_HXX
#include "QueryTableView.hxx"
#endif
#ifndef _SV_SVAPP_HXX
#include <vcl/svapp.hxx>
#endif
#ifndef _SV_HELP_HXX
#include <vcl/help.hxx>
#endif
#ifndef _SV_MENU_HXX
#include <vcl/menu.hxx>
#endif
#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif
#ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
#include "dbustrings.hrc"
#endif
#ifndef _CNTIDS_HRC
#include <sfx2/cntids.hrc>
#endif
#ifndef DBAUI_TABLEWINDOWLISTBOX_HXX
#include "TableWindowListBox.hxx"
#endif
#ifndef DBAUI_TABLECONNECTION_HXX
#include "TableConnection.hxx"
#endif
#ifndef _DBU_QRY_HRC_
#include "dbu_qry.hrc"
#endif
#ifndef DBAUI_QUERYDESIGNVIEW_HXX
#include "QueryDesignView.hxx"
#endif
#ifndef DBAUI_JOINCONTROLLER_HXX
#include "JoinController.hxx"
#endif

#include <algorithm>

using namespace dbaui;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::uno;
//==================================================================
// class OTableWindowTitle
//==================================================================
DBG_NAME(OTableWindowTitle)
//------------------------------------------------------------------------------
OTableWindowTitle::OTableWindowTitle( OTableWindow* pParent ) :
     FixedText( pParent, WB_3DLOOK|WB_LEFT|WB_NOLABEL|WB_VCENTER )
    ,m_pTabWin( pParent )
{
    DBG_CTOR(OTableWindowTitle,NULL);
    // Hintergrund- und Textfarbe setzen
    StyleSettings aSystemStyle = Application::GetSettings().GetStyleSettings();
    SetBackground(Wallpaper(Color(aSystemStyle.GetFaceColor())));
    SetTextColor(aSystemStyle.GetButtonTextColor());

    Font aFont( GetFont() );
    aFont.SetTransparent( TRUE );
    SetFont( aFont );
}

//------------------------------------------------------------------------------
OTableWindowTitle::~OTableWindowTitle()
{
    DBG_DTOR(OTableWindowTitle,NULL);
    m_pTabWin = NULL;
}

//------------------------------------------------------------------------------
void OTableWindowTitle::GetFocus()
{
    if(m_pTabWin)
        m_pTabWin->GetFocus();
}

//------------------------------------------------------------------------------
void OTableWindowTitle::LoseFocus()
{
    m_pTabWin->LoseFocus();
}
//------------------------------------------------------------------------------
void OTableWindowTitle::RequestHelp( const HelpEvent& rHEvt )
{
    if(m_pTabWin)
    {
        String aHelpText = m_pTabWin->GetComposedName();
        if( aHelpText.Len())
        {
            // Hilfe anzeigen
            Rectangle aItemRect(Point(0,0),GetSizePixel());
            aItemRect = LogicToPixel( aItemRect );
            Point aPt = OutputToScreenPixel( aItemRect.TopLeft() );
            aItemRect.Left()   = aPt.X();
            aItemRect.Top()    = aPt.Y();
            aPt = OutputToScreenPixel( aItemRect.BottomRight() );
            aItemRect.Right()  = aPt.X();
            aItemRect.Bottom() = aPt.Y();
            if( rHEvt.GetMode() == HELPMODE_BALLOON )
                Help::ShowBalloon( this, aItemRect.Center(), aItemRect, aHelpText);
            else
                Help::ShowQuickHelp( this, aItemRect, aHelpText );
        }
    }
}

//------------------------------------------------------------------------------
void OTableWindowTitle::Command( const CommandEvent& rEvt )
{
    switch( rEvt.GetCommand() )
    {
        case COMMAND_CONTEXTMENU:
        {
            GrabFocus();
            if ( m_pTabWin )
                m_pTabWin->Command( rEvt );
            else
                Control::Command(rEvt);
        }
    }
}

//------------------------------------------------------------------------------
//void OTableWindowTitle::Paint( const Rectangle& rRect )
//{
//  //////////////////////////////////////////////////////////////////////
//  // Ausgabe des Textes in der Titelzeile
//  Rectangle aWinRect( Point(0,0), GetSizePixel() );
//  DrawText( aWinRect, GetText(), TEXT_DRAW_CENTER|TEXT_DRAW_VCENTER|TEXT_DRAW_ENDELLIPSIS );
//}

//------------------------------------------------------------------------------
void OTableWindowTitle::KeyInput( const KeyEvent& rEvt )
{
    if ( m_pTabWin )
        m_pTabWin->KeyInput( rEvt );
}

//------------------------------------------------------------------------------
void OTableWindowTitle::MouseButtonDown( const MouseEvent& rEvt )
{
    if( rEvt.IsLeft() )
    {
        if( rEvt.GetClicks() == 2)
        {
            Size aSize(GetTextWidth(GetText()) + 20,
                        m_pTabWin->GetSizePixel().Height() - m_pTabWin->GetListBox()->GetSizePixel().Height());

            aSize.Height() += (m_pTabWin->GetListBox()->GetEntryCount() + 2) * m_pTabWin->GetListBox()->GetEntryHeight();
            if(m_pTabWin->GetSizePixel() != aSize)
            {
                m_pTabWin->SetSizePixel(aSize);

                OJoinTableView* pView = static_cast<OJoinTableView*>(m_pTabWin->getTableView());
                OSL_ENSURE(pView,"No OJoinTableView!");
                const ::std::vector<OTableConnection*>* pConns = pView->getTableConnections();
                ::std::for_each(pConns->begin(),
                                pConns->end(),
                                ::std::mem_fun(&OTableConnection::RecalcLines));

                pView->InvalidateConnections();
                pView->getDesignView()->getController()->setModified(sal_True);
                pView->Invalidate(INVALIDATE_NOCHILDREN);
            }
        }
        else
        {
            Point aPos = rEvt.GetPosPixel();
            aPos = OutputToScreenPixel( aPos );
            OJoinTableView* pView = static_cast<OJoinTableView*>(m_pTabWin->getTableView());
            OSL_ENSURE(pView,"No OJoinTableView!");
            pView->NotifyTitleClicked( static_cast<OTableWindow*>(GetParent()), aPos );
        }
        GrabFocus();
    }
    else
        Control::MouseButtonDown( rEvt );
}

//------------------------------------------------------------------------------
void OTableWindowTitle::DataChanged(const DataChangedEvent& rDCEvt)
{
    if (rDCEvt.GetType() == DATACHANGED_SETTINGS)
    {
        // nehmen wir den worst-case an : die Farben haben sich geaendert, also
        // mich anpassen
        StyleSettings aSystemStyle = Application::GetSettings().GetStyleSettings();
        SetBackground(Wallpaper(Color(aSystemStyle.GetFaceColor())));
        SetTextColor(aSystemStyle.GetButtonTextColor());
    }
}
// -----------------------------------------------------------------------------
void OTableWindowTitle::StateChanged( StateChangedType nType )
{
    Window::StateChanged( nType );

    if ( nType == STATE_CHANGE_ZOOM )
    {
        const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();

        Font aFont = rStyleSettings.GetGroupFont();
        if ( IsControlFont() )
            aFont.Merge( GetControlFont() );
        SetZoomedPointFont( aFont );

        Resize();
    }
}

<commit_msg>INTEGRATION: CWS changefileheader (1.23.162); FILE MERGED 2008/03/31 13:27:58 rt 1.23.162.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: TableWindowTitle.cxx,v $
 * $Revision: 1.24 $
 *
 * 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.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_dbaccess.hxx"
#ifndef DBAUI_TABLEWINDOWTITLE_HXX
#include "TableWindowTitle.hxx"
#endif
#ifndef DBAUI_TABLEWINDOW_HXX
#include "TableWindow.hxx"
#endif
#ifndef DBAUI_QUERYTABLEVIEW_HXX
#include "QueryTableView.hxx"
#endif
#ifndef _SV_SVAPP_HXX
#include <vcl/svapp.hxx>
#endif
#ifndef _SV_HELP_HXX
#include <vcl/help.hxx>
#endif
#ifndef _SV_MENU_HXX
#include <vcl/menu.hxx>
#endif
#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif
#ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
#include "dbustrings.hrc"
#endif
#ifndef _CNTIDS_HRC
#include <sfx2/cntids.hrc>
#endif
#ifndef DBAUI_TABLEWINDOWLISTBOX_HXX
#include "TableWindowListBox.hxx"
#endif
#ifndef DBAUI_TABLECONNECTION_HXX
#include "TableConnection.hxx"
#endif
#ifndef _DBU_QRY_HRC_
#include "dbu_qry.hrc"
#endif
#ifndef DBAUI_QUERYDESIGNVIEW_HXX
#include "QueryDesignView.hxx"
#endif
#ifndef DBAUI_JOINCONTROLLER_HXX
#include "JoinController.hxx"
#endif

#include <algorithm>

using namespace dbaui;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::uno;
//==================================================================
// class OTableWindowTitle
//==================================================================
DBG_NAME(OTableWindowTitle)
//------------------------------------------------------------------------------
OTableWindowTitle::OTableWindowTitle( OTableWindow* pParent ) :
     FixedText( pParent, WB_3DLOOK|WB_LEFT|WB_NOLABEL|WB_VCENTER )
    ,m_pTabWin( pParent )
{
    DBG_CTOR(OTableWindowTitle,NULL);
    // Hintergrund- und Textfarbe setzen
    StyleSettings aSystemStyle = Application::GetSettings().GetStyleSettings();
    SetBackground(Wallpaper(Color(aSystemStyle.GetFaceColor())));
    SetTextColor(aSystemStyle.GetButtonTextColor());

    Font aFont( GetFont() );
    aFont.SetTransparent( TRUE );
    SetFont( aFont );
}

//------------------------------------------------------------------------------
OTableWindowTitle::~OTableWindowTitle()
{
    DBG_DTOR(OTableWindowTitle,NULL);
    m_pTabWin = NULL;
}

//------------------------------------------------------------------------------
void OTableWindowTitle::GetFocus()
{
    if(m_pTabWin)
        m_pTabWin->GetFocus();
}

//------------------------------------------------------------------------------
void OTableWindowTitle::LoseFocus()
{
    m_pTabWin->LoseFocus();
}
//------------------------------------------------------------------------------
void OTableWindowTitle::RequestHelp( const HelpEvent& rHEvt )
{
    if(m_pTabWin)
    {
        String aHelpText = m_pTabWin->GetComposedName();
        if( aHelpText.Len())
        {
            // Hilfe anzeigen
            Rectangle aItemRect(Point(0,0),GetSizePixel());
            aItemRect = LogicToPixel( aItemRect );
            Point aPt = OutputToScreenPixel( aItemRect.TopLeft() );
            aItemRect.Left()   = aPt.X();
            aItemRect.Top()    = aPt.Y();
            aPt = OutputToScreenPixel( aItemRect.BottomRight() );
            aItemRect.Right()  = aPt.X();
            aItemRect.Bottom() = aPt.Y();
            if( rHEvt.GetMode() == HELPMODE_BALLOON )
                Help::ShowBalloon( this, aItemRect.Center(), aItemRect, aHelpText);
            else
                Help::ShowQuickHelp( this, aItemRect, aHelpText );
        }
    }
}

//------------------------------------------------------------------------------
void OTableWindowTitle::Command( const CommandEvent& rEvt )
{
    switch( rEvt.GetCommand() )
    {
        case COMMAND_CONTEXTMENU:
        {
            GrabFocus();
            if ( m_pTabWin )
                m_pTabWin->Command( rEvt );
            else
                Control::Command(rEvt);
        }
    }
}

//------------------------------------------------------------------------------
//void OTableWindowTitle::Paint( const Rectangle& rRect )
//{
//  //////////////////////////////////////////////////////////////////////
//  // Ausgabe des Textes in der Titelzeile
//  Rectangle aWinRect( Point(0,0), GetSizePixel() );
//  DrawText( aWinRect, GetText(), TEXT_DRAW_CENTER|TEXT_DRAW_VCENTER|TEXT_DRAW_ENDELLIPSIS );
//}

//------------------------------------------------------------------------------
void OTableWindowTitle::KeyInput( const KeyEvent& rEvt )
{
    if ( m_pTabWin )
        m_pTabWin->KeyInput( rEvt );
}

//------------------------------------------------------------------------------
void OTableWindowTitle::MouseButtonDown( const MouseEvent& rEvt )
{
    if( rEvt.IsLeft() )
    {
        if( rEvt.GetClicks() == 2)
        {
            Size aSize(GetTextWidth(GetText()) + 20,
                        m_pTabWin->GetSizePixel().Height() - m_pTabWin->GetListBox()->GetSizePixel().Height());

            aSize.Height() += (m_pTabWin->GetListBox()->GetEntryCount() + 2) * m_pTabWin->GetListBox()->GetEntryHeight();
            if(m_pTabWin->GetSizePixel() != aSize)
            {
                m_pTabWin->SetSizePixel(aSize);

                OJoinTableView* pView = static_cast<OJoinTableView*>(m_pTabWin->getTableView());
                OSL_ENSURE(pView,"No OJoinTableView!");
                const ::std::vector<OTableConnection*>* pConns = pView->getTableConnections();
                ::std::for_each(pConns->begin(),
                                pConns->end(),
                                ::std::mem_fun(&OTableConnection::RecalcLines));

                pView->InvalidateConnections();
                pView->getDesignView()->getController()->setModified(sal_True);
                pView->Invalidate(INVALIDATE_NOCHILDREN);
            }
        }
        else
        {
            Point aPos = rEvt.GetPosPixel();
            aPos = OutputToScreenPixel( aPos );
            OJoinTableView* pView = static_cast<OJoinTableView*>(m_pTabWin->getTableView());
            OSL_ENSURE(pView,"No OJoinTableView!");
            pView->NotifyTitleClicked( static_cast<OTableWindow*>(GetParent()), aPos );
        }
        GrabFocus();
    }
    else
        Control::MouseButtonDown( rEvt );
}

//------------------------------------------------------------------------------
void OTableWindowTitle::DataChanged(const DataChangedEvent& rDCEvt)
{
    if (rDCEvt.GetType() == DATACHANGED_SETTINGS)
    {
        // nehmen wir den worst-case an : die Farben haben sich geaendert, also
        // mich anpassen
        StyleSettings aSystemStyle = Application::GetSettings().GetStyleSettings();
        SetBackground(Wallpaper(Color(aSystemStyle.GetFaceColor())));
        SetTextColor(aSystemStyle.GetButtonTextColor());
    }
}
// -----------------------------------------------------------------------------
void OTableWindowTitle::StateChanged( StateChangedType nType )
{
    Window::StateChanged( nType );

    if ( nType == STATE_CHANGE_ZOOM )
    {
        const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();

        Font aFont = rStyleSettings.GetGroupFont();
        if ( IsControlFont() )
            aFont.Merge( GetControlFont() );
        SetZoomedPointFont( aFont );

        Resize();
    }
}

<|endoftext|>


<commit_before>/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

#include <thrift/test/gen-cpp/EnumTest_types.h>
#include <thrift/lib/cpp/util/EnumUtils.h>

#include <gtest/gtest.h>

using apache::thrift::TEnumTraits;
using namespace apache::thrift::util;

TEST(EnumTest, test_enum) {
  // Check that all the enum values match what we expect
  EXPECT_EQ(TEnumTraits<MyEnum1>::min(), 0);
  EXPECT_EQ(MyEnum1::ME1_0, 0);
  EXPECT_EQ(MyEnum1::ME1_1, 1);
  EXPECT_EQ(MyEnum1::ME1_2, 2);
  EXPECT_EQ(MyEnum1::ME1_3, 3);
  EXPECT_EQ(MyEnum1::ME1_5, 5);
  EXPECT_EQ(MyEnum1::ME1_6, 6);
  EXPECT_EQ(TEnumTraits<MyEnum1>::max(), 6);

  EXPECT_EQ(TEnumTraits<MyEnum2>::min(), 0);
  EXPECT_EQ(MyEnum2::ME2_0, 0);
  EXPECT_EQ(MyEnum2::ME2_1, 1);
  EXPECT_EQ(MyEnum2::ME2_2, 2);
  EXPECT_EQ(TEnumTraits<MyEnum2>::max(), 2);

  EXPECT_EQ(TEnumTraits<MyEnum3>::min(), -2);
  EXPECT_EQ(MyEnum3::ME3_0, 0);
  EXPECT_EQ(MyEnum3::ME3_1, 1);
  EXPECT_EQ(MyEnum3::ME3_N2, -2);
  EXPECT_EQ(MyEnum3::ME3_N1, -1);
  EXPECT_EQ(MyEnum3::ME3_D0, 0);
  EXPECT_EQ(MyEnum3::ME3_D1, 1);
  EXPECT_EQ(MyEnum3::ME3_9, 9);
  EXPECT_EQ(MyEnum3::ME3_10, 10);
  EXPECT_EQ(TEnumTraits<MyEnum3>::max(), 10);

  EXPECT_EQ(TEnumTraits<MyEnum4>::min(), 0x7ffffffd);
  EXPECT_EQ(MyEnum4::ME4_A, 0x7ffffffd);
  EXPECT_EQ(MyEnum4::ME4_B, 0x7ffffffe);
  EXPECT_EQ(MyEnum4::ME4_C, 0x7fffffff);
  EXPECT_EQ(TEnumTraits<MyEnum4>::max(), 0x7fffffff);
}

TEST(EnumTest, test_enum_constant) {
  MyStruct ms;
  EXPECT_EQ(ms.me2_2, 2);
  EXPECT_EQ(ms.me3_n2, -2);
  EXPECT_EQ(ms.me3_d1, 1);
}

TEST(EnumTest, test_enum_names) {
  EXPECT_EQ(enumName(MyEnum3::ME3_1), std::string{"ME3_1"});
  EXPECT_EQ(enumName(MyEnum2::ME2_2), std::string{"ME2_2"});
  EXPECT_EQ(enumName(static_cast<MyEnum2>(-10)), (const char*)nullptr);
  EXPECT_EQ(enumName(static_cast<MyEnum2>(-10), "foo"), "foo");
}

TEST(EnumTest, test_enum_parse) {
  MyEnum2 e2;
  MyEnum3 e3;

  EXPECT_TRUE(tryParseEnum("ME2_2", &e2));
  EXPECT_EQ((int)MyEnum2::ME2_2, (int)e2);
  EXPECT_TRUE(tryParseEnum("ME3_N2", &e3));
  EXPECT_EQ((int)MyEnum3::ME3_N2, (int)e3);

  EXPECT_FALSE(tryParseEnum("FOO_ME2_0", &e2));
  EXPECT_FALSE(tryParseEnum("BAR_ME3_N2", &e3));
}
<commit_msg>Work around UB invalid-enum-load in thrift/test/EnumTest.cpp<commit_after>/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

#include <thrift/test/gen-cpp/EnumTest_types.h>
#include <thrift/lib/cpp/util/EnumUtils.h>

#include <gtest/gtest.h>

using apache::thrift::TEnumTraits;
using namespace apache::thrift::util;

TEST(EnumTest, test_enum) {
  // Check that all the enum values match what we expect
  EXPECT_EQ(TEnumTraits<MyEnum1>::min(), 0);
  EXPECT_EQ(MyEnum1::ME1_0, 0);
  EXPECT_EQ(MyEnum1::ME1_1, 1);
  EXPECT_EQ(MyEnum1::ME1_2, 2);
  EXPECT_EQ(MyEnum1::ME1_3, 3);
  EXPECT_EQ(MyEnum1::ME1_5, 5);
  EXPECT_EQ(MyEnum1::ME1_6, 6);
  EXPECT_EQ(TEnumTraits<MyEnum1>::max(), 6);

  EXPECT_EQ(TEnumTraits<MyEnum2>::min(), 0);
  EXPECT_EQ(MyEnum2::ME2_0, 0);
  EXPECT_EQ(MyEnum2::ME2_1, 1);
  EXPECT_EQ(MyEnum2::ME2_2, 2);
  EXPECT_EQ(TEnumTraits<MyEnum2>::max(), 2);

  EXPECT_EQ(TEnumTraits<MyEnum3>::min(), -2);
  EXPECT_EQ(MyEnum3::ME3_0, 0);
  EXPECT_EQ(MyEnum3::ME3_1, 1);
  EXPECT_EQ(MyEnum3::ME3_N2, -2);
  EXPECT_EQ(MyEnum3::ME3_N1, -1);
  EXPECT_EQ(MyEnum3::ME3_D0, 0);
  EXPECT_EQ(MyEnum3::ME3_D1, 1);
  EXPECT_EQ(MyEnum3::ME3_9, 9);
  EXPECT_EQ(MyEnum3::ME3_10, 10);
  EXPECT_EQ(TEnumTraits<MyEnum3>::max(), 10);

  EXPECT_EQ(TEnumTraits<MyEnum4>::min(), 0x7ffffffd);
  EXPECT_EQ(MyEnum4::ME4_A, 0x7ffffffd);
  EXPECT_EQ(MyEnum4::ME4_B, 0x7ffffffe);
  EXPECT_EQ(MyEnum4::ME4_C, 0x7fffffff);
  EXPECT_EQ(TEnumTraits<MyEnum4>::max(), 0x7fffffff);
}

TEST(EnumTest, test_enum_constant) {
  MyStruct ms;
  EXPECT_EQ(ms.me2_2, 2);
  EXPECT_EQ(ms.me3_n2, -2);
  EXPECT_EQ(ms.me3_d1, 1);
}

TEST(EnumTest, test_enum_names) {
  EXPECT_EQ(enumName(MyEnum3::ME3_1), std::string{"ME3_1"});
  EXPECT_EQ(enumName(MyEnum2::ME2_2), std::string{"ME2_2"});
  EXPECT_EQ(enumName(static_cast<MyEnum2>(3)), (const char*)nullptr);
  EXPECT_EQ(enumName(static_cast<MyEnum2>(3), "foo"), "foo");
}

TEST(EnumTest, test_enum_parse) {
  MyEnum2 e2;
  MyEnum3 e3;

  EXPECT_TRUE(tryParseEnum("ME2_2", &e2));
  EXPECT_EQ((int)MyEnum2::ME2_2, (int)e2);
  EXPECT_TRUE(tryParseEnum("ME3_N2", &e3));
  EXPECT_EQ((int)MyEnum3::ME3_N2, (int)e3);

  EXPECT_FALSE(tryParseEnum("FOO_ME2_0", &e2));
  EXPECT_FALSE(tryParseEnum("BAR_ME3_N2", &e3));
}
<|endoftext|>