Panda3D

internalName.h

00001 // Filename: internalName.h
00002 // Created by:  drose (15Jul04)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef INTERNALNAME_H
00016 #define INTERNALNAME_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "typedWritableReferenceCount.h"
00021 #include "pointerTo.h"
00022 #include "pmap.h"
00023 #include "lightMutex.h"
00024 
00025 class FactoryParams;
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //       Class : InternalName
00029 // Description : Encodes a string name in a hash table, mapping it to
00030 //               a pointer.  This is used to tokenify names so they
00031 //               may be used efficiently in low-level Panda
00032 //               structures, for instance to differentiate the
00033 //               multiple sets of texture coordinates that might be
00034 //               stored on a Geom.
00035 //
00036 //               InternalNames are hierarchical, with the '.' used by
00037 //               convention as a separator character.  You can
00038 //               construct a single InternalName as a composition of
00039 //               one or more other names, or by giving it a source
00040 //               string directly.
00041 ////////////////////////////////////////////////////////////////////
00042 class EXPCL_PANDA_GOBJ InternalName : public TypedWritableReferenceCount {
00043 private:
00044   InternalName(InternalName *parent, const string &basename);
00045 
00046 PUBLISHED:
00047   virtual ~InternalName();
00048   virtual bool unref() const;
00049 
00050   INLINE static PT(InternalName) make(const string &name);
00051   static PT(InternalName) make(const string &name, int index);
00052   PT(InternalName) append(const string &basename);
00053 
00054   INLINE InternalName *get_parent() const;
00055   string get_name() const;
00056   INLINE const string &get_basename() const;
00057 
00058   int find_ancestor(const string &basename) const;
00059   const InternalName *get_ancestor(int n) const;
00060   const InternalName *get_top() const;
00061   string get_net_basename(int n) const;
00062 
00063   void output(ostream &out) const;
00064 
00065   // Some predefined built-in names.
00066   INLINE static PT(InternalName) get_root();
00067   INLINE static PT(InternalName) get_error();
00068   INLINE static PT(InternalName) get_vertex();
00069   INLINE static PT(InternalName) get_normal();
00070   INLINE static PT(InternalName) get_tangent();
00071   INLINE static PT(InternalName) get_tangent_name(const string &name);
00072   INLINE static PT(InternalName) get_binormal();
00073   INLINE static PT(InternalName) get_binormal_name(const string &name);
00074   INLINE static PT(InternalName) get_texcoord();
00075   INLINE static PT(InternalName) get_texcoord_name(const string &name);
00076   INLINE static PT(InternalName) get_color();
00077   INLINE static PT(InternalName) get_rotate();
00078   INLINE static PT(InternalName) get_size();
00079   INLINE static PT(InternalName) get_aspect_ratio();
00080   INLINE static PT(InternalName) get_transform_blend();
00081   INLINE static PT(InternalName) get_transform_weight();
00082   INLINE static PT(InternalName) get_transform_index();
00083   INLINE static PT(InternalName) get_morph(InternalName *column, const string &slider);
00084   INLINE static PT(InternalName) get_index();
00085   INLINE static PT(InternalName) get_world();
00086   INLINE static PT(InternalName) get_camera();
00087   INLINE static PT(InternalName) get_model();
00088   INLINE static PT(InternalName) get_view();
00089 
00090 private:
00091   PT(InternalName) _parent;
00092   string _basename;
00093 
00094   typedef phash_map<string, InternalName *, string_hash> NameTable;
00095   NameTable _name_table;
00096   LightMutex _name_table_lock;
00097 
00098   static PT(InternalName) _root;
00099   static PT(InternalName) _error;
00100   static PT(InternalName) _default;
00101   static PT(InternalName) _vertex;
00102   static PT(InternalName) _normal;
00103   static PT(InternalName) _tangent;
00104   static PT(InternalName) _binormal;
00105   static PT(InternalName) _texcoord;
00106   static PT(InternalName) _color;
00107   static PT(InternalName) _rotate;
00108   static PT(InternalName) _size;
00109   static PT(InternalName) _aspect_ratio;
00110   static PT(InternalName) _transform_blend;
00111   static PT(InternalName) _transform_weight;
00112   static PT(InternalName) _transform_index;
00113   static PT(InternalName) _index;
00114   static PT(InternalName) _world;
00115   static PT(InternalName) _camera;
00116   static PT(InternalName) _model;
00117   static PT(InternalName) _view;
00118   
00119 public:
00120   // Datagram stuff
00121   static void register_with_read_factory();
00122   virtual void write_datagram(BamWriter *manager, Datagram &me);
00123 
00124   virtual void finalize(BamReader *manager);
00125 
00126 protected:
00127   static TypedWritable *make_from_bam(const FactoryParams &params);
00128   static TypedWritable *make_texcoord_from_bam(const FactoryParams &params);
00129 
00130 public:
00131   static TypeHandle get_class_type() {
00132     return _type_handle;
00133   }
00134   static void init_type() {
00135     TypedWritableReferenceCount::init_type();
00136     register_type(_type_handle, "InternalName",
00137                   TypedWritableReferenceCount::get_class_type());
00138     // The _texcoord_type_handle is defined only to support older bam
00139     // files, generated before we renamed the type to InternalName.
00140     register_type(_texcoord_type_handle, "TexCoordName",
00141                   TypedWritableReferenceCount::get_class_type());
00142   }
00143   virtual TypeHandle get_type() const {
00144     return get_class_type();
00145   }
00146   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00147 
00148 private:
00149   static TypeHandle _type_handle;
00150   static TypeHandle _texcoord_type_handle;
00151 };
00152 
00153 INLINE ostream &operator << (ostream &out, const InternalName &tcn);
00154 
00155 #include "internalName.I"
00156 
00157 #endif
00158 
00159 
00160   
 All Classes Functions Variables Enumerations