0

Contextualization:

I am working on an algorithm of facial recognition and NIST is the organization that is trying to standardize the tests, measurement and comparison among all available algorithms. In order to be tested and compared, I need to implement their interface, which is available in FRVT Project, more specifically at frvt11.h file.

frvt11.h Relevant code for this question:

namespace FRVT {

//...A lot of code defining ReturnStatus, ReturnCode, etc.

/**
* @brief
* The interface to FRVT 1:1 implementation
*
* @details
* The submission software under test will implement this interface by
* sub-classing this class and implementing each method therein.
*/
class Interface {
public:
   virtual ~Interface() {}

   virtual ReturnStatus
    initialize(const std::string &configDir) = 0;

   /**
   * @brief
   * Factory method to return a managed pointer to the Interface object.
   * @details
   * This function is implemented by the submitted library and must return
   * a managed pointer to the Interface object.
   *
   * @note
   * A possible implementation might be:
   * return (std::make_shared<Implementation>());
   */
   static std::shared_ptr<Interface>
   getImplementation();
};
}

implementation.h Relevant code of the implementation I am developing:

#include "frvt11.h"
using namespace FRVT;

struct Implementation : public Interface {

    ReturnStatus
    initialize(const std::string &configDir) override;

    static std::shared_ptr<Interface>
    getImplementation();
};

implementation.cpp Relevant code of the implementation I am developing:

#include "implementation.h"
using namespace FRVT;

ReturnStatus
Implementation::initialize(
    const std::string &configDir) {
        return ReturnStatus(ReturnCode::Success," - initialize");
}

std::shared_ptr<Interface>
Implementation::getImplementation() {
    return (std::make_shared<Implementation>());
}

Finally my question:

Question: How to implement getImplementation() in order to return the referred "managed pointer to the Interface object"?

Carlos Ost
  • 492
  • 7
  • 22

1 Answers1

1

I think you can just do the following:

std::shared_ptr<Interface> Implementation::getImplementation() {
  return std::make_shared<Implementation>();
}

int main() {
    auto interface = Implementation::getImplementation();
}

And interface will be of type std::shared_ptr<Interface>. You can further pass it around.

Yuki
  • 3,857
  • 5
  • 25
  • 43
  • The comments made by NIST, suggests the use of make_shared inside the implementation. Why you recommend to use shared_ptr inside the implementation? Would it be a better approach? – Carlos Ost Jul 04 '18 at 13:21
  • The former is just shorter.)) – Yuki Jul 04 '18 at 13:40