root/trunk/ssphys/SSPhysLib/SSNameObject.cpp

Revision 157 (checked in by ldavis, 4 years ago)

added svn:eol-style to all files
added svn:mime-type to all files

  • Property svn:mime-type set to text/plain
  • Property svn:eol-style set to native
Line 
1 // SSNameObject.cpp: implementation of the SSNameObject class.
2 //
3 //////////////////////////////////////////////////////////////////////
4
5 #include "StdAfx.h"
6
7 #pragma warning (disable: 4786)
8 #include <string>
9 #include <map>
10 #include <boost/lexical_cast.hpp>
11
12 #include "SSNameObject.h"
13
14 //////////////////////////////////////////////////////////////////////
15 // Construction/Destruction
16 //////////////////////////////////////////////////////////////////////
17
18 SSNameObject::SSNameObject (SSRecordPtr pRecord)
19   : SSObject (pRecord, eNameCacheEntry)
20 {
21   Init (pRecord);
22 }
23
24 void SSNameObject::Init (SSRecordPtr pRecord)
25 {
26   if (pRecord->GetLen () < sizeof (NSMAP) + sizeof (NSMAP)) 
27     throw SSRecordException ("not enough data for name object");
28
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);
32
33   for (int i = 0; i<pMap->num; ++i)
34   {
35     warn_if (pEntry->id != 1 && pEntry->id != 2 && pEntry->id != 3 && pEntry->id != 10);
36    
37     m_NamesMap[pEntry->id] = pNames + pEntry->offset;
38
39     ++pEntry;
40   }
41 }
42
43 std::string SSNameObject::GetName (short id)
44 {
45   std::map<short, std::string>::iterator iter = m_NamesMap.find (id);
46   if (iter != m_NamesMap.end ())
47     return (*iter).second;
48
49   return "";
50 }
51
52
53 void SSNameObject::ToXml (XMLNode* pParent) const
54 {
55   XMLElement entries (pParent, "NrOfEntries", size ());
56
57   std::map<short, std::string>::const_iterator iter = m_NamesMap.begin ();
58   for (; iter != m_NamesMap.end (); ++iter)
59   {
60     AttribMap map;
61     map["id"] = boost::lexical_cast<std::string> ((*iter).first);
62     XMLElement name (pParent, "Entry", map, (*iter).second);
63   }
64 }
65
66 void SSNameObject::Dump (std::ostream& os) const
67 {
68   SSObject::Dump (os);
69
70   os << "Entries: " << m_NamesMap.size () << std::endl;
71
72   std::map<short, std::string>::const_iterator iter = m_NamesMap.begin ();
73   for (; iter != m_NamesMap.end (); ++iter)
74   {
75     os << "id(" << (*iter).first  << ") "/*, offset (" << pEntry->offset << ")*/ "= " << (*iter).second <<std::endl;
76   }
77 }
Note: See TracBrowser for help on using the browser.

PumaCode.org recommends CVSDude for fast, professional Subversion and Trac hosting:

CVSDude.com

These ads are automatically generated by Google. Revenue from these ads helps to pay for hosting this site; however, these ads do not constitute an endorsement by PumaCode.org.