79 return p1.size() < p2.size();
84 const vector<CConvGraph::TPath>& paths,
87 if (paths.size() == 0)
91 size_t count = 0, length;
92 length = paths[0].size();
93 ITERATE(vector<CConvGraph::TPath>, iter, paths) {
94 if ((*iter).size() > length)
104 ITERATE(vector<CConvGraph::TPath>, iter, paths) {
105 if ((*iter).size() > length)
110 if ((*iter).size() == 1) {
111 rel = registered[(*iter).front()];
116 complex->AddRelation(registered[*iter2]);
120 relations.push_back(rel);
122 composite->AddRelation(rel);
128 const string& to_type_in,
147 it = vertices.
find(from_type);
148 size_t from_vertex = (it != vertices.
end()) ?
151 it = vertices.
find(to_type);
152 size_t to_vertex = (it != vertices.
end()) ?
159 vector<CConvGraph::TPath> paths;
161 if (so && (to_type ==
"Object" || to_type ==
"SerialObject")) {
162 graph.
FindPaths(from_vertex, to_vertex, paths);
163 if (paths.size() > 0 && paths[0].size() <= 2)
171 if (from_type == to_type) {
176 graph.
FindPaths(from_vertex, to_vertex, paths);
178 if (paths.size() > 0) {
192 sm_Relations[idxContainer2Object]->GetRelated(scope, obj, related);
193 if (related.size() == 0)
203 if (from_type == to_type) {
208 it = vertices.
find(from_type);
209 from_vertex = (it != vertices.
end()) ?
212 vector<CConvGraph::TPath> paths2;
213 graph.
FindPaths(from_vertex, to_vertex, paths2);
214 ITERATE(vector<CConvGraph::TPath>, iter2, paths2)
218 if (pathSet.
size() == 0)
223 paths.push_back(*it);
226 (*it).insert((*it).begin(), idxContainer2Object);
240 ostream <<
"digraph {" << endl;
243 ostream <<
" \"" << vertices[(*iter)->GetTypeName()]
244 <<
"\" -> \"" << vertices[(*iter)->GetRelatedTypeName()] <<
"\";" << endl;
249 ostream <<
" \"" << (*iter)->GetTypeName()
250 <<
"\" -> \"" << (*iter)->GetRelatedTypeName() <<
"\";" << endl;
253 ostream <<
"}" << endl;
279 const string& to_type,
290 const string& to_type,
292 m_FromType(from_type),
294 m_TypeConverter(typeConverter) {}
298 const CObject& o = m_TypeConverter.GetObject();
299 return typeid(o).name();
311 virtual void Dump(ostream& ostream)
const
313 const CObject& o = m_TypeConverter.GetObject();
314 ostream <<
typeid(o).name() << endl;
324 objects::CScope& scope,
333 related.push_back(
SObject(iter->GetObject()));
338 const string& to_type,
377 const string& to_type_in)
381 return (relations.size() > 0);
394 const string& to_type_in, TObjList& objs,
402 ostr << endl << endl;
406 ostr <<
"Conversion: " << from_type <<
" -- > " << to_type_in << endl <<
"{" << endl;
409 int count = relations.size();
411 ostr <<
"*** Conversion not found ***" << endl;
413 for (
int i = 0;
i < count; ++
i) {
414 relations[
i]->Dump(ostr);
422 if (relations.size() == 0)
426 relations[0]->GetRelated(scope, obj, related,
flags);
430 iter->GetComment()));
437 size_t from_index, to_index;
438 string from_type = (*iter)->GetTypeName();
439 string to_type = (*iter)->GetRelatedTypeName();
442 if (it == vertices.
end()) {
443 from_index = vertices.
size();
444 vertices[from_type] = from_index;
447 from_index = it->second;
449 it = vertices.
find(to_type);
450 if (it == vertices.
end()) {
451 to_index = vertices.
size();
452 vertices[to_type] = to_index;
455 to_index = it->second;
457 graph.
add_edge(from_index, to_index);
464 if ((*iter)->GetName() == name) {
501 const string& type_name,
504 SCacheKey
key(scope, obj, type_name);
510 pair<CConvertCache::TCache::iterator, bool>
void FindPaths(size_t startVertex, size_t endVertex, vector< TPath > &paths) const
size_t add_edge(size_t from, size_t to)
virtual const TObjList & Convert(objects::CScope &scope, const CObject &obj, const CTypeInfo *info, CObjectConverter::TFlags flags=CObjectConverter::eDefault)
CObjectConverter::TObjList TObjList
static const char * m_Name
static void RegisterTypeAlias(const string &real_name, const string &alias)
static TTypeAliases sm_TypeAliases
static void SetDefaultFlags(TFlags flags)
static const CRelation * FindRelationByName(const string &name)
static void Register(CRelation *rel)
static const string & x_NormalizeTypeName(const string &str)
static size_t x_FindRelationByName(const string &name)
static void Convert(objects::CScope &scope, const CObject &obj, const CTypeInfo *info, TObjList &objs, TFlags flags=eDefault)
Convert an object of potentially unknown type to a set of objects of known type.
static void x_BuildGraph(CConvGraph &graph, map< string, size_t > &vertices)
vector< TRelation > TRelationVector
static TFlags sm_DefaultFlags
the default conversion flags
static void DumpDotGraph(ostream &ostream, bool dumpIDs=false)
static TFlags GetDefaultFlags(void)
static bool CanConvert(objects::CScope &scope, const CObject &obj, const CTypeInfo *type_info)
Determine whether an indicated conversion can be performed.
static TRelationVector sm_Relations
static void FindRelations(objects::CScope &scope, const CObject &obj, const string &to_type_in, TRelationVector &relations)
virtual void GetRelated(objects::CScope &scope, const CObject &obj, TObjects &related, TFlags flags=eDefault, ICanceled *cancel=NULL) const
virtual string GetRelatedTypeName() const
virtual string GetDescription() const
virtual void Dump(ostream &ostream) const
virtual string GetTypeName() const
CRelationTypeConverterAdapter()
CConstRef< ITypeConverter > m_TypeConverter
virtual string GetName() const
CRelationTypeConverterAdapter(const string &from_type, const string &to_type, ITypeConverter *typeConverter)
vector< SObject > TObjects
virtual void GetRelated(objects::CScope &scope, const CObject &obj, TObjects &related, TFlags flags=eDefault, ICanceled *cancel=NULL) const =0
virtual string GetName() const =0
Base class for all serializable objects.
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Interface for testing cancellation request in a long lasting operation.
@ eDefault
combined sets of flags
vector< SObject > TObjList
virtual void Convert(objects::CScope &scope, const CObject &obj, TObjList &objs, TFlags flags=eDefault) const =0
container_type::const_iterator const_iterator
container_type::iterator iterator
const_iterator end() const
iterator_bool insert(const value_type &val)
container_type::value_type value_type
const_iterator find(const key_type &key) const
iterator_bool insert(const value_type &val)
std::ofstream out("events_result.xml")
main entry point for tests
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
vector< CRef< CObject > > TObjects
virtual const CTypeInfo * GetThisTypeInfo(void) const =0
TObjectType * GetPointer(void) const THROWS_NONE
Get pointer,.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
IO_PREFIX::ofstream CNcbiOfstream
Portable alias for ofstream.
static int CompareCase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-sensitive compare of a substring with another string.
const string & GetName(void) const
Get name of this type.
#define NCBI_GUIOBJUTILS_EXPORT
constexpr auto sort(_Init &&init)
const struct ncbi::grid::netcache::search::fields::KEY key
Multi-threading – mutexes; rw-locks; semaphore.
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
static void x_BuildRelations(const CObjectConverter::TRelationVector ®istered, const vector< CConvGraph::TPath > &paths, CObjectConverter::TRelationVector &relations)
DEFINE_STATIC_MUTEX(s_ObjCvtMutex)
static bool PCompare(const CConvGraph::TPath &p1, const CConvGraph::TPath &p2)
static const char * str(char *buf, int n)
bool operator()(const SCacheKey &key1, const SCacheKey &key2) const
CConstRef< objects::CScope > m_Scope
CConstRef< CObject > m_Obj
struct SObject provides an interface for defining what is returned from object conversion.
struct SObject provides an interface for defining what is returned from object conversion.