Scopira 20080306

project.h

00001 
00002 /*
00003  *  Copyright (c) 2005    National Research Council
00004  *
00005  *  All rights reserved.
00006  *
00007  *  This material is confidential and proprietary information of
00008  *  National Research Council Canada ("Confidential Information").
00009  *  This Confidential Information may only be used and reproduced
00010  *  in accordance with the terms of the license agreement.
00011  *
00012  */
00013 
00014 #ifndef __INCLUDED_SCOPIRA_CORE_MODELGROUP_H__
00015 #define __INCLUDED_SCOPIRA_CORE_MODELGROUP_H__
00016 
00017 #include <map>
00018 
00019 #include <scopira/core/model.h>
00020 #include <scopira/tool/export.h>
00021 
00022 namespace scopira
00023 {
00024   namespace core
00025   {
00026     class project_i;
00027     class project_base;
00028   }
00029 }
00030 
00038 class scopira::core::project_i : public virtual scopira::core::model_i
00039 {
00040   public:
00042     typedef scopira::core::model_iterator model_iterator;
00043 
00044   public:
00046     virtual bool is_project(void) const { return true; }
00047 
00053     SCOPIRA_EXPORT virtual void add_model(model_i *parent, model_i *rec) = 0;
00059     SCOPIRA_EXPORT virtual void remove_model(model_i *parent, model_i *rec) = 0;
00065     SCOPIRA_EXPORT virtual bool contains_model(model_i *parent, model_i *rec) = 0;
00070     SCOPIRA_EXPORT virtual bool contains_model(model_i *rec) = 0;
00071 
00077     SCOPIRA_EXPORT virtual model_i * get_parent(model_i *child) = 0;
00078 
00079     // future functions
00080     // something about properties
00081     // named-models? (or is that what find_model is for?)
00082     // rename get_parent to get_parent_model
00083 
00091     SCOPIRA_EXPORT virtual model_i * find_model(model_i *parent, const std::string &title) const = 0;
00092 
00094     SCOPIRA_EXPORT virtual model_iterator get_model_iterator(model_i *parent) const = 0;
00095 
00101     SCOPIRA_EXPORT virtual bool is_project_empty(void) const = 0;
00102 
00108     SCOPIRA_EXPORT virtual void clear_project(void) = 0;
00109 
00115     SCOPIRA_EXPORT virtual void move_project(scopira::core::project_i *rhs) = 0;
00116 
00118     SCOPIRA_EXPORT virtual bool get_tagged_model_from_project(model_i *parent, const std::string &name,
00119       scopira::tool::count_ptr<scopira::core::model_i> &out) = 0;
00120 
00121   protected:
00123     SCOPIRA_EXPORT project_i(void);
00125     SCOPIRA_EXPORT project_i(const std::string &title);
00126 };
00127 
00135 class scopira::core::project_base : public virtual scopira::core::project_i
00136 {
00137   protected:
00138     // this is a MULTI map of parents->children
00139     typedef std::multimap< tool::count_ptr<core::model_i>, tool::count_ptr<core::model_i> > model_set_t;
00140     typedef std::pair<model_set_t::const_iterator, model_set_t::const_iterator> const_iterator_pair;
00141     typedef std::pair<model_set_t::iterator, model_set_t::iterator> iterator_pair;
00142 
00143     // this is a map of children, parent (reverse of the above)
00144     typedef std::map<core::model_i*, core::model_i*> child_map;
00145 
00146     // in the future, there will be a child->optional properties set
00147     // map here
00148 
00149     model_set_t dm_models;
00150     child_map dm_child;
00151 
00152   public:
00154     SCOPIRA_EXPORT project_base(void);
00156     SCOPIRA_EXPORT project_base(const std::string &title);
00157 
00159     SCOPIRA_EXPORT virtual ~project_base();
00160 
00161     SCOPIRA_EXPORT virtual bool load(tool::iobjflow_i& in);
00162     SCOPIRA_EXPORT virtual void save(tool::oobjflow_i& out) const;
00163 
00169     SCOPIRA_EXPORT virtual void add_model(model_i *parent, model_i *rec);
00175     SCOPIRA_EXPORT virtual void remove_model(model_i *parent, model_i *rec);
00181     SCOPIRA_EXPORT virtual bool contains_model(model_i *parent, model_i *rec);
00186     SCOPIRA_EXPORT virtual bool contains_model(model_i *rec);
00187 
00193     SCOPIRA_EXPORT virtual model_i * get_parent(model_i *child);
00194 
00202     SCOPIRA_EXPORT virtual model_i * find_model(model_i *parent, const std::string &title) const;
00203 
00205     SCOPIRA_EXPORT virtual model_iterator get_model_iterator(model_i *parent) const;
00206 
00207     SCOPIRA_EXPORT virtual bool is_project_empty(void) const;
00208     SCOPIRA_EXPORT virtual void clear_project(void);
00209     SCOPIRA_EXPORT virtual void move_project(scopira::core::project_i *rhs);
00210 
00212     SCOPIRA_EXPORT virtual bool get_tagged_model_from_project(model_i *parent, const std::string &name,
00213       scopira::tool::count_ptr<scopira::core::model_i> &out);
00214 
00215   private:
00219     void remove_by_range(model_set_t::iterator _begin, model_set_t::iterator _last);
00220 
00221     class project_iterator;
00222 };
00223 
00224 #endif
00225