product.h

Go to the documentation of this file.
00001 // OSB library ********************************************* -*- C++ -*-
00015 /*
00016   AUTHOR(S): Stephan Broennimann (vb)
00017 
00018   RCS information
00019    $Name: OSB_060808 $
00020    $Revision: 1.157 $
00021 
00022   License
00023    OSB rating and billing library for communication networks
00024    Copyright (C) 2004, 2005, 2006  OSB systems
00025 
00026    This file may be distributed and/or modify under the terms of the
00027    GNU General Public License (GPL) as published by the Free Software
00028    Foundation which is provided in the file LICENSE.GPL included in the
00029    packaging of this file.
00030 
00031    The file is distributed in the hope that it will be useful, but WITHOUT
00032    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00033    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00034    for more details.
00035 
00036    Holders of a OSB Commercial License may use this file under the terms
00037    and conditions of this commercial license.
00038  */
00039 #ifndef _PRODUCT_H_
00040 #define _PRODUCT_H_
00041 
00042 // *********************************************************************
00043 // included header files
00044 // + standard includes
00045 #include <iosfwd>
00046 #include <list>
00047 #include <vector>
00048 #include <map>
00049 #include <string>
00050 #include <memory>
00051 
00052 // + local headers
00053 #include "osberror.h"
00054 #include "osbid.h"
00055 #include "osbtype.h"
00056 #include "osbutils.h"
00057 
00058 // + class declarations
00059 namespace OSB_DB {
00060     class Session;
00061     class ProductGw;
00062 }
00063 
00064 namespace OSB_LIB {
00065     class ProductItemBase;              // productitem.h
00066     class ProductItem;                  // productitem.h
00067     class ProductCatalogue;             // productcat.h
00068     class Pricelist;                    // pricelist.h
00069 }
00070 
00071 // *********************************************************************
00072 // namespace extensions
00073 namespace OSB_LIB {
00074 
00075 // *********************************************************************
00076 // class definitions
00077 
00078     // *****************************************************************
00079     // class ProductNode
00080     class ProductNode;
00082     typedef std::list<ProductNode> ProductNodeParts;
00083 
00088     // ToDo: - A tree iterator is missing.
00089     //       - For the member `mandatory_', meaningful constants should
00090     //         be provided.
00091 
00092     class ProductNode {
00093     private:
00095         friend class Product;
00101         friend class OSB_DB::ProductGw;
00102 
00103     public:
00110         typedef Id<ProductNode> Oid;
00111 
00113 
00114 
00121         ProductNode(
00122             const Oid&                       id,
00123                   std::auto_ptr<ProductItem> item,
00124             const EditStatus&                es =
00125                     EditStatus(EditStatus::esCreated)
00126         );
00127 
00133         ProductNode(const ProductNode& node);
00134         ProductNode& operator=(const ProductNode& rhs);
00135 
00141         ~ProductNode();
00143 
00147         const Oid& oid() const;
00149         const Oid& parentId() const;
00151         int mandatory() const;
00153         const ProductItem* pItem() const;
00155         ProductItem* pItem();
00157         const ProductNodeParts& parts() const;
00159         ProductNodeParts& parts();
00161         EditStatus::Status editStatus() const;
00163 
00167         void setParentId(const ProductNode::Oid& parentId);
00169         void setMandatory(const int& man);
00171 
00173         std::ostream& prInfo(
00174                   std::ostream& o,
00175                   bool          printParts = false,
00176             const std::string&  indent = ""
00177         ) const;
00178 
00179     private:
00181         bool setDelete();
00182 
00183     private:
00184         Oid              oid_;          
00185         Oid              parentId_;     
00186         int              mandatory_;    
00187         ProductItem*     pItem_;        
00188         ProductNodeParts parts_;        
00189 
00196         EditStatus       editStatus_;
00197     };
00198 
00199     // *****************************************************************
00200     // class Product
00204     class Product {
00205         friend class OSB_DB::ProductGw;
00206         friend class ProductCatalogue;
00207         friend std::ostream& operator<<(std::ostream&, const Product&);
00208     public:
00210         typedef Id<Product> Oid;
00211 
00217         Product(
00218             const Oid&         oid,
00219             const std::string& name = "",
00220             const std::string& des  = ""
00221         );
00222 
00224 
00225 
00226         const Oid& oid() const;
00228         const std::string& name() const;
00230         const std::string& desc() const;
00239         const Id<Pricelist> getPricelistId() const;
00241         const ProductNodeParts& parts() const;
00243         ProductNodeParts& parts();
00245 
00247 
00248 
00249         void setName(std::string& name);
00251         void setDesc(std::string& desc);
00253 
00254     private:
00256         bool read(const OSB_DB::Session& session);
00257 
00259 
00260 
00261         long nextTempNodeId();
00262 
00264         void creProductNode(
00265             const OSB_DB::Session& session,
00266                   ProductNode&     node
00267         );
00268 
00278         void delProductNode(
00279             const OSB_DB::Session& session,
00280                   ProductNode&     node
00281         );
00282 
00284         void delNodeChildren(
00285             const OSB_DB::Session& session,
00286                   ProductNode&     parent
00287         );
00288 
00290         void saveItem(
00291             const OSB_DB::Session& session,
00292                   ProductItem*     item
00293         );
00294 
00307         bool saveNode(
00308             const OSB_DB::Session& session,
00309                   ProductNode&     node
00310         );
00311 
00313         void saveNodes(
00314             const OSB_DB::Session& session
00315         );
00316 
00318         void saveNodes(
00319             const OSB_DB::Session&  session,
00320                   ProductNodeParts& parts
00321         );
00323 
00342         int buildNodeTree(
00343             const ProductNodeParts&      nodes,
00344                   std::vector<OsbError>& errors
00345         );
00346 
00348         int buildNodeTree(
00349             const ProductNode::Oid&      parentId,
00350                   ProductNodeParts&      parts,
00351                   ProductNodeParts&      tmpList,
00352                   std::vector<OsbError>& errors,
00353                   int                    numErrors
00354         );
00356 
00358         void objVsPlus();
00359 
00365         void delNode(ProductNode& node);
00366 
00372         ProductNode* productNode(
00373             const ProductNode::Oid& nodeId,
00374                   ProductNodeParts& parts
00375         );
00376 
00377     public:
00379 
00380 
00394         ProductNode& addNode(
00395             const ProductNode::Oid&          parentId,
00396                   std::auto_ptr<ProductItem> item
00397         );
00398 
00406         void delNode(const ProductNode::Oid& nodeId);
00407 
00409         const ProductNode* findProductNode(
00410             const ProductNode::Oid& nodeId
00411         ) const;
00412 
00414         ProductNode* productNode(const ProductNode::Oid& nodeId);
00415 
00417         const ProductNode& getProductNode(
00418             const ProductNode::Oid& nodeId
00419         ) const;
00420 
00427         void sortNodeByName(bool desc = false);
00428 
00436         void sortNodeByName(
00437             ProductNodeParts& parts,
00438             bool              desc = false
00439         );
00441 
00442     private:
00443         Oid              oid_;          
00444         std::string      name_;         
00445         std::string      des_;          
00446         ProductNodeParts parts_;        
00447         long             objVs_;        
00448         long             tempNodeId_;   
00449     };
00450 
00452     typedef std::list<Product> Products;
00453 }                                       // namespace OSB_LIB
00454 #endif                                  // #ifndef _PRODUCT_H_
00455 

Generated on Sat Sep 2 14:06:34 2006 for OSB Library by  doxygen 1.4.7