Index: XIOS/trunk/src/object.cpp
===================================================================
--- XIOS/trunk/src/object.cpp	(revision 768)
+++ XIOS/trunk/src/object.cpp	(revision 769)
@@ -3,64 +3,75 @@
 namespace xios
 {
-   /// ////////////////////// DÃ©finitions ////////////////////// ///
+  /// ////////////////////// DÃ©finitions ////////////////////// ///
 
-   CObject::CObject(void)
-      : id(), IdDefined(false)
-   { /* Ne rien faire de plus */ }
+  CObject::CObject(void)
+    : id(), idDefined(false), idAutoGenerated(false)
+  { /* Ne rien faire de plus */ }
 
-   CObject::CObject(const StdString & id)
-      : id(id), IdDefined(true)
-   { /* Ne rien faire de plus */ }
+  CObject::CObject(const StdString& id, bool idAutoGenerated /*= false*/)
+    : id(id)
+    , idDefined(true)
+    , idAutoGenerated(idAutoGenerated)
+  { /* Ne rien faire de plus */ }
 
-   CObject::CObject(const CObject & object)
-      : id(object.id), IdDefined(object.IdDefined)
-   { /* Ne rien faire de plus */ }
+  CObject::CObject(const CObject& object)
+    : id(object.id)
+    , idDefined(object.idDefined)
+    , idAutoGenerated(object.idAutoGenerated)
+  { /* Ne rien faire de plus */ }
 
-   CObject::~CObject(void)
-   { /* Ne rien faire de plus */ }
+  CObject::~CObject(void)
+  { /* Ne rien faire de plus */ }
 
-   const StdString & CObject::getId(void) const
-   {
-      return (this->id);
-   }
+  const StdString& CObject::getId(void) const
+  {
+    return this->id;
+  }
 
-   const StdString& CObject::getIdServer()
-   {
-      return (this->id);
-   }
+  const StdString& CObject::getIdServer() const
+  {
+    return this->id;
+  }
 
-   bool CObject::hasId(void) const
-   {
-      return (this->IdDefined);
-   }
+  bool CObject::hasId(void) const
+  {
+    return this->idDefined;
+  }
 
-   void CObject::resetId(void)
-   {
-      this->IdDefined = false ;
-   }
+  bool CObject::hasAutoGeneratedId(void) const
+  {
+    return this->idAutoGenerated;
+  }
 
-   void CObject::setId(const StdString & id)
-   {
-      this->id = id ;
-      this->IdDefined = true ;
-   }
-/*
-   bool CObject::operator==(const CObject & other) const
-   {
-      if(!this->hasId() || !other.hasId())
-         return (false);
-      return (this->id.compare(other.id) == 0);
-   }
+  void CObject::resetId(void)
+  {
+    this->idDefined = false;
+  }
 
-   bool CObject::operator!=(const CObject & other) const
-   {
-      return (!(*this == other));
-   }
-*/
-   StdOStream & operator << (StdOStream & os, const CObject & object)
-   {
-      os << object.toString();
-      return (os);
-   }
+  void CObject::setId(const StdString& id, bool idAutoGenerated /*= false*/)
+  {
+    this->id = id;
+    this->idDefined = true;
+    this->idAutoGenerated = false;
+  }
 
+  /*
+  bool CObject::operator==(const CObject& other) const
+  {
+    if(!this->hasId() || !other.hasId())
+    return false;
+    return this->id.compare(other.id) == 0;
+  }
+
+  bool CObject::operator!=(const CObject& other) const
+  {
+    return !(*this == other);
+  }
+  */
+
+  StdOStream& operator<<(StdOStream& os, const CObject& object)
+  {
+    os << object.toString();
+    return os;
+  }
 } // namespace xios
Index: XIOS/trunk/src/object.hpp
===================================================================
--- XIOS/trunk/src/object.hpp	(revision 768)
+++ XIOS/trunk/src/object.hpp	(revision 769)
@@ -7,54 +7,50 @@
 namespace xios
 {
-   /// ////////////////////// DÃ©clarations ////////////////////// ///
+  /// ////////////////////// DÃ©clarations ////////////////////// ///
 
-   class CObject
-   {
-      public :
+  class CObject
+  {
+    public:
+      /// Destructeur ///
+      virtual ~CObject(void);
 
-         /// Destructeur ///
-         virtual ~CObject(void);
+      /// Accesseurs ///
+      const StdString& getId(void) const;
 
-         /// Accesseurs ///
-         const StdString & getId(void) const;
+      virtual const StdString& getIdServer() const;
 
-         virtual const StdString& getIdServer();
+      /// Mutateurs ///
+      void resetId(void);
+      void setId(const StdString& id, bool idAutoGenerated = false);
 
-         /// Mutateurs ///
-         void resetId(void);
-         void setId(const StdString & id);
+      /// Tests ///
+      bool hasId(void) const;
+      bool hasAutoGeneratedId(void) const;
 
-         /// Tests ///
-         bool hasId(void) const;
+      /// OpÃ©rateurs ///
+      // bool operator==(const CObject& other) const;
+      // bool operator!=(const CObject& other) const;
 
-         /// OpÃ©rateurs ///
-//         bool operator==(const CObject & other) const;
-//         bool operator!=(const CObject & other) const;
+      /// Flux ///
+      friend StdOStream& operator<<(StdOStream& os, const CObject& object);
 
-         /// Flux ///
-         friend StdOStream & operator << (StdOStream & os, const CObject & object);
+      /// Autres ///
+      virtual StdString toString(void) const = 0;
+      virtual void fromString(const StdString& str) = 0;
 
-         /// Autres ///
-         virtual StdString toString(void) const = 0;
-         virtual void fromString(const StdString & str) = 0;
+    protected:
+      /// Constructeurs ///
+      CObject(void);
+      explicit CObject(const StdString& id, bool idAutoGenerated = false);
+      CObject(const CObject& object);
+      CObject(const CObject* const object); // Not implemented.
 
-      protected :
-
-         /// Constructeurs ///
-         CObject(void);
-         explicit CObject(const StdString & id);
-         CObject(const CObject & object);
-         CObject(const CObject * const object); // Not implemented.
-
-      private :
-
-         /// PropriÃ©tÃ©s ///
-         StdString id ;    // identifiant de l'Object
-         bool IdDefined ;  // true si l'object est identifiÃ©, false sinon.
-
-   }; // class CObject
-
+    private:
+      /// PropriÃ©tÃ©s ///
+      StdString id;   // identifiant de l'Object
+      bool idDefined; // true si l'object est identifiÃ©, false sinon.
+      bool idAutoGenerated; //!< true if and only the id was automatically generated
+  }; // class CObject
 } // namespace xios
 
 #endif // __XIOS_CObject__
-
Index: XIOS/trunk/src/object_factory.hpp
===================================================================
--- XIOS/trunk/src/object_factory.hpp	(revision 768)
+++ XIOS/trunk/src/object_factory.hpp	(revision 769)
@@ -52,5 +52,7 @@
             static  boost::shared_ptr<U> CreateObject(const StdString & id = StdString(""));
 
-         template <typename U> static  StdString GenUId(void) ; 
+         template <typename U> static const StdString& GetUIdBase(void);
+         template <typename U> static StdString GenUId(void);
+         template <typename U> static bool IsGenUId(const StdString& id);
 
       private :
Index: XIOS/trunk/src/object_factory_decl.cpp
===================================================================
--- XIOS/trunk/src/object_factory_decl.cpp	(revision 768)
+++ XIOS/trunk/src/object_factory_decl.cpp	(revision 769)
@@ -5,14 +5,16 @@
 {
 #define macro(U) \
-  template shared_ptr<U> CObjectFactory::GetObject<U>(const StdString & id);  \
-  template shared_ptr<U> CObjectFactory::GetObject<U>(const StdString& context,const StdString & id); \
-  template shared_ptr<U> CObjectFactory::GetObject<U>(const U * const object); \
+  template shared_ptr<U> CObjectFactory::GetObject<U>(const StdString& id);  \
+  template shared_ptr<U> CObjectFactory::GetObject<U>(const StdString& context,const StdString& id); \
+  template shared_ptr<U> CObjectFactory::GetObject<U>(const U* const object); \
   template int CObjectFactory::GetObjectNum<U>(void); \
   template int CObjectFactory::GetObjectIdNum<U>(void); \
-  template const std::vector<shared_ptr<U> >& CObjectFactory::GetObjectVector<U>(const StdString & context ); \
-  template bool CObjectFactory::HasObject<U>(const StdString & id); \
-  template bool CObjectFactory::HasObject<U>(const StdString& context,const StdString & id); \
-  template boost::shared_ptr<U> CObjectFactory::CreateObject<U>(const StdString & id ); \
-  template  StdString CObjectFactory::GenUId<U>(void);
+  template const std::vector<shared_ptr<U> >& CObjectFactory::GetObjectVector<U>(const StdString& context ); \
+  template bool CObjectFactory::HasObject<U>(const StdString& id); \
+  template bool CObjectFactory::HasObject<U>(const StdString& context,const StdString& id); \
+  template boost::shared_ptr<U> CObjectFactory::CreateObject<U>(const StdString& id ); \
+  template const StdString& CObjectFactory::GetUIdBase<U>(void); \
+  template StdString CObjectFactory::GenUId<U>(void); \
+  template bool CObjectFactory::IsGenUId<U>(const StdString& id); \
 
   macro(CField)
Index: XIOS/trunk/src/object_factory_impl.hpp
===================================================================
--- XIOS/trunk/src/object_factory_impl.hpp	(revision 768)
+++ XIOS/trunk/src/object_factory_impl.hpp	(revision 769)
@@ -50,8 +50,8 @@
       std::vector<boost::shared_ptr<U> > & vect =
                      U::AllVectObj[CObjectFactory::CurrContext];
-                     
-      typename std::vector<boost::shared_ptr<U> >::const_iterator 
+
+      typename std::vector<boost::shared_ptr<U> >::const_iterator
          it = vect.begin(), end = vect.end();
-      
+
       for (; it != end; it++)
       {
@@ -60,5 +60,5 @@
             return (ptr);
       }
-      
+
       ERROR("CObjectFactory::GetObject(const U * const object)",
                << "[type = " << U::GetName() << ", adress = " << object << "] "
@@ -91,28 +91,22 @@
 
    template <typename U>
-      boost::shared_ptr<U> CObjectFactory::CreateObject(const StdString & id)
+   boost::shared_ptr<U> CObjectFactory::CreateObject(const StdString& id)
    {
-      if (CurrContext.size() == 0)
-         ERROR("CObjectFactory::CreateObject(const StdString & id)",
+      if (CurrContext.empty())
+         ERROR("CObjectFactory::CreateObject(const StdString& id)",
                << "[ id = " << id << " ] please define current context id !");
-      if (id.size() == 0)
+
+      if (CObjectFactory::HasObject<U>(id))
       {
-         boost::shared_ptr<U> value(new U(CObjectFactory::GenUId<U>()));
-         U::AllVectObj[CObjectFactory::CurrContext].insert
-            (U::AllVectObj[CObjectFactory::CurrContext].end(), value);
-         U::AllMapObj[CObjectFactory::CurrContext].insert(std::make_pair(value->getId(), value));
-         return (value);
-      }
-      else if (CObjectFactory::HasObject<U>(id))
-      {
-         return (CObjectFactory::GetObject<U>(id));
+         return CObjectFactory::GetObject<U>(id);
       }
       else
       {
-         boost::shared_ptr<U> value(new U(id));
-         U::AllVectObj[CObjectFactory::CurrContext].insert
-            (U::AllVectObj[CObjectFactory::CurrContext].end(), value);
-         U::AllMapObj[CObjectFactory::CurrContext].insert(std::make_pair(id, value));
-         return (value);
+         boost::shared_ptr<U> value(new U(id.empty() ? CObjectFactory::GenUId<U>() : id));
+
+         U::AllVectObj[CObjectFactory::CurrContext].insert(U::AllVectObj[CObjectFactory::CurrContext].end(), value);
+         U::AllMapObj[CObjectFactory::CurrContext].insert(std::make_pair(value->getId(), value));
+
+         return value;
       }
    }
@@ -124,29 +118,27 @@
       return (U::AllVectObj[context]);
    }
-   
-   template <typename U> 
-       StdString CObjectFactory::GenUId(void)
-       {
-          long int seed ;
-          
-          xios_map<StdString,long int>::iterator it ;
-          it=U::GenId.find(CObjectFactory::CurrContext);
-          if (it==U::GenId.end())
-          {
-            seed=0 ;
-            U::GenId[CObjectFactory::CurrContext]=seed ;
-          }
-          else
-          {
-            seed=it->second ;
-            seed++ ;
-            it->second=seed ;
-          }
-          
-          StdOStringStream oss ;
-          oss<<"__"<<U::GetName()<<"_undef_id_"<<seed ;
-          return StdString(oss.str()) ;
-        }
-          
+
+   template <typename U>
+   const StdString& CObjectFactory::GetUIdBase(void)
+   {
+      static const StdString base = "__" + U::GetName() + "_undef_id_";
+      return base;
+   }
+
+   template <typename U>
+   StdString CObjectFactory::GenUId(void)
+   {
+      StdOStringStream oss;
+      oss << GetUIdBase<U>() << U::GenId[CObjectFactory::CurrContext]++;
+      return oss.str();
+   }
+
+   template <typename U>
+   bool CObjectFactory::IsGenUId(const StdString& id)
+   {
+      const StdString& base = GetUIdBase<U>();
+      return (id.size() > base.size() && id.compare(0, base.size(), base) == 0);
+   }
+
 } // namespace xios
 
Index: XIOS/trunk/src/object_template_impl.hpp
===================================================================
--- XIOS/trunk/src/object_template_impl.hpp	(revision 768)
+++ XIOS/trunk/src/object_template_impl.hpp	(revision 769)
@@ -42,5 +42,5 @@
       CObjectTemplate<T>::CObjectTemplate(const StdString & id)
          : CAttributeMap()
-         , CObject(id)
+         , CObject(id, CObjectFactory::IsGenUId<T>(id))
    { /* Ne rien faire de plus */ }
 
@@ -52,5 +52,5 @@
    {
       if (object.hasId() && withId)
-         this->setId(object.getId());
+         this->setId(object.getId(), object.hasAutoGeneratedId());
       ERROR("CObjectTemplate<T> construtor 3", << "Not completly implemented yet !");
    }
