| 1 |
// SSProjectObject.cpp: implementation of the SSProjectObject class. |
|---|
| 2 |
// |
|---|
| 3 |
////////////////////////////////////////////////////////////////////// |
|---|
| 4 |
|
|---|
| 5 |
#include "StdAfx.h" |
|---|
| 6 |
#include "SSProjectObject.h" |
|---|
| 7 |
#include "SSName.h" |
|---|
| 8 |
#include <strstream> |
|---|
| 9 |
|
|---|
| 10 |
////////////////////////////////////////////////////////////////////// |
|---|
| 11 |
// Construction/Destruction |
|---|
| 12 |
////////////////////////////////////////////////////////////////////// |
|---|
| 13 |
|
|---|
| 14 |
SSProjectObject::SSProjectObject(const PROJECT_ENTRY& pe) |
|---|
| 15 |
: SSObject(SSRecordPtr (new SSRecord (eProjectEntry, &pe, sizeof (PROJECT_ENTRY))), eProjectEntry) |
|---|
| 16 |
{ |
|---|
| 17 |
if (GetRecord()->GetLen() < sizeof (PROJECT_ENTRY)) |
|---|
| 18 |
throw SSRecordException ("not enough data for project object"); |
|---|
| 19 |
|
|---|
| 20 |
m_pProjectEntry = (PROJECT_ENTRY*) SSObject::GetData (); |
|---|
| 21 |
} |
|---|
| 22 |
|
|---|
| 23 |
SSProjectObject::SSProjectObject(SSRecordPtr pRecord) |
|---|
| 24 |
: SSObject(pRecord, eProjectEntry) |
|---|
| 25 |
{ |
|---|
| 26 |
if (pRecord->GetLen() < sizeof (PROJECT_ENTRY)) |
|---|
| 27 |
throw SSRecordException ("not enough data for project object"); |
|---|
| 28 |
|
|---|
| 29 |
m_pProjectEntry = (PROJECT_ENTRY*) SSObject::GetData (); |
|---|
| 30 |
} |
|---|
| 31 |
|
|---|
| 32 |
SSProjectObject::~SSProjectObject() |
|---|
| 33 |
{ |
|---|
| 34 |
|
|---|
| 35 |
} |
|---|
| 36 |
|
|---|
| 37 |
std::string SSProjectObject::GetName () const |
|---|
| 38 |
{ |
|---|
| 39 |
SSName name (m_pProjectEntry->name); |
|---|
| 40 |
std::string fullName (name.GetFullName()); |
|---|
| 41 |
// if (IsShared()) |
|---|
| 42 |
if (GetPinnedToVersion() != 0) |
|---|
| 43 |
{ |
|---|
| 44 |
char buffer[66]; |
|---|
| 45 |
fullName += ";"; |
|---|
| 46 |
// note that Linux STL lacks itoa, as of FC2 |
|---|
| 47 |
sprintf(buffer, "%d", GetPinnedToVersion()); |
|---|
| 48 |
fullName += buffer; |
|---|
| 49 |
} |
|---|
| 50 |
return fullName; |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
std::string SSProjectObject::GetPhysFile () const |
|---|
| 54 |
{ |
|---|
| 55 |
return std::string (m_pProjectEntry->phys, 8); |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
int SSProjectObject::GetType () const |
|---|
| 59 |
{ |
|---|
| 60 |
return (m_pProjectEntry->type); |
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
eFileType SSProjectObject::GetFileType () const |
|---|
| 64 |
{ |
|---|
| 65 |
if (IsStoreBinaryDiff ()) |
|---|
| 66 |
return eFileTypeBinary; |
|---|
| 67 |
|
|---|
| 68 |
return eFileTypeText; |
|---|
| 69 |
} |
|---|
| 70 |
|
|---|
| 71 |
bool SSProjectObject::IsDeleted () const |
|---|
| 72 |
{ |
|---|
| 73 |
return (m_pProjectEntry->flags & 0x01) != 0; |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
bool SSProjectObject::IsStoreBinaryDiff () const |
|---|
| 77 |
{ |
|---|
| 78 |
return (m_pProjectEntry->flags & 0x02) != 0; |
|---|
| 79 |
} |
|---|
| 80 |
|
|---|
| 81 |
bool SSProjectObject::IsStoreLatestRev () const |
|---|
| 82 |
{ |
|---|
| 83 |
return (m_pProjectEntry->flags & 0x04) != 0; |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
bool SSProjectObject::IsShared () const |
|---|
| 87 |
{ |
|---|
| 88 |
return (m_pProjectEntry->flags & 0x08) != 0; |
|---|
| 89 |
} |
|---|
| 90 |
|
|---|
| 91 |
int SSProjectObject::GetPinnedToVersion () const |
|---|
| 92 |
{ |
|---|
| 93 |
return (m_pProjectEntry->pinnedToVersion); |
|---|
| 94 |
} |
|---|
| 95 |
|
|---|
| 96 |
// 0x08 shared |
|---|
| 97 |
// 0x02 store binary diffs |
|---|
| 98 |
// 0x01 deleted |
|---|
| 99 |
std::string FlagsToString (short flags) |
|---|
| 100 |
{ |
|---|
| 101 |
std::ostringstream ost; |
|---|
| 102 |
if (flags & 0x01) |
|---|
| 103 |
ost << "deleted"; |
|---|
| 104 |
if (flags & 0x02) |
|---|
| 105 |
ost << " binary"; |
|---|
| 106 |
if (flags & 0x08) |
|---|
| 107 |
ost << " shared"; |
|---|
| 108 |
if (flags & 0xf4) |
|---|
| 109 |
ost << " unknown(" << flags << ")"; |
|---|
| 110 |
|
|---|
| 111 |
ost << '\0'; |
|---|
| 112 |
return ost.str (); |
|---|
| 113 |
} |
|---|
| 114 |
|
|---|
| 115 |
std::string TypeToString (short type) |
|---|
| 116 |
{ |
|---|
| 117 |
warn_if (type != 1 && type != 2); |
|---|
| 118 |
|
|---|
| 119 |
char* types[2] = { "project", "file" }; |
|---|
| 120 |
if (type == 1 || type == 2) |
|---|
| 121 |
return types[type-1]; |
|---|
| 122 |
|
|---|
| 123 |
std::ostringstream ost; |
|---|
| 124 |
ost << "unknown type 0x" << std::hex << type << std::endl; |
|---|
| 125 |
return ost.str(); |
|---|
| 126 |
} |
|---|
| 127 |
|
|---|
| 128 |
void SSProjectObject::Delete () |
|---|
| 129 |
{ |
|---|
| 130 |
m_pProjectEntry->flags &= 0x01; |
|---|
| 131 |
} |
|---|
| 132 |
void SSProjectObject::Recover () |
|---|
| 133 |
{ |
|---|
| 134 |
m_pProjectEntry->flags &= ~0x01; |
|---|
| 135 |
} |
|---|
| 136 |
void SSProjectObject::Rename (SSNAME oldName, SSNAME newName) |
|---|
| 137 |
{ |
|---|
| 138 |
if (memcmp (&oldName, &m_pProjectEntry->name, sizeof (SSNAME)) != 0) |
|---|
| 139 |
throw SSException ("old name does not match"); |
|---|
| 140 |
|
|---|
| 141 |
m_pProjectEntry->name = newName; |
|---|
| 142 |
} |
|---|
| 143 |
|
|---|
| 144 |
void SSProjectObject::Pin (int version) |
|---|
| 145 |
{ |
|---|
| 146 |
m_pProjectEntry->pinnedToVersion = version; |
|---|
| 147 |
} |
|---|
| 148 |
|
|---|
| 149 |
void SSProjectObject::ToXml (XMLNode* pParent) const |
|---|
| 150 |
{ |
|---|
| 151 |
SSObject::ToXml (pParent); |
|---|
| 152 |
|
|---|
| 153 |
GetSSName().ToXml (pParent); |
|---|
| 154 |
XMLElement type (pParent, "Type", TypeToString (GetType ())); |
|---|
| 155 |
XMLElement flags (pParent, "Flags", GetData()->flags); |
|---|
| 156 |
XMLElement pinned (pParent, "PinnedToVersion", GetPinnedToVersion()); |
|---|
| 157 |
XMLElement phys (pParent, "Phys", GetPhysFile()); |
|---|
| 158 |
} |
|---|
| 159 |
|
|---|
| 160 |
void SSProjectObject::Dump (std::ostream& os) const |
|---|
| 161 |
{ |
|---|
| 162 |
SSObject::Dump (os); |
|---|
| 163 |
|
|---|
| 164 |
const PROJECT_ENTRY* pProjectEntry = GetData(); |
|---|
| 165 |
|
|---|
| 166 |
os << "Type: " << TypeToString (pProjectEntry->type) << std::endl; |
|---|
| 167 |
os << "Flags: 0x" << std::hex << pProjectEntry->flags << std::dec << ": " << FlagsToString (pProjectEntry->flags) << std::endl; |
|---|
| 168 |
SSName ssName (pProjectEntry->name); |
|---|
| 169 |
os << "SSName: " << ssName << std::endl; |
|---|
| 170 |
if (pProjectEntry->pinnedToVersion) |
|---|
| 171 |
os << "Pinned to version: " << pProjectEntry->pinnedToVersion << std::endl; |
|---|
| 172 |
os << "Phys file: " << pProjectEntry->phys << std::endl; |
|---|
| 173 |
} |
|---|