Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

vos/metaobjects/text/text.cc

Go to the documentation of this file.
00001 /* $Id: text.cc,v 1.1 2002/10/31 03:28:51 reed Exp $ */
00002 
00003 
00004 
00005 /* This file was generated by otd2cpp.pl, a script for ADR by Reed Hedges <reed@zerohour.net>.
00006    Search for TODO for stuff that needs editing. You will want to especially fill in constructors,
00007    destructors, message handlers, non-property subobjects...
00008 
00009    I can make no garuntee that this code will work, or even that it even is safe to run.
00010    Use it at your own risk.
00011 */
00012 
00013 /** @file text.cc Code: a MetaObject for Text object types. */
00014 
00015 #include "vos/vos.hh"
00016 #include "property/property.hh"
00017 #include "text.hh"
00018 
00019 
00020 /* Constructors */
00021 
00022 Text::Text(MetaObject* s) : MetaObject(s) {
00023 
00024 }
00025 
00026 LocalText::LocalText(MetaObject* s) : Text(s), MetaObject(s) {
00027 
00028 }
00029 
00030 
00031 /* Initialize required subobjects: */
00032 void LocalText::initialize() {
00033 }
00034 
00035 
00036 RemoteText::RemoteText(MetaObject* s) : Text(s), MetaObject(s) {
00037 
00038 }
00039 
00040 
00041 
00042 /* Return type string ("text:text") */
00043 
00044 const string Text::getType() {
00045     return string("text:text");
00046 }
00047 
00048 /* Register extenders with libvos MetaFactory */
00049 void Text::registerExtenders() {
00050     LocalSite::addLocalObjectExtension(typeid(LocalText).name(), &LocalText::new_LocalText);
00051     LocalSite::addLocalObjectExtension(typeid(Text).name(), &LocalText::new_LocalText);
00052     LocalSite::addLocalObjectExtension("text:text", &LocalText::new_LocalText);
00053     RemoteSite::addRemoteObjectExtension(typeid(RemoteText).name(), &RemoteText::new_RemoteText);
00054     RemoteSite::addRemoteObjectExtension(typeid(Text).name(), &RemoteText::new_RemoteText);
00055     RemoteSite::addRemoteObjectExtension("text:text", &RemoteText::new_RemoteText);
00056 }
00057 
00058 
00059 /* Get and set Subproperties and other Subobjects */
00060 
00061 string Text::getText(string lang) {
00062     string s;
00063     rREF(Vobject&, v, findObject("text:"+lang), s = meta_cast<Property&>(v).read(); );
00064     LOG("debug", 0, "Text::getText: returning " << s);
00065     return s;
00066 }
00067 
00068 
00069 string Text::getText() {
00070     return getPrimaryProperty().read();
00071 //    return getText(primaryLanguage());
00072 }
00073 
00074 
00075 string Text::getTextDatatype(string lang) {
00076     string s;
00077     rREF(Vobject&, v, findObject("text:"+lang), s = meta_cast<Property&>(v).getDataType(); );
00078     return s;
00079 }
00080 
00081 string Text::getTextDatatype() {
00082     string s;
00083     rREF(Property&, p, getPrimaryProperty(), s = p.getDataType(); );
00084     return s;
00085 }
00086 
00087 
00088 // build deque of all children starting with the prefix "text:"
00089 deque<string>* Text::listLanguages() {
00090     deque<string>* langs = new deque<string>;
00091     const ChildList& children = getChildren();
00092     ChildList::const_iterator i;
00093     string s;
00094     for(i = children.begin(); i != children.end(); i++) {
00095         s = (*i)->contextual_name;
00096         if( s.substr(0, 5) == "text:" ) {
00097             langs->push_back( s.substr(6) );
00098         }
00099     }
00100     return langs;
00101 }
00102 
00103 
00104 // find first child that starts with the prefix "text:"
00105 // not reference counted!!
00106 Property& Text::getPrimaryProperty() {
00107 
00108     // an alternative implementation method would be to store a pointer to first "text:*" child, updated by a a child change listener.
00109  //   LOG("debug", 0, "getPrimaryProperty: looking through children...");
00110     const ChildList& children = getChildren();
00111     ChildList::const_iterator i;
00112     for(i = children.begin(); i != children.end(); i++) {
00113 //        LOG("debug", 0, "Text::getPrimaryProperty: looking at child named " << (*i)->contextual_name << ". substr(0,5) is " << (*i)->contextual_name.substr(0, 5) );
00114         if( (*i)->contextual_name.substr(0, 5) == "text:" ) {
00115             return meta_cast<Property&>(*((*i)->child));
00116         }
00117     }
00118 
00119     // no "text:" object found.
00120     throw NoSuchObjectError("No \"text:\" objects found.");
00121 }
00122 
00123 Property& Text::getProperty(const string& lang) {
00124     return meta_cast<Property&>(findObject(string("text:") + lang));
00125 }
00126 
00127 string Text::primaryLanguage() {
00128     ParentChildRelation& rel = getPrimaryProperty().findParent(*this);
00129     return rel.contextual_name.substr(6);
00130 }
00131 
00132 
00133 
00134 
00135 
00136 void Text::setText(string lang, const string& value, const string& datatype = "?") {
00137     //TODO: you might want to use different access control on the property
00138     Property::setProperty(*this, "text:"+lang, value, datatype, &NoPropertyAccessControl::static_);
00139 }
00140 
00141 void Text::setText(const string& value, const string& datatype = "?") {
00142     string lang;
00143     try {
00144         lang = primaryLanguage();
00145     } catch(NoSuchObjectError) {
00146         lang = "UND";
00147     }
00148     setText(lang, value, datatype);
00149 }
00150 
00151 
00152 /* Process local object messages */
00153 void LocalText::sendMessage(Message* m) {
00154 
00155 
00156     /* Let superclass have message */
00157     Text::sendMessage(m);
00158 }
00159 
00160 
00161 
00162 
00163 
00164 /* Process remote update messages */
00165 void RemoteText::sendUpdateMessage(Message* m) {
00166 
00167 
00168     /* branch to update message handlers specific to RemoteText */
00169 
00170     /* let superclass have message... */
00171     Text::sendUpdateMessage(m);
00172 }
00173 
00174 /* Generators for factory */
00175 
00176 
00177 MetaObject* LocalText::new_LocalText(MetaObject* s, const string& type) {
00178     LocalText* o = new LocalText(s);
00179     o->initialize();
00180     return o;
00181 }
00182 
00183 MetaObject* RemoteText::new_RemoteText(MetaObject* s, const string& type) {
00184     return new RemoteText(s);
00185 }
00186 

Generated on Tue Aug 12 03:55:46 2003 for Interreality Project - VOS by doxygen 1.3.2