1 // Formatter.cpp: implementation of the CFormatter class.
3 //////////////////////////////////////////////////////////////////////
8 //////////////////////////////////////////////////////////////////////
9 // Construction/Destruction
10 //////////////////////////////////////////////////////////////////////
12 class CVssFormatter
: public IFormatter
15 virtual int DoWhoAmI (const COptions
& options
);
16 virtual int DoProject (const SSDatabase
& database
, const COptions
& options
);
18 virtual int DoDirectory (const SSItemPtr pItem
, const COptions
& options
);
19 virtual int DoProperties (const SSItemPtr pItem
, const COptions
& options
);
20 virtual int DoFiletype (const SSItemPtr pItem
, const COptions
& options
);
21 virtual int DoHistory (const SSItemPtr pItem
, const COptions
& options
);
26 int CVssFormatter::DoWhoAmI (const COptions
& options
)
28 if (options
.GetUser().empty ())
30 // TODO: get the current windows user name
31 return 100; // unknown user
33 std::cout
<< options
.GetUser () << std::endl
;
39 int CVssFormatter::DoProject (const SSDatabase
& database
, const COptions
& options
)
41 std::string cp
= database
.GetCurrentProject();
44 throw SSException ("could not read current project");
46 std::cout
<< "Current project is " << cp
<< std::endl
;
53 int CVssFormatter::DoDirectory (SSItemPtr pItem
, const COptions
& options
)
58 if (pItem
->GetType () != SSITEM_PROJECT
)
59 throw SSException ("please specify a project item");
62 std::cout
<< pItem
->GetSpec() << ":" << std::endl
;
64 std::auto_ptr
<SSItems
> pItems (pItem
->GetItems (options
.GetDeleted()));
67 std::cout
<< "No items found under " << pItem
->GetSpec() << std::endl
;
72 std::vector
<SSItemPtr
> filtered
;
73 for (long i
= 0; i
< pItems
->GetCount (); ++i
)
75 SSItemPtr pItem
= pItems
->GetItem(i
);
78 // filter delted items
79 if ( pItem
->GetDeleted () && options
.GetDeleted()
80 || !pItem
->GetDeleted() && !(options
.GetOnlyDeleted() && options
.GetDeleted()))
85 // filter file/project items
86 if ( pItem
->GetType() == SSITEM_FILE
&& options
.GetFiles()
87 || pItem
->GetType() == SSITEM_PROJECT
&& !(options
.GetOnlyFiles() && options
.GetFiles()))
94 filtered
.push_back(pItem
);
98 // first print all project items
99 std::vector
<SSItemPtr
>::iterator itor
;
100 std::vector
<SSItemPtr
>::iterator end
= filtered
.end ();
101 for (itor
= filtered
.begin(); itor
!= end
; ++itor
)
103 SSItemPtr pItem
= *itor
;
104 if (pItem
->GetType () == SSITEM_PROJECT
)
106 std::cout
<< "$" << pItem
->GetName();
107 if (options
.GetPhysOutput())
108 std::cout
<< "\t" << pItem
->GetPhysical();
109 std::cout
<< std::endl
;
113 // second print all file items
114 for (itor
= filtered
.begin(); itor
!= end
; ++itor
)
116 SSItemPtr pItem
= *itor
;
117 if (pItem
->GetType () == SSITEM_FILE
)
119 std::cout
<< pItem
->GetName();
120 if (options
.GetExtendedOutput () && pItem
->GetIsCheckedOut())
122 // User\tDate\Time\CheckouPath, z.B.:
123 // ValidatingEdit.cpp Mirco 4.06.04 13:07 C:\Mirco
124 // ValidatingEdit.h Mirco 4.06.04 13:07 C:\Mirco
125 std::cout
<< "\tTODO: Display check out information";
126 } else if (options
.GetPhysOutput())
127 std::cout
<< "\t" << pItem
->GetPhysical();
129 std::cout
<< std::endl
;
133 std::cout
<< std::endl
;
135 // recurse into all subdirectories
136 if (options
.GetRecursive())
138 for (itor
= filtered
.begin(); itor
!= end
; ++itor
)
140 SSItemPtr pItem
= *itor
;
141 if (pItem
->GetType () == SSITEM_PROJECT
)
142 DoDirectory (pItem
, options
);
146 catch (SSException
& ex
)
148 std::cerr
<< "error: " << ex
.what() << std::endl
;
156 int CVssFormatter::DoProperties (SSItemPtr pItem
, const COptions
& options
)
161 if (pItem
->GetType () == SSITEM_PROJECT
)
163 std::auto_ptr
<SSItems
> pItems (pItem
->GetItems (true));
167 for (long i
= 0; i
< pItems
->GetCount (); ++i
)
169 SSItemPtr pItem
= pItems
->GetItem(i
);
170 // filter delted items
171 if ( pItem
->GetDeleted ())
173 else if ( pItem
->GetType () == SSITEM_PROJECT
)
175 else if ( pItem
->GetType () == SSITEM_FILE
)
181 // 2 Files ( +30 deleted )
183 std::cout
<< "Project: " << pItem
->GetSpec() << std::endl
;
184 std::cout
<< "Contains: " << std::endl
;
185 std::cout
<< files
<< " Files ( +" << deleted
<< " deleted )" << std::endl
;
186 std::cout
<< projects
<< " Subproject(s)" << std::endl
;
188 else if (pItem
->GetType () == SSITEM_FILE
)
190 //File: $/ValidatingEdit.h
192 //Size: 624 bytes 31 lines
193 //Store only latest version: No
196 //Latest: Last Label: 1.9.3
197 // Version: 178 Version: 178
198 // Date: 15.11.04 17:13 Date: 15.11.04 17:13
201 catch (SSException
& ex
)
203 std::cerr
<< "error: " << ex
.what() << std::endl
;
211 int CVssFormatter::DoFiletype (const SSItemPtr pItem
, const COptions
& options
)
218 if (pItem
->GetType () == SSITEM_PROJECT
)
220 std::auto_ptr
<SSItems
> pItems (pItem
->GetItems (options
.GetDeleted()));
221 for (long i
= 0; i
< pItems
->GetCount (); ++i
)
223 SSItemPtr pItem
= pItems
->GetItem(i
);
225 if ( pItem
->GetType () == SSITEM_PROJECT
)
226 std::cout
<< "\n\n" << pItem
->GetSpec () << std::endl
;
227 else if ( pItem
->GetType () == SSITEM_FILE
)
229 std::string binary
= pItem
->GetBinary() ? "Binary" : "Text";
230 std::cout
<< pItem
->GetName () << "\t" << binary
<< std::endl
;
235 else if (pItem
->GetType () == SSITEM_FILE
)
237 std::string binary
= pItem
->GetBinary() ? "Binary" : "Text";
238 std::cout
<< pItem
->GetName () << "\t" << binary
<< std::endl
;
241 catch (SSException
& ex
)
243 std::cerr
<< "error: " << ex
.what() << std::endl
;
250 int CVssFormatter::DoHistory (const SSItemPtr pItem
, const COptions
& options
)
255 // std::auto_ptr<SSVersions> pVersions = pItem->GetVersions(0);
256 // for (long i = 0; i < pVersions->GetCount (); ++i)
258 // SSVersionPtr pVersions (pVersions->GetVersion(i));
259 // pVersions->ReportVssStyle
262 catch (SSException
& ex
)
264 std::cerr
<< "error: " << ex
.what() << std::endl
;
272 IFormatter
* CVssFormatterFactory::MakeFormatter ()
274 return new CVssFormatter ();