1 // SSNameObject.cpp: implementation of the SSNameObject class.
3 //////////////////////////////////////////////////////////////////////
7 #pragma warning (disable: 4786)
10 #include <boost/lexical_cast.hpp>
12 #include "SSNameObject.h"
14 //////////////////////////////////////////////////////////////////////
15 // Construction/Destruction
16 //////////////////////////////////////////////////////////////////////
18 SSNameObject::SSNameObject (SSRecordPtr pRecord
)
19 : SSObject (pRecord
, eNameCacheEntry
)
24 void SSNameObject::Init (SSRecordPtr pRecord
)
26 if (pRecord
->GetLen () < sizeof (NSMAP
) + sizeof (NSMAP
))
27 throw SSRecordException ("not enough data for name object");
29 const NSMAP
* pMap
= (NSMAP
*) pRecord
->GetBuffer();
30 const NSENTRY
* pEntry
= (NSENTRY
*) ((byte
*)pMap
+ sizeof (NSMAP
));
31 const char* pNames
= (const char*) ((byte
*)pEntry
+ sizeof (NSENTRY
) * pMap
->num
);
33 for (int i
= 0; i
<pMap
->num
; ++i
)
35 warn_if (pEntry
->id
!= 1 && pEntry
->id
!= 2 && pEntry
->id
!= 3 && pEntry
->id
!= 10);
37 m_NamesMap
[pEntry
->id
] = pNames
+ pEntry
->offset
;
43 std::string
SSNameObject::GetName (short id
)
45 std::map
<short, std::string
>::iterator iter
= m_NamesMap
.find (id
);
46 if (iter
!= m_NamesMap
.end ())
47 return (*iter
).second
;
53 void SSNameObject::ToXml (XMLNode
* pParent
) const
55 XMLElement
entries (pParent
, "NrOfEntries", size ());
57 std::map
<short, std::string
>::const_iterator iter
= m_NamesMap
.begin ();
58 for (; iter
!= m_NamesMap
.end (); ++iter
)
61 map
["id"] = boost::lexical_cast
<std::string
> ((*iter
).first
);
62 XMLElement
name (pParent
, "Entry", map
, (*iter
).second
);
66 void SSNameObject::Dump (std::ostream
& os
) const
70 os
<< "Entries: " << m_NamesMap
.size () << std::endl
;
72 std::map
<short, std::string
>::const_iterator iter
= m_NamesMap
.begin ();
73 for (; iter
!= m_NamesMap
.end (); ++iter
)
75 os
<< "id(" << (*iter
).first
<< ") "/*, offset (" << pEntry->offset << ")*/ "= " << (*iter
).second
<<std::endl
;