Back to index

unity  6.0.0
Model.h
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright (C) 2011 Canonical Ltd
00004  *
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 3 as
00007  * published by the Free Software Foundation.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  *
00017  * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
00018  */
00019 
00020 #ifndef UNITY_MODEL_H
00021 #define UNITY_MODEL_H
00022 
00023 #include <boost/noncopyable.hpp>
00024 #include <dee.h>
00025 #include <memory>
00026 #include <NuxCore/Property.h>
00027 #include <sigc++/trackable.h>
00028 
00029 #include "GLibSignal.h"
00030 #include "GLibWrapper.h"
00031 #include "ModelRowAdaptor.h"
00032 
00033 namespace unity
00034 {
00035 namespace dash
00036 {
00037 
00038 enum ModelType
00039 {
00040   REMOTE,
00041   LOCAL
00042 };
00043 
00044 /* This template class encapsulates the basics of talking to a DeeSharedModel,
00045  * however it is a template as you can choose your own RowAdaptor (see
00046  * ResultsRowAdaptor.h for an example) which then presents the data in the rows
00047  * in a instance-specific way.
00048  */
00049 template<class RowAdaptor>
00050 class Model : public sigc::trackable, boost::noncopyable
00051 {
00052 public:
00053   typedef std::shared_ptr<Model> Ptr;
00054 
00055   Model();
00056   Model (ModelType model_type);
00057   virtual ~Model();
00058 
00059   const RowAdaptor RowAtIndex(std::size_t index);
00060 
00061   nux::Property<std::string> swarm_name;
00062   nux::ROProperty<std::size_t> count;
00063   nux::ROProperty<unsigned long long> seqnum;
00064   nux::ROProperty<glib::Object<DeeModel>> model;
00065 
00066   sigc::signal<void, RowAdaptor&> row_added;
00067   sigc::signal<void, RowAdaptor&> row_changed;
00068   sigc::signal<void, RowAdaptor&> row_removed;
00069 
00070   sigc::signal<void, unsigned long long, unsigned long long> begin_transaction;
00071   sigc::signal<void, unsigned long long, unsigned long long> end_transaction;
00072 
00073 private:
00074   void Init();
00075   void OnRowAdded(DeeModel* model, DeeModelIter* iter);
00076   void OnRowChanged(DeeModel* model, DeeModelIter* iter);
00077   void OnRowRemoved(DeeModel* model, DeeModelIter* iter);
00078   void OnTransactionBegin(DeeModel* model, guint64 begin_seq, guint64 end_seq);
00079   void OnTransactionEnd(DeeModel* model, guint64 begin_seq, guint64 end_seq);
00080   void OnSwarmNameChanged(std::string const& swarm_name);
00081   std::size_t get_count();
00082   unsigned long long get_seqnum();
00083   glib::Object<DeeModel> get_model();
00084 
00085 private:
00086   glib::Object<DeeModel> model_;
00087   glib::SignalManager sig_manager_;
00088   DeeModelTag* renderer_tag_;
00089   ModelType model_type_;
00090 };
00091 
00092 }
00093 }
00094 
00095 #include "Model-inl.h"
00096 
00097 #endif