Skip to content

Commit d0d667a

Browse files
committed
added support for Var assignment to Var-enabled types
1 parent 1568abf commit d0d667a

12 files changed

Lines changed: 394 additions & 3 deletions

File tree

‎Data/Data_VS71.vcproj‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,12 @@
306306
<File
307307
RelativePath=".\include\Poco\Data\Date.h">
308308
</File>
309+
<File
310+
RelativePath=".\include\Poco\Data\DynamicDateTime.h">
311+
</File>
312+
<File
313+
RelativePath=".\include\Poco\Data\DynamicLOB.h">
314+
</File>
309315
<File
310316
RelativePath=".\include\Poco\Data\Extraction.h">
311317
</File>
@@ -409,6 +415,9 @@
409415
<File
410416
RelativePath=".\src\Date.cpp">
411417
</File>
418+
<File
419+
RelativePath=".\src\DynamicLOB.cpp">
420+
</File>
412421
<File
413422
RelativePath=".\src\Limit.cpp">
414423
</File>

‎Data/Data_VS80.vcproj‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,14 @@
421421
RelativePath=".\include\Poco\Data\Date.h"
422422
>
423423
</File>
424+
<File
425+
RelativePath=".\include\Poco\Data\DynamicDateTime.h"
426+
>
427+
</File>
428+
<File
429+
RelativePath=".\include\Poco\Data\DynamicLOB.h"
430+
>
431+
</File>
424432
<File
425433
RelativePath=".\include\Poco\Data\Extraction.h"
426434
>
@@ -557,6 +565,10 @@
557565
RelativePath=".\src\Date.cpp"
558566
>
559567
</File>
568+
<File
569+
RelativePath=".\src\DynamicLOB.cpp"
570+
>
571+
</File>
560572
<File
561573
RelativePath=".\src\Limit.cpp"
562574
>

‎Data/Data_VS90.vcproj‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,14 @@
422422
RelativePath=".\include\Poco\Data\Date.h"
423423
>
424424
</File>
425+
<File
426+
RelativePath=".\include\Poco\Data\DynamicDateTime.h"
427+
>
428+
</File>
429+
<File
430+
RelativePath=".\include\Poco\Data\DynamicLOB.h"
431+
>
432+
</File>
425433
<File
426434
RelativePath=".\include\Poco\Data\Extraction.h"
427435
>
@@ -562,6 +570,10 @@
562570
RelativePath=".\src\Date.cpp"
563571
>
564572
</File>
573+
<File
574+
RelativePath=".\src\DynamicLOB.cpp"
575+
>
576+
</File>
565577
<File
566578
RelativePath=".\src\Limit.cpp"
567579
>

‎Data/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ include $(POCO_BASE)/build/rules/global
1010

1111
objects = AbstractBinder AbstractBinding AbstractExtraction AbstractExtractor \
1212
AbstractPreparation AbstractPreparator ArchiveStrategy Transaction \
13-
Bulk Connector DataException Date Limit MetaColumn \
13+
Bulk Connector DataException Date DynamicLOB Limit MetaColumn \
1414
PooledSessionHolder PooledSessionImpl Position \
1515
Range RecordSet Row RowFilter RowFormatter RowIterator \
1616
SimpleRowFormatter Session SessionFactory SessionImpl \

‎Data/include/Poco/Data/Date.h‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ namespace Poco {
4949

5050
class DateTime;
5151

52+
namespace Dynamic {
53+
54+
class Var;
55+
56+
}
57+
5258
namespace Data {
5359

5460

@@ -84,9 +90,15 @@ class Data_API Date
8490
void assign(int year, int month, int day);
8591
/// Assigns date.
8692

93+
Date& operator = (const Date& d);
94+
/// Assignment operator for Date.
95+
8796
Date& operator = (const DateTime& dt);
8897
/// Assignment operator for DateTime.
8998

99+
Date& operator = (const Poco::Dynamic::Var& var);
100+
/// Assignment operator for Var.
101+
90102
bool operator == (const Date& date);
91103
/// Equality operator.
92104

@@ -127,6 +139,13 @@ inline int Date::day() const
127139
}
128140

129141

142+
inline Date& Date::operator = (const Date& d)
143+
{
144+
assign(d.year(), d.month(), d.day());
145+
return *this;
146+
}
147+
148+
130149
inline Date& Date::operator = (const DateTime& dt)
131150
{
132151
assign(dt.year(), dt.month(), dt.day());
@@ -158,7 +177,7 @@ inline bool Date::operator > (const Date& date)
158177

159178

160179
//
161-
// VarHolderImpl<BLOB>
180+
// VarHolderImpl<Date>
162181
//
163182

164183

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//
2+
// DynamicDateTime.h
3+
//
4+
// $Id: //poco/Main/Data/include/Poco/Data/DynamicDateTime.h#7 $
5+
//
6+
// Library: Data
7+
// Package: DataCore
8+
// Module: DynamicDateTime
9+
//
10+
// Definition of the Date and Time cast operators for Poco::Dynamic::Var.
11+
//
12+
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
13+
// and Contributors.
14+
//
15+
// Permission is hereby granted, free of charge, to any person or organization
16+
// obtaining a copy of the software and accompanying documentation covered by
17+
// this license (the "Software") to use, reproduce, display, distribute,
18+
// execute, and transmit the Software, and to prepare derivative works of the
19+
// Software, and to permit third-parties to whom the Software is furnished to
20+
// do so, all subject to the following:
21+
//
22+
// The copyright notices in the Software and this entire statement, including
23+
// the above license grant, this restriction and the following disclaimer,
24+
// must be included in all copies of the Software, in whole or in part, and
25+
// all derivative works of the Software, unless such copies or derivative
26+
// works are solely in the form of machine-executable object code generated by
27+
// a source language processor.
28+
//
29+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31+
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
32+
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33+
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
34+
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35+
// DEALINGS IN THE SOFTWARE.
36+
//
37+
38+
39+
#ifndef Data_DynamicDateTime_INCLUDED
40+
#define Data_DynamicDateTime_INCLUDED
41+
42+
43+
#include "Poco/Data/Data.h"
44+
#include "Poco/Dynamic/Var.h"
45+
46+
47+
namespace Poco {
48+
namespace Data {
49+
50+
class Date;
51+
class Time;
52+
53+
} } // namespace Poco::Data
54+
55+
56+
namespace Poco {
57+
namespace Dynamic {
58+
59+
60+
template <> Data_API Var::operator Poco::Data::Date () const;
61+
template <> Data_API Var::operator Poco::Data::Time () const;
62+
63+
64+
} } // namespace Poco::Dynamic
65+
66+
67+
#endif // Data_DynamicDateTime_INCLUDED
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//
2+
// DynamicLOB.h
3+
//
4+
// $Id: //poco/Main/Data/include/Poco/Data/DynamicLOB.h#12 $
5+
//
6+
// Library: Data
7+
// Package: DataCore
8+
// Module: DynamicLOB
9+
//
10+
// Definition of the Poco::Dynamic::Var LOB cast operators.
11+
//
12+
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
13+
// and Contributors.
14+
//
15+
// Permission is hereby granted, free of charge, to any person or organization
16+
// obtaining a copy of the software and accompanying documentation covered by
17+
// this license (the "Software") to use, reproduce, display, distribute,
18+
// execute, and transmit the Software, and to prepare derivative works of the
19+
// Software, and to permit third-parties to whom the Software is furnished to
20+
// do so, all subject to the following:
21+
//
22+
// The copyright notices in the Software and this entire statement, including
23+
// the above license grant, this restriction and the following disclaimer,
24+
// must be included in all copies of the Software, in whole or in part, and
25+
// all derivative works of the Software, unless such copies or derivative
26+
// works are solely in the form of machine-executable object code generated by
27+
// a source language processor.
28+
//
29+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31+
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
32+
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33+
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
34+
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35+
// DEALINGS IN THE SOFTWARE.
36+
//
37+
38+
39+
#ifndef Data_DynamicLOB_INCLUDED
40+
#define Data_DynamicLOB_INCLUDED
41+
42+
43+
#include "Poco/Data/Data.h"
44+
#include "Poco/Dynamic/Var.h"
45+
46+
47+
namespace Poco {
48+
namespace Data {
49+
50+
template <typename T> class LOB;
51+
typedef LOB<unsigned char> BLOB;
52+
typedef LOB<char> CLOB;
53+
54+
} } // namespace Poco::Data
55+
56+
57+
namespace Poco {
58+
namespace Dynamic {
59+
60+
template <> Data_API Var::operator Poco::Data::CLOB () const;
61+
template <> Data_API Var::operator Poco::Data::BLOB () const;
62+
63+
} } // namespace Poco::Dynamic
64+
65+
66+
#endif // Data_DynamicLOB_INCLUDED

‎Data/include/Poco/Data/Time.h‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@
4747

4848
namespace Poco {
4949

50+
namespace Dynamic {
51+
52+
class Var;
53+
54+
}
55+
5056
class DateTime;
5157

5258
namespace Data {
@@ -84,9 +90,15 @@ class Data_API Time
8490
void assign(int hour, int minute, int second);
8591
/// Assigns time.
8692

93+
Time& operator = (const Time& t);
94+
/// Assignment operator for Time.
95+
8796
Time& operator = (const DateTime& dt);
8897
/// Assignment operator for DateTime.
8998

99+
Time& operator = (const Poco::Dynamic::Var& var);
100+
/// Assignment operator for Var.
101+
90102
bool operator == (const Time& time);
91103
/// Equality operator.
92104

@@ -127,6 +139,13 @@ inline int Time::second() const
127139
}
128140

129141

142+
inline Time& Time::operator = (const Time& t)
143+
{
144+
assign(t.hour(), t.minute(), t.second());
145+
return *this;
146+
}
147+
148+
130149
inline Time& Time::operator = (const DateTime& dt)
131150
{
132151
assign(dt.hour(), dt.minute(), dt.second());
@@ -158,7 +177,7 @@ inline bool Time::operator > (const Time& time)
158177

159178

160179
//
161-
// VarHolderImpl<BLOB>
180+
// VarHolderImpl<Time>
162181
//
163182

164183

‎Data/src/Date.cpp‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@
3737
#include "Poco/Data/Date.h"
3838
#include "Poco/DateTime.h"
3939
#include "Poco/NumberFormatter.h"
40+
#include "Poco/Data/DynamicDateTime.h"
41+
#include "Poco/Dynamic/Var.h"
4042

4143

4244
using Poco::DateTime;
45+
using Poco::Dynamic::Var;
4346
using Poco::NumberFormatter;
4447

4548

@@ -109,4 +112,39 @@ bool Date::operator < (const Date& date)
109112
}
110113

111114

115+
Date& Date::operator = (const Var& var)
116+
{
117+
*this = var.operator Date(); // g++ workaround
118+
return *this;
119+
}
120+
121+
112122
} } // namespace Poco::Data
123+
124+
125+
namespace Poco {
126+
namespace Dynamic {
127+
128+
129+
using Poco::Data::Date;
130+
using Poco::DateTime;
131+
132+
133+
template <>
134+
Var::operator Date () const
135+
{
136+
if (!_pHolder)
137+
throw InvalidAccessException("Can not convert empty value.");
138+
139+
if (typeid(Date) == _pHolder->type())
140+
return extract<Date>();
141+
else
142+
{
143+
Poco::DateTime result;
144+
_pHolder->convert(result);
145+
return Date(result);
146+
}
147+
}
148+
149+
150+
} } // namespace Poco::Dynamic

0 commit comments

Comments
 (0)