Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
for (long trend = 1; trend <= m_Trends.GetCount(); trend++)
        {
            CRect    rect;
            float    iteration_factor;
            short    pen(0);
            CCsTrendPoint    trendpoint;
            CCsOpcValue        DisplayMaxPoint, DisplayMinPoint;
            POSITION pos;
            double        curtime;

            rect = CRect(CPoint(0,0), m_Trends[trend-1].m_TrendRect.Size());
            iteration_factor = m_TrendDurationSeconds/rect.right;

            for (pen = 0; pen < m_TrendItems.GetSize(); pen++)    // redraw each pen
            {
                pos = m_TrendItems[pen].GetTrendPoints().GetTailPosition();
                if(pos)
                    trendpoint = m_TrendItems[pen].GetTrendPoints().GetPrev(pos);

                while(pos)
                {
                    DisplayMaxPoint.SetValue(trendpoint.m_Value);
                    DisplayMaxPoint.SetTimeStamp(trendpoint.m_Time);
                    DisplayMinPoint.SetValue(trendpoint.m_Value);
                    DisplayMinPoint.SetTimeStamp(trendpoint.m_Time);

                    curtime = (trendpoint.m_Time).GetTotalSeconds();

                    while(pos && ((trendpoint.m_Time).GetTotalSeconds() >= curtime) && ((trendpoint.m_Time).GetTotalSeconds() < (curtime + iteration_factor)))
                    {
                        if(trendpoint.m_Value > DisplayMaxPoint.GetFloatValue())
                        {
                            DisplayMaxPoint.SetValue(trendpoint.m_Value);
                            DisplayMaxPoint.SetTimeStamp(trendpoint.m_Time);
                            MaxPoint = trendpoint;
                        }
                        if(trendpoint.m_Value < DisplayMinPoint.GetFloatValue())
                        {
                            DisplayMinPoint.SetValue(trendpoint.m_Value);
                            DisplayMinPoint.SetTimeStamp(trendpoint.m_Time);
                            MinPoint = trendpoint;
                        }
                        trendpoint = m_TrendItems[pen].GetTrendPoints().GetPrev(pos);
                    }
                    if (pen >= m_TrendDisplayItems.GetSize())
                    {
                        m_TrendDisplayItems.SetSize(pen+1);
                    }
                    m_TrendDisplayItems[pen].AddNewPoint(DisplayMaxPoint);
                    m_TrendDisplayItems[pen].AddNewPoint(DisplayMinPoint);
                }
            }
        }



I know this is a simple question. The above way i was passing the data of a trend array to the new array, but instaed of passing the data, i want to pass the pointer of the trendpoint(MinPoint and MaxPoint), i tried many ways but was not able to do it.

So my question is, how can i get the pointer of the min and max point and how to put these in an array? Plz help me its urgent!!
Posted
Comments
Emilio Garavaglia 24-Sep-10 5:12am    
"Plz help me its urgent!!" is the best way to get no answer.

1 solution

Can you follow ? :) :
class CCsOpcValue;

class CTrend
{
  CArray<CCsOpcValue*,CCsOpcValue*> m_arDisplayItems;
..
public:
 ~CTrend() { RemoveDisplayItems(); };

 void FillDiasplayItems(..);
 void RemoveDisplayItems(int iHowMuch = -1);
 void DrawDisplayItems(CDC* pcDC, const CRect& crBounds, ...);
..
};

void CTrend::FillDisplayItems(..)
{
  for (..) {
    CCsOpcValue* pcMin = new CCsOpcValue(this, CCsOpcValue::minItem, ..);
    CCsOpcValue* pcMax = new CCsOpcValue(this, CCsOpcValue::maxItem, ..);
    while (..) {
      // Modifications of the values
      // ..
    }
    m_arDisplayItems.Add(pcMin);
    m_arDisplayItems.Add(pcMax);
  }
}

void CTrend::RemoveDisplayItems(int iHowMuch /*= -1*/)
{
  int iCount = m_arDisplayItems.GetCount();
  int iUntil = (iHowMuch < 0 || iCount < iHowMuch) ?
               iCount :
               iHowMuch;
               
  for (int i = 0; i < iUntil; i++) {
    delete m_arDisplayItems[i];
    m_arDisplayItems.RemoveAt(i);
  }
}

void CTrend::DrawDisplayItems(CDC* pcDC, const CRect& crBounds, ...)
{
  for (int i = 0; i < m_arDisplayItems.GetCount(); i++) {
    // Check the stamps, indexes, values an draw
    // ...
  }
}
 
Share this answer
 
v2
Comments
amarasat 24-Sep-10 9:58am    
No, this is not what i have asked for, we are still moving the points into a different array{the csopcvalue array} right?

I dont wna tot move any items or their values, so i dont wna t a CsOpcValue array may be, i want a regular array which stores the pointer to a value in the

m_TrendItems[pen].GetTrendPoints().GetPrev(pos);

the above code returns a trend point, when this point is valid, i have to move a pointer for this point, to a new array, the new array will not have any values, just pointers only.

and when i redraw, i refer to pointers in stead of filtering the whole

m_TrendItems[pen].GetTrendPoints(); again.

pls let me know if you need some more info. and pls let me know how to do this way, just to store pointers for the trend data points.

Thanks a lo for your time.
amarasat 24-Sep-10 10:00am    
i meant i dont know, how to get the pointer for the trend point, do i have to use * or get the & value of it, i am confused.
Eugen Podsypalnikov 24-Sep-10 10:16am    
An operator 'new' returns a pointer of the constructed typed object allocated in the heap. Such pointers are valid until they will not be deleted by the operator 'delete'.
Othersides, you can get any typed pointer by 'ampersand', for example: { int i = 2; int* pointer = &i; }. Such pointers are valid only for the live-period of their "master-variables".
So you can use '&trendpoint', only when you are sure the trendpoint's live period is long enough... :)
amarasat 24-Sep-10 10:49am    
CCsTrendPoint* TrendPointPointer;
std::vector<ccstrendpoint*> m_TrendDisplayItemVect;

TrendPointPointer = &trendpoint; //pointer to the point that has been filtered and to be moved

m_TrendDisplayItemVect.push_back(TrendPointPointer);

this is buliding without any errors.

1.) Is this correct?
2.) how can i make m_TrendDisplayItemVect 2 dimensional, ie to push like m_TrendDisplayItemVect[pen].push_back(TrendPointPointer);
Eugen Podsypalnikov 25-Sep-10 7:35am    
1) It would be OK, when the validity of the pointers is granted for the whole time their usage.
2)
class CCsTrendPoint : public CObject // a point's data
{
..
}

class CDisplayItems : public CObList // collection of CCsTrendPoint* for a pen, second dim
{
..
};

class CDisplayData : public CObArray // collection of CDisplayItems* indexed by pens, first dim
{
..
};

:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900