~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to src/core/FlaimProvider/FlaimWrapper/.svn/text-base/CSPObjectIterator.cpp.svn-base

  • Committer: Jorge O. Castro
  • Date: 2007-12-03 06:56:46 UTC
  • Revision ID: jorge@ubuntu.com-20071203065646-mupcnjcwgm5mnhyt
* Remove a bunch of .svn directories we no longer need.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***********************************************************************
2
 
 *  $RCSfile$
3
 
 *
4
 
 *  Copyright (C) 2004 Novell, Inc.
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or
7
 
 *  modify it under the terms of the GNU General Public
8
 
 *  License as published by the Free Software Foundation; either
9
 
 *  version 2 of the License, or (at your option) any later version.
10
 
 *
11
 
 *  This program is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 
 *  General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public
17
 
 *  License along with this program; if not, write to the Free
18
 
 *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
 
 *
20
 
 *  Author: Russ Young
21
 
 *
22
 
 ***********************************************************************/
23
 
#include "CSPObjectIterator.h"
24
 
 
25
 
CSPObjectIterator::CSPObjectIterator(HFCURSOR cursor, int count, FLMBOOL includeColId) :
26
 
        m_Count(count),
27
 
        m_Index(0),
28
 
        m_pRecords(0),
29
 
        m_includeColId(includeColId)
30
 
{
31
 
        if (m_Count)
32
 
        {
33
 
                RCODE rc;
34
 
                m_pRecords = new FLMUINT[m_Count];
35
 
                if (m_pRecords)
36
 
                {
37
 
                        int i;
38
 
                        for (i = 0; i < count; ++i)
39
 
                        {
40
 
                                rc = FlmCursorNextDRN(cursor, &m_pRecords[i]);
41
 
                                if (RC_BAD(rc))
42
 
                                {
43
 
                                        m_Count = 0;
44
 
                                        break;
45
 
                                }
46
 
                        }
47
 
                }
48
 
        }
49
 
}
50
 
 
51
 
CSPObjectIterator::~CSPObjectIterator(void)
52
 
{
53
 
        if (m_pRecords)
54
 
        {
55
 
                delete [] m_pRecords;
56
 
        }
57
 
}
58
 
 
59
 
int CSPObjectIterator::NextXml(CSPStore *pStore, FLMUNICODE *pOriginalBuffer, int nChars)
60
 
{
61
 
        RCODE rc = FERR_OK;
62
 
        int charsWritten = nChars;
63
 
        int len = 0;
64
 
        FlmRecord       *pRec = 0;
65
 
        FLMUNICODE* pBuffer = pOriginalBuffer;
66
 
        int endTagLen = f_unilen((FLMUNICODE*)XmlObjectListEndString) + 1;
67
 
 
68
 
        if (m_Index < m_Count)
69
 
        {
70
 
                if ((len = flmstrcpy(pBuffer, (FLMUNICODE*)XmlObectListString, nChars)) != -1)
71
 
                {
72
 
                        nChars -= len + endTagLen;
73
 
                        pBuffer += len;
74
 
                        
75
 
                        while (RC_OK(rc) && m_Index < m_Count)
76
 
                        {
77
 
                                rc = FlmRecordRetrieve(pStore->GetDB(), FLM_DATA_CONTAINER, m_pRecords[m_Index], FO_EXACT, &pRec, 0);
78
 
                                if (RC_OK(rc) && pRec)
79
 
                                {
80
 
                                        CSPStoreObject *pObject = new CSPStoreObject(pStore, pRec);
81
 
                                        if (pObject)
82
 
                                        {
83
 
                                                if ((len = pObject->ToXML(pBuffer, nChars, false, m_includeColId)) != -1)
84
 
                                                {
85
 
                                                        nChars -= len;
86
 
                                                        pBuffer += len;
87
 
                                                        m_Index++;
88
 
                                                }
89
 
                                                else
90
 
                                                {
91
 
                                                        rc = FERR_MEM;
92
 
                                                }
93
 
                                                delete pObject;
94
 
                                                pRec = 0;
95
 
                                        }
96
 
                                }
97
 
                                else if (rc == FERR_NOT_FOUND)
98
 
                                {
99
 
                                        m_Index++;
100
 
                                        rc = FERR_OK;
101
 
                                }
102
 
                                else if (RC_BAD(rc))
103
 
                                {
104
 
                                        m_Index++;
105
 
                                        rc = FERR_OK;
106
 
                                }
107
 
                        }
108
 
                        if ((len = flmstrcpy(pBuffer, (FLMUNICODE*)XmlObjectListEndString, nChars + endTagLen)) != -1)
109
 
                        {
110
 
                                nChars++;
111
 
                        }
112
 
                }
113
 
        }
114
 
        return (len != -1 ? charsWritten - nChars : 0);
115
 
}
116
 
 
117
 
bool CSPObjectIterator::SetIndex(IndexOrigin origin, int offset)
118
 
{
119
 
        int newOffset = -1;
120
 
        switch (origin)
121
 
        {
122
 
        case CUR:
123
 
                newOffset += offset;
124
 
                break;
125
 
        case END:
126
 
                newOffset = m_Count + offset;
127
 
                break;
128
 
        case SET:
129
 
                newOffset = offset;
130
 
                break;
131
 
        }
132
 
 
133
 
        if (newOffset <= m_Count && newOffset >= 0)
134
 
        {
135
 
                        m_Index = newOffset;
136
 
                        return true;
137
 
        }
138
 
        else
139
 
                return false;
140
 
}
141
 
 
142
 
 
143