diff options
Diffstat (limited to 'cpp')
32 files changed, 587 insertions, 88 deletions
diff --git a/cpp/demo/Freeze/phonebook/.depend b/cpp/demo/Freeze/phonebook/.depend index e5e3b1f1f10..d324140b93b 100644 --- a/cpp/demo/Freeze/phonebook/.depend +++ b/cpp/demo/Freeze/phonebook/.depend @@ -3,7 +3,7 @@ Grammer.o: Grammer.cpp ../../../include/Ice/Ice.h ../../../include/Ice/Communica Scanner.o: Scanner.cpp ../../../include/Ice/Ice.h ../../../include/Ice/Communicator.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ProxyHandle.h ../../../include/Ice/Config.h ../../../include/IceUtil/Config.h ../../../include/Ice/ObjectF.h ../../../include/Ice/Handle.h ../../../include/IceUtil/Handle.h ../../../include/Ice/LocalObjectF.h ../../../include/Ice/Native.h ../../../include/Ice/LocalObject.h ../../../include/IceUtil/Shared.h ../../../include/Ice/LoggerF.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/PicklerF.h ../../../include/Ice/PropertiesF.h ../../../include/Ice/ServantFactoryF.h ../../../include/Ice/ObjectAdapter.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/LocalException.h ../../../include/Ice/Properties.h ../../../include/Ice/Logger.h ../../../include/Ice/ServantFactory.h ../../../include/Ice/Pickler.h ../../../include/Ice/Initialize.h ../../../include/Ice/InstanceF.h Parser.h PhoneBook.h ../../../include/Ice/Proxy.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/EmitterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/Object.h ../../../include/Ice/Outgoing.h ../../../include/Ice/Stream.h ../../../include/Ice/Buffer.h ../../../include/Ice/Incoming.h Grammer.h Parser.o: Parser.cpp ../../../include/Ice/Ice.h ../../../include/Ice/Communicator.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ProxyHandle.h ../../../include/Ice/Config.h ../../../include/IceUtil/Config.h ../../../include/Ice/ObjectF.h ../../../include/Ice/Handle.h ../../../include/IceUtil/Handle.h ../../../include/Ice/LocalObjectF.h ../../../include/Ice/Native.h ../../../include/Ice/LocalObject.h ../../../include/IceUtil/Shared.h ../../../include/Ice/LoggerF.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/PicklerF.h ../../../include/Ice/PropertiesF.h ../../../include/Ice/ServantFactoryF.h ../../../include/Ice/ObjectAdapter.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/LocalException.h ../../../include/Ice/Properties.h ../../../include/Ice/Logger.h ../../../include/Ice/ServantFactory.h ../../../include/Ice/Pickler.h ../../../include/Ice/Initialize.h ../../../include/Ice/InstanceF.h Parser.h PhoneBook.h ../../../include/Ice/Proxy.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/EmitterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/Object.h ../../../include/Ice/Outgoing.h ../../../include/Ice/Stream.h ../../../include/Ice/Buffer.h ../../../include/Ice/Incoming.h Client.o: Client.cpp Parser.h ../../../include/IceUtil/Handle.h ../../../include/IceUtil/Config.h ../../../include/Ice/Ice.h ../../../include/Ice/Communicator.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ProxyHandle.h ../../../include/Ice/Config.h ../../../include/Ice/ObjectF.h ../../../include/Ice/Handle.h ../../../include/Ice/LocalObjectF.h ../../../include/Ice/Native.h ../../../include/Ice/LocalObject.h ../../../include/IceUtil/Shared.h ../../../include/Ice/LoggerF.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/PicklerF.h ../../../include/Ice/PropertiesF.h ../../../include/Ice/ServantFactoryF.h ../../../include/Ice/ObjectAdapter.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/LocalException.h ../../../include/Ice/Properties.h ../../../include/Ice/Logger.h ../../../include/Ice/ServantFactory.h ../../../include/Ice/Pickler.h ../../../include/Ice/Initialize.h ../../../include/Ice/InstanceF.h PhoneBook.h ../../../include/Ice/Proxy.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/EmitterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/Object.h ../../../include/Ice/Outgoing.h ../../../include/Ice/Stream.h ../../../include/Ice/Buffer.h ../../../include/Ice/Incoming.h -PhoneBookI.o: PhoneBookI.cpp PhoneBookI.h ../../../include/Ice/Ice.h ../../../include/Ice/Communicator.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ProxyHandle.h ../../../include/Ice/Config.h ../../../include/IceUtil/Config.h ../../../include/Ice/ObjectF.h ../../../include/Ice/Handle.h ../../../include/IceUtil/Handle.h ../../../include/Ice/LocalObjectF.h ../../../include/Ice/Native.h ../../../include/Ice/LocalObject.h ../../../include/IceUtil/Shared.h ../../../include/Ice/LoggerF.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/PicklerF.h ../../../include/Ice/PropertiesF.h ../../../include/Ice/ServantFactoryF.h ../../../include/Ice/ObjectAdapter.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/LocalException.h ../../../include/Ice/Properties.h ../../../include/Ice/Logger.h ../../../include/Ice/ServantFactory.h ../../../include/Ice/Pickler.h ../../../include/Ice/Initialize.h ../../../include/Ice/InstanceF.h ../../../include/IceUtil/IceUtil.h ../../../include/IceUtil/Functional.h ../../../include/Freeze/Freeze.h ../../../include/Freeze/Initialize.h ../../../include/Freeze/DBF.h ../../../include/Freeze/DB.h PhoneBook.h ../../../include/Ice/Proxy.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/EmitterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/Object.h ../../../include/Ice/Outgoing.h ../../../include/Ice/Stream.h ../../../include/Ice/Buffer.h ../../../include/Ice/Incoming.h Evictor.h -ServantFactory.o: ServantFactory.cpp ServantFactory.h PhoneBookI.h ../../../include/Ice/Ice.h ../../../include/Ice/Communicator.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ProxyHandle.h ../../../include/Ice/Config.h ../../../include/IceUtil/Config.h ../../../include/Ice/ObjectF.h ../../../include/Ice/Handle.h ../../../include/IceUtil/Handle.h ../../../include/Ice/LocalObjectF.h ../../../include/Ice/Native.h ../../../include/Ice/LocalObject.h ../../../include/IceUtil/Shared.h ../../../include/Ice/LoggerF.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/PicklerF.h ../../../include/Ice/PropertiesF.h ../../../include/Ice/ServantFactoryF.h ../../../include/Ice/ObjectAdapter.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/LocalException.h ../../../include/Ice/Properties.h ../../../include/Ice/Logger.h ../../../include/Ice/ServantFactory.h ../../../include/Ice/Pickler.h ../../../include/Ice/Initialize.h ../../../include/Ice/InstanceF.h ../../../include/IceUtil/IceUtil.h ../../../include/IceUtil/Functional.h ../../../include/Freeze/Freeze.h ../../../include/Freeze/Initialize.h ../../../include/Freeze/DBF.h ../../../include/Freeze/DB.h PhoneBook.h ../../../include/Ice/Proxy.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/EmitterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/Object.h ../../../include/Ice/Outgoing.h ../../../include/Ice/Stream.h ../../../include/Ice/Buffer.h ../../../include/Ice/Incoming.h Evictor.h -Evictor.o: Evictor.cpp Evictor.h ../../../include/Ice/Ice.h ../../../include/Ice/Communicator.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ProxyHandle.h ../../../include/Ice/Config.h ../../../include/IceUtil/Config.h ../../../include/Ice/ObjectF.h ../../../include/Ice/Handle.h ../../../include/IceUtil/Handle.h ../../../include/Ice/LocalObjectF.h ../../../include/Ice/Native.h ../../../include/Ice/LocalObject.h ../../../include/IceUtil/Shared.h ../../../include/Ice/LoggerF.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/PicklerF.h ../../../include/Ice/PropertiesF.h ../../../include/Ice/ServantFactoryF.h ../../../include/Ice/ObjectAdapter.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/LocalException.h ../../../include/Ice/Properties.h ../../../include/Ice/Logger.h ../../../include/Ice/ServantFactory.h ../../../include/Ice/Pickler.h ../../../include/Ice/Initialize.h ../../../include/Ice/InstanceF.h ../../../include/Freeze/Freeze.h ../../../include/Freeze/Initialize.h ../../../include/Freeze/DBF.h ../../../include/Freeze/DB.h PhoneBookI.h ../../../include/IceUtil/IceUtil.h ../../../include/IceUtil/Functional.h PhoneBook.h ../../../include/Ice/Proxy.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/EmitterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/Object.h ../../../include/Ice/Outgoing.h ../../../include/Ice/Stream.h ../../../include/Ice/Buffer.h ../../../include/Ice/Incoming.h -Server.o: Server.cpp Evictor.h ../../../include/Ice/Ice.h ../../../include/Ice/Communicator.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ProxyHandle.h ../../../include/Ice/Config.h ../../../include/IceUtil/Config.h ../../../include/Ice/ObjectF.h ../../../include/Ice/Handle.h ../../../include/IceUtil/Handle.h ../../../include/Ice/LocalObjectF.h ../../../include/Ice/Native.h ../../../include/Ice/LocalObject.h ../../../include/IceUtil/Shared.h ../../../include/Ice/LoggerF.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/PicklerF.h ../../../include/Ice/PropertiesF.h ../../../include/Ice/ServantFactoryF.h ../../../include/Ice/ObjectAdapter.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/LocalException.h ../../../include/Ice/Properties.h ../../../include/Ice/Logger.h ../../../include/Ice/ServantFactory.h ../../../include/Ice/Pickler.h ../../../include/Ice/Initialize.h ../../../include/Ice/InstanceF.h ../../../include/Freeze/Freeze.h ../../../include/Freeze/Initialize.h ../../../include/Freeze/DBF.h ../../../include/Freeze/DB.h ServantFactory.h PhoneBookI.h ../../../include/IceUtil/IceUtil.h ../../../include/IceUtil/Functional.h PhoneBook.h ../../../include/Ice/Proxy.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/EmitterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/Object.h ../../../include/Ice/Outgoing.h ../../../include/Ice/Stream.h ../../../include/Ice/Buffer.h ../../../include/Ice/Incoming.h +PhoneBookI.o: PhoneBookI.cpp PhoneBookI.h ../../../include/Ice/Ice.h ../../../include/Ice/Communicator.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ProxyHandle.h ../../../include/Ice/Config.h ../../../include/IceUtil/Config.h ../../../include/Ice/ObjectF.h ../../../include/Ice/Handle.h ../../../include/IceUtil/Handle.h ../../../include/Ice/LocalObjectF.h ../../../include/Ice/Native.h ../../../include/Ice/LocalObject.h ../../../include/IceUtil/Shared.h ../../../include/Ice/LoggerF.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/PicklerF.h ../../../include/Ice/PropertiesF.h ../../../include/Ice/ServantFactoryF.h ../../../include/Ice/ObjectAdapter.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/LocalException.h ../../../include/Ice/Properties.h ../../../include/Ice/Logger.h ../../../include/Ice/ServantFactory.h ../../../include/Ice/Pickler.h ../../../include/Ice/Initialize.h ../../../include/Ice/InstanceF.h ../../../include/IceUtil/IceUtil.h ../../../include/IceUtil/Functional.h ../../../include/Freeze/Freeze.h ../../../include/Freeze/Initialize.h ../../../include/Freeze/DBF.h ../../../include/Freeze/DB.h ../../../include/Freeze/EvictorF.h ../../../include/Freeze/Evictor.h PhoneBook.h ../../../include/Ice/Proxy.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/EmitterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/Object.h ../../../include/Ice/Outgoing.h ../../../include/Ice/Stream.h ../../../include/Ice/Buffer.h ../../../include/Ice/Incoming.h Evictor.h +ServantFactory.o: ServantFactory.cpp ServantFactory.h PhoneBookI.h ../../../include/Ice/Ice.h ../../../include/Ice/Communicator.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ProxyHandle.h ../../../include/Ice/Config.h ../../../include/IceUtil/Config.h ../../../include/Ice/ObjectF.h ../../../include/Ice/Handle.h ../../../include/IceUtil/Handle.h ../../../include/Ice/LocalObjectF.h ../../../include/Ice/Native.h ../../../include/Ice/LocalObject.h ../../../include/IceUtil/Shared.h ../../../include/Ice/LoggerF.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/PicklerF.h ../../../include/Ice/PropertiesF.h ../../../include/Ice/ServantFactoryF.h ../../../include/Ice/ObjectAdapter.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/LocalException.h ../../../include/Ice/Properties.h ../../../include/Ice/Logger.h ../../../include/Ice/ServantFactory.h ../../../include/Ice/Pickler.h ../../../include/Ice/Initialize.h ../../../include/Ice/InstanceF.h ../../../include/IceUtil/IceUtil.h ../../../include/IceUtil/Functional.h ../../../include/Freeze/Freeze.h ../../../include/Freeze/Initialize.h ../../../include/Freeze/DBF.h ../../../include/Freeze/DB.h ../../../include/Freeze/EvictorF.h ../../../include/Freeze/Evictor.h PhoneBook.h ../../../include/Ice/Proxy.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/EmitterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/Object.h ../../../include/Ice/Outgoing.h ../../../include/Ice/Stream.h ../../../include/Ice/Buffer.h ../../../include/Ice/Incoming.h Evictor.h +Evictor.o: Evictor.cpp Evictor.h ../../../include/Ice/Ice.h ../../../include/Ice/Communicator.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ProxyHandle.h ../../../include/Ice/Config.h ../../../include/IceUtil/Config.h ../../../include/Ice/ObjectF.h ../../../include/Ice/Handle.h ../../../include/IceUtil/Handle.h ../../../include/Ice/LocalObjectF.h ../../../include/Ice/Native.h ../../../include/Ice/LocalObject.h ../../../include/IceUtil/Shared.h ../../../include/Ice/LoggerF.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/PicklerF.h ../../../include/Ice/PropertiesF.h ../../../include/Ice/ServantFactoryF.h ../../../include/Ice/ObjectAdapter.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/LocalException.h ../../../include/Ice/Properties.h ../../../include/Ice/Logger.h ../../../include/Ice/ServantFactory.h ../../../include/Ice/Pickler.h ../../../include/Ice/Initialize.h ../../../include/Ice/InstanceF.h ../../../include/Freeze/Freeze.h ../../../include/Freeze/Initialize.h ../../../include/Freeze/DBF.h ../../../include/Freeze/DB.h ../../../include/Freeze/EvictorF.h ../../../include/Freeze/Evictor.h PhoneBookI.h ../../../include/IceUtil/IceUtil.h ../../../include/IceUtil/Functional.h PhoneBook.h ../../../include/Ice/Proxy.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/EmitterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/Object.h ../../../include/Ice/Outgoing.h ../../../include/Ice/Stream.h ../../../include/Ice/Buffer.h ../../../include/Ice/Incoming.h +Server.o: Server.cpp Evictor.h ../../../include/Ice/Ice.h ../../../include/Ice/Communicator.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ProxyHandle.h ../../../include/Ice/Config.h ../../../include/IceUtil/Config.h ../../../include/Ice/ObjectF.h ../../../include/Ice/Handle.h ../../../include/IceUtil/Handle.h ../../../include/Ice/LocalObjectF.h ../../../include/Ice/Native.h ../../../include/Ice/LocalObject.h ../../../include/IceUtil/Shared.h ../../../include/Ice/LoggerF.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/PicklerF.h ../../../include/Ice/PropertiesF.h ../../../include/Ice/ServantFactoryF.h ../../../include/Ice/ObjectAdapter.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/LocalException.h ../../../include/Ice/Properties.h ../../../include/Ice/Logger.h ../../../include/Ice/ServantFactory.h ../../../include/Ice/Pickler.h ../../../include/Ice/Initialize.h ../../../include/Ice/InstanceF.h ../../../include/Freeze/Freeze.h ../../../include/Freeze/Initialize.h ../../../include/Freeze/DBF.h ../../../include/Freeze/DB.h ../../../include/Freeze/EvictorF.h ../../../include/Freeze/Evictor.h ServantFactory.h PhoneBookI.h ../../../include/IceUtil/IceUtil.h ../../../include/IceUtil/Functional.h PhoneBook.h ../../../include/Ice/Proxy.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/EmitterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/Object.h ../../../include/Ice/Outgoing.h ../../../include/Ice/Stream.h ../../../include/Ice/Buffer.h ../../../include/Ice/Incoming.h diff --git a/cpp/demo/Freeze/phonebook/Parser.cpp b/cpp/demo/Freeze/phonebook/Parser.cpp index 929b97bf3a2..05d581d5d79 100644 --- a/cpp/demo/Freeze/phonebook/Parser.cpp +++ b/cpp/demo/Freeze/phonebook/Parser.cpp @@ -446,7 +446,7 @@ Parser::parse(FILE* file, bool debug) yyin = file; assert(yyin); - _currentFile = "<standard input>"; + _currentFile.clear(); _currentLine = 0; _continue = false; nextLine(); diff --git a/cpp/doc/Makefile b/cpp/doc/Makefile index 2f63c4f482c..e99d1a4e723 100644 --- a/cpp/doc/Makefile +++ b/cpp/doc/Makefile @@ -28,7 +28,8 @@ ICEFILES = ../slice/Ice/Communicator.ice \ ICEPACKFILES = ../slice/IcePack/Admin.ice -FREEZEFILES = ../slice/Freeze/DB.ice +FREEZEFILES = ../slice/Freeze/DB.ice \ + ../slice/Freeze/Evictor.ice include $(top_srcdir)/config/Make.rules diff --git a/cpp/include/Freeze/Freeze.h b/cpp/include/Freeze/Freeze.h index 474c7eb5708..f2c60c93e2b 100644 --- a/cpp/include/Freeze/Freeze.h +++ b/cpp/include/Freeze/Freeze.h @@ -11,8 +11,8 @@ #ifndef FREEZE_FREEZE_H #define FREEZE_FREEZE_H -#include <Ice/Ice.h> #include <Freeze/Initialize.h> #include <Freeze/DB.h> +#include <Freeze/Evictor.h> #endif diff --git a/cpp/include/Freeze/Initialize.h b/cpp/include/Freeze/Initialize.h index f49101ac851..2493ddd8e32 100644 --- a/cpp/include/Freeze/Initialize.h +++ b/cpp/include/Freeze/Initialize.h @@ -11,7 +11,7 @@ #ifndef FREEZE_INITIALIZE_H #define FREEZE_INITIALIZE_H -#include <Ice/CommunicatorF.h> +#include <Ice/Ice.h> #include <Freeze/DBF.h> #ifdef WIN32 diff --git a/cpp/include/Slice/Parser.h b/cpp/include/Slice/Parser.h index a830c084da2..6e418beffd1 100644 --- a/cpp/include/Slice/Parser.h +++ b/cpp/include/Slice/Parser.h @@ -225,6 +225,7 @@ public: std::string scoped(); std::string scope(); std::string comment(); + std::string file(); enum ContainedType { @@ -250,6 +251,7 @@ protected: std::string _name; std::string _scoped; std::string _comment; + std::string _file; }; SLICE_API bool operator<(Contained&, Contained&); @@ -284,6 +286,7 @@ public: EnumList enums(); NativeList natives(); int includeLevel(); + void updateIncludeLevel(); bool hasProxies(); bool hasClassDecls(); bool hasClassDefs(); @@ -587,6 +590,7 @@ public: void setComment(const std::string&); std::string currentComment(); + std::string currentFile(); void nextLine(); void scanPosition(const char*); diff --git a/cpp/slice/Freeze/DB.ice b/cpp/slice/Freeze/DB.ice index f3b070c4429..bb2a5dbede9 100644 --- a/cpp/slice/Freeze/DB.ice +++ b/cpp/slice/Freeze/DB.ice @@ -11,6 +11,8 @@ #ifndef FREEZE_DB_ICE #define FREEZE_DB_ICE +#include <Freeze/EvictorF.ice> + /** * * The Ice module for object persistence. @@ -99,6 +101,17 @@ local interface DB * **/ void close(); + + /** + * + * Create a new Evictor that uses this database. + * + * @return The new Evictor. + * + * @see Evictor + * + **/ + Evictor createEvictor(); }; /** diff --git a/cpp/slice/Freeze/Evictor.ice b/cpp/slice/Freeze/Evictor.ice new file mode 100644 index 00000000000..6f89eb4d3cc --- /dev/null +++ b/cpp/slice/Freeze/Evictor.ice @@ -0,0 +1,69 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#ifndef FREEZE_EVICTOR_ICE +#define FREEZE_EVICTOR_ICE + +#include <Ice/ObjectAdapter.ice> + +module Freeze +{ + +/** + * + * A semi-automatic Ice Object persistence manager, based on the + * evictor pattern. The Evictor is an extended Servant Locator, with + * an implementation in the Freeze module. Instances of this + * implementation can be created with the operation + * <literal>DB::createEvictor</literal>, and must be registered with + * an Object Adapter like other Servant Locators. + * + * @see DB::createEvictor + * @see Ice::ServantLocator + * + **/ +local interface Evictor extends Ice::ServantLocator +{ + /** + * + * Create a new Ice Object for this Evictor. The state of the + * initial Servant passed to this operation is put into this + * Evictor's persistent store. Furthermore, the initial Servant is + * added to the head of the Evictor queue, so that it will be + * evicted last. + * + * @param identity The identity of the Ice Object to create. + * + * @param servant The initial Servant for the Ice Object to + * create. + * + * @see destroyObject + * + **/ + void createObject(string identity, Object servant); + + /** + * + * Permanently destroy an Ice Object by removing it from this + * Evictor's persistent store. Furthermore, if the Evictor + * currently holds a Servant for the Ice Object, such Servant will + * be removed. + * + * @param identity The identity of the Ice Object to destroy. + * + * @see createObject + * + **/ + void destroyObject(string identity); +}; + +}; + +#endif diff --git a/cpp/slice/Freeze/EvictorF.ice b/cpp/slice/Freeze/EvictorF.ice new file mode 100644 index 00000000000..ac941b7eb35 --- /dev/null +++ b/cpp/slice/Freeze/EvictorF.ice @@ -0,0 +1,21 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#ifndef FREEZE_EVICTOR_ICE +#define FREEZE_EVICTOR_ICE + +module Freeze +{ + +local interface Evictor; + +}; + +#endif diff --git a/cpp/slice/Ice/Communicator.ice b/cpp/slice/Ice/Communicator.ice index b80c9dabc7e..53b585f9bd7 100644 --- a/cpp/slice/Ice/Communicator.ice +++ b/cpp/slice/Ice/Communicator.ice @@ -38,7 +38,7 @@ module Ice * @see ServantFactory * **/ -local class Communicator +local interface Communicator { /** * diff --git a/cpp/slice/Ice/CommunicatorF.ice b/cpp/slice/Ice/CommunicatorF.ice index 25874e968f9..0565fa51c95 100644 --- a/cpp/slice/Ice/CommunicatorF.ice +++ b/cpp/slice/Ice/CommunicatorF.ice @@ -14,7 +14,7 @@ module Ice { -local class Communicator; +local interface Communicator; }; diff --git a/cpp/slice/Ice/Logger.ice b/cpp/slice/Ice/Logger.ice index cb1f56a4338..675aac882dc 100644 --- a/cpp/slice/Ice/Logger.ice +++ b/cpp/slice/Ice/Logger.ice @@ -24,7 +24,7 @@ module Ice * @see Communicator::setLogger * **/ -local class Logger +local interface Logger { /** * diff --git a/cpp/slice/Ice/LoggerF.ice b/cpp/slice/Ice/LoggerF.ice index d1329f995d4..654506ee40a 100644 --- a/cpp/slice/Ice/LoggerF.ice +++ b/cpp/slice/Ice/LoggerF.ice @@ -14,7 +14,7 @@ module Ice { -local class Logger; +local interface Logger; }; diff --git a/cpp/slice/Ice/ObjectAdapter.ice b/cpp/slice/Ice/ObjectAdapter.ice index f214b8ae9a8..8811747607e 100644 --- a/cpp/slice/Ice/ObjectAdapter.ice +++ b/cpp/slice/Ice/ObjectAdapter.ice @@ -16,7 +16,7 @@ module Ice { -local class ServantLocator; +local interface ServantLocator; /** * @@ -30,7 +30,7 @@ local class ServantLocator; * @see ServantLocator * **/ -local class ObjectAdapter +local interface ObjectAdapter { /** * @@ -231,7 +231,7 @@ local class ObjectAdapter * @see ObjectAdapter::getServantLocator * **/ -local class ServantLocator +local interface ServantLocator { /** * diff --git a/cpp/slice/Ice/ObjectAdapterF.ice b/cpp/slice/Ice/ObjectAdapterF.ice index 00bda6ea15f..abe5bbc7234 100644 --- a/cpp/slice/Ice/ObjectAdapterF.ice +++ b/cpp/slice/Ice/ObjectAdapterF.ice @@ -14,8 +14,8 @@ module Ice { -local class ServantLocator; -local class ObjectAdapter; +local interface ServantLocator; +local interface ObjectAdapter; }; diff --git a/cpp/slice/Ice/Pickler.ice b/cpp/slice/Ice/Pickler.ice index 334256a7400..609d7e7e1bf 100644 --- a/cpp/slice/Ice/Pickler.ice +++ b/cpp/slice/Ice/Pickler.ice @@ -30,7 +30,7 @@ native OutputStream; * @see Communicator::getPickler * **/ -local class Pickler +local interface Pickler { /** * diff --git a/cpp/slice/Ice/PicklerF.ice b/cpp/slice/Ice/PicklerF.ice index 5ea5c3c8e23..635eb7cb8f7 100644 --- a/cpp/slice/Ice/PicklerF.ice +++ b/cpp/slice/Ice/PicklerF.ice @@ -14,7 +14,7 @@ module Ice { -local class Pickler; +local interface Pickler; }; diff --git a/cpp/slice/Ice/Properties.ice b/cpp/slice/Ice/Properties.ice index c0a52a2191c..a20bffceeec 100644 --- a/cpp/slice/Ice/Properties.ice +++ b/cpp/slice/Ice/Properties.ice @@ -22,7 +22,7 @@ module Ice * <replaceable>application-name</replaceable>[[.<replaceable>category</replaceable>].<replaceable>sub-category</replaceable>].<replaceable>name</replaceable>. * **/ -local class Properties +local interface Properties { /** * diff --git a/cpp/slice/Ice/PropertiesF.ice b/cpp/slice/Ice/PropertiesF.ice index de16ad62f1b..3ebd9a7c059 100644 --- a/cpp/slice/Ice/PropertiesF.ice +++ b/cpp/slice/Ice/PropertiesF.ice @@ -14,7 +14,7 @@ module Ice { -local class Properties; +local interface Properties; }; diff --git a/cpp/slice/Ice/ServantFactory.ice b/cpp/slice/Ice/ServantFactory.ice index a413032ed12..1850dccf21f 100644 --- a/cpp/slice/Ice/ServantFactory.ice +++ b/cpp/slice/Ice/ServantFactory.ice @@ -26,14 +26,14 @@ module Ice * @see Pickler * **/ -local class ServantFactory +local interface ServantFactory { /** * * Create a new Servant for a given Servant type. The type is the * absolute Slice type name, i.e., the the name relative to the * unnamed top-level Slice module. For example, the absolute Slice - * type name for Servants for classes of type + * type name for Servants for interfacees of type * <literal>Bar</literal> in the module <literal>Foo</literal> is * <literal>::Foo::Bar</literal>. * diff --git a/cpp/slice/Ice/ServantFactoryF.ice b/cpp/slice/Ice/ServantFactoryF.ice index e22d6afaf09..cde7ba6eb94 100644 --- a/cpp/slice/Ice/ServantFactoryF.ice +++ b/cpp/slice/Ice/ServantFactoryF.ice @@ -14,7 +14,7 @@ module Ice { -local class ServantFactory; +local interface ServantFactory; }; diff --git a/cpp/src/Freeze/.depend b/cpp/src/Freeze/.depend index fd17057271f..3391e6fe15d 100644 --- a/cpp/src/Freeze/.depend +++ b/cpp/src/Freeze/.depend @@ -1,2 +1,4 @@ -DB.o: DB.cpp ../../include/Freeze/DB.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/Config.h ../../include/IceUtil/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Native.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/Stream.h ../../include/Ice/InstanceF.h ../../include/Ice/Buffer.h -DBI.o: DBI.cpp ../Freeze/DBI.h ../../include/IceUtil/IceUtil.h ../../include/IceUtil/Functional.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Config.h ../../include/IceUtil/Shared.h ../../include/Ice/Ice.h ../../include/Ice/Communicator.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Native.h ../../include/Ice/LocalObject.h ../../include/Ice/LoggerF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/PicklerF.h ../../include/Ice/PropertiesF.h ../../include/Ice/ServantFactoryF.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/CommunicatorF.h ../../include/Ice/LocalException.h ../../include/Ice/Properties.h ../../include/Ice/Logger.h ../../include/Ice/ServantFactory.h ../../include/Ice/Pickler.h ../../include/Ice/Initialize.h ../../include/Ice/InstanceF.h ../../include/Freeze/Initialize.h ../../include/Freeze/DBF.h ../../include/Freeze/DB.h ../../include/Ice/Stream.h ../../include/Ice/Buffer.h +DB.o: DB.cpp ../../include/Freeze/DB.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/Config.h ../../include/IceUtil/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Native.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Freeze/EvictorF.h ../../include/Ice/Stream.h ../../include/Ice/InstanceF.h ../../include/Ice/Buffer.h +DBI.o: DBI.cpp ../../include/Ice/Stream.h ../../include/Ice/InstanceF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/Buffer.h ../Freeze/DBI.h ../../include/IceUtil/IceUtil.h ../../include/IceUtil/Functional.h ../../include/IceUtil/Shared.h ../../include/Ice/Ice.h ../../include/Ice/Communicator.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Native.h ../../include/Ice/LocalObject.h ../../include/Ice/LoggerF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/PicklerF.h ../../include/Ice/PropertiesF.h ../../include/Ice/ServantFactoryF.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/CommunicatorF.h ../../include/Ice/LocalException.h ../../include/Ice/Properties.h ../../include/Ice/Logger.h ../../include/Ice/ServantFactory.h ../../include/Ice/Pickler.h ../../include/Ice/Initialize.h ../../include/Freeze/DB.h ../../include/Freeze/EvictorF.h ../Freeze/EvictorI.h ../../include/Freeze/Evictor.h ../../include/Freeze/Initialize.h ../../include/Freeze/DBF.h +Evictor.o: Evictor.cpp ../../include/Freeze/Evictor.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/Config.h ../../include/IceUtil/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Native.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/CommunicatorF.h ../../include/Ice/Stream.h ../../include/Ice/InstanceF.h ../../include/Ice/Buffer.h +EvictorI.o: EvictorI.cpp ../Freeze/EvictorI.h ../../include/IceUtil/IceUtil.h ../../include/IceUtil/Functional.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Config.h ../../include/IceUtil/Shared.h ../../include/Ice/Ice.h ../../include/Ice/Communicator.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Native.h ../../include/Ice/LocalObject.h ../../include/Ice/LoggerF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/PicklerF.h ../../include/Ice/PropertiesF.h ../../include/Ice/ServantFactoryF.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/CommunicatorF.h ../../include/Ice/LocalException.h ../../include/Ice/Properties.h ../../include/Ice/Logger.h ../../include/Ice/ServantFactory.h ../../include/Ice/Pickler.h ../../include/Ice/Initialize.h ../../include/Ice/InstanceF.h ../../include/Freeze/DB.h ../../include/Freeze/EvictorF.h ../../include/Freeze/Evictor.h diff --git a/cpp/src/Freeze/DBI.cpp b/cpp/src/Freeze/DBI.cpp index e2f941961ad..6a47191d8cb 100644 --- a/cpp/src/Freeze/DBI.cpp +++ b/cpp/src/Freeze/DBI.cpp @@ -8,8 +8,10 @@ // // ********************************************************************** +#include <Ice/Stream.h> // Not included in Ice/Ice.h #include <Freeze/DBI.h> -#include <Ice/Stream.h> +#include <Freeze/EvictorI.h> +#include <Freeze/Initialize.h> #include <sys/stat.h> #include <sstream> @@ -285,6 +287,24 @@ Freeze::DBI::close() _db = 0; } +EvictorPtr +Freeze::DBI::createEvictor() +{ + JTCSyncT<JTCMutex> sync(*this); + + if(!_db) + { + ostringstream s; + s << "Freeze::DB(\"" << _name << "\"): "; + s << "\"" << _name << "\" has been closed"; + DBException ex; + ex.message = s.str(); + throw ex; + } + + return new EvictorI(this); +} + Freeze::DBEnvI::DBEnvI(const CommunicatorPtr& communicator, const string& directory) : _communicator(communicator), _directory(directory), diff --git a/cpp/src/Freeze/DBI.h b/cpp/src/Freeze/DBI.h index 6959b6f8f87..f0149e6463d 100644 --- a/cpp/src/Freeze/DBI.h +++ b/cpp/src/Freeze/DBI.h @@ -13,7 +13,6 @@ #include <IceUtil/IceUtil.h> #include <Ice/Ice.h> -#include <Freeze/Initialize.h> #include <Freeze/DB.h> #include <db.h> @@ -34,6 +33,7 @@ public: virtual ::Ice::ObjectPtr get(const std::string&); virtual void del(const std::string&); virtual void close(); + virtual EvictorPtr createEvictor(); private: diff --git a/cpp/src/Freeze/EvictorI.cpp b/cpp/src/Freeze/EvictorI.cpp new file mode 100644 index 00000000000..d6cc72b47ed --- /dev/null +++ b/cpp/src/Freeze/EvictorI.cpp @@ -0,0 +1,192 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#include <Freeze/EvictorI.h> +#include <sstream> + +using namespace std; +using namespace Ice; +using namespace Freeze; + +Freeze::EvictorI::EvictorI(const DBPtr& db) : + _db(db), + _evictorSize(static_cast<map<string, EvictorElement>::size_type>(10)) +{ +} + +void +Freeze::EvictorI::createObject(const string& identity, const ObjectPtr& servant) +{ + // + // Save the new Ice Object to the database. + // + _db->put(identity, servant); + + // + // Evict one element, if necessary, to make room for a new + // one. Then add the new Ice Object to the evictor. + // + evict(); + add(identity, servant); +} + +void +Freeze::EvictorI::destroyObject(const string& identity) +{ + // + // Delete the Ice Object from the database. + // + _db->del(identity); + + // + // If the Ice Object is currently in the evictor, remove it. + // + map<string, EvictorElement>::iterator p = _evictorMap.find(identity); + if (p != _evictorMap.end()) + { + _evictorList.erase(p->second.position); + _evictorMap.erase(p); + } +} + +ObjectPtr +Freeze::EvictorI::locate(const ObjectAdapterPtr&, const string& identity, ObjectPtr&) +{ + JTCSyncT<JTCMutex> sync(*this); + + map<string, EvictorElement>::iterator p = _evictorMap.find(identity); + if (p != _evictorMap.end()) + { + // + // Ice Object found in evictor map. Push it to the front of + // the evictor list, so that it will be evicted last. + // + _evictorList.erase(p->second.position); + _evictorList.push_front(identity); + p->second.position = _evictorList.begin(); + + // + // Return the servant for the Ice Object. + // + return p->second.servant; + } + else + { + // + // Evict one element, if necessary, to make room for a new + // one. + // + evict(); + + // + // Find the Ice Object in the database and create a servant + // for it. + // + ObjectPtr servant = _db->get(identity); + if (!servant) + { + // + // Ice object with the given identity does not exist, + // client will get an ObjectNotExistException. + // + return 0; + } + +/* + // + // TODO: That's the only PhoneBook specific stuff! + // + ContactIPtr entry = ContactIPtr::dynamicCast(servant); + assert(entry); + entry->setIdentity(identity); +*/ + + // + // Add the new Ice Object and its Servant + // + add(identity, servant); + + // + // Return the new servant for the Ice Object from the database. + // + return servant; + } +} + +void +Freeze::EvictorI::finished(const ObjectAdapterPtr&, const string&, const ObjectPtr&, const ObjectPtr&) +{ + //JTCSyncT<JTCMutex> sync(*this); +} + +void +Freeze::EvictorI::deactivate() +{ + JTCSyncT<JTCMutex> sync(*this); + + // + // Save all Ice Objects in the database upon deactivation, and + // clear the evictor map and list. + // + for (map<string, EvictorElement>::iterator p = _evictorMap.begin(); p != _evictorMap.end(); ++p) + { + _db->put(*(p->second.position), p->second.servant); + } + _evictorMap.clear(); + _evictorList.clear(); +} + +void +Freeze::EvictorI::evict() +{ + // + // With most STL implementations, _evictorMap.size() is faster + // than _evictorList.size(). + // + if (_evictorMap.size() > _evictorSize) + { + // + // EvictorI size exceeded. Remove last element from the evictor list. + // + string identity = _evictorList.back(); + _evictorList.pop_back(); + + // + // Find corresponding element in the evictor map + // + map<string, EvictorElement>::iterator p = _evictorMap.find(identity); + assert(p != _evictorMap.end()); + + // + // Save the evicted Ice Object to the database. + // + _db->put(identity, p->second.servant); + + // + // Remove the element from the evictor map. + // + _evictorMap.erase(identity); + assert(_evictorMap.size() == _evictorSize); + } +} + +void +Freeze::EvictorI::add(const string& identity, const ObjectPtr& servant) +{ + // + // Add an Ice Object with its Servant to the evictor list and + // evictor map. + // + _evictorList.push_front(identity); + EvictorElement evictorElement; + evictorElement.servant = servant; + evictorElement.position = _evictorList.begin(); + _evictorMap[identity] = evictorElement; +} diff --git a/cpp/src/Freeze/EvictorI.h b/cpp/src/Freeze/EvictorI.h new file mode 100644 index 00000000000..7e4380d4f6a --- /dev/null +++ b/cpp/src/Freeze/EvictorI.h @@ -0,0 +1,59 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#ifndef FREEZE_EVICTOR_I_H +#define FREEZE_EVICTOR_I_H + +#include <IceUtil/IceUtil.h> +#include <Ice/Ice.h> +#include <Freeze/DB.h> +#include <Freeze/Evictor.h> +#include <list> + +namespace Freeze +{ + +class EvictorI; +typedef IceUtil::Handle<EvictorI> EvictorIPtr; + +class EvictorI : public Evictor, public JTCMutex +{ +public: + + EvictorI(const Freeze::DBPtr&); + + virtual void createObject(const std::string&, const Ice::ObjectPtr&); + virtual void destroyObject(const std::string&); + + virtual Ice::ObjectPtr locate(const Ice::ObjectAdapterPtr&, const std::string&, Ice::ObjectPtr&); + virtual void finished(const Ice::ObjectAdapterPtr&, const std::string&, const Ice::ObjectPtr&, + const Ice::ObjectPtr&); + virtual void deactivate(); + +private: + + void evict(); + void add(const std::string&, const Ice::ObjectPtr&); + + Freeze::DBPtr _db; + + struct EvictorElement + { + Ice::ObjectPtr servant; + std::list<std::string>::iterator position; + }; + std::map<std::string, EvictorElement> _evictorMap; + std::list<std::string> _evictorList; + std::map<std::string, EvictorElement>::size_type _evictorSize; +}; + +} + +#endif diff --git a/cpp/src/Freeze/Makefile b/cpp/src/Freeze/Makefile index ab888b45551..fcd6d5527db 100644 --- a/cpp/src/Freeze/Makefile +++ b/cpp/src/Freeze/Makefile @@ -19,7 +19,9 @@ VERSIONED_NAME = $(top_srcdir)/lib/$(VERSIONED_BASE) TARGETS = $(NAME) $(VERSIONED_NAME) OBJS = DB.o \ - DBI.o + DBI.o \ + Evictor.o \ + EvictorI.o SRCS = $(OBJS:.o=.cpp) @@ -57,4 +59,21 @@ $(HDIR)/DBF.h: $(IDIR)/DBF.ice $(SLICE) clean:: rm -f $(HDIR)/DBF.h +$(HDIR)/Evictor.h Evictor.cpp: $(IDIR)/Evictor.ice $(SLICE) + rm -f $(HDIR)/Evictor.h Evictor.cpp + $(SLICECMD) $(IDIR)/Evictor.ice + mv Evictor.h $(HDIR) + +clean:: + rm -f $(HDIR)/Evictor.h Evictor.cpp + +$(HDIR)/EvictorF.h: $(IDIR)/EvictorF.ice $(SLICE) + rm -f $(HDIR)/EvictorF.h EvictorF.cpp + $(SLICECMD) $(IDIR)/EvictorF.ice + mv EvictorF.h $(HDIR) + rm -f EvictorF.cpp + +clean:: + rm -f $(HDIR)/EvictorF.h + include .depend diff --git a/cpp/src/IcePack/Parser.cpp b/cpp/src/IcePack/Parser.cpp index 821ded8ead3..4f174bb1246 100644 --- a/cpp/src/IcePack/Parser.cpp +++ b/cpp/src/IcePack/Parser.cpp @@ -375,7 +375,7 @@ IcePack::Parser::parse(FILE* file, bool debug) yyin = file; assert(yyin); - _currentFile = "<standard input>"; + _currentFile = ""; _currentLine = 0; _continue = false; nextLine(); @@ -404,7 +404,7 @@ IcePack::Parser::parse(const std::string& commands, bool debug) assert(!_commands.empty()); yyin = 0; - _currentFile = "<command line>"; + _currentFile.clear(); _currentLine = 0; _continue = false; nextLine(); diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp index 5e187eca9be..c2580ba2e78 100644 --- a/cpp/src/Slice/Parser.cpp +++ b/cpp/src/Slice/Parser.cpp @@ -11,6 +11,16 @@ #include <IceUtil/Functional.h> #include <Slice/Parser.h> +// +// Stupid Visual C++ defines min and max as macros :-( +// +#ifdef min +# undef min +#endif +#ifdef max +# undef max +#endif + using namespace std; using namespace Slice; @@ -109,6 +119,12 @@ Slice::Contained::comment() return _comment; } +string +Slice::Contained::file() +{ + return _file; +} + Slice::Contained::Contained(const ContainerPtr& container, const string& name) : SyntaxTreeBase(container->unit()), _container(container), @@ -123,6 +139,7 @@ Slice::Contained::Contained(const ContainerPtr& container, const string& name) : assert(_unit); _unit->addContent(this); _comment = _unit->currentComment(); + _file = _unit->currentFile(); } bool @@ -133,13 +150,59 @@ Slice::operator<(Contained& l, Contained& r) return static_cast<int>(l.containedType()) < static_cast<int>(r.containedType()); } - return l.scoped() < r.scoped(); + if(l.scoped() < r.scoped()) + { + return true; + } + else if(l.scoped() != r.scoped()) + { + return false; + } + +/* + if(l.comment() < r.comment()) + { + return true; + } + else if(l.comment() != r.comment()) + { + return false; + } + + if(l.file() < r.file()) + { + return true; + } + else if(l.file() != r.file()) + { + return false; + } +*/ + + return false; } bool Slice::operator==(Contained& l, Contained& r) { - return l.scoped() == r.scoped(); + if(l.scoped() != r.scoped()) + { + return false; + } + +/* + if(l.comment() != r.comment()) + { + return false; + } + + if(l.file() != r.file()) + { + return false; + } +*/ + + return true; } // ---------------------------------------------------------------------- @@ -200,6 +263,7 @@ Slice::Container::createClassDef(const string& name, bool local, bool intf, cons { if (_unit->ignRedefs()) { + def->updateIncludeLevel(); return def; } @@ -463,7 +527,7 @@ Slice::Container::createEnum(const string& name, const StringList& enumerators) } EnumeratorPtr -Slice::Container::createEnumerator(const std::string& name) +Slice::Container::createEnumerator(const string& name) { ContainedList matches = _unit->findContents(thisScope() + name); if (!matches.empty()) @@ -769,6 +833,12 @@ Slice::Container::includeLevel() return _includeLevel; } +void +Slice::Container::updateIncludeLevel() +{ + _includeLevel = min(_includeLevel, _unit->currentIncludeLevel()); +} + bool Slice::Container::hasProxies() { @@ -898,6 +968,8 @@ Slice::Container::mergeModules() mod1->_comment.swap(mod2->_comment); } + mod1->_includeLevel = min(mod1->_includeLevel, mod2->_includeLevel); + _unit->removeContent(*q); q = _contents.erase(q); } @@ -1744,7 +1816,7 @@ Slice::Unit::ignRedefs() } void -Slice::Unit::setComment(const std::string& comment) +Slice::Unit::setComment(const string& comment) { _currentComment = ""; @@ -1762,7 +1834,7 @@ Slice::Unit::setComment(const std::string& comment) } } -std::string +string Slice::Unit::currentComment() { string comment; @@ -1770,6 +1842,12 @@ Slice::Unit::currentComment() return comment; } +string +Slice::Unit::currentFile() +{ + return _currentFile; +} + void Slice::Unit::nextLine() { @@ -1968,8 +2046,8 @@ Slice::Unit::parse(FILE* file, bool debug) _currentComment = ""; _currentLine = 1; _currentIncludeLevel = 0; - _currentFile = "<standard input>"; - _topLevelFile = _currentFile; + _currentFile.clear(); + _topLevelFile.clear(); _includeFiles.clear(); pushContainer(this); diff --git a/cpp/src/slice2docbook/Gen.cpp b/cpp/src/slice2docbook/Gen.cpp index 706950f6080..f14fcc7c63b 100644 --- a/cpp/src/slice2docbook/Gen.cpp +++ b/cpp/src/slice2docbook/Gen.cpp @@ -17,8 +17,7 @@ using namespace Slice; Slice::Gen::Gen(const string& name, const string& file, bool standAlone, bool noGlobals) : _standAlone(standAlone), _noGlobals(noGlobals), - _chapter("section"), // Could also be "chapter" - _nextId(0) + _chapter("section") // Could also be "chapter" { O.open(file.c_str()); if (!O) @@ -26,13 +25,6 @@ Slice::Gen::Gen(const string& name, const string& file, bool standAlone, bool no cerr << name << ": can't open `" << file << "' for writing: " << strerror(errno) << endl; return; } - - _idPrefix = file; - string::size_type pos = _idPrefix.find_last_of("/\\"); - if(pos != string::npos) - { - _idPrefix.erase(0, pos + 1); - } } Slice::Gen::~Gen() @@ -89,7 +81,7 @@ Slice::Gen::visitUnitEnd(const UnitPtr& p) bool Slice::Gen::visitModuleStart(const ModulePtr& p) { - start(_chapter + " id=" + scopedToId(p->scoped()), p->scoped().substr(2)); + start(_chapter + " id=" + containedToId(p), p->scoped().substr(2)); start("section", "Overview"); O.zeroIndent(); O << nl << "<synopsis>module <classname>" << p->name() << "</classname></synopsis>"; @@ -299,7 +291,7 @@ Slice::Gen::visitContainer(const ContainerPtr& p) { TypePtr type = (*q)->type(); - start("section id=" + scopedToId((*q)->scoped()), (*q)->name()); + start("section id=" + containedToId(*q), (*q)->name()); O.zeroIndent(); O << nl << "<synopsis>sequence< " << toString(type, p) << " > <type>" << (*q)->name() @@ -318,7 +310,7 @@ Slice::Gen::visitContainer(const ContainerPtr& p) TypePtr keyType = (*q)->keyType(); TypePtr valueType = (*q)->valueType(); - start("section id=" + scopedToId((*q)->scoped()), (*q)->name()); + start("section id=" + containedToId(*q), (*q)->name()); O.zeroIndent(); O << nl << "<synopsis>dictionary< " << toString(keyType, p) << ", " << toString(valueType, p) @@ -334,7 +326,7 @@ Slice::Gen::visitContainer(const ContainerPtr& p) { for (EnumList::iterator q = enums.begin(); q != enums.end(); ++q) { - start("section id=" + scopedToId((*q)->scoped()), (*q)->name()); + start("section id=" + containedToId(*q), (*q)->name()); O.zeroIndent(); O << nl << "<synopsis>enum <type>" << (*q)->name() << "</type>"; @@ -361,7 +353,7 @@ Slice::Gen::visitContainer(const ContainerPtr& p) { for (NativeList::iterator q = natives.begin(); q != natives.end(); ++q) { - start("section id=" + scopedToId((*q)->scoped()), (*q)->name()); + start("section id=" + containedToId(*q), (*q)->name()); O.zeroIndent(); O << nl << "<synopsis>native <type>" << (*q)->name() << "</type>;</synopsis>"; @@ -379,7 +371,7 @@ Slice::Gen::visitContainer(const ContainerPtr& p) bool Slice::Gen::visitClassDefStart(const ClassDefPtr& p) { - start(_chapter + " id=" + scopedToId(p->scoped()), p->scoped().substr(2)); + start(_chapter + " id=" + containedToId(p), p->scoped().substr(2)); start("section", "Overview"); O.zeroIndent(); @@ -494,7 +486,7 @@ Slice::Gen::visitClassDefStart(const ClassDefPtr& p) TypeStringList outputParams = (*q)->outputParameters(); TypeList throws = (*q)->throws(); - start("section id=" + scopedToId((*q)->scoped()), (*q)->name()); + start("section id=" + containedToId(*q), (*q)->name()); O.zeroIndent(); O << nl << "<synopsis>" << (nonmutating ? "nonmutating " : "") @@ -556,7 +548,7 @@ Slice::Gen::visitClassDefStart(const ClassDefPtr& p) { TypePtr type = (*q)->type(); - start("section id=" + scopedToId((*q)->scoped()), (*q)->name()); + start("section id=" + containedToId(*q), (*q)->name()); O.zeroIndent(); O << nl << "<synopsis>" << toString(type, p) << " <structfield>" << (*q)->name() @@ -577,7 +569,7 @@ Slice::Gen::visitClassDefStart(const ClassDefPtr& p) bool Slice::Gen::visitStructStart(const StructPtr& p) { - start(_chapter + " id=" + scopedToId(p->scoped()), p->scoped().substr(2)); + start(_chapter + " id=" + containedToId(p), p->scoped().substr(2)); start("section", "Overview"); O.zeroIndent(); @@ -618,7 +610,7 @@ Slice::Gen::visitStructStart(const StructPtr& p) { TypePtr type = (*q)->type(); - start("section id=" + scopedToId((*q)->scoped()), (*q)->name()); + start("section id=" + containedToId(*q), (*q)->name()); O.zeroIndent(); O << nl << "<synopsis>" << toString(type, p) << " <structfield>" << (*q)->name() @@ -876,28 +868,44 @@ Slice::Gen::end() } string -Slice::Gen::scopedToId(const string& scoped) +Slice::Gen::containedToId(const ContainedPtr& contained) { - string s; + assert(contained); + + string scoped = contained->scoped(); if (scoped[0] == ':') { - s = scoped.substr(2); + scoped.erase(0, 2); } - else + + string id = "\""; + + id.reserve(scoped.size() + 2); // Also reserve space for the two '"' + + for (unsigned int i = 0; i < scoped.size(); ++i) { - s = scoped; + if (scoped[i] == ':') + { + id.push_back('.'); + ++i; + } + else + { + id.push_back(scoped[i]); + } } - int id = _idMap[s]; - if (id == 0) + // + // TODO: At present, docbook tools limit link names (NAMELEN) to + // 44 characters. + // + if(id.size() > 1 + 44) { - id = ++_nextId; - _idMap[s] = id; + id.erase(1 + 44); } - ostringstream result; - result << '"' << _idPrefix << '.' << id << '"'; - return result.str(); + id.push_back('"'); + return id; } string @@ -926,6 +934,10 @@ Slice::Gen::getScopedMinimized(const ContainedPtr& contained, const ContainerPtr string Slice::Gen::toString(const SyntaxTreeBasePtr& p, const ContainerPtr& container) { + string tag; + string linkend; + string s; + static const char* builtinTable[] = { "byte", @@ -945,48 +957,60 @@ Slice::Gen::toString(const SyntaxTreeBasePtr& p, const ContainerPtr& container) BuiltinPtr builtin = BuiltinPtr::dynamicCast(p); if (builtin) { - return "<type>" + string(builtinTable[builtin->kind()]) + "</type>"; + s = builtinTable[builtin->kind()]; + tag = "type"; } - string tag; - string linkend; - string s; - ProxyPtr proxy = ProxyPtr::dynamicCast(p); if (proxy) { - tag = "classname"; - linkend = scopedToId(proxy->_class()->scoped()); + linkend = containedToId(proxy->_class()); s = getScopedMinimized(proxy->_class(), container); s += "*"; + tag = "classname"; } ClassDeclPtr cl = ClassDeclPtr::dynamicCast(p); if (cl) { - tag = "classname"; - linkend = scopedToId(cl->scoped()); + // + // We must generate the id from the definition, not from the + // declaration, provided that a definition is available. + // + ContainedPtr definition = cl->definition(); + if (definition) + { + linkend = containedToId(definition); + } s = getScopedMinimized(cl, container); + tag = "classname"; } StructPtr st = StructPtr::dynamicCast(p); if (st) { - tag = "structname"; - linkend = scopedToId(st->scoped()); + linkend = containedToId(st); s = getScopedMinimized(st, container); + tag = "structname"; } if (s.empty()) { ContainedPtr contained = ContainedPtr::dynamicCast(p); assert(contained); - tag = "type"; - linkend = scopedToId(contained->scoped()); + linkend = containedToId(contained); s = getScopedMinimized(contained, container); + tag = "type"; } - return "<link linkend=" + linkend + "><" + tag + ">" + s + "</" + tag + "></link>"; + if (linkend.empty()) + { + return "<" + tag + ">" + s + "</" + tag + ">"; + } + else + { + return "<link linkend=" + linkend + "><" + tag + ">" + s + "</" + tag + "></link>"; + } } string diff --git a/cpp/src/slice2docbook/Gen.h b/cpp/src/slice2docbook/Gen.h index c463c199be5..3d005d1f6c7 100644 --- a/cpp/src/slice2docbook/Gen.h +++ b/cpp/src/slice2docbook/Gen.h @@ -46,7 +46,7 @@ private: void start(const std::string&, const std::string&); void end(); - std::string scopedToId(const std::string&); + std::string containedToId(const ContainedPtr&); std::string getScopedMinimized(const ContainedPtr&, const ContainerPtr&); std::string toString(const SyntaxTreeBasePtr&, const ContainerPtr&); std::string toString(const std::string&, const ContainerPtr&); @@ -57,9 +57,6 @@ private: bool _noGlobals; std::string _chapter; std::stack<std::string> _elementStack; - std::string _idPrefix; - std::map<std::string, int> _idMap; - int _nextId; }; } diff --git a/cpp/src/slice2docbook/Main.cpp b/cpp/src/slice2docbook/Main.cpp index 0d5c380049c..ce1a2b7414f 100644 --- a/cpp/src/slice2docbook/Main.cpp +++ b/cpp/src/slice2docbook/Main.cpp @@ -149,7 +149,7 @@ main(int argc, char* argv[]) return EXIT_FAILURE; } - UnitPtr unit = Unit::createUnit(true, true); + UnitPtr unit = Unit::createUnit(true, false); int status = EXIT_SUCCESS; |