Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

constantpool.hpp

00001 /*
00002  * Copyright (c) 2003, Raymond Bosman
00003  * Copyright (c) 2003, Frederik Holljen
00004  * All Rights Reserved.
00005  *
00006  * See COPYING for licensing.
00007  */
00008 
00009 
00010 #ifndef CONSTANTPOOL_HPP
00011 #define CONSTANTPOOL_HPP
00012 
00013 #include <string>
00014 #include <fstream>
00015 #include <vector>
00016 
00017 #include "defs.hpp"
00018 #include "classwriterbase.hpp"
00019 
00020 namespace ClassEncoder
00021 {
00022 class cp_info;
00023 
00025 
00030 class ConstantPool
00031 {
00032 public:
00033     ConstantPool();
00034     ~ConstantPool();
00035 
00037     unsigned int count() const { return ConstantPoolCount; }
00038     unsigned int add( cp_info *entry );
00039     void write( std::ofstream &stream ) const;
00040 
00041 private:
00042     std::vector<cp_info*> Entries;
00043     unsigned int ConstantPoolCount;
00044 };
00045 
00047 
00050 class cp_info : public ClassWriterBase
00051 {
00052 public:
00054     virtual ~cp_info() {}
00055     virtual void write( std::ofstream &stream ) const;
00056 
00057 protected:
00059     cp_info() {}
00060 
00061 protected:
00062     u1 tag;
00063 };
00064 
00066 
00069 class Class_info : public cp_info
00070 {
00071 public:
00073 
00076     Class_info( u2 index ) { name_index = index; tag = CONSTANT_Class;}
00078     virtual ~Class_info() {}
00079     virtual void write( std::ofstream &stream ) const;
00080 
00081 private:
00082     u2 name_index;
00083 };
00084 
00086 
00089 class Methodref_info : public cp_info
00090 {
00091 public:
00093 
00097     Methodref_info( u2 classi, u2 nameati )
00098         { class_index = classi; name_and_type_index = nameati; tag = CONSTANT_Methodref; }
00100     virtual ~Methodref_info() {}
00101     virtual void write( std::ofstream &stream ) const;
00102 
00103 private:
00104     u2 class_index;
00105     u2 name_and_type_index;
00106 };
00107 
00109 
00112 class InterfaceMethodref_info : public cp_info
00113 {
00114 public:
00116 
00120     InterfaceMethodref_info( u2 classi, u2 nameati )
00121         { class_index = classi; name_and_type_index = nameati; tag = CONSTANT_InterfaceMethodref; }
00123     virtual ~InterfaceMethodref_info() {}
00124     virtual void write( std::ofstream &stream ) const;
00125 
00126 private:
00127     u2 class_index;
00128     u2 name_and_type_index;
00129 };
00130 
00132 
00135 class Fieldref_info : public cp_info
00136 {
00137 public:
00139 
00143     Fieldref_info( u2 classi, u2 nameati )
00144         { class_index = classi; name_and_type_index = nameati; tag = CONSTANT_Fieldref; }
00146     virtual ~Fieldref_info() {}
00147     virtual void write( std::ofstream &stream ) const;
00148 
00149 private:
00150     u2 class_index;
00151     u2 name_and_type_index;
00152 };
00153 
00154 
00156 
00159 class NameAndType_info : public cp_info
00160 {
00161 public:
00163 
00167     NameAndType_info( u2 namei, u2 desci)
00168         { name_index = namei; descriptor_index = desci; tag = CONSTANT_NameAndType; }
00170     virtual ~NameAndType_info() {}
00171     virtual void write( std::ofstream &stream ) const;
00172 
00173 private:
00174     u2 name_index; // method name (utf8)
00175     u2 descriptor_index; // method parameters (utf8)
00176 };
00177 
00178 
00180 
00183 class String_info : public cp_info
00184 {
00185 public:
00186     String_info() { tag = CONSTANT_String; }
00188     virtual ~String_info() {}
00189     virtual void write( std::ofstream &stream ) const;
00190 
00191 private:
00192     u2 string_index;
00193 };
00194 
00196 
00199 class Integer_info : public cp_info
00200 {
00201 public:
00202     Integer_info() { tag = CONSTANT_Integer; }
00204     virtual ~Integer_info() {}
00205     virtual void write( std::ofstream &stream ) const;
00206 
00207 private:
00208     u4 bytes;
00209 };
00210 
00212 
00215 class Float_info : public cp_info
00216 {
00217 public:
00218     Float_info() { tag = CONSTANT_Float; }
00220     virtual ~Float_info() {}
00221     virtual void write( std::ofstream &stream ) const;
00222 
00223 private:
00224     u4 bytes;
00225 };
00226 
00228 
00231 class Long_info : public cp_info
00232 {
00233 public:
00234     Long_info() { tag = CONSTANT_Long; }
00236     virtual ~Long_info() {}
00237     virtual void write( std::ofstream &stream ) const;
00238 
00239 private:
00240     u4 high_bytes;
00241     u4 low_bytes;
00242 };
00243 
00245 
00248 class Double_info : public cp_info
00249 {
00250 public:
00251     Double_info() { tag = CONSTANT_Double; }
00253     virtual ~Double_info() {}
00254     virtual void write( std::ofstream &stream ) const;
00255 
00256 private:
00257     u4 high_bytes;
00258     u4 low_bytes;
00259 };
00260 
00262 
00265 class Utf8_info : public cp_info
00266 {
00267 public:
00269 
00272     Utf8_info( const std::string &data ) { bytes = data; length = bytes.length(); tag = CONSTANT_Utf8; }
00274     virtual ~Utf8_info() {}
00275     virtual void write( std::ofstream &stream ) const;
00276 
00277 private:
00278     u2 length;
00279     std::string bytes; // encode with u1
00280 };
00281 
00282 } // end namespace
00283 #endif // CONSTANTPOOL_HPP

Generated on Mon Dec 1 14:26:27 2003 for Ck by doxygen 1.3.3