Home | History | Annotate | Download | only in fpdfdoc
      1 // Copyright 2016 PDFium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
      6 
      7 #ifndef CORE_FPDFDOC_CPVT_WORDPLACE_H_
      8 #define CORE_FPDFDOC_CPVT_WORDPLACE_H_
      9 
     10 #include "core/fxcrt/fx_system.h"
     11 
     12 struct CPVT_WordPlace {
     13   CPVT_WordPlace() : nSecIndex(-1), nLineIndex(-1), nWordIndex(-1) {}
     14 
     15   CPVT_WordPlace(int32_t other_nSecIndex,
     16                  int32_t other_nLineIndex,
     17                  int32_t other_nWordIndex)
     18       : nSecIndex(other_nSecIndex),
     19         nLineIndex(other_nLineIndex),
     20         nWordIndex(other_nWordIndex) {}
     21 
     22   void Reset() {
     23     nSecIndex = -1;
     24     nLineIndex = -1;
     25     nWordIndex = -1;
     26   }
     27 
     28   void AdvanceSection() {
     29     nSecIndex++;
     30     nLineIndex = 0;
     31     nWordIndex = -1;
     32   }
     33 
     34   inline bool operator==(const CPVT_WordPlace& wp) const {
     35     return wp.nSecIndex == nSecIndex && wp.nLineIndex == nLineIndex &&
     36            wp.nWordIndex == nWordIndex;
     37   }
     38   inline bool operator!=(const CPVT_WordPlace& wp) const {
     39     return !(*this == wp);
     40   }
     41   inline bool operator<(const CPVT_WordPlace& wp) const {
     42     if (nSecIndex != wp.nSecIndex)
     43       return nSecIndex < wp.nSecIndex;
     44     if (nLineIndex != wp.nLineIndex)
     45       return nLineIndex < wp.nLineIndex;
     46     return nWordIndex < wp.nWordIndex;
     47   }
     48   inline bool operator>(const CPVT_WordPlace& wp) const {
     49     if (nSecIndex != wp.nSecIndex)
     50       return nSecIndex > wp.nSecIndex;
     51     if (nLineIndex != wp.nLineIndex)
     52       return nLineIndex > wp.nLineIndex;
     53     return nWordIndex > wp.nWordIndex;
     54   }
     55   inline bool operator<=(const CPVT_WordPlace& wp) const {
     56     return *this < wp || *this == wp;
     57   }
     58   inline bool operator>=(const CPVT_WordPlace& wp) const {
     59     return *this > wp || *this == wp;
     60   }
     61 
     62   inline int32_t LineCmp(const CPVT_WordPlace& wp) const {
     63     if (nSecIndex != wp.nSecIndex)
     64       return nSecIndex - wp.nSecIndex;
     65     return nLineIndex - wp.nLineIndex;
     66   }
     67 
     68   int32_t nSecIndex;
     69   int32_t nLineIndex;
     70   int32_t nWordIndex;
     71 };
     72 
     73 #endif  // CORE_FPDFDOC_CPVT_WORDPLACE_H_
     74