Added a EditorSocial.
[UnsignedByte.git] / src / DAL / FieldValues.cpp
bloba244f609509c9027c0c9e540e676246f54e31070
1 /***************************************************************************
2 * Copyright (C) 2008 by Sverre Rabbelier *
3 * sverre@rabbelier.nl *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "FieldImpl.h"
22 #include "FieldValue.h"
23 #include "FieldValues.h"
24 #include "KeyImpl.h"
25 #include "KeyValue.h"
26 #include "Parse.h"
27 #include "StringUtilities.h"
28 #include "TableImpl.h"
30 FieldValues::FieldValues(TableImplPtr table) :
31 m_table(table)
33 Assert(table);
36 FieldValues::~FieldValues()
41 ValuePtr FieldValues::getField(FieldImplPtr field) const
43 Assert(field);
44 ValueMap::const_iterator it = m_fields.find(field.get());
45 Assert(it != m_fields.end());
47 return it->second;
50 TableImplPtr FieldValues::getTable() const
52 return m_table;
55 void FieldValues::addValue(ValuePtr value)
57 Assert(value);
59 TableImplPtr table = value->getTable();
60 bool isReachableTable = false;
62 if(table == m_table)
63 isReachableTable = true;
65 for(TableImplVector::const_iterator it = m_joinedTables.begin(); it != m_joinedTables.end(); it++)
67 TableImplPtr joinedTable = *it;
68 if(table == joinedTable)
69 isReachableTable = true;
72 Assert(isReachableTable);
74 m_fields[value->getField().get()] = value;
77 void FieldValues::addValue(FieldImplPtr field, value_type value)
79 Assert(field);
81 FieldValuePtr fieldvalue(new FieldValue(field, value));
82 addValue(fieldvalue);
85 void FieldValues::addValue(FieldImplPtr field, cstring value)
87 Assert(field);
89 FieldValuePtr fieldvalue(new FieldValue(field, value));
90 addValue(fieldvalue);
93 void FieldValues::addJoinedTable(TableImplPtr joinedTable)
95 Assert(joinedTable);
97 m_joinedTables.push_back(joinedTable);
100 size_t FieldValues::size() const
102 return m_fields.size();
105 ValuePtr FieldValues::first() const
107 Assert(m_fields.size() > 0);
109 return m_fields.begin()->second;
112 ValueMap::const_iterator FieldValues::begin() const
114 return m_fields.begin();
117 ValueMap::const_iterator FieldValues::end() const
119 return m_fields.end();
122 ValueMap::const_iterator FieldValues::find(FieldImplPtr field) const
124 Assert(field);
126 return m_fields.find(field.get());