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 
     23   void Default() { nSecIndex = nLineIndex = nWordIndex = -1; }
     24 
     25   bool operator==(const CPVT_WordPlace& wp) const {
     26     return wp.nSecIndex == nSecIndex && wp.nLineIndex == nLineIndex &&
     27            wp.nWordIndex == nWordIndex;
     28   }
     29 
     30   bool operator!=(const CPVT_WordPlace& wp) const { return !(*this == wp); }
     31 
     32   inline int32_t WordCmp(const CPVT_WordPlace& wp) const {
     33     if (nSecIndex > wp.nSecIndex)
     34       return 1;
     35     if (nSecIndex < wp.nSecIndex)
     36       return -1;
     37     if (nLineIndex > wp.nLineIndex)
     38       return 1;
     39     if (nLineIndex < wp.nLineIndex)
     40       return -1;
     41     if (nWordIndex > wp.nWordIndex)
     42       return 1;
     43     if (nWordIndex < wp.nWordIndex)
     44       return -1;
     45     return 0;
     46   }
     47 
     48   inline int32_t LineCmp(const CPVT_WordPlace& wp) const {
     49     if (nSecIndex > wp.nSecIndex)
     50       return 1;
     51     if (nSecIndex < wp.nSecIndex)
     52       return -1;
     53     if (nLineIndex > wp.nLineIndex)
     54       return 1;
     55     if (nLineIndex < wp.nLineIndex)
     56       return -1;
     57     return 0;
     58   }
     59 
     60   inline int32_t SecCmp(const CPVT_WordPlace& wp) const {
     61     if (nSecIndex > wp.nSecIndex)
     62       return 1;
     63     if (nSecIndex < wp.nSecIndex)
     64       return -1;
     65     return 0;
     66   }
     67 
     68   int32_t nSecIndex;
     69   int32_t nLineIndex;
     70   int32_t nWordIndex;
     71 };
     72 
     73 #endif  // CORE_FPDFDOC_CPVT_WORDPLACE_H_
     74