Changeset 99
- Timestamp:
- 11/08/06 13:56:05 (6 years ago)
- Files:
-
- trunk/freeuniverse/arc/io/serialization/basicarchive.d (modified) (4 diffs)
- trunk/freeuniverse/init/init.d (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/freeuniverse/arc/io/serialization/basicarchive.d
r59 r99 77 77 static if (is(POINTERTYPE == class)) 78 78 { 79 pragma(msg, "Error: class pointers are not supported and should also be unneccessary."); 80 pragma(error, "See the above msg."); 79 static assert(0, "class pointers are not supported and should also be unneccessary"); 81 80 } 82 81 else … … 99 98 else 100 99 { 101 pragma(msg, "Error: describe called with unsupported type."); 102 pragma(error, "See the above msg."); 100 static assert(0, "describe called with unsupported type"); 103 101 } 104 102 } … … 123 121 if (write_or_read == WriteRead.Write) 124 122 { 125 // if we haven't encountered the class yet, it's an error 126 if(!(T.classinfo in class_register.by_classinfo)) 127 throw new Exception("Class " ~ T.classinfo.name ~ " must be registered to be written."); 123 // check if x's type is registered 124 if(!(x.classinfo in class_register.by_classinfo)) 125 { 126 // if T is default constructible, not registering isn't an error 127 static if( is(typeof(new T)) ) 128 { 129 // if we're not serializing through a base pointer, register! 130 if(T.classinfo is x.classinfo) 131 registerClass!(T)(); 132 else 133 throw new Exception("Trying to write unregistered class " ~ x.classinfo.name ~ 134 " through class reference of type " ~ T.classinfo.name ~ ".\nYou need to register the former ahead of time."); 135 } 136 else // otherwise, it is! 137 { 138 throw new Exception("Trying to write unregistered class " ~ x.classinfo.name ~ 139 "\nIt is not default-constructible, so you need to register it ahead of time."); 140 } 141 } 128 142 129 143 char[] name = class_register.by_classinfo[x.classinfo].name; … … 145 159 //FIXME: If throwing Exception, archive should be in ok state! 146 160 //file.position(position); 147 throw new Exception("Class must be registered to be read:\nThe name " ~ name ~ " is not known."); 161 162 // if the name is the mangle of the class reference type we're serializing through 163 // it is ok to just default-register the class 164 if(name == T.mangleof) 165 { 166 static if( is(typeof(new T)) ) 167 registerClass!(T)(); 168 else 169 throw new Exception("Trying to read unregistered class - probably " ~ T.classinfo.name ~ 170 " - through a class reference of that type.\nBut " ~ T.classinfo.name ~ 171 " is not default-constructible, so you need to register it ahead of time."); 172 } 173 else 174 { 175 throw new Exception("Trying to read class that has been written with the " ~ name ~ " tag " ~ 176 "through a class reference of type " ~ T.classinfo.name ~ "." ~ 177 "\nThe tag is unknown, you need to register this tag ahead of time."); 178 } 148 179 } 149 180 trunk/freeuniverse/init/init.d
r89 r99 686 686 gameTime = new Time(); 687 687 688 InitSerialization();689 690 688 GameObjects.init(); 691 689 //SpaceObjects = new dlinkedlist!(FU_OBJECT); … … 716 714 arc.io.window.close(); 717 715 } 718 719 void InitSerialization()720 {721 Serializer.registerClass!(FU_OBJECT)();722 Serializer.registerClass!(FU_SHIP)();723 Serializer.registerClass!(FU_ITEM)();724 Serializer.registerClass!(FU_ITEMVARS)();725 Serializer.registerClass!(FU_JOB)();726 Serializer.registerClass!(FU_OBJECTIVE)();727 Serializer.registerClass!(dlinkedlist!(FU_ITEM))();728 Serializer.registerClass!(dlinkedlist!(FU_SHIP))();729 Serializer.registerClass!(dlinkedlist!(FU_OBJECT))();730 Serializer.registerClass!(dlinkedlist!(FU_JOB))();731 Serializer.registerClass!(FU_DOCKINFO)();732 }
