LCOV - code coverage report
Current view: top level - include/formula - grammar.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 35 0.0 %
Date: 2014-04-14 Functions: 0 9 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_FORMULA_GRAMMAR_HXX
      21             : #define INCLUDED_FORMULA_GRAMMAR_HXX
      22             : 
      23             : #include <com/sun/star/sheet/FormulaLanguage.hpp>
      24             : #include <formula/formuladllapi.h>
      25             : #include <tools/debug.hxx>
      26             : 
      27             : namespace formula
      28             : {
      29             : 
      30             : /** Grammars digested by ScCompiler.
      31             :  */
      32             : class FORMULA_DLLPUBLIC FormulaGrammar
      33             : {
      34             : public:
      35             :     enum AddressConvention{
      36             :         CONV_UNSPECIFIED = -1,  /* useful when we want method to chose, must be first */
      37             : 
      38             :         /* elements must be sequential and changes should be reflected in ScCompiler::pCharTables */
      39             :         CONV_OOO     =  0,  /* 'doc'#sheet.A1:sheet2.B2 */
      40             :         CONV_ODF,           /* ['doc'#sheet.A1:sheet2.B2] */
      41             :         CONV_XL_A1,         /* [doc]sheet:sheet2!A1:B2 */
      42             :         CONV_XL_R1C1,       /* [doc]sheet:sheet2!R1C1:R2C2 */
      43             :         CONV_XL_OOX,        /* [#]sheet:sheet2!A1:B2 */
      44             : 
      45             :         CONV_LOTUS_A1,      /* external? 3d? A1.B2 <placeholder/> */
      46             : 
      47             :         CONV_LAST   /* for loops, must always be last */
      48             :     };
      49             : 
      50             :     //! CONV_UNSPECIFIED is a negative value!
      51             :     static const int kConventionOffset = - CONV_UNSPECIFIED + 1;
      52             :     // Room for 32k hypothetical languages plus EXTERNAL.
      53             :     static const int kConventionShift  = 16;
      54             :     // Room for 256 reference conventions.
      55             :     static const int kEnglishBit       = (1 << (kConventionShift + 8));
      56             :     // Mask off all non-language bits.
      57             :     static const int kFlagMask         = ~((~int(0)) << kConventionShift);
      58             : 
      59             :     /** Values encoding the formula language plus address reference convention
      60             :         plus English parsing/formatting
      61             :      */
      62             :     //! When adding new values adapt isSupported() below as well.
      63             :     enum Grammar
      64             :     {
      65             :         /// Used only in ScCompiler ctor and in some XML import API context.
      66             :         GRAM_UNSPECIFIED    = -1,
      67             :         /// ODFF with default ODF A1 bracketed references.
      68             :         GRAM_ODFF           = ::com::sun::star::sheet::FormulaLanguage::ODFF    |
      69             :                                 ((CONV_ODF           +
      70             :                                   kConventionOffset) << kConventionShift)       |
      71             :                                 kEnglishBit,
      72             :         /// ODF 1.1 with default ODF A1 bracketed references.
      73             :         GRAM_PODF           = ::com::sun::star::sheet::FormulaLanguage::ODF_11  |
      74             :                                 ((CONV_ODF           +
      75             :                                   kConventionOffset) << kConventionShift)       |
      76             :                                 kEnglishBit,
      77             :         /// English with default A1 reference style.
      78             :         GRAM_ENGLISH        = ::com::sun::star::sheet::FormulaLanguage::ENGLISH |
      79             :                                 ((CONV_OOO           +
      80             :                                   kConventionOffset) << kConventionShift)       |
      81             :                                 kEnglishBit,
      82             :         /// Native with default A1 reference style.
      83             :         GRAM_NATIVE         = ::com::sun::star::sheet::FormulaLanguage::NATIVE  |
      84             :                                 ((CONV_OOO           +
      85             :                                   kConventionOffset) << kConventionShift),
      86             :         /// ODFF with reference style as set in UI, may be A1 or R1C1.
      87             :         GRAM_ODFF_UI        = ::com::sun::star::sheet::FormulaLanguage::ODFF    |
      88             :                                 ((CONV_UNSPECIFIED   +
      89             :                                   kConventionOffset) << kConventionShift)       |
      90             :                                 kEnglishBit,
      91             :         /// ODFF with A1 reference style, unbracketed.
      92             :         GRAM_ODFF_A1        = ::com::sun::star::sheet::FormulaLanguage::ODFF    |
      93             :                                 ((CONV_OOO           +
      94             :                                   kConventionOffset) << kConventionShift)       |
      95             :                                 kEnglishBit,
      96             :         /// ODF 1.1 with reference style as set in UI, may be A1 or R1C1.
      97             :         GRAM_PODF_UI        = ::com::sun::star::sheet::FormulaLanguage::ODF_11  |
      98             :                                 ((CONV_UNSPECIFIED   +
      99             :                                   kConventionOffset) << kConventionShift)       |
     100             :                                 kEnglishBit,
     101             :         /// ODF 1.1 with A1 reference style, unbracketed.
     102             :         GRAM_PODF_A1        = ::com::sun::star::sheet::FormulaLanguage::ODF_11  |
     103             :                                 ((CONV_OOO           +
     104             :                                   kConventionOffset) << kConventionShift)       |
     105             :                                 kEnglishBit,
     106             :         /// Native with reference style as set in UI, may be A1 or R1C1.
     107             :         GRAM_NATIVE_UI      = ::com::sun::star::sheet::FormulaLanguage::NATIVE  |
     108             :                                 ((CONV_UNSPECIFIED   +
     109             :                                   kConventionOffset) << kConventionShift),
     110             :         /// Native with ODF A1 bracketed references. Not very useful but supported.
     111             :         GRAM_NATIVE_ODF     = ::com::sun::star::sheet::FormulaLanguage::NATIVE  |
     112             :                                 ((CONV_ODF           +
     113             :                                   kConventionOffset) << kConventionShift),
     114             :         /// Native with Excel A1 reference style.
     115             :         GRAM_NATIVE_XL_A1   = ::com::sun::star::sheet::FormulaLanguage::NATIVE  |
     116             :                                 ((CONV_XL_A1         +
     117             :                                   kConventionOffset) << kConventionShift),
     118             :         /// Native with Excel R1C1 reference style.
     119             :         GRAM_NATIVE_XL_R1C1 = ::com::sun::star::sheet::FormulaLanguage::NATIVE  |
     120             :                                 ((CONV_XL_R1C1       +
     121             :                                   kConventionOffset) << kConventionShift),
     122             :         /// English with Excel A1 reference style.
     123             :         GRAM_ENGLISH_XL_A1   = ::com::sun::star::sheet::FormulaLanguage::XL_ENGLISH  |
     124             :                                 ((CONV_XL_A1         +
     125             :                                   kConventionOffset) << kConventionShift)            |
     126             :                                 kEnglishBit,
     127             :         /// English with Excel R1C1 reference style.
     128             :         GRAM_ENGLISH_XL_R1C1 = ::com::sun::star::sheet::FormulaLanguage::XL_ENGLISH  |
     129             :                                 ((CONV_XL_R1C1       +
     130             :                                   kConventionOffset) << kConventionShift)            |
     131             :                                 kEnglishBit,
     132             :         /// English with Excel OOXML reference style.
     133             :         GRAM_ENGLISH_XL_OOX  = ::com::sun::star::sheet::FormulaLanguage::XL_ENGLISH  |
     134             :                                 ((CONV_XL_OOX        +
     135             :                                   kConventionOffset) << kConventionShift)            |
     136             :                                 kEnglishBit,
     137             :         /// Excel OOXML with Excel OOXML reference style.
     138             :         GRAM_OOXML           = ::com::sun::star::sheet::FormulaLanguage::OOXML  |
     139             :                                 ((CONV_XL_OOX        +
     140             :                                   kConventionOffset) << kConventionShift)       |
     141             :                                 kEnglishBit,
     142             :         /// Central definition of the default grammar to be used.
     143             :         GRAM_DEFAULT        = GRAM_NATIVE_UI,
     144             : 
     145             :         /// Central definition of the default storage grammar to be used.
     146             :         GRAM_STORAGE_DEFAULT = GRAM_ODFF,
     147             : 
     148             :         /** OpCodeMap set by external filter and merged with reference
     149             :             convention plus English bit on top. Plain value acts as
     150             :             FormulaLanguage. */
     151             :         GRAM_EXTERNAL       = (1 << (kConventionShift - 1))
     152             :     };
     153             : 
     154             :     /// If English parsing/formatting is associated with a grammar.
     155           0 :     static inline bool isEnglish( const Grammar eGrammar )
     156             :     {
     157           0 :         return (eGrammar & kEnglishBit) != 0;
     158             :     }
     159             : 
     160             :     /** Compatibility helper for old "bCompileEnglish, bCompileXML" API calls
     161             :         to obtain the new grammar. */
     162           0 :     static Grammar mapAPItoGrammar( const bool bEnglish, const bool bXML )
     163             :     {
     164             :         Grammar eGrammar;
     165           0 :         if (bEnglish && bXML)
     166           0 :             eGrammar = GRAM_PODF;
     167           0 :         else if (bEnglish && !bXML)
     168           0 :             eGrammar = GRAM_PODF_A1;
     169           0 :         else if (!bEnglish && bXML)
     170           0 :             eGrammar = GRAM_NATIVE_ODF;
     171             :         else // (!bEnglish && !bXML)
     172           0 :             eGrammar = GRAM_NATIVE;
     173           0 :         return eGrammar;
     174             :     }
     175             : 
     176             :     static bool isSupported( const Grammar eGrammar )
     177             :     {
     178             :         switch (eGrammar)
     179             :         {
     180             :             case GRAM_ODFF           :
     181             :             case GRAM_PODF           :
     182             :             case GRAM_ENGLISH        :
     183             :             case GRAM_NATIVE         :
     184             :             case GRAM_ODFF_UI        :
     185             :             case GRAM_ODFF_A1        :
     186             :             case GRAM_PODF_UI        :
     187             :             case GRAM_PODF_A1        :
     188             :             case GRAM_NATIVE_UI      :
     189             :             case GRAM_NATIVE_ODF     :
     190             :             case GRAM_NATIVE_XL_A1   :
     191             :             case GRAM_NATIVE_XL_R1C1 :
     192             :             case GRAM_ENGLISH_XL_A1  :
     193             :             case GRAM_ENGLISH_XL_R1C1:
     194             :             case GRAM_ENGLISH_XL_OOX :
     195             :             case GRAM_OOXML          :
     196             :                 return true;
     197             :             default:
     198             :                 return extractFormulaLanguage( eGrammar) == GRAM_EXTERNAL;
     199             :         }
     200             :     }
     201             : 
     202           0 :     static inline sal_Int32 extractFormulaLanguage( const Grammar eGrammar )
     203             :     {
     204           0 :         return eGrammar & kFlagMask;
     205             :     }
     206             : 
     207           0 :     static inline AddressConvention extractRefConvention( const Grammar eGrammar )
     208             :     {
     209             :         return static_cast<AddressConvention>(
     210           0 :                 ((eGrammar & ~kEnglishBit) >> kConventionShift) -
     211           0 :                 kConventionOffset);
     212             :     }
     213             : 
     214           0 :     static inline Grammar setEnglishBit( const Grammar eGrammar, const bool bEnglish )
     215             :     {
     216           0 :         if (bEnglish)
     217           0 :             return static_cast<Grammar>( eGrammar | kEnglishBit);
     218             :         else
     219           0 :             return static_cast<Grammar>( eGrammar & ~kEnglishBit);
     220             :     }
     221             : 
     222           0 :     static inline Grammar mergeToGrammar( const Grammar eGrammar, const AddressConvention eConv )
     223             :     {
     224           0 :         bool bEnglish = isEnglish( eGrammar);
     225             :         Grammar eGram = static_cast<Grammar>(
     226           0 :                 extractFormulaLanguage( eGrammar) |
     227           0 :                 ((eConv + kConventionOffset) << kConventionShift));
     228           0 :         eGram = setEnglishBit( eGram, bEnglish);
     229             :         DBG_ASSERT( isSupported( eGram), "CompilerGrammarMap::mergeToGrammar: unsupported grammar");
     230           0 :         return eGram;
     231             :     }
     232             : 
     233             :     /// If grammar is of ODF 1.1
     234           0 :     static inline bool isPODF( const Grammar eGrammar )
     235             :     {
     236           0 :         return extractFormulaLanguage( eGrammar) ==
     237           0 :             ::com::sun::star::sheet::FormulaLanguage::ODF_11;
     238             :     }
     239             : 
     240             :     /// If grammar is of ODFF
     241           0 :     static inline bool isODFF( const Grammar eGrammar )
     242             :     {
     243           0 :         return extractFormulaLanguage( eGrammar) ==
     244           0 :             ::com::sun::star::sheet::FormulaLanguage::ODFF;
     245             :     }
     246             : 
     247             :     /// If grammar is of OOXML
     248           0 :     static inline bool isOOXML( const Grammar eGrammar )
     249             :     {
     250           0 :         return extractFormulaLanguage( eGrammar) ==
     251           0 :             ::com::sun::star::sheet::FormulaLanguage::OOXML;
     252             :     }
     253             : 
     254             : };
     255             : 
     256             : } // formula
     257             : 
     258             : 
     259             : #endif // INCLUDED_FORMULA_GRAMMAR_HXX
     260             : 
     261             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10