LCOV - code coverage report
Current view: top level - include/formula - grammar.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 16 16 100.0 %
Date: 2015-06-13 12:38:46 Functions: 6 6 100.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             : 
      26             : namespace formula
      27             : {
      28             : 
      29             : /** Grammars digested by ScCompiler.
      30             :  */
      31             : class FORMULA_DLLPUBLIC FormulaGrammar
      32             : {
      33             : public:
      34             :     enum AddressConvention{
      35             :         CONV_UNSPECIFIED = -1,  /* useful when we want method to chose, must be first */
      36             : 
      37             :         /* elements must be sequential and changes should be reflected in ScCompiler::pCharTables */
      38             :         CONV_OOO     =  0,  /* 'doc'#sheet.A1:sheet2.B2 */
      39             :         CONV_ODF,           /* ['doc'#sheet.A1:sheet2.B2] */
      40             :         CONV_XL_A1,         /* [doc]sheet:sheet2!A1:B2 */
      41             :         CONV_XL_R1C1,       /* [doc]sheet:sheet2!R1C1:R2C2 */
      42             :         CONV_XL_OOX,        /* [#]sheet:sheet2!A1:B2 */
      43             : 
      44             :         CONV_LOTUS_A1,      /* external? 3d? A1.B2 <placeholder/> */
      45             : 
      46             :         CONV_LAST   /* for loops, must always be last */
      47             :     };
      48             : 
      49             :     //! CONV_UNSPECIFIED is a negative value!
      50             :     static const int kConventionOffset = - CONV_UNSPECIFIED + 1;
      51             :     // Room for 32k hypothetical languages plus EXTERNAL.
      52             :     static const int kConventionShift  = 16;
      53             :     // Room for 256 reference conventions.
      54             :     static const int kEnglishBit       = (1 << (kConventionShift + 8));
      55             :     // Mask off all non-language bits.
      56             :     static const int kFlagMask         = ~((~unsigned(0)) << kConventionShift);
      57             : 
      58             :     /** Values encoding the formula language plus address reference convention
      59             :         plus English parsing/formatting
      60             :      */
      61             :     //! When adding new values adapt isSupported() below as well.
      62             :     enum Grammar
      63             :     {
      64             :         /// Used only in ScCompiler ctor and in some XML import API context.
      65             :         GRAM_UNSPECIFIED    = -1,
      66             :         /// ODFF with default ODF A1 bracketed references.
      67             :         GRAM_ODFF           = ::com::sun::star::sheet::FormulaLanguage::ODFF    |
      68             :                                 ((CONV_ODF           +
      69             :                                   kConventionOffset) << kConventionShift)       |
      70             :                                 kEnglishBit,
      71             :         /// ODF 1.1 with default ODF A1 bracketed references.
      72             :         GRAM_PODF           = ::com::sun::star::sheet::FormulaLanguage::ODF_11  |
      73             :                                 ((CONV_ODF           +
      74             :                                   kConventionOffset) << kConventionShift)       |
      75             :                                 kEnglishBit,
      76             :         /// English with default A1 reference style.
      77             :         GRAM_ENGLISH        = ::com::sun::star::sheet::FormulaLanguage::ENGLISH |
      78             :                                 ((CONV_OOO           +
      79             :                                   kConventionOffset) << kConventionShift)       |
      80             :                                 kEnglishBit,
      81             :         /// Native with default A1 reference style.
      82             :         GRAM_NATIVE         = ::com::sun::star::sheet::FormulaLanguage::NATIVE  |
      83             :                                 ((CONV_OOO           +
      84             :                                   kConventionOffset) << kConventionShift),
      85             :         /// ODFF with reference style as set in UI, may be A1 or R1C1.
      86             :         GRAM_ODFF_UI        = ::com::sun::star::sheet::FormulaLanguage::ODFF    |
      87             :                                 ((CONV_UNSPECIFIED   +
      88             :                                   kConventionOffset) << kConventionShift)       |
      89             :                                 kEnglishBit,
      90             :         /// ODFF with A1 reference style, unbracketed.
      91             :         GRAM_ODFF_A1        = ::com::sun::star::sheet::FormulaLanguage::ODFF    |
      92             :                                 ((CONV_OOO           +
      93             :                                   kConventionOffset) << kConventionShift)       |
      94             :                                 kEnglishBit,
      95             :         /// ODF 1.1 with reference style as set in UI, may be A1 or R1C1.
      96             :         GRAM_PODF_UI        = ::com::sun::star::sheet::FormulaLanguage::ODF_11  |
      97             :                                 ((CONV_UNSPECIFIED   +
      98             :                                   kConventionOffset) << kConventionShift)       |
      99             :                                 kEnglishBit,
     100             :         /// ODF 1.1 with A1 reference style, unbracketed.
     101             :         GRAM_PODF_A1        = ::com::sun::star::sheet::FormulaLanguage::ODF_11  |
     102             :                                 ((CONV_OOO           +
     103             :                                   kConventionOffset) << kConventionShift)       |
     104             :                                 kEnglishBit,
     105             :         /// Native with reference style as set in UI, may be A1 or R1C1.
     106             :         GRAM_NATIVE_UI      = ::com::sun::star::sheet::FormulaLanguage::NATIVE  |
     107             :                                 ((CONV_UNSPECIFIED   +
     108             :                                   kConventionOffset) << kConventionShift),
     109             :         /// Native with ODF A1 bracketed references. Not very useful but supported.
     110             :         GRAM_NATIVE_ODF     = ::com::sun::star::sheet::FormulaLanguage::NATIVE  |
     111             :                                 ((CONV_ODF           +
     112             :                                   kConventionOffset) << kConventionShift),
     113             :         /// Native with Excel A1 reference style.
     114             :         GRAM_NATIVE_XL_A1   = ::com::sun::star::sheet::FormulaLanguage::NATIVE  |
     115             :                                 ((CONV_XL_A1         +
     116             :                                   kConventionOffset) << kConventionShift),
     117             :         /// Native with Excel R1C1 reference style.
     118             :         GRAM_NATIVE_XL_R1C1 = ::com::sun::star::sheet::FormulaLanguage::NATIVE  |
     119             :                                 ((CONV_XL_R1C1       +
     120             :                                   kConventionOffset) << kConventionShift),
     121             :         /// English with Excel A1 reference style.
     122             :         GRAM_ENGLISH_XL_A1   = ::com::sun::star::sheet::FormulaLanguage::XL_ENGLISH  |
     123             :                                 ((CONV_XL_A1         +
     124             :                                   kConventionOffset) << kConventionShift)            |
     125             :                                 kEnglishBit,
     126             :         /// English with Excel R1C1 reference style.
     127             :         GRAM_ENGLISH_XL_R1C1 = ::com::sun::star::sheet::FormulaLanguage::XL_ENGLISH  |
     128             :                                 ((CONV_XL_R1C1       +
     129             :                                   kConventionOffset) << kConventionShift)            |
     130             :                                 kEnglishBit,
     131             :         /// English with Excel OOXML reference style.
     132             :         GRAM_ENGLISH_XL_OOX  = ::com::sun::star::sheet::FormulaLanguage::XL_ENGLISH  |
     133             :                                 ((CONV_XL_OOX        +
     134             :                                   kConventionOffset) << kConventionShift)            |
     135             :                                 kEnglishBit,
     136             :         /// Excel OOXML with Excel OOXML reference style.
     137             :         GRAM_OOXML           = ::com::sun::star::sheet::FormulaLanguage::OOXML  |
     138             :                                 ((CONV_XL_OOX        +
     139             :                                   kConventionOffset) << kConventionShift)       |
     140             :                                 kEnglishBit,
     141             :         /// Central definition of the default grammar to be used.
     142             :         GRAM_DEFAULT        = GRAM_NATIVE_UI,
     143             : 
     144             :         /// Central definition of the default storage grammar to be used.
     145             :         GRAM_STORAGE_DEFAULT = GRAM_ODFF,
     146             : 
     147             :         /** OpCodeMap set by external filter and merged with reference
     148             :             convention plus English bit on top. Plain value acts as
     149             :             FormulaLanguage. */
     150             :         GRAM_EXTERNAL       = (1 << (kConventionShift - 1))
     151             :     };
     152             : 
     153             :     /// If English parsing/formatting is associated with a grammar.
     154       56404 :     static inline bool isEnglish( const Grammar eGrammar )
     155             :     {
     156       56404 :         return (eGrammar & kEnglishBit) != 0;
     157             :     }
     158             : 
     159             :     /** Compatibility helper for old "bCompileEnglish, bCompileXML" API calls
     160             :         to obtain the new grammar. */
     161             :     static Grammar mapAPItoGrammar( const bool bEnglish, const bool bXML );
     162             : 
     163             :     static bool isSupported( const Grammar eGrammar );
     164             : 
     165      134885 :     static inline sal_Int32 extractFormulaLanguage( const Grammar eGrammar )
     166             :     {
     167      134885 :         return eGrammar & kFlagMask;
     168             :     }
     169             : 
     170      137460 :     static inline AddressConvention extractRefConvention( const Grammar eGrammar )
     171             :     {
     172             :         return static_cast<AddressConvention>(
     173      137460 :                 ((eGrammar & ~kEnglishBit) >> kConventionShift) -
     174      137460 :                 kConventionOffset);
     175             :     }
     176             : 
     177             :     static Grammar setEnglishBit( const Grammar eGrammar, const bool bEnglish );
     178             : 
     179             :     static Grammar mergeToGrammar( const Grammar eGrammar, const AddressConvention eConv );
     180             : 
     181             :     /// If grammar is of ODF 1.1
     182        8529 :     static inline bool isPODF( const Grammar eGrammar )
     183             :     {
     184        8529 :         return extractFormulaLanguage( eGrammar) ==
     185        8529 :             ::com::sun::star::sheet::FormulaLanguage::ODF_11;
     186             :     }
     187             : 
     188             :     /// If grammar is of ODFF
     189       17173 :     static inline bool isODFF( const Grammar eGrammar )
     190             :     {
     191       17173 :         return extractFormulaLanguage( eGrammar) ==
     192       17173 :             ::com::sun::star::sheet::FormulaLanguage::ODFF;
     193             :     }
     194             : 
     195             :     /// If grammar is of OOXML
     196        8283 :     static inline bool isOOXML( const Grammar eGrammar )
     197             :     {
     198        8283 :         return extractFormulaLanguage( eGrammar) ==
     199        8283 :             ::com::sun::star::sheet::FormulaLanguage::OOXML;
     200             :     }
     201             : 
     202             : };
     203             : 
     204             : } // formula
     205             : 
     206             : 
     207             : #endif // INCLUDED_FORMULA_GRAMMAR_HXX
     208             : 
     209             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11