1
// TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2023 - TortoiseGit
4 // Copyright (C) 2007-2011, 2013-2014 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "DiffStates.h"
34 * \ingroup TortoiseMerge
35 * Holds the information which is required to define a single line of text.
43 const CString
& sLineInit
,
48 bool markedInit
= false)
50 , linenumber(linenumberInit
)
59 DiffState state
= DiffState::Unknown
;
62 bool movedFrom
= true;
63 EOL ending
= EOL::AutoLine
;
64 HideState hidestate
= HideState::Hidden
;
69 * \ingroup TortoiseMerge
70 * Handles the view and diff data a TortoiseMerge view needs.
78 void AddData(const CString
& sLine
, DiffState state
, int linenumber
, EOL ending
, HideState hide
, int movedline
);
79 void AddData(const viewdata
& data
);
80 void AddEmpty() {AddData(CString(), DiffState::Empty
, -1, EOL::NoEnding
, HideState::Shown
, -1);}
81 void InsertData(int index
, const CString
& sLine
, DiffState state
, int linenumber
, EOL ending
, HideState hide
, int movedline
);
82 void InsertData(int index
, const viewdata
& data
);
83 void RemoveData(int index
) {m_data
.erase(m_data
.begin() + index
);}
85 const viewdata
& GetData(int index
) const {return m_data
[index
];}
86 const CString
& GetLine(int index
) const {return m_data
[index
].sLine
;}
87 DiffState
GetState(int index
) const {return m_data
[index
].state
;}
88 HideState
GetHideState(int index
) const {return m_data
[index
].hidestate
;}
89 int GetLineNumber(int index
) const {return m_data
.size() ? m_data
[index
].linenumber
: 0;}
90 int GetMovedIndex(int index
) const {return m_data
.size() ? m_data
[index
].movedIndex
: 0;}
91 bool IsMoved(int index
) const {return m_data
.size() ? m_data
[index
].movedIndex
>= 0 : false;}
92 bool IsMovedFrom(int index
) const {return m_data
.size() ? m_data
[index
].movedFrom
: true;}
93 int FindLineNumber(int number
) const;
94 EOL
GetLineEnding(int index
) const {return m_data
[index
].ending
;}
95 bool GetMarked(int index
) const {return m_data
[index
].marked
;}
97 int GetCount() const { return static_cast<int>(m_data
.size()); }
99 void SetData(int index
, const viewdata
& data
)
101 bool oldmarked
= m_data
[index
].marked
;
102 bool marked
= data
.marked
;
103 if (oldmarked
&& !marked
&& m_nMarkedBlocks
> 0)
105 else if (!oldmarked
&& marked
)
107 m_data
[index
] = data
;
109 void SetState(int index
, DiffState state
) {m_data
[index
].state
= state
;}
110 void SetLine(int index
, const CString
& sLine
) {m_data
[index
].sLine
= sLine
;}
111 void SetLineNumber(int index
, int linenumber
) {m_data
[index
].linenumber
= linenumber
;}
112 void SetLineEnding(int index
, EOL ending
) {m_data
[index
].ending
= ending
;}
113 void SetMovedIndex(int index
, int movedIndex
, bool movedFrom
) {m_data
[index
].movedIndex
= movedIndex
; m_data
[index
].movedFrom
= movedFrom
;}
114 void SetLineHideState(int index
, HideState state
) {m_data
[index
].hidestate
= state
;}
115 void SetMarked(int index
, bool marked
)
117 bool oldmarked
= m_data
[index
].marked
;
118 if (oldmarked
&& !marked
&& m_nMarkedBlocks
> 0)
120 else if (!oldmarked
&& marked
)
122 m_data
[index
].marked
= marked
;
124 bool HasMarkedBlocks() const { return m_nMarkedBlocks
> 0; }
126 void Clear() { m_data
.clear(); m_nMarkedBlocks
= 0; }
127 void Reserve(int length
) {m_data
.reserve(length
);}
130 std::vector
<viewdata
> m_data
;
131 int m_nMarkedBlocks
= 0;