Skip to content

Commit

Permalink
Rename "new_sgserializable" to "create"
Browse files Browse the repository at this point in the history
  • Loading branch information
lisitsyn committed Jul 6, 2017
1 parent 728a9f5 commit 4063204
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/shogun/base/Parameter.cpp
Expand Up @@ -2195,7 +2195,7 @@ TParameter::new_sgserial(CSGObject** param,
if (*param != NULL)
SG_UNREF(*param);

*param = new_sgserializable(sgserializable_name, generic);
*param = create(sgserializable_name, generic);

if (*param == NULL) {
string_t buf = {'\0'};
Expand Down
2 changes: 1 addition & 1 deletion src/shogun/base/SGObject.cpp
Expand Up @@ -727,7 +727,7 @@ bool CSGObject::equals(CSGObject* other, float64_t accuracy, bool tolerant)
CSGObject* CSGObject::clone()
{
SG_DEBUG("Constructing an empty instance of %s\n", get_name());
CSGObject* copy=new_sgserializable(get_name(), this->m_generic);
CSGObject* copy = create(get_name(), this->m_generic);

SG_REF(copy);

Expand Down
11 changes: 5 additions & 6 deletions src/shogun/base/class_list.cpp.templ
Expand Up @@ -44,12 +44,12 @@ REPLACE template_definitions THIS

REPLACE complex_template_definitions THIS

typedef CSGObject* (*new_sgserializable_t)(EPrimitiveType generic);
typedef CSGObject* (*create_function)(EPrimitiveType generic);
#ifndef DOXYGEN_SHOULD_SKIP_THIS
typedef struct
{
const char* m_class_name;
new_sgserializable_t m_new_sgserializable;
create_function m_create_function;
} class_list_entry_t;
#endif

Expand All @@ -58,14 +58,13 @@ REPLACE struct THIS
{NULL, NULL}
};

CSGObject* shogun::new_sgserializable(const char* sgserializable_name,
EPrimitiveType generic)
CSGObject* shogun::create(const char* classname, EPrimitiveType generic)
{
for (class_list_entry_t* i=class_list; i->m_class_name != NULL;
i++)
{
if (strncmp(i->m_class_name, sgserializable_name, STRING_LEN) == 0)
return i->m_new_sgserializable(generic);
if (strncmp(i->m_class_name, classname, STRING_LEN) == 0)
return i->m_create_function(generic);
}

return NULL;
Expand Down
5 changes: 2 additions & 3 deletions src/shogun/base/class_list.h
Expand Up @@ -18,12 +18,11 @@
namespace shogun {
class CSGObject;

/** new shogun serializable
/** new shogun instance
* @param sgserializable_name
* @param generic
*/
CSGObject* new_sgserializable(const char* sgserializable_name,
EPrimitiveType generic);
CSGObject* create(const char* sgserializable_name, EPrimitiveType generic);
}

#endif /* __SG_CLASS_LIST_H__ */
Expand Up @@ -24,7 +24,7 @@ TEST(DynamicObjectArray,array_{{class}}_clone_equals)
index_t length=2;
CDynamicObjectArray* array1=new CDynamicObjectArray();
for (index_t i=0; i<length; ++i)
array1->push_back(new_sgserializable(class_name, PT_NOT_GENERIC));
array1->push_back(create(class_name, PT_NOT_GENERIC));

/* test for clone and equals */
CDynamicObjectArray* array2=dynamic_cast<CDynamicObjectArray*>(array1->clone());
Expand All @@ -50,7 +50,7 @@ TEST(DynamicObjectArray,array_{{class}}_{{type}}_clone_equals)
index_t length=2;
CDynamicObjectArray* array1=new CDynamicObjectArray();
for (index_t i=0; i<length; ++i)
array1->push_back(new_sgserializable(class_name, {{type}}));
array1->push_back(create(class_name, {{type}}));

/* test for clone and equals */
CDynamicObjectArray* array2=dynamic_cast<CDynamicObjectArray*>(array1->clone());
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/base/MockObject.h
Expand Up @@ -30,4 +30,4 @@ class CMockObject : public CSGObject
private:
int32_t m_integer = 0;
};
}
}
8 changes: 4 additions & 4 deletions tests/unit/base/clone_unittest.cc.jinja2
Expand Up @@ -19,14 +19,14 @@ TEST(SGObject,clone_equals_{{class}})
{% endif %}
{
const char* class_name="{{class}}";
CSGObject* object = new_sgserializable(class_name, PT_NOT_GENERIC);
CSGObject* object = create(class_name, PT_NOT_GENERIC);
ASSERT_TRUE(object != NULL);

/* test for get_name() */
ASSERT_TRUE(strcmp(object->get_name(), class_name) == 0);

/* test for .equals() */
CSGObject* object2 = new_sgserializable(class_name, PT_NOT_GENERIC);
CSGObject* object2 = create(class_name, PT_NOT_GENERIC);
ASSERT_TRUE(object2 != NULL);
ASSERT_TRUE(object->equals(object2));
SG_UNREF(object2);
Expand All @@ -52,14 +52,14 @@ TEST(SGObject,clone_equals_{{class}}_{{type}})
{% endif %}
{
const char* class_name="{{class}}";
CSGObject* object = new_sgserializable(class_name, {{type}});
CSGObject* object = create(class_name, {{type}});
ASSERT_TRUE(object != NULL);

/* test for get_name() */
ASSERT_TRUE(strcmp(object->get_name(), class_name) == 0);

/* test for .equals() */
CSGObject* object2 = new_sgserializable(class_name, {{type}});
CSGObject* object2 = create(class_name, {{type}});
ASSERT_TRUE(object2 != NULL);
ASSERT_TRUE(object->equals(object2));
SG_UNREF(object2);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/distribution/MixtureModel_unittest.cc
Expand Up @@ -98,4 +98,4 @@ TEST(MixtureModel,gaussian_mixture_model)
SG_UNREF(mix)
}

#endif /* HAVE_LAPACK */
#endif /* HAVE_LAPACK */
8 changes: 4 additions & 4 deletions tests/unit/io/SerializationAscii_unittest.cc.jinja2
Expand Up @@ -24,7 +24,7 @@ TEST(SerializationAscii, {{class}})
std::string class_name("{{class}}");
std::string filename = "shogun-unittest-serialization-ascii-" + class_name + ".XXXXXX";
generate_temp_filename(const_cast<char*>(filename.c_str()));
CSGObject* object = new_sgserializable(class_name.c_str(), PT_NOT_GENERIC);
CSGObject* object = create(class_name.c_str(), PT_NOT_GENERIC);
ASSERT_TRUE(object != NULL);

// save object to an ascii file
Expand All @@ -36,7 +36,7 @@ TEST(SerializationAscii, {{class}})

// load parameter from an ascii file
file=new CSerializableAsciiFile(filename.c_str(), 'r');
CSGObject* deserializedObject = new_sgserializable(class_name.c_str(), PT_NOT_GENERIC);
CSGObject* deserializedObject = create(class_name.c_str(), PT_NOT_GENERIC);
ASSERT_TRUE(deserializedObject != NULL);
bool load_success = deserializedObject->load_serializable(file);
file->close();
Expand Down Expand Up @@ -66,7 +66,7 @@ TEST(SerializationAscii,{{class}}_{{type}})
std::string class_name("{{class}}");
std::string filename = "/tmp/shogun-unittest-serialization-ascii-" + class_name + "_{{type}}" + ".XXXXXX";
generate_temp_filename(const_cast<char*>(filename.c_str()));
CSGObject* object = new_sgserializable(class_name.c_str(), {{type}});
CSGObject* object = create(class_name.c_str(), {{type}});
ASSERT_TRUE(object != NULL);

// save object to an ascii file
Expand All @@ -78,7 +78,7 @@ TEST(SerializationAscii,{{class}}_{{type}})

// load parameter from an ascii file
file=new CSerializableAsciiFile(filename.c_str(), 'r');
CSGObject* deserializedObject = new_sgserializable(class_name.c_str(), {{type}});
CSGObject* deserializedObject = create(class_name.c_str(), {{type}});
ASSERT_TRUE(deserializedObject != NULL);
bool load_success = deserializedObject->load_serializable(file);
file->close();
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/io/SerializationHDF5_unittest.cc.jinja2
Expand Up @@ -31,7 +31,7 @@ TEST(SerializationHDF5, {{class}})
std::string class_name("{{class}}");
std::string filename = "shogun-unittest-serialization-hdfs-" + class_name + ".XXXXXX";
generate_temp_filename(const_cast<char*>(filename.c_str()));
CSGObject* object = new_sgserializable(class_name.c_str(), PT_NOT_GENERIC);
CSGObject* object = create(class_name.c_str(), PT_NOT_GENERIC);
ASSERT_TRUE(object != NULL);

// save object to an ascii file
Expand All @@ -43,7 +43,7 @@ TEST(SerializationHDF5, {{class}})

// load parameter from an ascii file
file=new CSerializableHdf5File(filename.c_str(), 'r');
CSGObject* deserializedObject = new_sgserializable(class_name.c_str(), PT_NOT_GENERIC);
CSGObject* deserializedObject = create(class_name.c_str(), PT_NOT_GENERIC);
ASSERT_TRUE(deserializedObject != NULL);
bool load_success = deserializedObject->load_serializable(file);
file->close();
Expand Down Expand Up @@ -72,7 +72,7 @@ TEST(SerializationHDF5,{{class}}_{{type}})
std::string class_name("{{class}}");
std::string filename = "shogun-unittest-serialization-hdfs-" + class_name + "_{{type}}" + ".XXXXXX";
generate_temp_filename(const_cast<char*>(filename.c_str()));
CSGObject* object = new_sgserializable(class_name.c_str(), {{type}});
CSGObject* object = create(class_name.c_str(), {{type}});
ASSERT_TRUE(object != NULL);

// save object to an ascii file
Expand All @@ -84,7 +84,7 @@ TEST(SerializationHDF5,{{class}}_{{type}})

// load parameter from an ascii file
file=new CSerializableHdf5File(filename.c_str(), 'r');
CSGObject* deserializedObject = new_sgserializable(class_name.c_str(), {{type}});
CSGObject* deserializedObject = create(class_name.c_str(), {{type}});
ASSERT_TRUE(deserializedObject != NULL);
bool load_success = deserializedObject->load_serializable(file);
file->close();
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/io/SerializationJSON_unittest.cc.jinja2
Expand Up @@ -27,7 +27,7 @@ TEST(SerializationJSON, {{class}})
std::string class_name("{{class}}");
std::string filename = "shogun-unittest-serialization-json-" + class_name + ".XXXXXX";
generate_temp_filename(const_cast<char*>(filename.c_str()));
CSGObject* object = new_sgserializable(class_name.c_str(), PT_NOT_GENERIC);
CSGObject* object = create(class_name.c_str(), PT_NOT_GENERIC);
ASSERT_TRUE(object != NULL);

// save object to an ascii file
Expand All @@ -39,7 +39,7 @@ TEST(SerializationJSON, {{class}})

// load parameter from an ascii file
file=new CSerializableJsonFile(filename.c_str(), 'r');
CSGObject* deserializedObject = new_sgserializable(class_name.c_str(), PT_NOT_GENERIC);
CSGObject* deserializedObject = create(class_name.c_str(), PT_NOT_GENERIC);
ASSERT_TRUE(deserializedObject != NULL);
bool load_success = deserializedObject->load_serializable(file);
file->close();
Expand Down Expand Up @@ -69,7 +69,7 @@ TEST(SerializationJSON,{{class}}_{{type}})
std::string class_name("{{class}}");
std::string filename = "shogun-unittest-serialization-json-" + class_name + "_{{type}}" + ".XXXXXX";
generate_temp_filename(const_cast<char*>(filename.c_str()));
CSGObject* object = new_sgserializable(class_name.c_str(), {{type}});
CSGObject* object = create(class_name.c_str(), {{type}});
ASSERT_TRUE(object != NULL);

// save object to an ascii file
Expand All @@ -81,7 +81,7 @@ TEST(SerializationJSON,{{class}}_{{type}})

// load parameter from an ascii file
file=new CSerializableJsonFile(filename.c_str(), 'r');
CSGObject* deserializedObject = new_sgserializable(class_name.c_str(), {{type}});
CSGObject* deserializedObject = create(class_name.c_str(), {{type}});
ASSERT_TRUE(deserializedObject != NULL);
bool load_success = deserializedObject->load_serializable(file);
file->close();
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/io/SerializationXML_unittest.cc.jinja2
Expand Up @@ -26,7 +26,7 @@ TEST(SerializationXML, {{class}})
std::string class_name("{{class}}");
std::string filename = "shogun-unittest-serialization-xml-" + class_name + ".XXXXXX";
generate_temp_filename(const_cast<char*>(filename.c_str()));
CSGObject* object = new_sgserializable(class_name.c_str(), PT_NOT_GENERIC);
CSGObject* object = create(class_name.c_str(), PT_NOT_GENERIC);
ASSERT_TRUE(object != NULL);

// save object to an ascii file
Expand All @@ -38,7 +38,7 @@ TEST(SerializationXML, {{class}})

// load parameter from an ascii file
file=new CSerializableXmlFile(filename.c_str(), 'r');
CSGObject* deserializedObject = new_sgserializable(class_name.c_str(), PT_NOT_GENERIC);
CSGObject* deserializedObject = create(class_name.c_str(), PT_NOT_GENERIC);
ASSERT_TRUE(deserializedObject != NULL);
bool load_success = deserializedObject->load_serializable(file);
file->close();
Expand Down Expand Up @@ -68,7 +68,7 @@ TEST(SerializationXML,{{class}}_{{type}})
std::string class_name("{{class}}");
std::string filename = "shogun-unittest-serialization-xml-" + class_name + "_{{type}}" + ".XXXXXX";
generate_temp_filename(const_cast<char*>(filename.c_str()));
CSGObject* object = new_sgserializable(class_name.c_str(), {{type}});
CSGObject* object = create(class_name.c_str(), {{type}});
ASSERT_TRUE(object != NULL);

// save object to an ascii file
Expand All @@ -80,7 +80,7 @@ TEST(SerializationXML,{{class}}_{{type}})

// load parameter from an ascii file
file=new CSerializableXmlFile(filename.c_str(), 'r');
CSGObject* deserializedObject = new_sgserializable(class_name.c_str(), {{type}});
CSGObject* deserializedObject = create(class_name.c_str(), {{type}});
ASSERT_TRUE(deserializedObject != NULL);
bool load_success = deserializedObject->load_serializable(file);
file->close();
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/machine/kerneldensity_unittest.cc
Expand Up @@ -195,4 +195,4 @@ TEST(KernelDensity,dual_tree_single_tree_equivalence)
SG_UNREF(testfeats);
SG_UNREF(feats);
SG_UNREF(k);
}
}
2 changes: 1 addition & 1 deletion tests/unit/multiclass/tree/BallTree_unittest.cc
Expand Up @@ -114,4 +114,4 @@ TEST(BallTree, knn_query)
SG_UNREF(qfeats);
SG_UNREF(feats);
SG_UNREF(tree);
}
}
2 changes: 1 addition & 1 deletion tests/unit/multiclass/tree/KDTree_unittest.cc
Expand Up @@ -119,4 +119,4 @@ TEST(KDTree, knn_query)
SG_UNREF(qfeats);
SG_UNREF(feats);
SG_UNREF(tree);
}
}
2 changes: 1 addition & 1 deletion tests/unit/multiclass/tree/KNNHeap_unittest.cc
Expand Up @@ -54,4 +54,4 @@ TEST(KNNHeap, heap_formation)
EXPECT_EQ(sorted[4],5);

delete(heap);
}
}

0 comments on commit 4063204

Please sign in to comment.