Skip to content

Commit

Permalink
Merge pull request #3099 from joshmoore/dsl-units
Browse files Browse the repository at this point in the history
DB 5.1__DEV11: unit support for time
  • Loading branch information
sbesson committed Oct 28, 2014
2 parents cd125c1 + e0891b1 commit a746e72
Show file tree
Hide file tree
Showing 41 changed files with 1,422 additions and 159 deletions.
2 changes: 1 addition & 1 deletion components/blitz/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<attribute name="todir"/>
<element name="filesetAndMapper" implicit="true"/>
<sequential>
<copy todir="@{todir}">
<copy todir="@{todir}" encoding="utf-8" outputencoding="utf-8">
<filesetAndMapper/>
<filterchain>
<linecontainsregexp>
Expand Down
66 changes: 66 additions & 0 deletions components/blitz/resources/omero/model/Time.ice
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (C) 2014 University of Dundee & Open Microscopy Environment.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef CLASS_TIME
#define CLASS_TIME

#include <omero/model/UnitsTime.ice>

module omero {

module model {

/**
* Unit of time which is used through the model. This is not
* an [omero::model::IObject] implementation and as such does
* not have an ID value. Instead, the entire object is embedded
* into the containing class, so that the value and unit rows
* can be found on the table itself (e.g. planeInfo.exposureTime
* and planeInfo.exposureTimeUnit).
**/
["protected"] class Time
{

double value;

UnitsTime unit;

/**
* Actual value for this unit-based field. The interpretation of
* the value is only possible along with the [omero::model::UnitsTime]
* enum.
**/
double getValue();

void setValue(double time);

/**
* [omero::model::UnitsTime] instance which is an [omero::model::IObject]
* meaning that its ID is sufficient for identying equality.
**/
UnitsTime getUnit();

void setUnit(UnitsTime unit);

Time copy();

};
};
};
#endif
28 changes: 27 additions & 1 deletion components/blitz/resources/templates/combined.vm
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,31 @@ DECLARATION BLOCK:
[$ice] module enums {
#foreach($prop in $type.properties)
#if($prop.class.name == "ome.dsl.EntryField")
[$ice] const string ${Pojo}${prop.name.replaceAll("[^a-zA-Z0-9]","")} = "${prop.name}";
### HACK: the enum
### bf/components/xsd-fu/xsd-fu: def enum_value_name()
#set($enumSymbol = ${prop.name.replaceAll("[^a-zA-Z0-9]","")})
#if($Pojo.startsWith("Units"))
#set($enumSymbol1 = ${enumSymbol.substring(1)})
#if($prop.name.startsWith("M"))
#set($enumSymbol = "mega${enumSymbol1}")
#elseif($prop.name.startsWith("G"))
#set($enumSymbol = "giga${enumSymbol1}")
#elseif($prop.name.startsWith("P"))
#set($enumSymbol = "peta${enumSymbol1}")
#elseif($prop.name.startsWith("E"))
#set($enumSymbol = "exa${enumSymbol1}")
#elseif($prop.name.startsWith("Z"))
#set($enumSymbol = "zetta${enumSymbol1}")
#elseif($prop.name.startsWith("Y"))
#set($enumSymbol = "yotta${enumSymbol1}")
#elseif($prop.name.startsWith("T") && !$prop.name.startsWith("o"))
#set($enumSymbol = "tera${enumSymbol1}")
#elseif($prop.name.codePointAt(0) > 128) ## Workaround: startsWith("µ") fails on non-UTF-8 locales
#set($enumSymbol = "micro${enumSymbol1}")
#end
#end
#set($enumName = "${Pojo}${enumSymbol}")
[$ice] const string ${enumName} = "${prop.name}";
#end
#end
[$ice] };
Expand Down Expand Up @@ -601,6 +625,8 @@ and protect later FOREACH blocks with "if (name == 'id' || name == 'details') sk
[$jav] copy.${property.name}Seq.add( item == null ? null : (${property.shortType}) item.proxy() );
[$jav] }
[$jav] }
#elseif($property.type.startsWith("ome.model.units"))
[$jav] copy.${property.name} = ${property.name} == null ? null : (${property.shortType}) ${property.name}.copy();
#elseif($property.type.startsWith("ome") || $property.type.startsWith("IObject"))
[$jav] copy.${property.name} = ${property.name} == null ? null : (${property.shortType}) ${property.name}.proxy();
#else
Expand Down
182 changes: 101 additions & 81 deletions components/blitz/resources/templates/cpp_obj_reg.vm
Original file line number Diff line number Diff line change
@@ -1,81 +1,101 @@
#*
* $Id$
*
* Copyright 2006 University of Dundee. All rights reserved.
* Use is subject to license terms supplied in LICENSE.txt
*
*#
/*
* $$Id$$
*
* Copyright 2006 University of Dundee. All rights reserved.
* Use is subject to license terms supplied in LICENSE.txt
*
*/

//
// ObjectFactory registrar generated by templates/cpp_objs_reg.vm
//

\#include <omero/ObjectFactoryRegistrar.h>
#foreach($type in $types)
#if(!$type.abstract)
\#include <omero/model/${type.shortname}I.h>
#end
#end

namespace omero {
namespace model {

#foreach($type in $types)
#if(!$type.abstract)
#set( $ObjFac = "${type.shortname}ObjectFactory" )
class ${ObjFac} : virtual public Ice::ObjectFactory {
public:
${ObjFac}() : Ice::ObjectFactory() { }

~${ObjFac}() {}

Ice::ObjectPtr create(const std::string& type) {
return new omero::model::${type.shortname}I();
}

void destroy() {}
};
#end
#end

class PermissionsObjectFactory : virtual public Ice::ObjectFactory {
public:
PermissionsObjectFactory() : Ice::ObjectFactory() { }

~PermissionsObjectFactory() {}

Ice::ObjectPtr create(const std::string& type) {
return new omero::model::PermissionsI();
}

void destroy() {}

};

void conditionalAdd(const std::string& name, const Ice::CommunicatorPtr& ic, const Ice::ObjectFactoryPtr& of) {

if (0==ic->findObjectFactory(name)) {
ic->addObjectFactory(of, name);
}

}

void registerObjectFactory(const Ice::CommunicatorPtr ic) {
conditionalAdd("::omero::model::Permissions", ic, new PermissionsObjectFactory());
#foreach($type in $types)
#if(!$type.abstract)
conditionalAdd("::omero::model::${type.shortname}", ic, new ${type.shortname}ObjectFactory());
#end
#end
}

} // End model
} // End omero
#stop
#*
* $Id$
*
* Copyright 2006 University of Dundee. All rights reserved.
* Use is subject to license terms supplied in LICENSE.txt
*
*#
/*
* $$Id$$
*
* Copyright 2006 University of Dundee. All rights reserved.
* Use is subject to license terms supplied in LICENSE.txt
*
*/

//
// ObjectFactory registrar generated by templates/cpp_objs_reg.vm
//

\#include <omero/ObjectFactoryRegistrar.h>
\#include <omero/model/TimeI.h>
#foreach($type in $types)
#if(!$type.abstract)
\#include <omero/model/${type.shortname}I.h>
#end
#end

namespace omero {
namespace model {

#foreach($type in $types)
#if(!$type.abstract)
#set( $ObjFac = "${type.shortname}ObjectFactory" )
class ${ObjFac} : virtual public Ice::ObjectFactory {

public:
${ObjFac}() : Ice::ObjectFactory() { }

~${ObjFac}() {}

Ice::ObjectPtr create(const std::string& /*type*/) {
return new omero::model::${type.shortname}I();
}

void destroy() {}

};
#end
#end

class PermissionsObjectFactory : virtual public Ice::ObjectFactory {

public:
PermissionsObjectFactory() : Ice::ObjectFactory() { }

~PermissionsObjectFactory() {}

Ice::ObjectPtr create(const std::string& /*type*/) {
return new omero::model::PermissionsI();
}

void destroy() {}

};

class TimeObjectFactory : virtual public Ice::ObjectFactory {

public:
TimeObjectFactory() : Ice::ObjectFactory() { }

~TimeObjectFactory() {}

Ice::ObjectPtr create(const std::string& type) {
return new omero::model::TimeI();
}

void destroy() {}

};

void conditionalAdd(const std::string& name, const Ice::CommunicatorPtr& ic, const Ice::ObjectFactoryPtr& of) {

if (0==ic->findObjectFactory(name)) {
ic->addObjectFactory(of, name);
}

}

void registerObjectFactory(const Ice::CommunicatorPtr ic) {
conditionalAdd("::omero::model::Permissions", ic, new PermissionsObjectFactory());
conditionalAdd("::omero::model::Time", ic, new TimeObjectFactory());
#foreach($type in $types)
#if(!$type.abstract)
conditionalAdd("::omero::model::${type.shortname}", ic, new ${type.shortname}ObjectFactory());
#end
#end
}

} // End model
} // End omero
#stop
5 changes: 5 additions & 0 deletions components/blitz/resources/templates/java_ice_map.vm
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ public class IceMap {
_ome2omero.put(ome.model.roi.Rect.class, omero.model.SmartRectI.class);
_ome2omero.put(ome.model.roi.Label.class, omero.model.SmartTextI.class);

// Units
_ome2omero.put(ome.model.units. Time.class, omero.model.TimeI.class);
_omero2ome.put(omero.model.Time.class, ome.model.units.Time.class);
_omero2ome.put(omero.model.TimeI.class, ome.model.units.Time.class);

// Sealing
OMEtoOMERO = Collections.unmodifiableMap(_ome2omero);
OMEROtoOME = Collections.unmodifiableMap(_omero2ome);
Expand Down
3 changes: 3 additions & 0 deletions components/blitz/resources/templates/java_obj_reg.vm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import omero.util.ObjectFactoryRegistry;

import omero.model.DetailsI;
import omero.model.PermissionsI;
import omero.model.TimeI;

import Ice.Communicator;
import Ice.Object;
Expand All @@ -37,6 +38,7 @@ public class ModelObjectFactoryRegistry extends ObjectFactoryRegistry {
// Non-conditional
ic.addObjectFactory(DetailsI.makeFactory(client), DetailsI.ice_staticId());
ic.addObjectFactory(PermissionsI.Factory, PermissionsI.ice_staticId());
ic.addObjectFactory(TimeI.makeFactory(client), TimeI.ice_staticId());

// Conditional
super.setIceCommunicator(ic);
Expand All @@ -48,6 +50,7 @@ public class ModelObjectFactoryRegistry extends ObjectFactoryRegistry {
// Non-conditional
ic.addObjectFactory(DetailsI.Factory, DetailsI.ice_staticId());
ic.addObjectFactory(PermissionsI.Factory, PermissionsI.ice_staticId());
ic.addObjectFactory(TimeI.Factory, TimeI.ice_staticId());

// Conditional
super.setIceCommunicator(ic);
Expand Down
14 changes: 14 additions & 0 deletions components/blitz/resources/templates/py_obj_reg.vm
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,27 @@ class DetailsObjectFactory(Ice.ObjectFactory):
def destroy(self):
pass

class TimeObjectFactory(Ice.ObjectFactory):

from omero_model_TimeI import TimeI

def __init__(self, client = None):
self.client = client

def create(self, type):
return self.TimeI(self.client)

def destroy(self):
pass

def conditionalAdd(name, ic, of):
if not ic.findObjectFactory(name):
ic.addObjectFactory(of, name)

def registerObjectFactory(ic, client = None):
conditionalAdd("::omero::model::Permissions", ic, PermissionsObjectFactory())
conditionalAdd("::omero::model::Details", ic, DetailsObjectFactory(client))
conditionalAdd("::omero::model::Time", ic, TimeObjectFactory(client))
#foreach($type in $types)
#if(!$type.abstract)
conditionalAdd("::omero::model::${type.shortname}", ic, ${type.shortname}ObjectFactory())
Expand Down

0 comments on commit a746e72

Please sign in to comment.