Garmin Fleet Management Controller  2.19.0
ClientListItem.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * MODULE NAME:
4 * ClientListItem.cpp
5 *
6 * Copyright 2008-2009 by Garmin Ltd. or its subsidiaries.
7 *---------------------------------------------------------------------
8 * $NoKeywords$
9 *********************************************************************/
10 
11 #include "ClientListItem.h"
12 
13 //----------------------------------------------------------------------
16 //----------------------------------------------------------------------
18 {
19  mCurrentName = _T("");
20  mUpdateName = _T("");
21  mIsValid = FALSE;
22  mParent = NULL;
23 }
24 
25 //----------------------------------------------------------------------
28 //----------------------------------------------------------------------
30 {
32  setValid();
33 }
34 
35 //----------------------------------------------------------------------
38 //----------------------------------------------------------------------
40 {
41  return mCurrentName;
42 }
43 
44 //----------------------------------------------------------------------
48 //----------------------------------------------------------------------
50 {
51  return mId;
52 }
53 
54 //----------------------------------------------------------------------
57 //----------------------------------------------------------------------
59 {
60  return mIsValid;
61 }
62 
63 //----------------------------------------------------------------------
68 //----------------------------------------------------------------------
70  (
71  std::istream &aStream
72  )
73 {
74  char utf8Name[200];
75  TCHAR tcharName[200];
76  int idx = 0;
77  char temp;
78 
79  memset( utf8Name, 0, sizeof( utf8Name ) );
80 
81  aStream >> mId;
82  aStream.get(); // consume '-' inserted between id and name
83 
84  while( aStream.peek() != '\n' && !aStream.eof() )
85  {
86  aStream.read( &temp, 1 );
87  utf8Name[idx++] = temp;
88  }
89  aStream.get(); // consume '\n' inserted after name
90  MultiByteToWideChar( CP_UTF8, 0, utf8Name, -1, tcharName, 200 );
91  mCurrentName.SetString( tcharName );
92  mUpdateName.SetString( _T("") );
93  mIsValid = TRUE;
94 }
95 
96 //----------------------------------------------------------------------
99 //----------------------------------------------------------------------
101  (
102  const ClientListItem::key_type & aId
103  )
104 {
105  mId = aId;
106 }
107 
108 //----------------------------------------------------------------------
111 //----------------------------------------------------------------------
113  (
115  )
116 {
117  mParent = aParent;
118 }
119 
120 //----------------------------------------------------------------------
125 //----------------------------------------------------------------------
127  (
128  CString aName
129  )
130 {
131  mUpdateName = aName;
132 }
133 
134 //----------------------------------------------------------------------
139 //----------------------------------------------------------------------
141  (
142  BOOL aValid
143  )
144 {
145  mIsValid = aValid;
146  save();
147 }
148 
149 //----------------------------------------------------------------------
153 //----------------------------------------------------------------------
155  (
156  std::ofstream &aStream
157  ) const
158 {
159  int nameLength = WideCharToMultiByte( CP_UTF8, 0, mCurrentName, -1, NULL, 0, NULL, NULL );
160  char* name = new char[nameLength];
161 
162  WideCharToMultiByte( CP_UTF8, 0, mCurrentName, -1, name, nameLength, NULL, NULL );
163  aStream << mId << "-" << name << '\n';
164 
165  delete [] name;
166 }
167 
168 //----------------------------------------------------------------------
171 //----------------------------------------------------------------------
173 {
174  if( mParent )
175  {
176  mParent->save();
177  }
178 }
BOOL isValid() const
Check whether this item is valid.
ClientListItem()
Constructor.
void setId(const key_type &aId)
Set item&#39;s ID.
virtual void readFromStream(std::istream &aStream)
Read a ClientListItem from an input stream.
virtual void save()
Save this item.
CString getCurrentName() const
Get the current name of this item.
CString mUpdateName
The last name entered by the user.
#define FALSE
Definition: garmin_types.h:46
const key_type & getId() const
Get item&#39;s ID.
void commitName()
Commit the item name.
void setValid(BOOL aValid=TRUE)
Set this item as valid.
#define TRUE
Definition: garmin_types.h:45
virtual void writeToStream(std::ofstream &aStream) const
Write a ClientListItem to an output stream.
CString mCurrentName
The last name acknowledged by the client.
void setUpdateName(CString aName)
Set pending name.
uint32 key_type
key type
BOOL mIsValid
True if this list item is mIsValid.
void setParent(FileBackedMap< ClientListItem > *aParent)
Set the parent.
FileBackedMap< ClientListItem > * mParent
The map that this item belongs to, or NULL if none.
key_type mId
The unique ID of this item.
void save()
Save the map to disk.