Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 41 lines (34 sloc) 1.549 kB
5ac444f @Whiteknight small, quick cleanups and modernizations for ObjectFactory
authored
1 /* A generic object factory type which serves as the basis for other
1a8ebdd @Whiteknight cleanup Core with nicer syntax
authored
2 factory types. A factory must provide a "create" method, which returns
3 an object of the type which the factory is responsible for. Also, the
4 factory should provide a "create_typed" method, to attempt creating
5ac444f @Whiteknight small, quick cleanups and modernizations for ObjectFactory
authored
5 an object of a different, albeit related, type (such as a subclass).
1a8ebdd @Whiteknight cleanup Core with nicer syntax
authored
6
5ac444f @Whiteknight small, quick cleanups and modernizations for ObjectFactory
authored
7 This is the base class for other factory-like classes in Rosella. This class
8 can be used directly as a generic factory type or it can be subclassed.
1a8ebdd @Whiteknight cleanup Core with nicer syntax
authored
9 */
10 class Rosella.ObjectFactory
c8f8bcd @Whiteknight Simplify ObjectFactory. Move it from container to core. Add in a .win…
authored
11 {
1a8ebdd @Whiteknight cleanup Core with nicer syntax
authored
12 var target_type;
a7c3645 @Whiteknight some cleanups and docs for the action library
authored
13
bd17c74 @Whiteknight [All] First pass, update all libraries to use the new optional parame…
authored
14 function ObjectFactory(var target_type = null)
c8f8bcd @Whiteknight Simplify ObjectFactory. Move it from container to core. Add in a .win…
authored
15 {
bd17c74 @Whiteknight [All] First pass, update all libraries to use the new optional parame…
authored
16 self.target_type = target_type;
1a8ebdd @Whiteknight cleanup Core with nicer syntax
authored
17 }
15ba11a @Whiteknight ObjectFactory can now take an optional type parameter in BUILD. MockO…
authored
18
1a8ebdd @Whiteknight cleanup Core with nicer syntax
authored
19 // If the default target type is set, call .create_typed with it.
20 // Otherwise, throw an error.
21 function create(var pos [slurpy], var named [slurpy,named])
22 {
23 if (self.target_type != null)
24 return self.create_typed(self.target_type, pos:[flat], named:[flat,named]);
1f6bbf6 @Whiteknight [Core] Use Rosella.Error.error to report errors in Core
authored
25 Rosella.Error.error("Cannot create an object without a type.\n" +
69bf85f @Whiteknight Fix typo in ObjectFactory. Alphabetize directories in t/harness
authored
26 "You must provide a type to create_typed or pass one to the " +
1a8ebdd @Whiteknight cleanup Core with nicer syntax
authored
27 "constructor for ObjectFactory"
28 );
29 }
5a6dc98 @Whiteknight refactor ObjectFactory to have create and create_typed methods. proxy…
authored
30
1a8ebdd @Whiteknight cleanup Core with nicer syntax
authored
31 // Create an object given a type and a list of parameters. The default
32 // behavior is to pass the given parameters to the object constructor.
33 // subclasses may do something different
34 function create_typed(var type, var pos [slurpy], var named [slurpy,named])
35 {
5ac444f @Whiteknight small, quick cleanups and modernizations for ObjectFactory
authored
36 return Rosella.construct(type, pos:[flat], named:[flat,named]);
c8f8bcd @Whiteknight Simplify ObjectFactory. Move it from container to core. Add in a .win…
authored
37 }
38 }
06310c4 @Whiteknight [Core] Update Rosella.Error.error to be more useful. Add a Rosella.Gl…
authored
39
40
Something went wrong with that request. Please try again.