<commit_before>//
// Number Theory
//
#define IsComp(n)  (_c[n>>6]&(1<<((n>>1)&31)))
#define SetComp(n) _c[n>>6]|=(1<<((n>>1)&31))
const int MAX = 1000000;  // 10^6
const int LMT =    1000;  // sqrt(MAX)
int _c[(MAX>>6)+1];
IV primes;
void prime_sieve() {
    for (int i = 3; i <= LMT; i += 2)
        if (!IsComp(i)) for (int j = i*i; j <= MAX; j+=i+i) SetComp(j);
    primes.push_back(2);
    for (int i=3; i <= MAX; i+=2) if (!IsComp(i)) primes.push_back(i);
}
bool is_prime(int n) {
    if (n < 2 || (n > 2 && n % 2 == 0)) return false;
    return ! IsComp(n);
}

// Finds prime numbers between a and b, using basic primes up to sqrt(b)
// pre cond: a > 2 (handle that separately)
void prime_seg_sieve(i64 a, i64 b, IV &seg_primes) {
    BV pmap(b - a + 1, true);
    i64 sqr_b = sqrt(b);
    For (IV, pp, primes) {
        int p = *pp;
        if (p > sqr_b) break;
        for (i64 j = (a+p-1)/p, v=(j==1?p+p:j*p); v <= b; v += p)
            pmap[v-a] = false;
    }
    seg_primes.clear();
    for (int i = a%2 ? 0 : 1, I = b - a + 1; i < I; i += 2)
        if (pmap[i])
            seg_primes.push_back(a + i);
}

void prime_factorize(int n, IIV &f) {
    int sn = sqrt(n);
    For (IV, p, primes) {
        int prime = *p;
        if (prime > sn) break; if (n % prime) continue;
        int e = 0; for (; n % prime == 0; e++, n /= prime);
        f.push_back(II(prime, e));
        sn = sqrt(n);
    }
    if (n > 1) f.push_back(II(n, 1));
}
void divisors(int n, IV &ds)
{
    ds.clear();
    ds.push_back(1);
    int sn = sqrt(n);
    For (IV, pp, primes) {
        int p = *pp;
        if (p > sn) break;
        if (n % p != 0) continue;
        IV aux(ds.begin(), ds.end());
        int q = 1;
        while (n % p == 0) {
            q *= p; n /= p;
            For(IV, v, ds) aux.push_back(*v * q);
        }
        sn = sqrt(n); ds = aux;
    }
    if (n > 1) {
        IV aux(ds.begin(), ds.end());
        For (IV, v, ds) aux.push_back(*v * n);
        ds = aux;
    }
}

void euler_phi(int a[], int N) {
    for (int i = 1; i <= N; i++) a[i] = i;
    for (int i = 2; i <= N; i += 2) a[i] = i/2;
    for (int i = 3; i <= N; i += 2)
        if (a[i] == i) {
            a[i]--; for (int j = i+i; j <= N; j += i) a[j] -= a[j]/i;
        }
}

int mod_pow(int _b, i64 e, int m) {
    i64 res = 1;
    for (i64 b=_b; e; e >>= 1, b = b*b%m) if (e & 1) res = res*b%m;
    return res;
}

template<typename TB, typename TE>
TB sq_pow(TB b, TE e) {
    TB res = 1; for (; e; e >>= 1, b *= b) if (e & 1) res *= b;
    return res;
}

template<typename T>
T gcd(T a, T b) { for (T c = a%b; c != 0; a=b,b=c,c=a%b); return b; }

template<typename T>
void ext_euclid(T a, T b, T &x, T &y, T &g) {
    x = 0; y = 1; g = b;
    T m, n, q, r;
    for (T u=1, v=0; a != 0; g=a, a=r) {
        q = g / a; r = g % a;
        m = x-u*q; n = y-v*q;
        x=u; y=v; u=m; v=n;
    }
}

template <typename T>
T chinese_rem(int k, T *ns, T *as)
{
    T N = 1, x = 0, r, s, g;
    for (int i = 0; i < k; ++i) N *= ns[i];
    for (int i = 0; i < k; ++i) {
        ext_euclid(ns[i], N/ns[i], r, s, g);
        x += as[i]*s*(N/ns[i]);
        x %= N;
    }
    if (x < 0) x += N;
    return x;
}

int mod_inv(int n, int m) {
    int x, y, gcd;
    ext_euclid(n, m, x, y, gcd);
    if (gcd == 1) return x % m;
    return 0;
}

// Calculates the highest exponent of prime p that divides n!
int pow_div_fact(int n, int p) {
    int sd = 0; for (int N=n; N; N /= p) sd += N % p; return (n-sd)/(p-1);
}

// Binomial coefficients
#define BCSIZE 1000
int bc[BCSIZE + 1][BCSIZE + 1];
void choose_table() {
    for (int n = 1; n <= BCSIZE; n++) { bc[n][n] = 1; bc[n][1] = n; }
    for (int n = 3; n <= BCSIZE; n++)
        for (int k = 2; k < n; k++)
            bc[n][k] = (bc[n-1][k-1] + bc[n-1][k]) % MOD;
}

int choose(int n, int k) {
    if (k > n) return 0;
    i64 r=1;
    for (int d = 1; d <= k; d++) {
        r *= n--;
        r /= d;
    }
    return r;
}
<commit_msg>Changed prime sieve to use standard array<commit_after>//
// Number Theory
//
#define IsComp(n)  (_c[n>>6]&(1<<((n>>1)&31)))
#define SetComp(n) _c[n>>6]|=(1<<((n>>1)&31))
const int MAXP   = 46341;  // sqrt(2^31)
const int SQRP   =   216;  // sqrt(MAX)
const int MAX_NP =  5435;  // 1.26 * MAXP/log(MAXP)
int _c[(MAXP>>6)+1];
int primes[MAX_NP];
int nprimes;
void prime_sieve() {
    for (int i = 3; i <= SQRP; i += 2)
        if (!IsComp(i)) for (int j = i*i; j <= MAXP; j+=i+i) SetComp(j);
    primes[nprimes++] = 2;
    for (int i=3; i <= MAXP; i+=2) if (!IsComp(i)) primes[nprimes++] = i;
}
bool is_prime(int n) {
    if (n < 2 || (n > 2 && n % 2 == 0)) return false;
    return ! IsComp(n);
}

// Finds prime numbers between a and b, using basic primes up to sqrt(b)
// pre cond: a > 2 (handle that separately)
void prime_seg_sieve(i64 a, i64 b, IV &seg_primes) {
    BV pmap(b - a + 1, true);
    i64 sqr_b = sqrt(b);
    For (IV, pp, primes) {
        int p = *pp;
        if (p > sqr_b) break;
        for (i64 j = (a+p-1)/p, v=(j==1?p+p:j*p); v <= b; v += p)
            pmap[v-a] = false;
    }
    seg_primes.clear();
    for (int i = a%2 ? 0 : 1, I = b - a + 1; i < I; i += 2)
        if (pmap[i])
            seg_primes.push_back(a + i);
}

void prime_factorize(int n, IIV &f) {
    int sn = sqrt(n);
    For (IV, p, primes) {
        int prime = *p;
        if (prime > sn) break; if (n % prime) continue;
        int e = 0; for (; n % prime == 0; e++, n /= prime);
        f.push_back(II(prime, e));
        sn = sqrt(n);
    }
    if (n > 1) f.push_back(II(n, 1));
}
void divisors(int n, IV &ds)
{
    ds.clear();
    ds.push_back(1);
    int sn = sqrt(n);
    For (IV, pp, primes) {
        int p = *pp;
        if (p > sn) break;
        if (n % p != 0) continue;
        IV aux(ds.begin(), ds.end());
        int q = 1;
        while (n % p == 0) {
            q *= p; n /= p;
            For(IV, v, ds) aux.push_back(*v * q);
        }
        sn = sqrt(n); ds = aux;
    }
    if (n > 1) {
        IV aux(ds.begin(), ds.end());
        For (IV, v, ds) aux.push_back(*v * n);
        ds = aux;
    }
}

void euler_phi(int a[], int N) {
    for (int i = 1; i <= N; i++) a[i] = i;
    for (int i = 2; i <= N; i += 2) a[i] = i/2;
    for (int i = 3; i <= N; i += 2)
        if (a[i] == i) {
            a[i]--; for (int j = i+i; j <= N; j += i) a[j] -= a[j]/i;
        }
}

int mod_pow(int _b, i64 e, int m) {
    i64 res = 1;
    for (i64 b=_b; e; e >>= 1, b = b*b%m) if (e & 1) res = res*b%m;
    return res;
}

template<typename TB, typename TE>
TB sq_pow(TB b, TE e) {
    TB res = 1; for (; e; e >>= 1, b *= b) if (e & 1) res *= b;
    return res;
}

template<typename T>
T gcd(T a, T b) { for (T c = a%b; c != 0; a=b,b=c,c=a%b); return b; }

template<typename T>
void ext_euclid(T a, T b, T &x, T &y, T &g) {
    x = 0; y = 1; g = b;
    T m, n, q, r;
    for (T u=1, v=0; a != 0; g=a, a=r) {
        q = g / a; r = g % a;
        m = x-u*q; n = y-v*q;
        x=u; y=v; u=m; v=n;
    }
}

template <typename T>
T chinese_rem(int k, T *ns, T *as)
{
    T N = 1, x = 0, r, s, g;
    for (int i = 0; i < k; ++i) N *= ns[i];
    for (int i = 0; i < k; ++i) {
        ext_euclid(ns[i], N/ns[i], r, s, g);
        x += as[i]*s*(N/ns[i]);
        x %= N;
    }
    if (x < 0) x += N;
    return x;
}

int mod_inv(int n, int m) {
    int x, y, gcd;
    ext_euclid(n, m, x, y, gcd);
    if (gcd == 1) return x % m;
    return 0;
}

// Calculates the highest exponent of prime p that divides n!
int pow_div_fact(int n, int p) {
    int sd = 0; for (int N=n; N; N /= p) sd += N % p; return (n-sd)/(p-1);
}

// Binomial coefficients
#define BCSIZE 1000
int bc[BCSIZE + 1][BCSIZE + 1];
void choose_table() {
    for (int n = 1; n <= BCSIZE; n++) { bc[n][n] = 1; bc[n][1] = n; }
    for (int n = 3; n <= BCSIZE; n++)
        for (int k = 2; k < n; k++)
            bc[n][k] = (bc[n-1][k-1] + bc[n-1][k]) % MOD;
}

int choose(int n, int k) {
    if (k > n) return 0;
    i64 r=1;
    for (int d = 1; d <= k; d++) {
        r *= n--;
        r /= d;
    }
    return r;
}
<|endoftext|>


<commit_before><commit_msg>the secondary axis should be on the right<commit_after><|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: controlpropertyhdl.cxx,v $
 *
 *  $Revision: 1.21 $
 *
 *  last change: $Author: kz $ $Date: 2008-04-03 16:45:19 $
 *
 *  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_xmloff.hxx"

#ifndef _XMLOFF_FORMS_CONTROLPROPERTYHDL_HXX_
#include <xmloff/controlpropertyhdl.hxx>
#endif
#ifndef _COM_SUN_STAR_AWT_TEXTALIGN_HPP_
#include <com/sun/star/awt/TextAlign.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_FONTWIDTH_HPP_
#include <com/sun/star/awt/FontWidth.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_FONTEMPHASISMARK_HPP_
#include <com/sun/star/awt/FontEmphasisMark.hpp>
#endif
#ifndef _XMLOFF_XMLTYPES_HXX
#include <xmloff/xmltypes.hxx>
#endif
#include "xmloff/NamedBoolPropertyHdl.hxx"
#ifndef _XMLOFF_FORMENUMS_HXX_
#include "formenums.hxx"
#endif
#ifndef _XMLOFF_XMLUCONV_HXX
#include <xmloff/xmluconv.hxx>
#endif
#ifndef _XMLOFF_XMLTOKEN_HXX
#include <xmloff/xmltoken.hxx>
#endif
#ifndef _RTL_USTRBUF_HXX_
#include <rtl/ustrbuf.hxx>
#endif
#ifndef _OSL_DIAGNOSE_H_
#include <osl/diagnose.h>
#endif
#ifndef _XMLOFF_FORMS_CALLBACKS_HXX_
#include "callbacks.hxx"
#endif
#ifndef _XMLOFF_XMLCONSTANTSPROPERTYHANDLER_HXX
#include <xmloff/XMLConstantsPropertyHandler.hxx>
#endif

//.........................................................................
namespace xmloff
{
//.........................................................................

    using namespace ::com::sun::star::uno;
    using namespace ::com::sun::star::awt;
    using namespace ::com::sun::star::beans;
    using namespace ::xmloff::token;

    //=====================================================================
    //= OControlPropertyHandlerFactory
    //=====================================================================
    //---------------------------------------------------------------------
    OControlPropertyHandlerFactory::OControlPropertyHandlerFactory()
        :m_pTextAlignHandler(NULL)
        ,m_pControlBorderStyleHandler(NULL)
        ,m_pControlBorderColorHandler(NULL)
        ,m_pRotationAngleHandler(NULL)
        ,m_pFontWidthHandler(NULL)
        ,m_pFontEmphasisHandler(NULL)
        ,m_pFontReliefHandler(NULL)
    {
    }

    //---------------------------------------------------------------------
    OControlPropertyHandlerFactory::~OControlPropertyHandlerFactory()
    {
        delete m_pTextAlignHandler;
        delete m_pControlBorderStyleHandler;
        delete m_pControlBorderColorHandler;
        delete m_pRotationAngleHandler;
        delete m_pFontWidthHandler;
        delete m_pFontEmphasisHandler;
        delete m_pFontReliefHandler;
    }

    //---------------------------------------------------------------------
    const XMLPropertyHandler* OControlPropertyHandlerFactory::GetPropertyHandler(sal_Int32 _nType) const
    {
        const XMLPropertyHandler* pHandler = NULL;

        switch (_nType)
        {
            case XML_TYPE_TEXT_ALIGN:
                if (!m_pTextAlignHandler)
                    m_pTextAlignHandler = new XMLConstantsPropertyHandler(OEnumMapper::getEnumMap(OEnumMapper::epTextAlign), XML_TOKEN_INVALID );
                pHandler = m_pTextAlignHandler;
                break;

            case XML_TYPE_CONTROL_BORDER:
                if (!m_pControlBorderStyleHandler)
                    m_pControlBorderStyleHandler = new OControlBorderStyleHandler;
                pHandler = m_pControlBorderStyleHandler;
                break;

            case XML_TYPE_CONTROL_BORDER_COLOR:
                if ( !m_pControlBorderColorHandler )
                    m_pControlBorderColorHandler = new OControlBorderColorHandler;
                pHandler = m_pControlBorderColorHandler;
                break;

            case XML_TYPE_ROTATION_ANGLE:
                if (!m_pRotationAngleHandler)
                    m_pRotationAngleHandler = new ORotationAngleHandler;
                pHandler = m_pRotationAngleHandler;
                break;

            case XML_TYPE_FONT_WIDTH:
                if (!m_pFontWidthHandler)
                    m_pFontWidthHandler = new OFontWidthHandler;
                pHandler = m_pFontWidthHandler;
                break;

            case XML_TYPE_CONTROL_TEXT_EMPHASIZE:
                if (!m_pFontEmphasisHandler)
                    m_pFontEmphasisHandler = new XMLConstantsPropertyHandler( OEnumMapper::getEnumMap(OEnumMapper::epFontEmphasis), XML_NONE );
                pHandler = m_pFontEmphasisHandler;
                break;

            case XML_TYPE_TEXT_FONT_RELIEF:
                if (!m_pFontReliefHandler)
                    m_pFontReliefHandler = new XMLConstantsPropertyHandler( OEnumMapper::getEnumMap(OEnumMapper::epFontRelief), XML_NONE );
                pHandler = m_pFontReliefHandler;
                break;
            case XML_TYPE_TEXT_LINE_MODE:
                pHandler = new XMLNamedBoolPropertyHdl(
                                            ::xmloff::token::XML_SKIP_WHITE_SPACE,
                                            ::xmloff::token::XML_CONTINUOUS);
                break;
        }

        if (!pHandler)
            pHandler = XMLPropertyHandlerFactory::GetPropertyHandler(_nType);
        return pHandler;
    }

    //=====================================================================
    //= OControlTextEmphasisHandler
    //=====================================================================
    OControlTextEmphasisHandler::OControlTextEmphasisHandler()
    {
    }

    //---------------------------------------------------------------------
    sal_Bool OControlTextEmphasisHandler::exportXML( ::rtl::OUString& _rStrExpValue, const Any& _rValue, const SvXMLUnitConverter& ) const
    {
        ::rtl::OUStringBuffer aReturn;
        sal_Bool bSuccess = sal_False;
        sal_Int16 nFontEmphasis = sal_Int16();
        if (_rValue >>= nFontEmphasis)
        {
            // the type
            sal_Int16 nType = nFontEmphasis & ~(FontEmphasisMark::ABOVE | FontEmphasisMark::BELOW);
            // the position of the mark
            sal_Bool bBelow = 0 != (nFontEmphasis & FontEmphasisMark::BELOW);

            // convert
            bSuccess = SvXMLUnitConverter::convertEnum(aReturn, nType, OEnumMapper::getEnumMap(OEnumMapper::epFontEmphasis), XML_NONE);
            if (bSuccess)
            {
                aReturn.append( (sal_Unicode)' ' );
                aReturn.append( GetXMLToken(bBelow ? XML_BELOW : XML_ABOVE) );

                _rStrExpValue = aReturn.makeStringAndClear();
            }
        }

        return bSuccess;
    }

    //---------------------------------------------------------------------
    sal_Bool OControlTextEmphasisHandler::importXML( const ::rtl::OUString& _rStrImpValue, Any& _rValue, const SvXMLUnitConverter& ) const
    {
        sal_Bool bSuccess = sal_True;
        sal_uInt16 nEmphasis = FontEmphasisMark::NONE;

        sal_Bool bBelow = sal_False;
        sal_Bool bHasPos = sal_False, bHasType = sal_False;

        ::rtl::OUString sToken;
        SvXMLTokenEnumerator aTokenEnum(_rStrImpValue);
        while (aTokenEnum.getNextToken(sToken))
        {
            if (!bHasPos)
            {
                if (IsXMLToken(sToken, XML_ABOVE))
                {
                    bBelow = sal_False;
                    bHasPos = sal_True;
                }
                else if (IsXMLToken(sToken, XML_BELOW))
                {
                    bBelow = sal_True;
                    bHasPos = sal_True;
                }
            }
            if (!bHasType)
            {
                if (SvXMLUnitConverter::convertEnum(nEmphasis, sToken, OEnumMapper::getEnumMap(OEnumMapper::epFontEmphasis)))
                {
                    bHasType = sal_True;
                }
                else
                {
                    bSuccess = sal_False;
                    break;
                }
            }
        }

        if (bSuccess)
        {
            nEmphasis |= bBelow ? FontEmphasisMark::BELOW : FontEmphasisMark::ABOVE;
            _rValue <<= (sal_Int16)nEmphasis;
        }

        return bSuccess;
    }

    //=====================================================================
    //= OControlBorderHandlerFactory
    //=====================================================================
    //---------------------------------------------------------------------
    const XMLPropertyHandler* OControlBorderHandlerFactory::createBorderHandler()
    {
        return new OControlBorderStyleHandler;
    }

    //---------------------------------------------------------------------
    const XMLPropertyHandler* OControlBorderHandlerFactory::createBorderColorHandler()
    {
        return new OControlBorderColorHandler;
    }

    //=====================================================================
    //= OControlBorderHandlerBase
    //=====================================================================
    //---------------------------------------------------------------------
    OControlBorderHandlerBase::OControlBorderHandlerBase()
    {
    }

    //---------------------------------------------------------------------
    sal_Bool OControlBorderHandlerBase::importXML( const ::rtl::OUString& _rStrImpValue, Any& _rValue, const SvXMLUnitConverter& ) const
    {
        ::rtl::OUString sToken;
        SvXMLTokenEnumerator aTokens(_rStrImpValue);

        sal_uInt16 nStyle = 1;
        Color aColor;

        sal_Bool bFoundStyle = sal_False;
        sal_Bool bFoundColor = sal_False;

        while   (   !( bFoundStyle && bFoundColor ) // did not yet find both aspects
                &&  aTokens.getNextToken(sToken)    // have a new token
                &&  (0 != sToken.getLength())       // really have a new token
                )
        {
            // is it a valid enum value?
            if ( !bFoundStyle )
                bFoundStyle = SvXMLUnitConverter::convertEnum(nStyle, sToken, OEnumMapper::getEnumMap(OEnumMapper::epBorderWidth));
            // is it a color value?
            if ( !bFoundColor )
                bFoundColor = SvXMLUnitConverter::convertColor( aColor, sToken );
        }

        if ( !bFoundStyle && !bFoundColor )
            return sal_False;

        // if we're here, the string could have had more or less than the requested 3 tokens, but we ignore this.
        // At least we have a valid style or a valid, which is everything we're interested in.
        pickOne( aColor, (sal_Int16)nStyle, _rValue );
        return sal_True;
    }

    //=====================================================================
    //= OControlBorderStyleHandler
    //=====================================================================
    //---------------------------------------------------------------------
    OControlBorderStyleHandler::OControlBorderStyleHandler()
    {
    }

    //---------------------------------------------------------------------
    sal_Bool OControlBorderStyleHandler::exportXML( ::rtl::OUString& _rStrExpValue, const Any& _rValue, const SvXMLUnitConverter& ) const
    {
        sal_Bool bSuccess = sal_False;
        sal_Int16 nBorder = 0;

        ::rtl::OUStringBuffer aOut;
        bSuccess =  (_rValue >>= nBorder)
                &&  SvXMLUnitConverter::convertEnum(aOut, nBorder, OEnumMapper::getEnumMap(OEnumMapper::epBorderWidth));

        if ( _rStrExpValue.getLength() )
            _rStrExpValue += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ) );
        _rStrExpValue += aOut.makeStringAndClear();
        return bSuccess;
    }

    //---------------------------------------------------------------------
    void OControlBorderStyleHandler::pickOne( const Color&, sal_Int16 _nStyle, Any& _rValue ) const
    {
        _rValue <<= _nStyle;
    }

    //=====================================================================
    //= OControlBorderColorHandler
    //=====================================================================
    //---------------------------------------------------------------------
    OControlBorderColorHandler::OControlBorderColorHandler()
    {
    }

    //---------------------------------------------------------------------
    sal_Bool OControlBorderColorHandler::exportXML( ::rtl::OUString& _rStrExpValue, const Any& _rValue, const SvXMLUnitConverter& ) const
    {
        sal_Bool bSuccess = sal_False;
        sal_Int32 nBorderColor = 0;

        ::rtl::OUStringBuffer aOut;
        if ( _rValue >>= nBorderColor )
        {
            SvXMLUnitConverter::convertColor( aOut, Color( nBorderColor ) );
            bSuccess = sal_True;
        }

        if ( _rStrExpValue.getLength() )
            _rStrExpValue += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ) );
        _rStrExpValue += aOut.makeStringAndClear();
        return bSuccess;
    }

    //---------------------------------------------------------------------
    void OControlBorderColorHandler::pickOne( const Color& _rColor, sal_Int16 /*_nStyle*/, Any& _rValue ) const
    {
        _rValue <<= (sal_Int32)_rColor.GetColor();
    }

    //=====================================================================
    //= OFontWidthHandler
    //=====================================================================
    //---------------------------------------------------------------------
    OFontWidthHandler::OFontWidthHandler()
    {
    }

    //---------------------------------------------------------------------
    sal_Bool OFontWidthHandler::importXML( const ::rtl::OUString& _rStrImpValue, Any& _rValue, const SvXMLUnitConverter& ) const
    {
        sal_Int32 nWidth = 0;
        sal_Bool bSuccess = SvXMLUnitConverter::convertMeasure(nWidth, _rStrImpValue, MAP_POINT);
        if (bSuccess)
            _rValue <<= (sal_Int16)nWidth;

        return bSuccess;
    }

    //---------------------------------------------------------------------
    sal_Bool OFontWidthHandler::exportXML( ::rtl::OUString& _rStrExpValue, const Any& _rValue, const SvXMLUnitConverter& ) const
    {
        sal_Int16 nWidth = 0;
        ::rtl::OUStringBuffer aResult;
        if (_rValue >>= nWidth)
            SvXMLUnitConverter::convertMeasure(aResult, nWidth, MAP_POINT, MAP_POINT);
        _rStrExpValue = aResult.makeStringAndClear();

        return _rStrExpValue.getLength() != 0;
    }

    //=====================================================================
    //= ORotationAngleHandler
    //=====================================================================
    //---------------------------------------------------------------------
    ORotationAngleHandler::ORotationAngleHandler()
    {
    }

    //---------------------------------------------------------------------
    sal_Bool ORotationAngleHandler::importXML( const ::rtl::OUString& _rStrImpValue, Any& _rValue, const SvXMLUnitConverter& ) const
    {
        double fValue;
        sal_Bool bSucces =
            SvXMLUnitConverter::convertDouble(fValue, _rStrImpValue);
        if (bSucces)
        {
            fValue *= 10;
            _rValue <<= (float)fValue;
        }

        return bSucces;
    }

    //---------------------------------------------------------------------
    sal_Bool ORotationAngleHandler::exportXML( ::rtl::OUString& _rStrExpValue, const Any& _rValue, const SvXMLUnitConverter& ) const
    {
        float fAngle = 0;
        sal_Bool bSuccess = (_rValue >>= fAngle);

        if (bSuccess)
        {
            rtl::OUStringBuffer sValue;
            SvXMLUnitConverter::convertDouble(sValue, ((double)fAngle) / 10);
            _rStrExpValue = sValue.makeStringAndClear();
        }

        return bSuccess;
    }

//.........................................................................
}   // namespace xmloff
//.........................................................................

<commit_msg>INTEGRATION: CWS changefileheader (1.20.160); FILE MERGED 2008/04/01 16:09:45 thb 1.20.160.3: #i85898# Stripping all external header guards 2008/04/01 13:04:48 thb 1.20.160.2: #i85898# Stripping all external header guards 2008/03/31 16:28:11 rt 1.20.160.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: controlpropertyhdl.cxx,v $
 * $Revision: 1.22 $
 *
 * 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_xmloff.hxx"
#include <xmloff/controlpropertyhdl.hxx>
#include <com/sun/star/awt/TextAlign.hpp>
#include <com/sun/star/awt/FontWidth.hpp>
#include <com/sun/star/awt/FontEmphasisMark.hpp>
#include <xmloff/xmltypes.hxx>
#include "xmloff/NamedBoolPropertyHdl.hxx"
#include "formenums.hxx"
#include <xmloff/xmluconv.hxx>
#include <xmloff/xmltoken.hxx>
#include <rtl/ustrbuf.hxx>
#include <osl/diagnose.h>
#include "callbacks.hxx"
#include <xmloff/XMLConstantsPropertyHandler.hxx>

//.........................................................................
namespace xmloff
{
//.........................................................................

    using namespace ::com::sun::star::uno;
    using namespace ::com::sun::star::awt;
    using namespace ::com::sun::star::beans;
    using namespace ::xmloff::token;

    //=====================================================================
    //= OControlPropertyHandlerFactory
    //=====================================================================
    //---------------------------------------------------------------------
    OControlPropertyHandlerFactory::OControlPropertyHandlerFactory()
        :m_pTextAlignHandler(NULL)
        ,m_pControlBorderStyleHandler(NULL)
        ,m_pControlBorderColorHandler(NULL)
        ,m_pRotationAngleHandler(NULL)
        ,m_pFontWidthHandler(NULL)
        ,m_pFontEmphasisHandler(NULL)
        ,m_pFontReliefHandler(NULL)
    {
    }

    //---------------------------------------------------------------------
    OControlPropertyHandlerFactory::~OControlPropertyHandlerFactory()
    {
        delete m_pTextAlignHandler;
        delete m_pControlBorderStyleHandler;
        delete m_pControlBorderColorHandler;
        delete m_pRotationAngleHandler;
        delete m_pFontWidthHandler;
        delete m_pFontEmphasisHandler;
        delete m_pFontReliefHandler;
    }

    //---------------------------------------------------------------------
    const XMLPropertyHandler* OControlPropertyHandlerFactory::GetPropertyHandler(sal_Int32 _nType) const
    {
        const XMLPropertyHandler* pHandler = NULL;

        switch (_nType)
        {
            case XML_TYPE_TEXT_ALIGN:
                if (!m_pTextAlignHandler)
                    m_pTextAlignHandler = new XMLConstantsPropertyHandler(OEnumMapper::getEnumMap(OEnumMapper::epTextAlign), XML_TOKEN_INVALID );
                pHandler = m_pTextAlignHandler;
                break;

            case XML_TYPE_CONTROL_BORDER:
                if (!m_pControlBorderStyleHandler)
                    m_pControlBorderStyleHandler = new OControlBorderStyleHandler;
                pHandler = m_pControlBorderStyleHandler;
                break;

            case XML_TYPE_CONTROL_BORDER_COLOR:
                if ( !m_pControlBorderColorHandler )
                    m_pControlBorderColorHandler = new OControlBorderColorHandler;
                pHandler = m_pControlBorderColorHandler;
                break;

            case XML_TYPE_ROTATION_ANGLE:
                if (!m_pRotationAngleHandler)
                    m_pRotationAngleHandler = new ORotationAngleHandler;
                pHandler = m_pRotationAngleHandler;
                break;

            case XML_TYPE_FONT_WIDTH:
                if (!m_pFontWidthHandler)
                    m_pFontWidthHandler = new OFontWidthHandler;
                pHandler = m_pFontWidthHandler;
                break;

            case XML_TYPE_CONTROL_TEXT_EMPHASIZE:
                if (!m_pFontEmphasisHandler)
                    m_pFontEmphasisHandler = new XMLConstantsPropertyHandler( OEnumMapper::getEnumMap(OEnumMapper::epFontEmphasis), XML_NONE );
                pHandler = m_pFontEmphasisHandler;
                break;

            case XML_TYPE_TEXT_FONT_RELIEF:
                if (!m_pFontReliefHandler)
                    m_pFontReliefHandler = new XMLConstantsPropertyHandler( OEnumMapper::getEnumMap(OEnumMapper::epFontRelief), XML_NONE );
                pHandler = m_pFontReliefHandler;
                break;
            case XML_TYPE_TEXT_LINE_MODE:
                pHandler = new XMLNamedBoolPropertyHdl(
                                            ::xmloff::token::XML_SKIP_WHITE_SPACE,
                                            ::xmloff::token::XML_CONTINUOUS);
                break;
        }

        if (!pHandler)
            pHandler = XMLPropertyHandlerFactory::GetPropertyHandler(_nType);
        return pHandler;
    }

    //=====================================================================
    //= OControlTextEmphasisHandler
    //=====================================================================
    OControlTextEmphasisHandler::OControlTextEmphasisHandler()
    {
    }

    //---------------------------------------------------------------------
    sal_Bool OControlTextEmphasisHandler::exportXML( ::rtl::OUString& _rStrExpValue, const Any& _rValue, const SvXMLUnitConverter& ) const
    {
        ::rtl::OUStringBuffer aReturn;
        sal_Bool bSuccess = sal_False;
        sal_Int16 nFontEmphasis = sal_Int16();
        if (_rValue >>= nFontEmphasis)
        {
            // the type
            sal_Int16 nType = nFontEmphasis & ~(FontEmphasisMark::ABOVE | FontEmphasisMark::BELOW);
            // the position of the mark
            sal_Bool bBelow = 0 != (nFontEmphasis & FontEmphasisMark::BELOW);

            // convert
            bSuccess = SvXMLUnitConverter::convertEnum(aReturn, nType, OEnumMapper::getEnumMap(OEnumMapper::epFontEmphasis), XML_NONE);
            if (bSuccess)
            {
                aReturn.append( (sal_Unicode)' ' );
                aReturn.append( GetXMLToken(bBelow ? XML_BELOW : XML_ABOVE) );

                _rStrExpValue = aReturn.makeStringAndClear();
            }
        }

        return bSuccess;
    }

    //---------------------------------------------------------------------
    sal_Bool OControlTextEmphasisHandler::importXML( const ::rtl::OUString& _rStrImpValue, Any& _rValue, const SvXMLUnitConverter& ) const
    {
        sal_Bool bSuccess = sal_True;
        sal_uInt16 nEmphasis = FontEmphasisMark::NONE;

        sal_Bool bBelow = sal_False;
        sal_Bool bHasPos = sal_False, bHasType = sal_False;

        ::rtl::OUString sToken;
        SvXMLTokenEnumerator aTokenEnum(_rStrImpValue);
        while (aTokenEnum.getNextToken(sToken))
        {
            if (!bHasPos)
            {
                if (IsXMLToken(sToken, XML_ABOVE))
                {
                    bBelow = sal_False;
                    bHasPos = sal_True;
                }
                else if (IsXMLToken(sToken, XML_BELOW))
                {
                    bBelow = sal_True;
                    bHasPos = sal_True;
                }
            }
            if (!bHasType)
            {
                if (SvXMLUnitConverter::convertEnum(nEmphasis, sToken, OEnumMapper::getEnumMap(OEnumMapper::epFontEmphasis)))
                {
                    bHasType = sal_True;
                }
                else
                {
                    bSuccess = sal_False;
                    break;
                }
            }
        }

        if (bSuccess)
        {
            nEmphasis |= bBelow ? FontEmphasisMark::BELOW : FontEmphasisMark::ABOVE;
            _rValue <<= (sal_Int16)nEmphasis;
        }

        return bSuccess;
    }

    //=====================================================================
    //= OControlBorderHandlerFactory
    //=====================================================================
    //---------------------------------------------------------------------
    const XMLPropertyHandler* OControlBorderHandlerFactory::createBorderHandler()
    {
        return new OControlBorderStyleHandler;
    }

    //---------------------------------------------------------------------
    const XMLPropertyHandler* OControlBorderHandlerFactory::createBorderColorHandler()
    {
        return new OControlBorderColorHandler;
    }

    //=====================================================================
    //= OControlBorderHandlerBase
    //=====================================================================
    //---------------------------------------------------------------------
    OControlBorderHandlerBase::OControlBorderHandlerBase()
    {
    }

    //---------------------------------------------------------------------
    sal_Bool OControlBorderHandlerBase::importXML( const ::rtl::OUString& _rStrImpValue, Any& _rValue, const SvXMLUnitConverter& ) const
    {
        ::rtl::OUString sToken;
        SvXMLTokenEnumerator aTokens(_rStrImpValue);

        sal_uInt16 nStyle = 1;
        Color aColor;

        sal_Bool bFoundStyle = sal_False;
        sal_Bool bFoundColor = sal_False;

        while   (   !( bFoundStyle && bFoundColor ) // did not yet find both aspects
                &&  aTokens.getNextToken(sToken)    // have a new token
                &&  (0 != sToken.getLength())       // really have a new token
                )
        {
            // is it a valid enum value?
            if ( !bFoundStyle )
                bFoundStyle = SvXMLUnitConverter::convertEnum(nStyle, sToken, OEnumMapper::getEnumMap(OEnumMapper::epBorderWidth));
            // is it a color value?
            if ( !bFoundColor )
                bFoundColor = SvXMLUnitConverter::convertColor( aColor, sToken );
        }

        if ( !bFoundStyle && !bFoundColor )
            return sal_False;

        // if we're here, the string could have had more or less than the requested 3 tokens, but we ignore this.
        // At least we have a valid style or a valid, which is everything we're interested in.
        pickOne( aColor, (sal_Int16)nStyle, _rValue );
        return sal_True;
    }

    //=====================================================================
    //= OControlBorderStyleHandler
    //=====================================================================
    //---------------------------------------------------------------------
    OControlBorderStyleHandler::OControlBorderStyleHandler()
    {
    }

    //---------------------------------------------------------------------
    sal_Bool OControlBorderStyleHandler::exportXML( ::rtl::OUString& _rStrExpValue, const Any& _rValue, const SvXMLUnitConverter& ) const
    {
        sal_Bool bSuccess = sal_False;
        sal_Int16 nBorder = 0;

        ::rtl::OUStringBuffer aOut;
        bSuccess =  (_rValue >>= nBorder)
                &&  SvXMLUnitConverter::convertEnum(aOut, nBorder, OEnumMapper::getEnumMap(OEnumMapper::epBorderWidth));

        if ( _rStrExpValue.getLength() )
            _rStrExpValue += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ) );
        _rStrExpValue += aOut.makeStringAndClear();
        return bSuccess;
    }

    //---------------------------------------------------------------------
    void OControlBorderStyleHandler::pickOne( const Color&, sal_Int16 _nStyle, Any& _rValue ) const
    {
        _rValue <<= _nStyle;
    }

    //=====================================================================
    //= OControlBorderColorHandler
    //=====================================================================
    //---------------------------------------------------------------------
    OControlBorderColorHandler::OControlBorderColorHandler()
    {
    }

    //---------------------------------------------------------------------
    sal_Bool OControlBorderColorHandler::exportXML( ::rtl::OUString& _rStrExpValue, const Any& _rValue, const SvXMLUnitConverter& ) const
    {
        sal_Bool bSuccess = sal_False;
        sal_Int32 nBorderColor = 0;

        ::rtl::OUStringBuffer aOut;
        if ( _rValue >>= nBorderColor )
        {
            SvXMLUnitConverter::convertColor( aOut, Color( nBorderColor ) );
            bSuccess = sal_True;
        }

        if ( _rStrExpValue.getLength() )
            _rStrExpValue += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ) );
        _rStrExpValue += aOut.makeStringAndClear();
        return bSuccess;
    }

    //---------------------------------------------------------------------
    void OControlBorderColorHandler::pickOne( const Color& _rColor, sal_Int16 /*_nStyle*/, Any& _rValue ) const
    {
        _rValue <<= (sal_Int32)_rColor.GetColor();
    }

    //=====================================================================
    //= OFontWidthHandler
    //=====================================================================
    //---------------------------------------------------------------------
    OFontWidthHandler::OFontWidthHandler()
    {
    }

    //---------------------------------------------------------------------
    sal_Bool OFontWidthHandler::importXML( const ::rtl::OUString& _rStrImpValue, Any& _rValue, const SvXMLUnitConverter& ) const
    {
        sal_Int32 nWidth = 0;
        sal_Bool bSuccess = SvXMLUnitConverter::convertMeasure(nWidth, _rStrImpValue, MAP_POINT);
        if (bSuccess)
            _rValue <<= (sal_Int16)nWidth;

        return bSuccess;
    }

    //---------------------------------------------------------------------
    sal_Bool OFontWidthHandler::exportXML( ::rtl::OUString& _rStrExpValue, const Any& _rValue, const SvXMLUnitConverter& ) const
    {
        sal_Int16 nWidth = 0;
        ::rtl::OUStringBuffer aResult;
        if (_rValue >>= nWidth)
            SvXMLUnitConverter::convertMeasure(aResult, nWidth, MAP_POINT, MAP_POINT);
        _rStrExpValue = aResult.makeStringAndClear();

        return _rStrExpValue.getLength() != 0;
    }

    //=====================================================================
    //= ORotationAngleHandler
    //=====================================================================
    //---------------------------------------------------------------------
    ORotationAngleHandler::ORotationAngleHandler()
    {
    }

    //---------------------------------------------------------------------
    sal_Bool ORotationAngleHandler::importXML( const ::rtl::OUString& _rStrImpValue, Any& _rValue, const SvXMLUnitConverter& ) const
    {
        double fValue;
        sal_Bool bSucces =
            SvXMLUnitConverter::convertDouble(fValue, _rStrImpValue);
        if (bSucces)
        {
            fValue *= 10;
            _rValue <<= (float)fValue;
        }

        return bSucces;
    }

    //---------------------------------------------------------------------
    sal_Bool ORotationAngleHandler::exportXML( ::rtl::OUString& _rStrExpValue, const Any& _rValue, const SvXMLUnitConverter& ) const
    {
        float fAngle = 0;
        sal_Bool bSuccess = (_rValue >>= fAngle);

        if (bSuccess)
        {
            rtl::OUStringBuffer sValue;
            SvXMLUnitConverter::convertDouble(sValue, ((double)fAngle) / 10);
            _rStrExpValue = sValue.makeStringAndClear();
        }

        return bSuccess;
    }

//.........................................................................
}   // namespace xmloff
//.........................................................................

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: controlpropertymap.cxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: fs $ $Date: 2001-01-18 13:51:30 $
 *
 *  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 EXPRESS 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 _XMLOFF_XMLNMSPE_HXX
#include "xmlnmspe.hxx"
#endif
#ifndef _XMLOFF_XMLKYWD_HXX
#include "xmlkywd.hxx"
#endif
#ifndef _XMLOFF_PROPMAPPINGTYPES_HXX
#include "maptype.hxx"
#endif
#ifndef _XMLOFF_XMLTYPES_HXX
#include "xmltypes.hxx"
#endif
#ifndef __SGI_STL_ALGORITHM
#include <stl/algorithm>
#endif

#ifndef _XMLOFF_FORMS_STRINGS_HXX_
#include "strings.hxx"
#endif
#include <string.h>

//.........................................................................
namespace xmloff
{
//.........................................................................

    XMLPropertyMapEntry aControlStyleProperties[] =
    {
        { PROPERTY_BACKGROUNDCOLOR, XML_NAMESPACE_FO, sXML_background_color,    XML_TYPE_COLOR, 0 },
        { PROPERTY_ALIGN,   XML_NAMESPACE_STYLE,    sXML_text_align,            XML_TYPE_TEXT_ALIGN, 0 },
        { PROPERTY_BORDER,  XML_NAMESPACE_FO,       sXML_border,                XML_TYPE_CONTROL_BORDER, 0 },
        { "FontCharWidth",  XML_NAMESPACE_STYLE,    sXML_font_char_width,       XML_TYPE_NUMBER16, 0 },
        { "FontCharset",    XML_NAMESPACE_STYLE,    sXML_font_charset,          XML_TYPE_TEXT_FONTENCODING, 0 },
        { "FontFamily",     XML_NAMESPACE_STYLE,    sXML_font_family_generic,   XML_TYPE_TEXT_FONTFAMILY, 0 },
        { "FontHeight",     XML_NAMESPACE_FO,       sXML_font_size,             XML_TYPE_CHAR_HEIGHT, 0 },
        { "FontKerning",    XML_NAMESPACE_STYLE,    sXML_letter_kerning,        XML_TYPE_BOOL, 0 },
        { "FontName",       XML_NAMESPACE_STYLE,    sXML_font_name,             XML_TYPE_STRING, 0 },
        { "FontOrientation",XML_NAMESPACE_STYLE,    sXML_rotation_angle,        XML_TYPE_ROTATION_ANGLE, 0 },
        { "FontPitch",      XML_NAMESPACE_STYLE,    sXML_font_pitch,            XML_TYPE_TEXT_FONTPITCH, 0 },
        { "FontSlant",      XML_NAMESPACE_FO,       sXML_font_style,            XML_TYPE_TEXT_POSTURE, 0 },
        { "FontStrikeout",  XML_NAMESPACE_STYLE,    sXML_text_crossing_out,     XML_TYPE_TEXT_CROSSEDOUT, 0 },
        { "FontStyleName",  XML_NAMESPACE_STYLE,    sXML_font_style_name,       XML_TYPE_STRING, 0 },
        // "FontType" - ignored - UnoControls don't use a FontType
        { "FontUnderline",  XML_NAMESPACE_STYLE,    sXML_text_underline,        XML_TYPE_TEXT_UNDERLINE, 0 },
        { "FontWeight",     XML_NAMESPACE_FO,       sXML_font_weight,           XML_TYPE_TEXT_WEIGHT, 0 },
        { "FontWidth",      XML_NAMESPACE_STYLE,    sXML_font_width,            XML_TYPE_FONT_WIDTH, 0 },
        { "FontWordLineMode",XML_NAMESPACE_FO,      sXML_score_spaces,          XML_TYPE_NBOOL, 0 },
        { 0, 0, 0, 0 }
    };

    //=====================================================================
    //---------------------------------------------------------------------
    struct XMLPropertyMapEntryLess
    {
        sal_Bool operator()(const XMLPropertyMapEntry& _rLeft, const XMLPropertyMapEntry& _rRight)
        {
            return strcmp(_rLeft.msApiName, _rRight.msApiName) < 0;
        }
    };

    //---------------------------------------------------------------------
    void implSortMap(XMLPropertyMapEntry* _pMap)
    {
        // determine the last element
        for (XMLPropertyMapEntry* pEnd = _pMap; pEnd->msApiName; ++pEnd)
            ;
        ::std::sort(_pMap, pEnd, XMLPropertyMapEntryLess());
    }

    //---------------------------------------------------------------------
    void initializePropertyMaps()
    {
        static sal_Bool bSorted = sal_False;
        if (!bSorted)
        {
            implSortMap(aControlStyleProperties);
            bSorted = sal_True;
        }
    }

//.........................................................................
}   // namespace xmloff
//.........................................................................

/*************************************************************************
 * history:
 *  $Log: not supported by cvs2svn $
 *  Revision 1.3  2000/12/19 12:13:57  fs
 *  some changes ... now the exported styles are XSL conform
 *
 *  Revision 1.1  2000/12/18 15:15:32  fs
 *  initial checkin - property maps
 *
 *
 *  Revision 1.0 14.12.00 10:09:14  fs
 ************************************************************************/

<commit_msg>chg: header<commit_after>/*************************************************************************
 *
 *  $RCSfile: controlpropertymap.cxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: mh $ $Date: 2001-02-01 17:41:18 $
 *
 *  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 EXPRESS 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 _XMLOFF_XMLNMSPE_HXX
#include "xmlnmspe.hxx"
#endif
#ifndef _XMLOFF_XMLKYWD_HXX
#include "xmlkywd.hxx"
#endif
#ifndef _XMLOFF_PROPMAPPINGTYPES_HXX
#include "maptype.hxx"
#endif
#ifndef _XMLOFF_XMLTYPES_HXX
#include "xmltypes.hxx"
#endif
#ifndef __SGI_STL_ALGORITHM
#include <algorithm>
#endif

#ifndef _XMLOFF_FORMS_STRINGS_HXX_
#include "strings.hxx"
#endif
#include <string.h>

//.........................................................................
namespace xmloff
{
//.........................................................................

    XMLPropertyMapEntry aControlStyleProperties[] =
    {
        { PROPERTY_BACKGROUNDCOLOR, XML_NAMESPACE_FO, sXML_background_color,    XML_TYPE_COLOR, 0 },
        { PROPERTY_ALIGN,   XML_NAMESPACE_STYLE,    sXML_text_align,            XML_TYPE_TEXT_ALIGN, 0 },
        { PROPERTY_BORDER,  XML_NAMESPACE_FO,       sXML_border,                XML_TYPE_CONTROL_BORDER, 0 },
        { "FontCharWidth",  XML_NAMESPACE_STYLE,    sXML_font_char_width,       XML_TYPE_NUMBER16, 0 },
        { "FontCharset",    XML_NAMESPACE_STYLE,    sXML_font_charset,          XML_TYPE_TEXT_FONTENCODING, 0 },
        { "FontFamily",     XML_NAMESPACE_STYLE,    sXML_font_family_generic,   XML_TYPE_TEXT_FONTFAMILY, 0 },
        { "FontHeight",     XML_NAMESPACE_FO,       sXML_font_size,             XML_TYPE_CHAR_HEIGHT, 0 },
        { "FontKerning",    XML_NAMESPACE_STYLE,    sXML_letter_kerning,        XML_TYPE_BOOL, 0 },
        { "FontName",       XML_NAMESPACE_STYLE,    sXML_font_name,             XML_TYPE_STRING, 0 },
        { "FontOrientation",XML_NAMESPACE_STYLE,    sXML_rotation_angle,        XML_TYPE_ROTATION_ANGLE, 0 },
        { "FontPitch",      XML_NAMESPACE_STYLE,    sXML_font_pitch,            XML_TYPE_TEXT_FONTPITCH, 0 },
        { "FontSlant",      XML_NAMESPACE_FO,       sXML_font_style,            XML_TYPE_TEXT_POSTURE, 0 },
        { "FontStrikeout",  XML_NAMESPACE_STYLE,    sXML_text_crossing_out,     XML_TYPE_TEXT_CROSSEDOUT, 0 },
        { "FontStyleName",  XML_NAMESPACE_STYLE,    sXML_font_style_name,       XML_TYPE_STRING, 0 },
        // "FontType" - ignored - UnoControls don't use a FontType
        { "FontUnderline",  XML_NAMESPACE_STYLE,    sXML_text_underline,        XML_TYPE_TEXT_UNDERLINE, 0 },
        { "FontWeight",     XML_NAMESPACE_FO,       sXML_font_weight,           XML_TYPE_TEXT_WEIGHT, 0 },
        { "FontWidth",      XML_NAMESPACE_STYLE,    sXML_font_width,            XML_TYPE_FONT_WIDTH, 0 },
        { "FontWordLineMode",XML_NAMESPACE_FO,      sXML_score_spaces,          XML_TYPE_NBOOL, 0 },
        { 0, 0, 0, 0 }
    };

    //=====================================================================
    //---------------------------------------------------------------------
    struct XMLPropertyMapEntryLess
    {
        sal_Bool operator()(const XMLPropertyMapEntry& _rLeft, const XMLPropertyMapEntry& _rRight)
        {
            return strcmp(_rLeft.msApiName, _rRight.msApiName) < 0;
        }
    };

    //---------------------------------------------------------------------
    void implSortMap(XMLPropertyMapEntry* _pMap)
    {
        // determine the last element
        for (XMLPropertyMapEntry* pEnd = _pMap; pEnd->msApiName; ++pEnd)
            ;
        ::std::sort(_pMap, pEnd, XMLPropertyMapEntryLess());
    }

    //---------------------------------------------------------------------
    void initializePropertyMaps()
    {
        static sal_Bool bSorted = sal_False;
        if (!bSorted)
        {
            implSortMap(aControlStyleProperties);
            bSorted = sal_True;
        }
    }

//.........................................................................
}   // namespace xmloff
//.........................................................................

/*************************************************************************
 * history:
 *  $Log: not supported by cvs2svn $
 *  Revision 1.4  2001/01/18 13:51:30  fs
 *  the background-color is part of the fo (not style) namespace
 *
 *  Revision 1.3  2000/12/19 12:13:57  fs
 *  some changes ... now the exported styles are XSL conform
 *
 *  Revision 1.1  2000/12/18 15:15:32  fs
 *  initial checkin - property maps
 *
 *
 *  Revision 1.0 14.12.00 10:09:14  fs
 ************************************************************************/

<|endoftext|>


<commit_before>#include "stdsneezy.h"

int task_sacrifice(TBeing *ch, cmdTypeT cmd, const char *, int pulse, TRoom *, TObj *obj)
{
  TThing *t, *t2;
  TMonster *guard;
  TTool *totem=NULL;
  int found=0;
  //  TBeing *dummy;
  int learning = ch->getSkillValue(SKILL_SACRIFICE);
  TBaseCorpse *corpse = dynamic_cast<TBaseCorpse *>(obj);
  int clev = ch->GetMaxLevel();
  int percent = ::number(1, 100);
  int factor = ::number(1, ((clev * learning) / 2));
  int factor2 = ((::number(1, (clev * learning)) / 20) * 4);

  if (ch->utilityTaskCommand(cmd) || ch->nobrainerTaskCommand(cmd))
    return FALSE;

  if (ch->isLinkdead() || (ch->in_room != ch->task->wasInRoom) || (ch->getPosition() < POSITION_RESTING)) {
    act("You cease the ritual sacrifice of $p.", FALSE, ch, corpse, 0, TO_CHAR);
    act("$n stops trying to sacrifice $p.", TRUE, ch, corpse, 0, TO_ROOM);
    ch->stopTask();
    if (corpse->isCorpseFlag(CORPSE_SACRIFICE))
      corpse->remCorpseFlag(CORPSE_SACRIFICE);
    return FALSE;
  }

  if ((obj != ch->heldInPrimHand()) && (obj != ch->heldInSecHand())) {
    for (t = ch->roomp->stuff; t; t = t2) {
      t2 = t->nextThing;
      if (obj == dynamic_cast<TObj *>(t))
        found = 1;
    }
    if (!found) {
      act("You can't find the object of the ritual! Wasn't there a corpse here?", FALSE, ch, 0, 0, TO_CHAR);
      act("$n stops singing and looks confused.", TRUE, ch, 0, 0, TO_ROOM);
      ch->stopTask();
      return FALSE;
    }
  }

  if (!(t = get_thing_char_using(ch, "totem", 0, FALSE, FALSE)) || !(totem=dynamic_cast<TTool *>(t))) {
    ch->sendTo("You need to own a totem to perform the ritual.\n\r");
    ch->stopTask();
    if (corpse->isCorpseFlag(CORPSE_SACRIFICE))
      corpse->remCorpseFlag(CORPSE_SACRIFICE);
    return FALSE;
  }

  for (t = ch->roomp->stuff; t; t = t2) {
    t2 = t->nextThing;
    guard = dynamic_cast<TMonster *>(t);
    if (!guard)
      continue;
    if (!guard->isPolice() || !guard->canSee(ch) || !guard->awake())
      continue;
    int saything = (::number(0,3));
    switch (saything) {
      case 0:
	guard->doSay("Hey! Get the hell out of here! Damn Voodoo Witch!");
	break;
      case 1:
	guard->doSay("Hey! Don't you have any respect for the dead?!? Get the hell out of here!");
	break;
      case 2:
	guard->doSay("Damn Shaman! Take your voodoo crap and PISS OFF!!!");
	break;
      case 3:
	guard->doSay("Hey witch!! Are you some sort of whacked out necrophiliac? Bugger off!!");
	break;
    }
    act("You cease the ritual sacrifice of $p.", FALSE, ch, corpse, 0, TO_CHAR);
    act("$n stops chanting over the corpse of $p.", TRUE, ch, corpse, 0, TO_ROOM);
    ch->stopTask();
    if (corpse->isCorpseFlag(CORPSE_SACRIFICE))
      corpse->remCorpseFlag(CORPSE_SACRIFICE);
    return FALSE;
  }

  if (ch->task->timeLeft < 0){
    act("You have completed the sacrifice of $p.", FALSE, ch, corpse, 0, TO_CHAR);
    act("$n has completed $s ritual sacrifice of $p.", FALSE, ch, corpse, 0, TO_ROOM);
    act("Some <r>blood<z> from $p has been left behind.", FALSE, ch, corpse, 0, TO_ROOM);
    act("Some <r>blood<z> from $p has been left behind for the dogs!", FALSE, ch, corpse, 0, TO_CHAR);
    ch->dropPool(1, LIQ_BLOOD);
    ch->stopTask();
    if (corpse->isCorpseFlag(CORPSE_SACRIFICE))
      corpse->remCorpseFlag(CORPSE_SACRIFICE);
    return DELETE_ITEM;
  }

  if (percent < ch->getSkillValue(SKILL_SACRIFICE)) {
    act("Your sacrifice is being accepted by the loa.", FALSE, ch, 0, 0, TO_CHAR);
    ch->addToLifeforce(factor);
    ch->updatePos();
  } else {
    ch->addToLifeforce(-factor2);
    if (0 >= ch->getLifeforce()) {
      ch->setLifeforce(0);
      act("The loa demands that you cease this vain sacrifice, and you comply.", FALSE, ch, 0, 0, TO_CHAR);
      ch->addToHit(-2);
      ch->updatePos();
      ch->task->timeLeft = -1;
    }
  }

  switch (cmd) {
  case CMD_TASK_CONTINUE:
    ch->task->calcNextUpdate(pulse, 2);
    totem->addToToolUses(-1);
    if (totem->getToolUses() <= 0) {
      act("Your $o has been confiscated by the loa! It must have been too weak.", FALSE, ch, totem, 0, TO_CHAR);
      act("$n looks pale as $s $o shatters.", FALSE, ch, totem, 0, TO_ROOM);
      ch->stopTask();
      delete totem;
      if (corpse->isCorpseFlag(CORPSE_SACRIFICE))
	corpse->remCorpseFlag(CORPSE_SACRIFICE);
      return FALSE;
    }
    switch (ch->task->timeLeft) {
      case 2:
	if (!corpse) {
	  act("You can't find the object of the ritual! Wasn't there $p's corpse here?", FALSE, ch, corpse, 0, TO_CHAR);
	  act("$n stops singing and looks confused.", TRUE, ch, 0, 0, TO_ROOM);
	  return FALSE;
	} else {
  	  if (10 >= corpse->obj_flags.decay_time) {
	    corpse->obj_flags.decay_time = 10;
	  }
          act("You continue the rada song to the loa in hopes they will accept your sacrifice.", FALSE, ch, 0, 0, TO_CHAR);
          act("$n sings in an unfamiliar tongue over $p.", TRUE, ch, corpse, 0, TO_ROOM);
	  if (bSuccess(ch, learning, SKILL_SACRIFICE)) {
	    ch->task->timeLeft--;
	  } else {
	    ch->task->timeLeft = 2;
	  }
	}
	break;
      case 1:
	if (!corpse) {
	  act("You can't find the object of the ritual! Wasn't there a corpse here?", FALSE, ch, 0, 0, TO_CHAR);
	  act("$n stops singing and looks confused.", TRUE, ch, 0, 0, TO_ROOM);
	  return FALSE;
	} else {
  	  if (10 >= corpse->obj_flags.decay_time) {
	    corpse->obj_flags.decay_time = 10;
	  }
          act("Your $o's eyes glow <r>blood red<1>.", FALSE, ch, totem, 0, TO_CHAR);
          act("The eyes on $n's $o begin to glow a <r>blood red<1>.", TRUE, ch, totem, 0, TO_ROOM);
	  if (bSuccess(ch, learning, SKILL_SACRIFICE)) {
	    ch->task->timeLeft--;
 	  } else {
	    ch->task->timeLeft = 1;
	  }
	}
	break;
      case 0:
	if (!corpse) {
	  act("You can't find the object of the ritual! Wasn't there a corpse here?", FALSE, ch, 0, 0, TO_CHAR);
	  act("$n stops singing and looks confused.", TRUE, ch, 0, 0, TO_ROOM);
	  return FALSE;
	} else {
  	  if (10 >= corpse->obj_flags.decay_time) {
	    corpse->obj_flags.decay_time = 10;
	  }
	  act("You continue to sing the rada song over $p.", FALSE, ch, corpse, 0, TO_CHAR);
	  act("$n's ritual sacrifice causes $p's face to glow <G>pale green<1>.", FALSE, ch, corpse, 0, TO_ROOM);
	  if (bSuccess(ch, learning, SKILL_SACRIFICE)) {
	    ch->task->timeLeft--;
	  } else {
	    ch->task->timeLeft = 0;
	  }
	}
	break;
    }
    break;
  case CMD_ABORT:
  case CMD_STOP:
      act("You stop performing the ritual.", FALSE, ch, 0, 0, TO_CHAR);
      act("$n stops singing.", TRUE, ch, 0, 0, TO_ROOM);
      ch->stopTask();
      delete corpse;
      break;
  case CMD_TASK_FIGHTING:
      ch->sendTo("You can't sacrifice a corpse while under attack.\n\r");
      ch->stopTask();
      delete corpse;
      break;
  default:
      if (cmd < MAX_CMD_LIST)
        warn_busy(ch);
      break;
  }
  return TRUE;
}
<commit_msg>opps formula mistake<commit_after>#include "stdsneezy.h"

int task_sacrifice(TBeing *ch, cmdTypeT cmd, const char *, int pulse, TRoom *, TObj *obj)
{
  TThing *t, *t2;
  TMonster *guard;
  TTool *totem=NULL;
  int found=0;
  //  TBeing *dummy;
  int learning = ch->getSkillValue(SKILL_SACRIFICE);
  TBaseCorpse *corpse = dynamic_cast<TBaseCorpse *>(obj);
  int clev = ch->GetMaxLevel();
  int percent = ::number(1, 100);
  int factor = ::number(1, ((clev + learning) / 2));
  int factor2 = ((::number(1, (clev + learning)) / 20) * 4);

  if (ch->utilityTaskCommand(cmd) || ch->nobrainerTaskCommand(cmd))
    return FALSE;

  if (ch->isLinkdead() || (ch->in_room != ch->task->wasInRoom) || (ch->getPosition() < POSITION_RESTING)) {
    act("You cease the ritual sacrifice of $p.", FALSE, ch, corpse, 0, TO_CHAR);
    act("$n stops trying to sacrifice $p.", TRUE, ch, corpse, 0, TO_ROOM);
    ch->stopTask();
    if (corpse->isCorpseFlag(CORPSE_SACRIFICE))
      corpse->remCorpseFlag(CORPSE_SACRIFICE);
    return FALSE;
  }

  if ((obj != ch->heldInPrimHand()) && (obj != ch->heldInSecHand())) {
    for (t = ch->roomp->stuff; t; t = t2) {
      t2 = t->nextThing;
      if (obj == dynamic_cast<TObj *>(t))
        found = 1;
    }
    if (!found) {
      act("You can't find the object of the ritual! Wasn't there a corpse here?", FALSE, ch, 0, 0, TO_CHAR);
      act("$n stops singing and looks confused.", TRUE, ch, 0, 0, TO_ROOM);
      ch->stopTask();
      return FALSE;
    }
  }

  if (!(t = get_thing_char_using(ch, "totem", 0, FALSE, FALSE)) || !(totem=dynamic_cast<TTool *>(t))) {
    ch->sendTo("You need to own a totem to perform the ritual.\n\r");
    ch->stopTask();
    if (corpse->isCorpseFlag(CORPSE_SACRIFICE))
      corpse->remCorpseFlag(CORPSE_SACRIFICE);
    return FALSE;
  }

  for (t = ch->roomp->stuff; t; t = t2) {
    t2 = t->nextThing;
    guard = dynamic_cast<TMonster *>(t);
    if (!guard)
      continue;
    if (!guard->isPolice() || !guard->canSee(ch) || !guard->awake())
      continue;
    int saything = (::number(0,3));
    switch (saything) {
      case 0:
	guard->doSay("Hey! Get the hell out of here! Damn Voodoo Witch!");
	break;
      case 1:
	guard->doSay("Hey! Don't you have any respect for the dead?!? Get the hell out of here!");
	break;
      case 2:
	guard->doSay("Damn Shaman! Take your voodoo crap and PISS OFF!!!");
	break;
      case 3:
	guard->doSay("Hey witch!! Are you some sort of whacked out necrophiliac? Bugger off!!");
	break;
    }
    act("You cease the ritual sacrifice of $p.", FALSE, ch, corpse, 0, TO_CHAR);
    act("$n stops chanting over the corpse of $p.", TRUE, ch, corpse, 0, TO_ROOM);
    ch->stopTask();
    if (corpse->isCorpseFlag(CORPSE_SACRIFICE))
      corpse->remCorpseFlag(CORPSE_SACRIFICE);
    return FALSE;
  }

  if (ch->task->timeLeft < 0){
    act("You have completed the sacrifice of $p.", FALSE, ch, corpse, 0, TO_CHAR);
    act("$n has completed $s ritual sacrifice of $p.", FALSE, ch, corpse, 0, TO_ROOM);
    act("Some <r>blood<z> from $p has been left behind.", FALSE, ch, corpse, 0, TO_ROOM);
    act("Some <r>blood<z> from $p has been left behind for the dogs!", FALSE, ch, corpse, 0, TO_CHAR);
    ch->dropPool(1, LIQ_BLOOD);
    ch->stopTask();
    if (corpse->isCorpseFlag(CORPSE_SACRIFICE))
      corpse->remCorpseFlag(CORPSE_SACRIFICE);
    return DELETE_ITEM;
  }

  if (percent < ch->getSkillValue(SKILL_SACRIFICE)) {
    act("Your sacrifice is being accepted by the loa.", FALSE, ch, 0, 0, TO_CHAR);
    ch->addToLifeforce(factor);
    ch->updatePos();
  } else {
    ch->addToLifeforce(-factor2);
    if (0 >= ch->getLifeforce()) {
      ch->setLifeforce(0);
      act("The loa demands that you cease this vain sacrifice, and you comply.", FALSE, ch, 0, 0, TO_CHAR);
      ch->addToHit(-2);
      ch->updatePos();
      ch->task->timeLeft = -1;
    }
  }

  switch (cmd) {
  case CMD_TASK_CONTINUE:
    ch->task->calcNextUpdate(pulse, 2);
    totem->addToToolUses(-1);
    if (totem->getToolUses() <= 0) {
      act("Your $o has been confiscated by the loa! It must have been too weak.", FALSE, ch, totem, 0, TO_CHAR);
      act("$n looks pale as $s $o shatters.", FALSE, ch, totem, 0, TO_ROOM);
      ch->stopTask();
      delete totem;
      if (corpse->isCorpseFlag(CORPSE_SACRIFICE))
	corpse->remCorpseFlag(CORPSE_SACRIFICE);
      return FALSE;
    }
    switch (ch->task->timeLeft) {
      case 2:
	if (!corpse) {
	  act("You can't find the object of the ritual! Wasn't there $p's corpse here?", FALSE, ch, corpse, 0, TO_CHAR);
	  act("$n stops singing and looks confused.", TRUE, ch, 0, 0, TO_ROOM);
	  return FALSE;
	} else {
  	  if (10 >= corpse->obj_flags.decay_time) {
	    corpse->obj_flags.decay_time = 10;
	  }
          act("You continue the rada song to the loa in hopes they will accept your sacrifice.", FALSE, ch, 0, 0, TO_CHAR);
          act("$n sings in an unfamiliar tongue over $p.", TRUE, ch, corpse, 0, TO_ROOM);
	  if (bSuccess(ch, learning, SKILL_SACRIFICE)) {
	    ch->task->timeLeft--;
	  } else {
	    ch->task->timeLeft = 2;
	  }
	}
	break;
      case 1:
	if (!corpse) {
	  act("You can't find the object of the ritual! Wasn't there a corpse here?", FALSE, ch, 0, 0, TO_CHAR);
	  act("$n stops singing and looks confused.", TRUE, ch, 0, 0, TO_ROOM);
	  return FALSE;
	} else {
  	  if (10 >= corpse->obj_flags.decay_time) {
	    corpse->obj_flags.decay_time = 10;
	  }
          act("Your $o's eyes glow <r>blood red<1>.", FALSE, ch, totem, 0, TO_CHAR);
          act("The eyes on $n's $o begin to glow a <r>blood red<1>.", TRUE, ch, totem, 0, TO_ROOM);
	  if (bSuccess(ch, learning, SKILL_SACRIFICE)) {
	    ch->task->timeLeft--;
 	  } else {
	    ch->task->timeLeft = 1;
	  }
	}
	break;
      case 0:
	if (!corpse) {
	  act("You can't find the object of the ritual! Wasn't there a corpse here?", FALSE, ch, 0, 0, TO_CHAR);
	  act("$n stops singing and looks confused.", TRUE, ch, 0, 0, TO_ROOM);
	  return FALSE;
	} else {
  	  if (10 >= corpse->obj_flags.decay_time) {
	    corpse->obj_flags.decay_time = 10;
	  }
	  act("You continue to sing the rada song over $p.", FALSE, ch, corpse, 0, TO_CHAR);
	  act("$n's ritual sacrifice causes $p's face to glow <G>pale green<1>.", FALSE, ch, corpse, 0, TO_ROOM);
	  if (bSuccess(ch, learning, SKILL_SACRIFICE)) {
	    ch->task->timeLeft--;
	  } else {
	    ch->task->timeLeft = 0;
	  }
	}
	break;
    }
    break;
  case CMD_ABORT:
  case CMD_STOP:
      act("You stop performing the ritual.", FALSE, ch, 0, 0, TO_CHAR);
      act("$n stops singing.", TRUE, ch, 0, 0, TO_ROOM);
      ch->stopTask();
      delete corpse;
      break;
  case CMD_TASK_FIGHTING:
      ch->sendTo("You can't sacrifice a corpse while under attack.\n\r");
      ch->stopTask();
      delete corpse;
      break;
  default:
      if (cmd < MAX_CMD_LIST)
        warn_busy(ch);
      break;
  }
  return TRUE;
}
<|endoftext|>


<commit_before><commit_msg>defining methods<commit_after>#include <iostream>

class Number
{

private:
    int number;

    std::vector<int> function getFactors();
    int function getLargestPrimeFactor();
}

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: treeiterators.hxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-08 03:22:17 $
 *
 *  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 CONFIGMGR_TREEITERATORS_HXX_
#define CONFIGMGR_TREEITERATORS_HXX_

#ifndef CONFIGMGR_CONFIGNODE_HXX_
#include "noderef.hxx"
#endif

#ifndef _COM_SUN_STAR_BEANS_PROPERTY_HPP_
#include <com/sun/star/beans/Property.hpp>
#endif
#ifndef _RTL_USTRING_HXX_
#include <rtl/ustring.hxx>
#endif

#ifndef INCLUDED_VECTOR
#include <vector>
#define INCLUDED_VECTOR
#endif

// .......................................................................
namespace configmgr
{
// .......................................................................
    using rtl::OUString;

    namespace configapi
    {
        // ===================================================================
        // = CollectNodeNames
        // ===================================================================
        class CollectNodeNames :  public configuration::NodeVisitor
        {
        public:
            typedef std::vector<OUString> NameList;

        protected:
            NameList    m_aList;

        public:
            CollectNodeNames() { }

            virtual Result handle(configuration::Tree const& aTree, configuration::NodeRef const& aNode); // NodeVisitor
            virtual Result handle(configuration::Tree const& aTree, configuration::ValueRef const& aNode); // NodeVisitor

            NameList const& list() const { return m_aList; }
        };

        // ===================================================================
        // = CollectPropertyInfo
        // ===================================================================
        class CollectPropertyInfo :  public configuration::NodeVisitor
        {
        public:
            typedef com::sun::star::beans::Property Property;
            typedef std::vector<Property> PropertyList;

        protected:
            PropertyList    m_aList;

        public:
            CollectPropertyInfo() { }

            virtual Result handle(configuration::Tree const& aTree, configuration::NodeRef const& aNode); // NodeVisitor
            virtual Result handle(configuration::Tree const& aTree, configuration::ValueRef const& aNode); // NodeVisitor

            PropertyList const& list() const { return m_aList; }
        };
    }
// .......................................................................
}   // namespace configmgr
// .......................................................................

#endif // _CONFIGMGR_TREEITERATORS_HXX_

<commit_msg>INTEGRATION: CWS changefileheader (1.3.130); FILE MERGED 2008/04/01 15:06:34 thb 1.3.130.3: #i85898# Stripping all external header guards 2008/04/01 12:27:14 thb 1.3.130.2: #i85898# Stripping all external header guards 2008/03/31 12:22:38 rt 1.3.130.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: treeiterators.hxx,v $
 * $Revision: 1.4 $
 *
 * 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 CONFIGMGR_TREEITERATORS_HXX_
#define CONFIGMGR_TREEITERATORS_HXX_

#include "noderef.hxx"
#include <com/sun/star/beans/Property.hpp>
#include <rtl/ustring.hxx>

#ifndef INCLUDED_VECTOR
#include <vector>
#define INCLUDED_VECTOR
#endif

// .......................................................................
namespace configmgr
{
// .......................................................................
    using rtl::OUString;

    namespace configapi
    {
        // ===================================================================
        // = CollectNodeNames
        // ===================================================================
        class CollectNodeNames :  public configuration::NodeVisitor
        {
        public:
            typedef std::vector<OUString> NameList;

        protected:
            NameList    m_aList;

        public:
            CollectNodeNames() { }

            virtual Result handle(configuration::Tree const& aTree, configuration::NodeRef const& aNode); // NodeVisitor
            virtual Result handle(configuration::Tree const& aTree, configuration::ValueRef const& aNode); // NodeVisitor

            NameList const& list() const { return m_aList; }
        };

        // ===================================================================
        // = CollectPropertyInfo
        // ===================================================================
        class CollectPropertyInfo :  public configuration::NodeVisitor
        {
        public:
            typedef com::sun::star::beans::Property Property;
            typedef std::vector<Property> PropertyList;

        protected:
            PropertyList    m_aList;

        public:
            CollectPropertyInfo() { }

            virtual Result handle(configuration::Tree const& aTree, configuration::NodeRef const& aNode); // NodeVisitor
            virtual Result handle(configuration::Tree const& aTree, configuration::ValueRef const& aNode); // NodeVisitor

            PropertyList const& list() const { return m_aList; }
        };
    }
// .......................................................................
}   // namespace configmgr
// .......................................................................

#endif // _CONFIGMGR_TREEITERATORS_HXX_

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: backendfactory.hxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: hr $ $Date: 2003-03-19 16:18:53 $
 *
 *  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 CONFIGMGR_BACKENDFACTORY_HXX_
#define CONFIGMGR_BACKENDFACTORY_HXX_

#ifndef _RTL_REF_HXX_
#include <rtl/ref.hxx>
#endif

#ifndef _COM_SUN_STAR_UNO_XCOMPONENTCONTEXT_HPP_
#include <com/sun/star/uno/XComponentContext.hpp>
#endif
#include <drafts/com/sun/star/configuration/backend/XBackend.hpp>

namespace configmgr
{
//-----------------------------------------------------------------------------
    namespace backend
    {
//-----------------------------------------------------------------------------

        struct IMergedDataProvider;
//-----------------------------------------------------------------------------
        class BackendFactory
        {
        public:
            typedef com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
                CreationContext;

            typedef com::sun::star::uno::Reference< drafts::com::sun::star::configuration::backend::XBackend >
                UnoBackend;

            rtl::Reference<IMergedDataProvider> createBackend();

            UnoBackend getUnoBackend();

            static BackendFactory instance(CreationContext const & _xCtx);

        private:
            explicit
            BackendFactory(CreationContext const & _xCtx)
            : m_xCtx(_xCtx)
            {}

            CreationContext m_xCtx;
        };
//-----------------------------------------------------------------------------
    }
//-----------------------------------------------------------------------------
}

#endif

<commit_msg>INTEGRATION: CWS configapi01 (1.4.10); FILE MERGED 2003/04/10 15:47:19 jb 1.4.10.1: #1077715# Move configuration backend API out of drafts; adjust to API changes<commit_after>/*************************************************************************
 *
 *  $RCSfile: backendfactory.hxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: rt $ $Date: 2003-04-17 13:27:47 $
 *
 *  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 CONFIGMGR_BACKENDFACTORY_HXX_
#define CONFIGMGR_BACKENDFACTORY_HXX_

#ifndef _RTL_REF_HXX_
#include <rtl/ref.hxx>
#endif

#ifndef _COM_SUN_STAR_UNO_XCOMPONENTCONTEXT_HPP_
#include <com/sun/star/uno/XComponentContext.hpp>
#endif
#ifndef _COM_SUN_STAR_CONFIGURATION_BACKEND_XBACKEND_HPP_
#include <com/sun/star/configuration/backend/XBackend.hpp>
#endif

namespace configmgr
{
//-----------------------------------------------------------------------------
    namespace backend
    {
//-----------------------------------------------------------------------------

        struct IMergedDataProvider;
//-----------------------------------------------------------------------------
        class BackendFactory
        {
        public:
            typedef com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
                CreationContext;

            typedef com::sun::star::uno::Reference< com::sun::star::configuration::backend::XBackend >
                UnoBackend;

            rtl::Reference<IMergedDataProvider> createBackend();

            UnoBackend getUnoBackend();

            static BackendFactory instance(CreationContext const & _xCtx);

        private:
            explicit
            BackendFactory(CreationContext const & _xCtx)
            : m_xCtx(_xCtx)
            {}

            CreationContext m_xCtx;
        };
//-----------------------------------------------------------------------------
    }
//-----------------------------------------------------------------------------
}

#endif

<|endoftext|>


<commit_before>//===--- CodeGenTypes.cpp - Type translation for LLVM CodeGen -------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file was developed by Chris Lattner and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This is the code that handles AST -> LLVM type lowering.
//
//===----------------------------------------------------------------------===//

#include "CodeGenTypes.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/AST/AST.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Module.h"

using namespace clang;
using namespace CodeGen;

CodeGenTypes::CodeGenTypes(ASTContext &Ctx, llvm::Module& M)
  : Context(Ctx), Target(Ctx.Target), TheModule(M) {
}

/// ConvertType - Convert the specified type to its LLVM form.
const llvm::Type *CodeGenTypes::ConvertType(QualType T) {
  // FIXME: Cache these, move the CodeGenModule, expand, etc.
  const clang::Type &Ty = *T.getCanonicalType();

  switch (Ty.getTypeClass()) {
  case Type::TypeName:        // typedef isn't canonical.
  case Type::TypeOfExp:       // typeof isn't canonical.
  case Type::TypeOfTyp:       // typeof isn't canonical.
    assert(0 && "Non-canonical type, shouldn't happen");
  case Type::Builtin: {
    switch (cast<BuiltinType>(Ty).getKind()) {
    case BuiltinType::Void:
      // LLVM void type can only be used as the result of a function call.  Just
      // map to the same as char.
      return llvm::IntegerType::get(8);

    case BuiltinType::Bool:
      // FIXME: This is very strange.  We want scalars to be i1, but in memory
      // they can be i1 or i32.  Should the codegen handle this issue?
      return llvm::Type::Int1Ty;

    case BuiltinType::Char_S:
    case BuiltinType::Char_U:
    case BuiltinType::SChar:
    case BuiltinType::UChar:
    case BuiltinType::Short:
    case BuiltinType::UShort:
    case BuiltinType::Int:
    case BuiltinType::UInt:
    case BuiltinType::Long:
    case BuiltinType::ULong:
    case BuiltinType::LongLong:
    case BuiltinType::ULongLong:
      return llvm::IntegerType::get(Context.getTypeSize(T, SourceLocation()));

    case BuiltinType::Float:      return llvm::Type::FloatTy;
    case BuiltinType::Double:     return llvm::Type::DoubleTy;
    case BuiltinType::LongDouble:
      // FIXME: mapping long double onto double.
      return llvm::Type::DoubleTy;
    }
    break;
  }
  case Type::Complex: {
    std::vector<const llvm::Type*> Elts;
    Elts.push_back(ConvertType(cast<ComplexType>(Ty).getElementType()));
    Elts.push_back(Elts[0]);
    return llvm::StructType::get(Elts);
  }
  case Type::Pointer: {
    const PointerType &P = cast<PointerType>(Ty);
    return llvm::PointerType::get(ConvertType(P.getPointeeType()));
  }
  case Type::Reference: {
    const ReferenceType &R = cast<ReferenceType>(Ty);
    return llvm::PointerType::get(ConvertType(R.getReferenceeType()));
  }

  case Type::Array: {
    const ArrayType &A = cast<ArrayType>(Ty);
    assert(A.getSizeModifier() == ArrayType::Normal &&
           A.getIndexTypeQualifier() == 0 &&
           "FIXME: We only handle trivial array types so far!");

    llvm::APSInt Size(32);
    if (A.getSizeExpr() &&
        A.getSizeExpr()->isIntegerConstantExpr(Size, Context)) {
      const llvm::Type *EltTy = ConvertType(A.getElementType());
      return llvm::ArrayType::get(EltTy, Size.getZExtValue());
    } else {
      assert(0 && "FIXME: VLAs not implemented yet!");
    }
  }
  case Type::OCUVector:
  case Type::Vector: {
    const VectorType &VT = cast<VectorType>(Ty);
    return llvm::VectorType::get(ConvertType(VT.getElementType()),
                                 VT.getNumElements());
  }
  case Type::FunctionNoProto:
  case Type::FunctionProto: {
    const FunctionType &FP = cast<FunctionType>(Ty);
    const llvm::Type *ResultType;

    if (FP.getResultType()->isVoidType())
      ResultType = llvm::Type::VoidTy;    // Result of function uses llvm void.
    else
      ResultType = ConvertType(FP.getResultType());

    // FIXME: Convert argument types.
    bool isVarArg;
    std::vector<const llvm::Type*> ArgTys;

    // Struct return passes the struct byref.
    if (!ResultType->isFirstClassType() && ResultType != llvm::Type::VoidTy) {
      ArgTys.push_back(llvm::PointerType::get(ResultType));
      ResultType = llvm::Type::VoidTy;
    }

    if (const FunctionTypeProto *FTP = dyn_cast<FunctionTypeProto>(&FP)) {
      DecodeArgumentTypes(*FTP, ArgTys);
      isVarArg = FTP->isVariadic();
    } else {
      isVarArg = true;
    }

    return llvm::FunctionType::get(ResultType, ArgTys, isVarArg, 0);
  }
  case Type::Tagged:
    const TagType &TT = cast<TagType>(Ty);
    const TagDecl *TD = TT.getDecl();
    llvm::Type *&ResultType = TagDeclTypes[TD];

    if (ResultType)
      return ResultType;

    if (!TD->isDefinition()) {
      ResultType = llvm::OpaqueType::get();
    } else if (TD->getKind() == Decl::Struct) {
      const RecordDecl *RD = cast<const RecordDecl>(TD);
      std::vector<const llvm::Type*> Fields;
      for (unsigned i = 0, e = RD->getNumMembers(); i != e; ++i)
        Fields.push_back(ConvertType(RD->getMember(i)->getType()));
      ResultType = llvm::StructType::get(Fields);
    } else if (TD->getKind() == Decl::Union) {
      const RecordDecl *RD = cast<const RecordDecl>(TD);
      // Just use the largest element of the union, breaking ties with the
      // highest aligned member.
      std::vector<const llvm::Type*> Fields;
      if (RD->getNumMembers() != 0) {
        std::pair<uint64_t, unsigned> MaxElt =
          Context.getTypeInfo(RD->getMember(0)->getType(), SourceLocation());
        unsigned MaxEltNo = 0;

        for (unsigned i = 1, e = RD->getNumMembers(); i != e; ++i) {
          std::pair<uint64_t, unsigned> EltInfo =
            Context.getTypeInfo(RD->getMember(i)->getType(), SourceLocation());
          if (EltInfo.first > MaxElt.first ||
              (EltInfo.first == MaxElt.first &&
               EltInfo.second > MaxElt.second)) {
            MaxElt = EltInfo;
            MaxEltNo = i;
          }
        }

        Fields.push_back(ConvertType(RD->getMember(MaxEltNo)->getType()));
      }
      ResultType = llvm::StructType::get(Fields);
    } else {
      assert(0 && "FIXME: Implement tag decl kind!");
    }

    std::string TypeName(TD->getKindName());
    TypeName += '.';
    TypeName += TD->getName();

    TheModule.addTypeName(TypeName, ResultType);
    return ResultType;
  }

  // FIXME: implement.
  return llvm::OpaqueType::get();
}

void CodeGenTypes::DecodeArgumentTypes(const FunctionTypeProto &FTP,
                                       std::vector<const llvm::Type*> &ArgTys) {
  for (unsigned i = 0, e = FTP.getNumArgs(); i != e; ++i) {
    const llvm::Type *Ty = ConvertType(FTP.getArgType(i));
    if (Ty->isFirstClassType())
      ArgTys.push_back(Ty);
    else
      ArgTys.push_back(llvm::PointerType::get(Ty));
  }
}

<commit_msg>int X[] isn't a VLA.  This improves support for stdio.h on darwin.<commit_after>//===--- CodeGenTypes.cpp - Type translation for LLVM CodeGen -------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file was developed by Chris Lattner and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This is the code that handles AST -> LLVM type lowering.
//
//===----------------------------------------------------------------------===//

#include "CodeGenTypes.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/AST/AST.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Module.h"

using namespace clang;
using namespace CodeGen;

CodeGenTypes::CodeGenTypes(ASTContext &Ctx, llvm::Module& M)
  : Context(Ctx), Target(Ctx.Target), TheModule(M) {
}

/// ConvertType - Convert the specified type to its LLVM form.
const llvm::Type *CodeGenTypes::ConvertType(QualType T) {
  // FIXME: Cache these, move the CodeGenModule, expand, etc.
  const clang::Type &Ty = *T.getCanonicalType();

  switch (Ty.getTypeClass()) {
  case Type::TypeName:        // typedef isn't canonical.
  case Type::TypeOfExp:       // typeof isn't canonical.
  case Type::TypeOfTyp:       // typeof isn't canonical.
    assert(0 && "Non-canonical type, shouldn't happen");
  case Type::Builtin: {
    switch (cast<BuiltinType>(Ty).getKind()) {
    case BuiltinType::Void:
      // LLVM void type can only be used as the result of a function call.  Just
      // map to the same as char.
      return llvm::IntegerType::get(8);

    case BuiltinType::Bool:
      // FIXME: This is very strange.  We want scalars to be i1, but in memory
      // they can be i1 or i32.  Should the codegen handle this issue?
      return llvm::Type::Int1Ty;

    case BuiltinType::Char_S:
    case BuiltinType::Char_U:
    case BuiltinType::SChar:
    case BuiltinType::UChar:
    case BuiltinType::Short:
    case BuiltinType::UShort:
    case BuiltinType::Int:
    case BuiltinType::UInt:
    case BuiltinType::Long:
    case BuiltinType::ULong:
    case BuiltinType::LongLong:
    case BuiltinType::ULongLong:
      return llvm::IntegerType::get(Context.getTypeSize(T, SourceLocation()));

    case BuiltinType::Float:      return llvm::Type::FloatTy;
    case BuiltinType::Double:     return llvm::Type::DoubleTy;
    case BuiltinType::LongDouble:
      // FIXME: mapping long double onto double.
      return llvm::Type::DoubleTy;
    }
    break;
  }
  case Type::Complex: {
    std::vector<const llvm::Type*> Elts;
    Elts.push_back(ConvertType(cast<ComplexType>(Ty).getElementType()));
    Elts.push_back(Elts[0]);
    return llvm::StructType::get(Elts);
  }
  case Type::Pointer: {
    const PointerType &P = cast<PointerType>(Ty);
    return llvm::PointerType::get(ConvertType(P.getPointeeType()));
  }
  case Type::Reference: {
    const ReferenceType &R = cast<ReferenceType>(Ty);
    return llvm::PointerType::get(ConvertType(R.getReferenceeType()));
  }

  case Type::Array: {
    const ArrayType &A = cast<ArrayType>(Ty);
    assert(A.getSizeModifier() == ArrayType::Normal &&
           A.getIndexTypeQualifier() == 0 &&
           "FIXME: We only handle trivial array types so far!");

    llvm::APSInt Size(32);
    if (A.getSizeExpr() == 0) {
      // int X[] -> [0 x int]
      return llvm::ArrayType::get(ConvertType(A.getElementType()), 0);
    } else if (A.getSizeExpr()->isIntegerConstantExpr(Size, Context)) {
      const llvm::Type *EltTy = ConvertType(A.getElementType());
      return llvm::ArrayType::get(EltTy, Size.getZExtValue());
    } else {
      assert(0 && "FIXME: VLAs not implemented yet!");
    }
  }
  case Type::OCUVector:
  case Type::Vector: {
    const VectorType &VT = cast<VectorType>(Ty);
    return llvm::VectorType::get(ConvertType(VT.getElementType()),
                                 VT.getNumElements());
  }
  case Type::FunctionNoProto:
  case Type::FunctionProto: {
    const FunctionType &FP = cast<FunctionType>(Ty);
    const llvm::Type *ResultType;

    if (FP.getResultType()->isVoidType())
      ResultType = llvm::Type::VoidTy;    // Result of function uses llvm void.
    else
      ResultType = ConvertType(FP.getResultType());

    // FIXME: Convert argument types.
    bool isVarArg;
    std::vector<const llvm::Type*> ArgTys;

    // Struct return passes the struct byref.
    if (!ResultType->isFirstClassType() && ResultType != llvm::Type::VoidTy) {
      ArgTys.push_back(llvm::PointerType::get(ResultType));
      ResultType = llvm::Type::VoidTy;
    }

    if (const FunctionTypeProto *FTP = dyn_cast<FunctionTypeProto>(&FP)) {
      DecodeArgumentTypes(*FTP, ArgTys);
      isVarArg = FTP->isVariadic();
    } else {
      isVarArg = true;
    }

    return llvm::FunctionType::get(ResultType, ArgTys, isVarArg, 0);
  }
  case Type::Tagged:
    const TagType &TT = cast<TagType>(Ty);
    const TagDecl *TD = TT.getDecl();
    llvm::Type *&ResultType = TagDeclTypes[TD];

    if (ResultType)
      return ResultType;

    if (!TD->isDefinition()) {
      ResultType = llvm::OpaqueType::get();
    } else if (TD->getKind() == Decl::Struct) {
      const RecordDecl *RD = cast<const RecordDecl>(TD);
      std::vector<const llvm::Type*> Fields;
      for (unsigned i = 0, e = RD->getNumMembers(); i != e; ++i)
        Fields.push_back(ConvertType(RD->getMember(i)->getType()));
      ResultType = llvm::StructType::get(Fields);
    } else if (TD->getKind() == Decl::Union) {
      const RecordDecl *RD = cast<const RecordDecl>(TD);
      // Just use the largest element of the union, breaking ties with the
      // highest aligned member.
      std::vector<const llvm::Type*> Fields;
      if (RD->getNumMembers() != 0) {
        std::pair<uint64_t, unsigned> MaxElt =
          Context.getTypeInfo(RD->getMember(0)->getType(), SourceLocation());
        unsigned MaxEltNo = 0;

        for (unsigned i = 1, e = RD->getNumMembers(); i != e; ++i) {
          std::pair<uint64_t, unsigned> EltInfo =
            Context.getTypeInfo(RD->getMember(i)->getType(), SourceLocation());
          if (EltInfo.first > MaxElt.first ||
              (EltInfo.first == MaxElt.first &&
               EltInfo.second > MaxElt.second)) {
            MaxElt = EltInfo;
            MaxEltNo = i;
          }
        }

        Fields.push_back(ConvertType(RD->getMember(MaxEltNo)->getType()));
      }
      ResultType = llvm::StructType::get(Fields);
    } else {
      assert(0 && "FIXME: Implement tag decl kind!");
    }

    std::string TypeName(TD->getKindName());
    TypeName += '.';
    TypeName += TD->getName();

    TheModule.addTypeName(TypeName, ResultType);
    return ResultType;
  }

  // FIXME: implement.
  return llvm::OpaqueType::get();
}

void CodeGenTypes::DecodeArgumentTypes(const FunctionTypeProto &FTP,
                                       std::vector<const llvm::Type*> &ArgTys) {
  for (unsigned i = 0, e = FTP.getNumArgs(); i != e; ++i) {
    const llvm::Type *Ty = ConvertType(FTP.getArgType(i));
    if (Ty->isFirstClassType())
      ArgTys.push_back(Ty);
    else
      ArgTys.push_back(llvm::PointerType::get(Ty));
  }
}

<|endoftext|>