-
October 13th, 2010, 09:37 AM
#1
Obtain a pointer to data inside a trend items array
position = m_TrendItems[pen].GetTrendPoints().GetHeadPosition();
while(trendpoint .m_time < requiredtime)
trendpoint = m_TrendItems[pen].GetTrendPoints().GetPrev(position);
m_TrendItems is the global array which has almost 10,000 points for each pen. My question is instead of getting the trendpoint, i want to get the pointer for the (position or point).
I want to store this pointer in a separate array and use it in the future so that i don't have to go from the head position always.
How can i do this?
Do i have to go through all the time i have to find a point can't i store a pointer?
-
October 13th, 2010, 09:41 AM
#2
Re: Obtain a pointer to data inside a trend items array
Head position implies a list, not an array. What is it really?
Why would you want to store a single pointer in an array?
What trouble are you having storing a pointer?
-
October 13th, 2010, 10:01 AM
#3
Re: Obtain a pointer to data inside a trend items array
It sounds like you want to do more efficient lookups in this data structure? In that case, you should try a std::map or std::unordered_map.
-
October 13th, 2010, 10:02 AM
#4
Re: Obtain a pointer to data inside a trend items array
I am sorry it is a list.
i meant not to store a single point, i just want to know how to get a pointer, so that i can store as many as i want.
I have 10 hours of data points in my list, if i have to display points between 3 and 4 hours on the trend, the code is
position = m_TrendItems[pen].GetTrendPoints().GetHeadPosition();
while(trendpoint .m_time < requiredtime)
trendpoint = m_TrendItems[pen].GetTrendPoints().GetPrev(position);
if i have to display points between 5 and 6 hours on the trend, the code is again,
position = m_TrendItems[pen].GetTrendPoints().GetHeadPosition();
while(trendpoint .m_time < requiredtime)
trendpoint = m_TrendItems[pen].GetTrendPoints().GetPrev(position);
if i have to display points between 8 and 9 hours on the trend, the code is again,
position = m_TrendItems[pen].GetTrendPoints().GetHeadPosition();
while(trendpoint .m_time < requiredtime)
trendpoint = m_TrendItems[pen].GetTrendPoints().GetPrev(position);
here i am wasting time by iterating through all the data points that were present. Instead of this what if i can break my 10 hours of data into 10 parts (each of one hour) and store the pointers for the beginning of each hour.
That way if i have to display points between 8 and 9 hours on the trend i will go to the pointer which has position of datapoint starting at 8th hour and then iterate from there. So instead of
position = m_TrendItems[pen].GetTrendPoints().GetHeadPosition();
i will have position = &pointer for 8th hour. How can i do this!!
-
October 13th, 2010, 10:05 AM
#5
Re: Obtain a pointer to data inside a trend items array
@Linley,
can you explain me how to use a map in my case.
-
October 13th, 2010, 10:06 AM
#6
Re: Obtain a pointer to data inside a trend items array
It definitely seems like you want a std::map or std::multimap. In particular, check out the lower_bound and upper_bound member functions.
http://www.cplusplus.com/reference/stl/map/
Now, *if* the linked list is in sorted order and *if* it conforms to the STL container interface (it doesn't look to right now), then you could use std::lower_bound() directly on it without needing to use a map as the underlying container....but it would still be more efficient if you had random access iterators rather than merely bidirectional iterators, eg, you had a vector or deque rather than a list.
Last edited by Lindley; October 13th, 2010 at 10:10 AM.
-
October 13th, 2010, 10:07 AM
#7
Re: Obtain a pointer to data inside a trend items array
What kind of list? Can you post the exact definition please?
-
October 13th, 2010, 10:12 AM
#8
Re: Obtain a pointer to data inside a trend items array
@GCDEF, is this what you are asking for?
typedef CArray<CTrendItem, CTrendItem&> CTrendItems;
CTrendItems m_TrendItems;
@Lindley, sure will check now.
-
October 13th, 2010, 10:14 AM
#9
Re: Obtain a pointer to data inside a trend items array
Ah---you're using MFC containers rather than STL containers. Well, I don't know those very well, but it's possible MFC has a binary tree container equivalent to std::map.....
-
October 13th, 2010, 10:15 AM
#10
Re: Obtain a pointer to data inside a trend items array
@Lindley,
the array is sorted according to timestamps of the data points.
-
October 13th, 2010, 10:42 AM
#11
Re: Obtain a pointer to data inside a trend items array
do you have any suggestions GCDEF?
-
October 13th, 2010, 10:55 AM
#12
Re: Obtain a pointer to data inside a trend items array
I am having problems following exactly what is going on.
1) You are calling GetHeadPositiion() and then looping on GetPrev() ??
2) Could you show the data members for CTrendItem ?
-
October 13th, 2010, 10:59 AM
#13
Re: Obtain a pointer to data inside a trend items array
Originally Posted by amara.fortheworld@gmail.com
do you have any suggestions GCDEF?
No. I'm still confused about what data types you're working with and I'm tired of trying to figure it out.
GetHeadPosition and GetPrev are members of MFC's CList class. They return a POSITION. You can store that and use it to position yourself anywhere in the list you want. If you need a position in an array, just store the index.
Last edited by GCDEF; October 13th, 2010 at 11:02 AM.
-
October 13th, 2010, 11:15 AM
#14
Re: Obtain a pointer to data inside a trend items array
@CDEFG and @ Philip Nicoletti
Thinks this should help,
CTrendItems m_TrendItems;
typedef CArray<CTrendItem, CTrendItem&> CTrendItems;
CCsTrendPoints& GetTrendPoints(){
return m_TrendPoints;
}
CCsTrendPoints m_TrendPoints;
typedef CList<CCsTrendPoint, CCsTrendPoint> CCsTrendPoints;
class CCsTrendPoint
{
public:
// functions
CCsTrendPoint() {m_Time = (time_t)0; m_Value =0;}
CCsTrendPoint(CTime time, float value) {m_Time = time; m_Value = value;}
CCsTrendPoint(CCsTime time, float value){m_Time = time; m_Value = value;}
CCsTrendPoint(CCsTrendPoint& point) { *this = point; }
CCsTrendPoint& operator =(CCsTrendPoint& point)
{m_Time = point.m_Time; m_Value = point.m_Value; return *this;}
// variables
CCsTime m_Time;
float m_Value;
};
@Philip
yes i am looping through prev
members of dataitems has
CCsTrendPoints m_TrendPoints; which is protected.
Let me know if you guys need mroe info, thanks for all the time.
-
October 13th, 2010, 11:35 AM
#15
Re: Obtain a pointer to data inside a trend items array
I haven't used the MFC containers for a while, so maybe I am missing
something simple. But I still do not understand the following:
Code:
position = m_TrendItems[pen].GetTrendPoints().GetHeadPosition();
while(trendpoint.m_time < requiredtime)
trendpoint = m_TrendItems[pen].GetTrendPoints().GetPrev(position);
After the first time thru the while loop, won't position equal NULL ?
Where did trendpoint come from initially ?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|