Update of /cvsroot/objecthandler/ObjectHandler/Examples/C++
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv29781/Examples/C++
Modified Files:
account.cpp account.hpp example.cpp
Log Message:
cleaner processing for object references
Index: example.cpp
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/Examples/C++/example.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** example.cpp 25 May 2006 17:01:56 -0000 1.3
--- example.cpp 9 Jun 2006 18:58:27 -0000 1.4
***************
*** 29,32 ****
--- 29,34 ----
#include <exception>
+ ObjHandler::ObjectHandler oh;
+
int main() {
try {
***************
*** 46,50 ****
try {
// construct some objects and store them in the object handler
! ObjHandler::obj_ptr accountObject1(new AccountObject(
123456789,
"savings"));
--- 48,52 ----
try {
// construct some objects and store them in the object handler
! boost::shared_ptr < ObjHandler::Object > accountObject1(new AccountObject(
123456789,
"savings"));
***************
*** 52,58 ****
boost::shared_ptr<ObjHandler::ValueObject>(new AccountValueObject(
"account1", 123456789, "savings")));
! ObjHandler::storeObject("account1", accountObject1);
! ObjHandler::obj_ptr accountObject2(new AccountObject(
987654321,
"current"));
--- 54,60 ----
boost::shared_ptr<ObjHandler::ValueObject>(new AccountValueObject(
"account1", 123456789, "savings")));
! ObjHandler::ObjectHandler::instance().storeObject("account1", accountObject1);
! boost::shared_ptr < ObjHandler::Object > accountObject2(new AccountObject(
987654321,
"current"));
***************
*** 60,64 ****
boost::shared_ptr<ObjHandler::ValueObject>(new AccountValueObject(
"account2", 987654321, "current")));
! ObjHandler::storeObject("account2", accountObject2);
// high level interrogation
--- 62,66 ----
boost::shared_ptr<ObjHandler::ValueObject>(new AccountValueObject(
"account2", 987654321, "current")));
! ObjHandler::ObjectHandler::instance().storeObject("account2", accountObject2);
// high level interrogation
***************
*** 67,77 ****
// retrieve an object and update it
! OH_GET_OBJECT(accountObject2_retrieve, "account2", AccountObject)
accountObject2_retrieve->setBalance(100);
// low-level interrogation
ObjHandler::logMessage("low-level interrogation - after update");
! OH_GET_REFERENCE(accountObjectUnderlying, "account2",
! AccountObject, Account);
std::ostringstream msg;
msg << "result of getBalance on underlying = " << accountObjectUnderlying->getBalance();
--- 69,78 ----
// retrieve an object and update it
! OH_GET_OBJECT( accountObject2_retrieve, "account2", AccountObject )
accountObject2_retrieve->setBalance(100);
// low-level interrogation
ObjHandler::logMessage("low-level interrogation - after update");
! OH_GET_REFERENCE( accountObjectUnderlying, "account2", AccountObject, Account ) \
std::ostringstream msg;
msg << "result of getBalance on underlying = " << accountObjectUnderlying->getBalance();
Index: account.hpp
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/Examples/C++/account.hpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** account.hpp 19 May 2006 15:12:41 -0000 1.1
--- account.hpp 9 Jun 2006 18:58:27 -0000 1.2
***************
*** 20,30 ****
#include <oh/objhandler.hpp>
- #include <oh/valueobject.hpp>
class Account {
public:
Account(const int &accountNumber,
! const std::string &accountType,
! const int &balance = 0)
: accountNumber_(accountNumber), accountType_(accountType), balance_(balance) {}
void setBalance(const int &balance) {
--- 20,29 ----
#include <oh/objhandler.hpp>
class Account {
public:
Account(const int &accountNumber,
! const std::string &accountType,
! const int &balance = 0)
: accountNumber_(accountNumber), accountType_(accountType), balance_(balance) {}
void setBalance(const int &balance) {
***************
*** 40,52 ****
};
! class AccountObject : public ObjHandler::Object {
public:
! AccountObject(const int &accountNumber,
! const std::string &accountType);
void setBalance(const int &balance);
const int &getBalance();
- virtual boost::shared_ptr<void> getReference() const;
- private:
- boost::shared_ptr<Account> account_;
};
--- 39,49 ----
};
! class AccountObject : public ObjHandler::LibraryObject<Account> {
public:
! AccountObject(
! const int &accountNumber,
! const std::string &accountType);
void setBalance(const int &balance);
const int &getBalance();
};
Index: account.cpp
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/Examples/C++/account.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** account.cpp 19 May 2006 15:12:41 -0000 1.1
--- account.cpp 9 Jun 2006 18:58:27 -0000 1.2
***************
*** 21,39 ****
AccountObject::AccountObject(
! const int &accountNumber,
! const std::string &accountType) {
! account_ = boost::shared_ptr<Account>(new Account(accountNumber, accountType));
}
void AccountObject::setBalance(const int &balance) {
! account_->setBalance(balance);
}
const int &AccountObject::getBalance() {
! return account_->getBalance();
! }
!
! boost::shared_ptr<void> AccountObject::getReference() const {
! return boost::static_pointer_cast<void>(account_);
}
--- 21,35 ----
AccountObject::AccountObject(
! const int &accountNumber,
! const std::string &accountType) {
! libraryObject_ = boost::shared_ptr<Account>(new Account(accountNumber, accountType));
}
void AccountObject::setBalance(const int &balance) {
! libraryObject_->setBalance(balance);
}
const int &AccountObject::getBalance() {
! return libraryObject_->getBalance();
}
***************
*** 44,56 ****
std::vector<std::string> AccountValueObject::getPropertyNames() const {
- #ifdef OBJHANDLER_PATCH_MSVC6
- std::vector<std::string> ret;
- const int max = sizeof(mPropertyNames)/sizeof(const char*);
- for (int i=0; i<max; i++) ret.push_back(mPropertyNames[i]);
- return ret;
- #else
return std::vector<std::string>(
mPropertyNames, mPropertyNames + sizeof(mPropertyNames)/sizeof(const char*));
- #endif
}
--- 40,45 ----
|