Home | History | Annotate | Download | only in Edit
      1 //===----- FileOffset.h - Offset in a file ----------------------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 #ifndef LLVM_CLANG_EDIT_FILEOFFSET_H
     11 #define LLVM_CLANG_EDIT_FILEOFFSET_H
     12 
     13 #include "clang/Basic/SourceLocation.h"
     14 
     15 namespace clang {
     16 
     17 namespace edit {
     18 
     19 class FileOffset {
     20   FileID FID;
     21   unsigned Offs;
     22 public:
     23   FileOffset() : Offs(0) { }
     24   FileOffset(FileID fid, unsigned offs) : FID(fid), Offs(offs) { }
     25 
     26   bool isInvalid() const { return FID.isInvalid(); }
     27 
     28   FileID getFID() const { return FID; }
     29   unsigned getOffset() const { return Offs; }
     30 
     31   FileOffset getWithOffset(unsigned offset) const {
     32     FileOffset NewOffs = *this;
     33     NewOffs.Offs += offset;
     34     return NewOffs;
     35   }
     36 
     37   friend bool operator==(FileOffset LHS, FileOffset RHS) {
     38     return LHS.FID == RHS.FID && LHS.Offs == RHS.Offs;
     39   }
     40   friend bool operator!=(FileOffset LHS, FileOffset RHS) {
     41     return !(LHS == RHS);
     42   }
     43   friend bool operator<(FileOffset LHS, FileOffset RHS) {
     44     if (LHS.FID != RHS.FID)
     45       return LHS.FID < RHS.FID;
     46     return LHS.Offs < RHS.Offs;
     47   }
     48   friend bool operator>(FileOffset LHS, FileOffset RHS) {
     49     if (LHS.FID != RHS.FID)
     50       return LHS.FID > RHS.FID;
     51     return LHS.Offs > RHS.Offs;
     52   }
     53   friend bool operator>=(FileOffset LHS, FileOffset RHS) {
     54     return LHS > RHS || LHS == RHS;
     55   }
     56   friend bool operator<=(FileOffset LHS, FileOffset RHS) {
     57     return LHS < RHS || LHS == RHS;
     58   }
     59 };
     60 
     61 }
     62 
     63 } // end namespace clang
     64 
     65 #endif
     66