Hello,

QxOrm is a new open source ORM (Object Relational Mapping) C++ library designed to provide :
* Persistence (based on QtSql Qt module)
* Serialization (xml and binary, based on boost::serialization)
* Reflection (invoke class methods and access to properties)

QxOrm has been tested on Windows (Visual C++ 2008 and 2010) and Linux (GCC 4.4.1).

QxOrm is based on a simple and non intrusive 'setting function' (that can be compared with Hibernate Xml Mapping file).

A quick sample (and a tutorial) is avaible on this web site (only in french, an english translation is in progress...) : http://www.qxorm.com

PS: Sorry for my poor english

________

Quick sample using QxOrm :

* 1- 'drug.h' file : drug class definition with 3 properties : 'id', 'name' and 'description'
* 2- 'drug.cpp' file : setting function 'void qx::register_class()'
* 3- 'main.cpp' file : using QxOrm with drug class
* 4- Execute test program and print log output
* 5- 'export_drugs.xml' file created by test program

* -----------------------------------------------------------------------------------------------------
* 1- 'drug.h' file : drug class definition with 3 properties : 'id', 'name' and 'description'
* -----------------------------------------------------------------------------------------------------
Qt Code:
  1. #ifndef _CLASS_DRUG_H_
  2. #define _CLASS_DRUG_H_
  3.  
  4. class drug
  5. {
  6. public:
  7. long id;
  8. QString name;
  9. QString description;
  10.  
  11. drug() : id(0) { ; }
  12. virtual ~drug() { ; }
  13. };
  14.  
  15. QX_REGISTER_HPP_MY_TEST_EXE(drug, qx::trait::no_base_class_defined, 1)
  16.  
  17. /* This macro is necessary to register 'drug' class in QxOrm context */
  18. /* param 1 : the current class to register => 'drug' */
  19. /* param 2 : the base class, if no base class, use the qx trait => 'qx::trait::no_base_class_defined' */
  20. /* param 3 : the class version used by serialization to provide 'ascendant compatibility' */
  21.  
  22. #endif // _CLASS_DRUG_H_
To copy to clipboard, switch view to plain text mode 

* -----------------------------------------------------------------------------------------------------
* 2- 'drug.cpp' file : setting function 'void qx::register_class()'
* -----------------------------------------------------------------------------------------------------
Qt Code:
  1. #include "precompiled.h" // Precompiled-header with '#include <QxOrm.h>' and '#include "export.h"'
  2. #include "drug.h" // Class definition 'drug'
  3. #include <QxMemLeak.h> // Automatic memory leak detection
  4.  
  5. QX_REGISTER_CPP_MY_TEST_EXE(drug) // This macro is necessary to register 'drug' class in QxOrm context
  6.  
  7. namespace qx {
  8. template <> void register_class(QxClass<drug> & t)
  9. {
  10. t.id(& drug::id, "id"); // Register 'drug::id' <=> primary key in your database
  11. t.data(& drug::name, "name", 1); // Register 'drug::name' property with key 'name' and version '1'
  12. t.data(& drug::description, "desc"); // Register 'drug::description' property with key 'desc'
  13. }}
To copy to clipboard, switch view to plain text mode 


* -----------------------------------------------------------------------------------------------------
* 3- 'main.cpp' file : using QxOrm with drug class
* -----------------------------------------------------------------------------------------------------
Qt Code:
  1. #include "precompiled.h"
  2. #include "drug.h"
  3. #include <QxMemLeak.h>
  4.  
  5. int main(int argc, char * argv[])
  6. {
  7. QApplication app(argc, argv); // Qt application
  8.  
  9. // Create 3 new drugs
  10. // It is possible to use 'boost' and 'Qt' smart pointer : 'boost::shared_ptr', 'QSharedPointer', etc...
  11. typedef boost::shared_ptr<drug> drug_ptr;
  12. drug_ptr d1; d1.reset(new drug()); d1->name = "name1"; d1->description = "desc1";
  13. drug_ptr d2; d2.reset(new drug()); d2->name = "name2"; d2->description = "desc2";
  14. drug_ptr d3; d3.reset(new drug()); d3->name = "name3"; d3->description = "desc3";
  15.  
  16. // Insert drugs into container
  17. // It is possible to use a lot of containers from 'std', 'boost', 'Qt' and 'qx::QxCollection<Key, Value>'
  18. typedef std::vector<drug_ptr> type_lst_drug;
  19. type_lst_drug lst_drug;
  20. lst_drug.push_back(d1);
  21. lst_drug.push_back(d2);
  22. lst_drug.push_back(d3);
  23.  
  24. // Init parameters to communicate with a database
  25. qx::QxSqlDatabase::getSingleton()->setDriverName("QSQLITE");
  26. qx::QxSqlDatabase::getSingleton()->setDatabaseName("./test_qxorm.db");
  27. qx::QxSqlDatabase::getSingleton()->setHostName("localhost");
  28. qx::QxSqlDatabase::getSingleton()->setUserName("root");
  29. qx::QxSqlDatabase::getSingleton()->setPassword("");
  30.  
  31. // Create table 'drug' into database to store drugs
  32. QSqlError daoError = qx::dao::create_table<drug>();
  33.  
  34. // Insert drugs from container to database
  35. // 'id' property of 'd1', 'd2' and 'd3' are auto-updated
  36. daoError = qx::dao::insert(lst_drug);
  37.  
  38. // Modify and update the second drug into database
  39. d2->name = "name2 modified";
  40. d2->description = "desc2 modified";
  41. daoError = qx::dao::update(d2);
  42.  
  43. // Delete the first drug from database
  44. daoError = qx::dao::delete_by_id(d1);
  45.  
  46. // Count drugs into database
  47. long lDrugCount = qx::dao::count<drug>();
  48.  
  49. // Fetch drug with id '3' into a new variable
  50. drug_ptr d_tmp; d_tmp.reset(new drug());
  51. d_tmp->id = 3;
  52. daoError = qx::dao::fetch_by_id(d_tmp);
  53.  
  54. // Export drugs from container to a file under xml format (serialization)
  55. qx::serialization::xml::to_file(lst_drug, "./export_drugs.xml");
  56.  
  57. // Import drugs from xml file into a new container
  58. type_lst_drug lst_drug_tmp;
  59. qx::serialization::xml::from_file(lst_drug_tmp, "./export_drugs.xml");
  60.  
  61. // Clone a drug
  62. drug_ptr d_clone = qx::clone(* d1);
  63.  
  64. // Create a new drug by class name (factory)
  65. boost::any d_any = qx::create("drug");
  66.  
  67. // Insert drugs container into 'qx::cache'
  68. qx::cache::set("drugs", lst_drug);
  69.  
  70. // Remove all elements from 'qx::cache'
  71. qx::cache::clear();
  72.  
  73. // Create a dummy memory leak
  74. drug * pDummy = new drug();
  75.  
  76. return 0;
  77. }
To copy to clipboard, switch view to plain text mode 

* -----------------------------------------------------------------------------------------------------
* 4- Execute test program and print log output
* -----------------------------------------------------------------------------------------------------
Qt Code:
  1. [QxOrm] qx::QxSqlDatabase : create new database connection in thread '3616' with key '{d315250c-b5c9-46e0-9402-f800368a6673}'
  2. [QxOrm] sql query (78 ms) : CREATE TABLE drug (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name TEXT, desc TEXT)
  3. [QxOrm] sql query (63 ms) : INSERT INTO drug (name, desc) VALUES (:name, :desc)
  4. [QxOrm] sql query (62 ms) : UPDATE drug SET id = :id, name = :name, desc = :desc WHERE id = :id_bis
  5. [QxOrm] sql query (63 ms) : DELETE FROM drug WHERE id = :id
  6. [QxOrm] sql query (0 ms) : SELECT COUNT(*) FROM drug
  7. [QxOrm] sql query (0 ms) : SELECT drug.id AS drug_id_0, drug.name AS drug_name_0, drug.desc AS drug_desc_0 FROM drug WHERE drug_id_0 = :id
  8. [QxOrm] Leaked object at 0xf52ad8 (size 16, src\main.cpp:74)
  9. [QxOrm] **** 1 memory leaks found ****
To copy to clipboard, switch view to plain text mode 

* -----------------------------------------------------------------------------------------------------
* 5- 'export_drugs.xml' file created by test program
* -----------------------------------------------------------------------------------------------------
Qt Code:
  1. <std.vector-boost.shared_ptr-drug-- class_id="0" tracking_level="0" version="0">
  2. <count>3</count>
  3. <item_version>1</item_version>
  4. <item class_id="1" tracking_level="0" version="1">
  5. <px class_id="2" tracking_level="1" version="1" object_id="_0">
  6. <id>1</id>
  7. <name class_id="3" tracking_level="0" version="0">name1</name>
  8. <desc>desc1</desc>
  9. </px>
  10. </item>
  11. <item>
  12. <px class_id_reference="2" object_id="_1">
  13. <id>2</id>
  14. <name>name2 modified</name>
  15. <desc>desc2 modified</desc>
  16. </px>
  17. </item>
  18. <item>
  19. <px class_id_reference="2" object_id="_2">
  20. <id>3</id>
  21. <name>name3</name>
  22. <desc>desc3</desc>
  23. </px>
  24. </item>
  25. </std.vector-boost.shared_ptr-drug-->
To copy to clipboard, switch view to plain text mode