00001 // -*- C++ -*- 00002 /***************************************************************************** 00003 * 00004 * |_|_|_ |_|_ |_ |_|_|_ |_ C O M M U N I C A T I O N 00005 * |_ |_ |_ |_ |_ |_ N E T W O R K S 00006 * |_ |_ |_ |_ |_ |_ C L A S S 00007 * |_|_|_ |_ |_|_ |_|_|_ |_|_|_|_ L I B R A R Y 00008 * 00009 * $Id: Class.h,v 1.2 2002/01/14 11:03:24 spee Exp $ 00010 * 00011 * CNClass: CNClass --- CNClass description class 00012 * 00013 ***************************************************************************** 00014 * Copyright (C) 1992-2002 Communication Networks 00015 * Aachen University of Technology 00016 * D-52056 Aachen 00017 * Germany 00018 * Email: cncl-adm@comnets.rwth-aachen.de 00019 ***************************************************************************** 00020 * This file is part of the CN class library. All files marked with 00021 * this header are free software; you can redistribute it and/or modify 00022 * it under the terms of the GNU Library General Public License as 00023 * published by the Free Software Foundation; either version 2 of the 00024 * License, or (at your option) any later version. This library is 00025 * distributed in the hope that it will be useful, but WITHOUT ANY 00026 * WARRANTY; without even the implied warranty of MERCHANTABILITY or 00027 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00028 * License for more details. You should have received a copy of the GNU 00029 * Library General Public License along with this library; if not, write 00030 * to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, 00031 * USA. 00032 *****************************************************************************/ 00033 00034 #ifndef __Class_h 00035 #define __Class_h 00036 00037 00038 #include <CNCL/Object.h> 00039 00040 00041 class CNClass; 00042 class CNParam; 00043 00044 00045 /* 00046 * Type description for class CNClass 00047 */ 00048 00049 extern CNClassDesc CN_CLASS; 00050 00051 00052 00053 /* 00054 * CNClass provides description of classes and creation of new objects 00055 * via exemplar objects. CNClass is used for the type description 00056 * objects. For each class in the CNCL hierarchy there is a 00057 * corresponding object of type CNClass. A pointer to this object is 00058 * used for the CNCL runtime type information. */ 00059 class CNClass : public CNObject 00060 { 00061 public: 00068 CNClass(char *new_name, char *new_version, 00069 CNObject *(*new_func)(CNParam *param)) 00070 : c_name(new_name), c_version(new_version), c_func(new_func) {} 00071 private: 00072 const char *c_name; // CNClass name 00073 const char *c_version; // CNClass version 00074 CNObject *(*c_func)(CNParam *param); // CLASS::new_object() function 00075 00076 public: 00077 00078 virtual CNClassDesc class_desc() const // CNClass description 00079 { return CN_CLASS; } 00080 00082 virtual bool is_a(CNClassDesc desc) const 00083 { return desc == CN_CLASS ? TRUE : CNObject::is_a(desc); } 00084 00085 00087 static CNClass *cast_from_object(CNObject *obj) 00088 { 00089 # ifdef NO_TYPE_CHECK 00090 return (CNClass *)obj; 00091 # else 00092 return (CNClass *)( !obj || obj->is_a(CN_CLASS) 00093 ? obj : fatal_type(obj->class_desc(), CN_CLASS) ); 00094 # endif 00095 } 00096 00097 00099 const char *name() const 00100 { 00101 return c_name; 00102 } 00104 const char *get_name() const 00105 { 00106 return c_name; 00107 } 00109 const char *version() const 00110 { 00111 return c_version; 00112 } 00114 const char *get_version() const 00115 { 00116 return c_version; 00117 } 00118 00123 CNObject *new_object(CNParam *param = NIL) const; 00128 CNObject *new_object(CNParam ¶m) const; 00129 00130 // Print/debug output 00131 virtual void print(ostream &strm = cout) const; 00132 virtual void dump (ostream &strm = cout) const; 00133 }; 00134 00135 00136 #endif
1.2.13.1 written by Dimitri van Heesch,
© 1997-2001