/[rtss_sdk]/trunk/Samples/SharedMemory/RTSSSharedMemorySample/GroupedString.cpp
ViewVC logotype

Annotation of /trunk/Samples/SharedMemory/RTSSSharedMemorySample/GroupedString.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (hide annotations) (download)
Fri Aug 8 11:41:35 2014 UTC (5 years, 5 months ago) by william
File size: 2487 byte(s)
initial commit of RTSS SDK (from 6.1.0.7305)
Available from: http://www.guru3d.com/files-details/rtss-rivatuner-statistics-server-download.html
1 william 2 // GroupedString.cpp: implementation of the CGroupedString class.
2     //
3     // created by Unwinder
4     //////////////////////////////////////////////////////////////////////
5     #include "stdafx.h"
6     #include "GroupedString.h"
7     //////////////////////////////////////////////////////////////////////
8     #ifdef _DEBUG
9     #undef THIS_FILE
10     static char THIS_FILE[]=__FILE__;
11     #define new DEBUG_NEW
12     #endif
13     //////////////////////////////////////////////////////////////////////
14     // Construction/Destruction
15     //////////////////////////////////////////////////////////////////////
16     CGroupedString::CGroupedString(int nMaxLen)
17     {
18     m_nMaxLen = nMaxLen;
19     }
20     //////////////////////////////////////////////////////////////////////
21     CGroupedString::~CGroupedString()
22     {
23     }
24     //////////////////////////////////////////////////////////////////////
25     void CGroupedString::Add(LPCSTR lpValue, LPCSTR lpGroup, LPCSTR lpSeparator)
26     {
27     for (int i=0; i<GetSize(); i+=2)
28     {
29     if (!stricmp(GetAt(i), lpGroup))
30     {
31     CString s = GetAt(i+1);
32    
33     if (!s.IsEmpty())
34     {
35     if (strlen(lpGroup))
36     s += ", ";
37     else
38     s += lpSeparator;
39     }
40    
41     s += lpValue;
42    
43     if (s.GetLength() < m_nMaxLen)
44     SetAt(i+1,s);
45    
46     return;
47     }
48     }
49    
50     CStringArray::Add(lpGroup);
51     CStringArray::Add(lpValue);
52     }
53     //////////////////////////////////////////////////////////////////////
54     CString CGroupedString::Get(BOOL& bTruncated)
55     {
56     CString result = "";
57     int iMaxWidth = 0;
58     bTruncated = FALSE;
59    
60     int i;
61    
62     for (i=0; i<GetSize(); i+=2)
63     {
64     CString strGroup = GetAt(i);
65    
66     int iCurWidth = strGroup.GetLength();
67     if (iMaxWidth < iCurWidth)
68     iMaxWidth = iCurWidth;
69     }
70    
71     for (i=0; i<GetSize(); i+=2)
72     {
73     CString strGroup = GetAt(i);
74     CString strValue = GetAt(i+1);
75     strGroup.TrimLeft();
76    
77     if (strGroup.IsEmpty())
78     {
79     if (result.GetLength() + strValue.GetLength() < m_nMaxLen)
80     {
81     if (!result.IsEmpty())
82     result += "\n";
83    
84     result += strValue;
85     }
86     else
87     bTruncated = TRUE;
88     }
89     else
90     {
91     CString buf;
92     buf.Format("%-*s \t: %s", iMaxWidth, strGroup, strValue);
93    
94     if (result.GetLength() + buf.GetLength() < m_nMaxLen)
95     {
96     if (!result.IsEmpty())
97     result += "\n";
98    
99     result += buf;
100     }
101     else
102     bTruncated = TRUE;
103     }
104     }
105    
106    
107     if (result.GetLength() < m_nMaxLen)
108     return result;
109    
110     bTruncated = TRUE;
111    
112     return result.Left(m_nMaxLen);
113     }
114     //////////////////////////////////////////////////////////////////////

  ViewVC Help
Powered by ViewVC 1.1.22